On Feb 26, 2013, at 9:44 AM, dalia <dalia....@gmail.com> wrote:
> Retrieving from database - now I want the file to be downloaded as an excel 
> (.xls) file
> 
> def  _get_report(self):
>   tbl = model.ReportFiles
>   file = meta.Session.query(tbl).get(id=1)
>   contentstr = file.report_file
>   response.content_type = 'application/vnd.ms-excel; charset=utf-8'
>   response.headers['Content-disposition'] = 'attachment; filename = %s' 
> %file.file_name
>   response.content_length = len(contentstr)
>   print "Length = %s" %len(contentstr)
>   return contentstr
> 
> 
> This downloads the .xls file fine. The print statement prints the file size 
> as 5632. The download dialogue says the file size is 5.5KB. But when I open 
> the file, it says 'file type not in right format'. When I open it in notepad, 
> it is a 0 KB file. When I list the file in the directory, it is a 0KB file.

two things:

1. when you open the file from the filesystem using the Python open() call, in 
preparation for persisting it to the database, make sure you're using binary 
mode, open("myfile.xls", "rb"), because you're on windows.   It's possible the 
files are being stored with modified line endings otherwise.

2. the "notepad" application isn't appropriate for displaying an .xls file.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to