python 接口生成excel提供下载


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM