这里介绍两种方式导出成excel:
A方式:会用到xlwt库,请下载安装。
views.py
def output(request):
response = HttpResponse(mimetype='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment;filename=user.xls'
wb = xlwt.Workbook(encoding = 'utf-8')
sheet = wb.add_sheet(u'人员表单')
#1st line
sheet.write(0,0, '姓名')
sheet.write(0,1, '英文名')
sheet.write(0,2, '职位')
sheet.write(0,3, '公司电话')
sheet.write(0,4, '手机')
sheet.write(0,5, 'QQ')
sheet.write(0,6, 'MSN')
sheet.write(0,7, 'Email')
sheet.write(0,8, '办公地点')
sheet.write(0,9, '部门')
row = 1
for usa in employesInfo.objects.all():
sheet.write(row,0, usa.name)
sheet.write(row,1, usa.eName)
sheet.write(row,2, usa.pos