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