Python Forum

Full Version: Applying row height to all rows including and after row 7
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Using openpyxl, I cannot figure out how to apply a row height on an existing worksheet unless I do it one row at a time.

This works for a single row:
ws4.row_dimensions[14].height = 25
But I want to set the row height for row 7 and any subsequent rows.

This approach does nothing yet does not throw an error:
for rows in ws4.iter_rows(min_row=7, max_row=None):
    ws4.row_dimensions.height = 25
wb4.save('C:\\folder\\DataplusRows.xlsx')
Any idea how to do this? I can't glean the answer from the openpyxl documentation. And I can't seem to find examples anywhere.
I came up with this to to set the row height to 20. It will not start at row 7 though. It ignores that and sets row height for all the rows from row one to the max_row. Any idea where I am going wrong?

startRow = 7
endRow = ws4.max_row
for i in range(startRow,endRow):
    ws4.row_dimensions[i+1].height=20
Never mind. I can do this with a variety of approaches. The issue is that the file I am trying to set the row height on has something in it keeping the code from working right. It works fine on other files.