作者:青大柠的小号_247 | 来源:互联网 | 2023-09-13 18:47
项目使用的是
+
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| from django.http import HttpResponse
from openpyxl import Workbook, load_workbook
from openpyxl.writer.excel import save_virtual_workbook
class ExcelTableObj(object):
def __init__(self, file_name=None, write_Only=False):
if file_name:
self.file_name = file_name
self.wb = load_workbook(file_name)
else:
self.wb = Workbook(write_Only=write_only)
self.write_Only= write_only
def fix_save_excel(self, header, sheet_name, data_lists):
ws = self.wb.create_sheet(title=sheet_name)
ws.append(header)
for data in data_lists:
ws.append(data)
# Django view
excel = ExcelTableObj(write_Only=True)
try:
excel.fix_save_excel(title, sheetname, data_lists)
except Exception as e:
import traceback as t; t.print_exc()
logger.error(repr(e))
finally:
respOnse= HttpResponse(save_virtual_workbook(excel.wb),
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-Disposition'] = 'attachment; filename={}'.format(filename) |
因为 excel 文件很大, 所以使用
模式
好像 uwsgi+lxml 会影响 openpyxl excel 文件的生成
请大佬帮忙看看原因, 以及可以优化的点, 非常感谢
感谢之前问题中 @superrichman 大佬的建议
不考虑向作者反馈重现一下?