import pandas as pd import os import openpyxl import xlwt def Category1_excel ( request ): #saving file category1 =Download . objects . all () file =[] for i in category1 : p = i .column1 s = i .column2 q = i .column3 row =[ p , s , q , e , l ] file . append ( row ) document = pd . DataFrame ( file ) document . to_excel ( 'media/file_downloads/category1.xlsx' ) #downloading file category1 =Download . objects . all () response = HttpResponse ( content_type = 'application/ms-excel' ) response [ 'Content-Disposition' ] = 'attachment; filename="file.xls"' wb = xlwt . Workbook ( encoding = 'utf-8' ) ws = wb . add_sheet ( "sheet1" ) font_style = xlwt . XFStyle () font_style . font . bold = True row_num = 0 ws .write( row_num , 0 , 'PURCHASED GOODS' , font_style ) ws .write( row_n