Django: openpyxl saving workbook as attachment

后端 未结 3 527
既然无缘
既然无缘 2020-12-31 02:02

Hi I have a quick question. I didn\'t find answer in internet maybe someone of you can help me.

So i want to save workbook as attachment but I don\'t know how lets s

3条回答
  •  臣服心动
    2020-12-31 02:24

    Give it a try:

    from openpyxl.writer.excel import save_virtual_workbook
    ...
    response = HttpResponse(save_virtual_workbook(wb), content_type='application/vnd.ms-excel')
    

    save_virtual_workbook was specially designed for your use case. Here's a docstring:

    """Return an in-memory workbook, suitable for a Django response."""

提交回复
热议问题