我想您是在询问如何使用创建内存中的excel文件
xlsxwriter并通过返回
HttpResponse。这是一个例子:
try: import cStringIO as StringIOexcept importError: import StringIOfrom django.http import HttpResponsefrom xlsxwriter.workbook import Workbookdef your_view(request): # your view logic here # create a 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
希望能有所帮助。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)