Python: 2.7.11
Django: 1.9
Pandas: 0.17.1
How should I go about creating a potentially large xlsx file download? I\'m creating a xlsx file with panda
Maybe a bit off-topic, but it's worth pointing out that the to_csv
method is generally faster than to_excel
, since excel contains format information of the sheets. If you only have data and not formatting information, consider to_csv
. Microsoft Excel can view and edit csv files with no problem.
One gain by using to_csv
is that to_csv
function can take any file-like object as the first argument, not only a filename string. Since Django response object is file-like, to_csv
function can directly write to it. Some codes in your view function will look like:
df =
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename='
df.to_csv(response, index=False)
return response
Reference: