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 ファイルを生成しますが、シートの列が生成されたデータに合わせて調整されていないという問題があります。これらの列を調整する解決策はありますか?