[Django]-Django: How do I download .xls file through a django view

3👍

You are trying to send a xlrd.book.Book object, not a file.

You used xlrd to do your things in the workbook, and then saved to a file.

workbook = xlrd.open_workbook(path)
#... do something
workbook.save(path)

Now you send it like any other file:

with open(path, 'rb') as f:
  response = HttpResponse(f.read(), content_type="application/ms-excel")
  response['Content-Disposition'] = 'attachment; filename={}_Report{}'.format(testname, extension)
👤Txema

Leave a comment