2024-04-25 17:59:26 发布
网友
我有一些数据的数据库,我想下载它作为一个excel文件。换句话说,当我点击应用程序上的下载按钮时,如何以编程方式将模型转换为excel文件?在
使用优秀的xlsxwriter库。我用过django的,非常棒 容易的。在
from django.http import HttpResponse import xlsxwriter def returnexcel(): response = HttpResponse(content_type='application/vnd.ms-excel') response['Content-Disposition'] = 'attachment; filename="mymodel.xlsx"' workbook = xlsxwriter.Workbook(response, {'in_memory': True}) # add a worksheet worksheet = workbook.add_worksheet() worksheet.write_... # use xlsxwriter routines to create the worksheet # now write it out workbook.close() return response
http://xlsxwriter.readthedocs.io/index.html
使用优秀的xlsxwriter库。我用过django的,非常棒 容易的。在
http://xlsxwriter.readthedocs.io/index.html
相关问题 更多 >
编程相关推荐