Reputation: 137
This link shows how to do for one column but how can I efficiently do it for all the columns?
I found this documentation page but couldn't figure out the usage of it
Upvotes: 0
Views: 137
Reputation: 6368
Having looked at openpyxl I understand your concerns about efficiency. There's a lot of looping. But this seems to work:
import openpyxl
wb = openpyxl.load_workbook('openpyxl/tests/data/genuine/libreoffice_nrt.xlsx')
sheet = wb.active
column_letters = (col[0].column_letter for col in sheet)
for letter in column_letters:
sheet.column_dimensions[letter].width = 25
Upvotes: 1