ExcelResponse doesn't send file correctly

61 Views Asked by At

I'm using django-excel-response 2.0.5 to download Excel sheet using Django.

sheet = [['a', 'b', 'c'], [1, 2, 3], [4, 5, 6], [7, 8, 9]]
response = ExcelResponse(sheet, 'test')
return response

Instead of downloading file, it doesn't open anything and response.data is byte version of file, like PK�����5���� ��GEp,���L�v��>�ݾ��cb�x����Ш=���0����E &o��PK Is there a problem in Django rest settings, or I'm using lib wrong?

I tried to change view class, different response classes, but nothing helped

1

There are 1 best solutions below

0
On

Bytes shown are likely to come from ZIP files.

Office OpenXML format is a ZIP file of several XML files. So by renaming the file as XLSX you should be able to read it.

If you want to get directly XLSX files you should define content disposition and type in your header.