首页 > 其他 > 详细

django使用pandas下载excel文件

时间:2020-02-25 20:01:05      阅读:228      评论:0      收藏:0      [点我收藏+]

最开始是将数据库数据写到本地excel中,再读出来返回给前端,后面发现可以使用BytesIO(),不用再使用本地文件

x_io = BytesIO()
df = pd.DataFrame(list(res[data]))
df.to_excel(x_io, sheet_name=table_name, index=False)
excel_name = table_name + .xlsx
response = HttpResponse()
response[Content-Type] = application/octet-stream
response[Content-Disposition] = attachment;filename="%s" % excel_name
response.write(x_io.getvalue())
return response

 

django使用pandas下载excel文件

原文:https://www.cnblogs.com/shouwangrenjian/p/12363088.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!