Applying row height to all rows including and after row 7

左心房为你撑大大i 提交于 2020-05-31 03:41:52

问题


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.


回答1:


Comment: There must be something in my sheet preventing me from setting the row height.

Tested with existing Workbook, load_workbook(...,
the Rows 4 - 6 set to .height = 48, are shown OK.

Relevant:

  • column-and-row-dimensions-in-openpyxl-are-always-none
  • adjusting-cells-width-and-height-in-excel-in-mm-cm-through-python-script

Question: Applying row height to all rows including and after row 7

Note: Test Workscheet has 6 Rows, starting at Row 4.

import openpyxl 

wb = openpyxl.Workbook()
ws = wb.active

for _ in range(6):
    ws.append(('TEST' for _ in range(4)))

for row in range(4, ws.max_row + 1):
    ws.row_dimensions[row].height = 48

# wb.save(...)


来源:https://stackoverflow.com/questions/58368340/applying-row-height-to-all-rows-including-and-after-row-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!