1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import xlwt
def tool_excel_export(self, request, obj, button):
response = HttpResponse(mimetype="application/ms-excel")
response['Content-Disposition'] = 'attachment; filename=file.xls'
wb = xlwt.Workbook()
ws = wb.add_sheet('Sheetname')
ws.write(0, 0, 'Firstname')
ws.write(0, 1, 'Surname')
ws.write(1, 0, 'Hans')
ws.write(1, 1, 'Muster')
wb.save(response)
return response
|
More like this
- ExcelResponse by Tarken 4 years, 7 months ago
- Generic admin action export selected rows to excel by jordic 1 year, 7 months ago
- Generic admin action export selected rows to excel by aemb87 7 months ago
- UnicodeWriter and UnicodeDictWriter - write unicode strings out to Excel compatible CSV files by simon 4 years, 9 months ago
- Excel Spreadsheet Export by MasonM 4 years, 10 months ago
Comments
IE seems to require that file.xls be "file.xls" Or it will puke saying it can't save the file if your url ends in a slash.
#
The following is also missing:
Finally, the MIME type is wrong, it should be like this:
#