export excel with python using xlwt and adjusting width -


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:

basically, should keep track of maximum data length in each column , adjust column width manually based on font size , style.

hope helps.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -