Content Disposition
am using xlwt module to create xls file with multiple sheets and i want to display Content disposition with the created file. wbk = xlwt.Workbook(encoding='utf-8') sheet = workb
Solution 1:
Looking at the docs, it seems that you could write out to a StringIO, and then print that out.
import StringIO
output = StringIO.StringIO()
wbk.save(output)
and then use output.getvalue()
.
I have not tested this at all.
Solution 2:
[dis]claimer: I'm the maintainer of xlwt.
Workbook.save(destination)
...
if destination
is an object with a write
method (e.g. obtained by [c]StringIO.StringIO()):
xlwt writes to this but doesn't close it. What you use this for and how you dispose of the object are up to you.
else:
xlwt assumes that destination
is a string which is interpreted as a file path; xlwt attempts to open a file, write to it, and close it.
Solution 3:
Use the response.body
attribute to write the excel file:
wbk.save(response.body)
Solution 4:
in Django you would simply :
response = HttpResponse(my_data, mimetype='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=foo.xls'
wbk.save(response)
Post a Comment for "Content Disposition"