xlsxwriter object save http response create download in django?
i think you're asking how create excel file in memory using xlsxwriter
, return via httpresponse
. here's example:
try: import cstringio stringio except importerror: import stringio django.http import httpresponse xlsxwriter.workbook import workbook def your_view(request): # view logic here # create workbook in memory output = stringio.stringio() book = workbook(output) sheet = book.add_worksheet('test') sheet.write(0, 0, 'hello, world!') book.close() # construct response output.seek(0) response = httpresponse(output.read(), mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") response['content-disposition'] = "attachment; filename=test.xlsx" return response
hope helps.
Comments
Post a Comment