How to set the default row and column height in openpyxl?

Viewed 171

I would like to change the row and column height using Openpyxl. I can change the specific row and height by apply this

import openpyxl
wb = openpyxl.Workbook()
ws = wb.active
ws.row_dimensions[1].height = 10

But I want to change the default height and width of rows and column so that I dont have to apply in each rows and cols.

Is it possible to do this ?

2 Answers

Please take a look at this post:-

https://stackoverflow.com/questions/13197574/openpyxl-adjust-column-width-size

According to this piece of Microsoft docs you can have 1,048,576 rows and 16,384 columns. I searched in openpyxl to find a way to set default column width. Could not find a way, even tho this is possible in excel. I guess the openpyxl does not provide an interface to set this.

You could create a ticket here to request such a feature. However you can also just set the maximum of columns yourself:

for i in range(1, 16384):
    worksheet.column_dimensions[get_column_letter(i)].width = 1.89

I dot his for a gannt diagram. You can do the same thing for the height.

Related