On May 14, 5:16 pm, Bob Dively <[EMAIL PROTECTED]> wrote:
> The file is sent to the browser (Firefox), which understands the
> mimetype correctly and hands the file off to Excel. However, Excel
> says that the file is in an unrecognized format. When I open the file
> with Excel, it's garbled. The text file is a known good file. Any
> ideas?
The problem turned out to be Windows' differentiation between binary
and text files. Once I explicitly opened the file in binary mode,
everything worked fine:
fullpath = os.path.join('C:/', 'text.xls')
handle = file(fullpath, 'rb')
filecontents = handle.read()
handle.close()
response = HttpResponse(filecontents, mimetype='application/
vnd.ms-excel')
response['Content-disposition'] = 'Attachment; filename=extract.xls'
return response
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---