I am using openpylx
to create a spreadsheet and return it in an HttpResponse
object in Django (1.7). Currently, this is working except that the spreadsheet is not downloaded; it is displayed in the browser as a bunch of characters (pic related).
Here is my code:
from openpyxl import Workbook
from openpyxl.writer.excel import save_virtual_workbook
workbook = Workbook()
...
#Create the workbook here
...
filestream = save_virtual_workbook(workbook)
response = HttpResponse(filestream,
content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename="my_sheet.xlsx"'
return response
This code is pretty much identical to several other solutions offered in other questions here on SO. Unfortunately, I can't figure out what the difference is. Maybe Django version?
I know that I am missing someething stupid here. What is it?
EDIT: I know that the issue is not with the spreadsheet itself. If I save the page with the characters as "my_sheet.xlsx", then open it in Excel, all of the proper data is present.