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