export excel with python using xlwt and adjusting width -
this question has answer here:
i have exported list using 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 country in countries: ws1.write(index, 0, country.country_name) ws1.write(index, 1, country.country_id) index +=1
it generate excel file list of countries problem columns of sheet not adjusted data generated. there solution adjust columns ?
there's no built-in way adjust column width data inside using xlwt
.
the question asked here, i'll refer you:
- python xlwt - accessing existing cell content, auto-adjust column width
- python xlwt adjusting column widths
- john machin's answers on topic
basically, should keep track of maximum data length in each column , adjust column width manually based on font size , style.
hope helps.
Comments
Post a Comment