How to get a fjango file instance from pyexcelerate workbook?

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)'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 ?

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


from django.http import HttpResponse

In your Django

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)
return response
Back to Top