Kayra Uckilinc
Kayra Uckilinc

Reputation: 137

How openpyxl can change "all" the sizes of cells?

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

Answers (1)

Chris Wesseling
Chris Wesseling

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

Related Questions