Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python xlsxwriter, set border dynamically

I am using python's xlsxwriter package to format the excel report that I am generating through a mysql query.

The problem is that the report generated by sql the returns the columns dynamically so their is no way of knowing how many column will be returned before hand. I am trying to set border only to the returned number of columns. But so far I am only able to hard code the number of columns(A:DC). Can anyone help me with this, I am using the following query-

worksheet = writer.sheets['Sheet1']
formater = workbook.add_format({'border':1})
worksheet.set_column('A:DC',15,formater)
writer.save()
like image 661
Uasthana Avatar asked Oct 31 '22 08:10

Uasthana


1 Answers

Set the range dynamically based on the length of the data you receive

data = [...]
worksheet.set_column(0, len(data), 15, formater)

set_column() docs for the reference.

like image 54
alecxe Avatar answered Nov 09 '22 22:11

alecxe