Python Forum
Applying row height to all rows including and after row 7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Applying row height to all rows including and after row 7
#1
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.
Reply
#2
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
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function to count words in a list up to and including Sam Oldman45 15 6,341 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  gspread - applying ValueRenderOption to a range of cells dwassner 0 1,651 Jan-12-2022, 03:05 PM
Last Post: dwassner
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,589 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Including data files in a package ChrisOfBristol 4 2,440 Oct-27-2021, 04:14 PM
Last Post: ChrisOfBristol
  Not including a constructor __init__ in the class definition... bytecrunch 3 11,353 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,067 May-04-2021, 10:51 PM
Last Post: rhat398
  image.thumbnail(width, height) not working PCesarano 2 3,290 Apr-08-2021, 06:09 PM
Last Post: PCesarano
  Applying function mapypy 1 2,227 Mar-11-2021, 09:49 PM
Last Post: nilamo
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 6,905 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  how to create pythonic codes including for loop and if statement? aupres 1 1,867 Jan-02-2021, 06:10 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020