How to export Excel from Database in Django 1.7
- Install xlwt
pip install xlwt
Create Database Item
Export Excel in Views
def export_item_list(request): wb=xlwt.Workbook(uncoding="utf-8") sheet=wb.add_sheet("ITEMS") sheet.write(0,0,"code") sheet.write(0,1,"name") row=1 for item in Item.objects.all(): sheet.write(row,0,item.code) sheet.write(row,1,item.name) row=row+1 response=HttpResponse(content_type="application/vnd.ms-excel") response['Content-Description']="attachment;filename=EXCEL_NAME.xls" wb.save(response) return response