I need to provide an excel formatted data from django\'s database to visitors.
The only way I can think of is with these steps:
Since save_virtual_workbook will be obsolete, I used stream insted.
from openpyxl import Workbook
from tempfile import NamedTemporaryFile
def exportToExcel(request):
workbook = Workbook()
...
with NamedTemporaryFile() as tmp:
workbook.save(tmp.name)
tmp.seek(0)
stream = tmp.read()
response = HttpResponse(content=stream, content_type='application/ms-excel', )
response['Content-Disposition'] = f'attachment; filename=ExportedExcel-{datetime.now().strftime("%Y%m%d%H%M")}.xlsx'
return response