python 接口生成excel提供下载

时间:2020-01-06 19:02:07   收藏:0   阅读:168

主要使用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

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!