将行高应用于所有行,包括第7行及之后的行 [英] Applying row height to all rows including and after row 7
问题描述
除非我一次只行一行,否则我无法弄清楚如何在现有工作表上应用行高.
I cannot figure out how to apply a row height on an existing worksheet unless I do it one row at a time.
这适用于单行:
ws4.row_dimensions[14].height = 25
但是我想为第7行及以后的所有行设置行高.
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')
任何想法如何做到这一点?我无法从openpyxl文档中收集答案.而且我似乎在任何地方都找不到示例.
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.
推荐答案
评论:我的工作表中一定有东西阻止我设置行高.
Comment: There must be something in my sheet preventing me from setting the row height.
使用现有工作簿load_workbook(...
和
进行了测试
在行4 - 6
设置为.height = 48
时,显示为OK.
Tested with existing Workbook, load_workbook(...
,
the Rows 4 - 6
set to .height = 48
, are shown OK.
相关:
- column-and-row-dimensions-in-openpyxl-are-always-none
- adjusting-cells-width-and-height-in-excel-in-mm-cm-through-python-script
问题:将行高应用于包括第7行及之后的所有行
Question: Applying row height to all rows including and after row 7
注意:测试
Workscheet
有6行,从第4行开始.
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(...)
这篇关于将行高应用于所有行,包括第7行及之后的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!