-1

I have recently checked the pyexcelerate to help improve the performace of exporting a pandas data frame to excel file i have the following code

values = [my_df.columns] + list(my_df.values)
wb = Workbook()
wb.new_sheet('outputs', data=values) 
wb.save('outputfile.xlsx') 

I have a django model that has a filefield into it how can i save the generated wb to a django file field ?

petezurich
  • 9,280
  • 9
  • 43
  • 57
Mohamed Ibrahim
  • 195
  • 1
  • 2
  • 8

1 Answers1

0

If you are using Django and pyexcelerate, you can return/download the file with the following:

Import:

from django.http import HttpResponse

In your Django views.py:

excel_filename = "example.xlsx"
response = HttpResponse(content_type='xlsx')
response['Content-Disposition'] = 'attachment;filename=' + excel_filename
workbook = Workbook()        
sheet1 = workbook.new_sheet("data example", data=data)
workbook.save(response)
return response
A. Cloete
  • 69
  • 6