我已经使用 xlwt 导出了我的列表:
response = HttpResponse(mimetype="application/ms-excel")
response['Content-Disposition'] = 'attachment; filename=Countries.xls'
wb = xlwt.Workbook()
ws1 = wb.add_sheet('Countries')
ws1.write(0, 0, 'Country Name')
ws1.write(0, 1, 'Country ID')
countries = Country.objects.all()
index = 1
for country in countries:
ws1.write(index, 0, country.country_name)
ws1.write(index, 1, country.country_id)
index +=1
它会生成一个包含国家/地区列表的 Excel 文件,但问题是工作表的列未根据生成的数据进行调整。有什么解决方案可以调整这些列吗?