首页 > 编程语言 > 详细

python 接口生成excel提供下载

时间:2020-01-06 19:02:07      阅读:168      评论:0      收藏:0      [点我收藏+]

主要使用pandas

from flask import Response
@login_blu.route(/download) def download(): import pandas as pd from io import BytesIO # 内存管理器(excel存入内存) excel = pd.DataFrame(list)#二维数组,对应表头的相应数据 excel.columns = header_list #表头 [xx,xx,xx,xx] file = BytesIO() excel.to_excel(file, index=False) response = Response(content_type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) execl_name = ‘excel下载.xlsx response.headers["Content-disposition"] = attachment; filename=%s % execl_name.encode().decode(latin-1) response.data = file.getvalue() return response

python 接口生成excel提供下载

原文:https://www.cnblogs.com/nixindecat/p/12157563.html

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