使用xlwt和调整宽度使用python导出excel
我已使用xlwt导出我的列表:使用xlwt和调整宽度使用python导出excel,python,excel,xlwt,Python,Excel,Xlwt,我已使用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, 'Co
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文件,但问题是工作表的列没有根据生成的数据进行调整。
有没有调整这些列的解决方案?没有内置的方法可以使用
xlwt
将列宽调整到数据中
这里已经有人问了这个问题,所以我只向您介绍:
- John Machin对该主题的回答
希望这能有所帮助。相关信息:正确的做法是投票关闭(作为副本),但由于您还没有代表,您已经做了下一个最好的选择,即提供一个好的摘要,并提供好的链接以供进一步阅读。值得投一票!(尽管我投了赞成票。)