首页 > 解决方案 > Python,openpyxl:下载多个 excel 表

问题描述

早上好,

在我的应用程序中,我试图下载多个 - id 存储在一个列表中 - excel-sheets 与 openpyxl 一起。对于我使用这种方式的单个文件:

qs = Data.objects.get(id=pk)
df = read_frame(qs)
...
wb = Workbook()
...
ws = wb.get_sheet_by_name('Example')
for row in dataframe_to_rows(df, index=False, header=False):
    ws.append(row)    
...
response = HttpResponse(content=save_virtual_workbook(wb), content_type='application/ms-excel')
response['Content-Disposition'] = f'attachment; filename={file_text}.xlsx'

return response

当然,for 循环中的return会破坏它,但是还有其他方法可以实现这一点吗?

谢谢你,祝你有美好的一天!

标签: pythonfor-loopreturnopenpyxl

解决方案


推荐阅读