0

我正在处理一个表格,并希望在填充了值后查询它的最终高度。这样我就可以根据它的大小调整它在幻灯片 (graphicframe.top) 上的位置。我用这些行添加表格:

graphicframe = shapes.add_table(rows = 41, cols = 5, left = Inches(0), top = Inches(2), width = Inches(5.7), height = Inches(4)) table = graphicframe.table

然后循环遍历其单元格以单独填充它们。表格高度会改变以适应输入(例如:文本可能会换行到 2 行,增加高度,大量行可能会将表格推高到我最初指定的高度等)。

graphicsframe.height 返回我输入到 add_table 的原始高度,而不是数据填充后的最终高度。table.rows[i].height 也一样。

我发现看起来是 XML 文件中每一行的高度,这些也对应于 add_table 的原始高度,而不是数据填充后表的经验最终高度。从 XML 文件中,有 41 行指定高度 h,对应于我表中的 41 行。它们看起来像这样:< a:tr h="89209" > ...</a:tr >

你知道我的桌子的经验高度(填充后)是否记录在任何地方?谢谢!!

4

1 回答 1

0

The short answer is no, you cannot determine the rendered height of a table you have just created with python-pptx. This is because any height adjustments for "fit" are made by the PowerPoint rendering engine, which is not available until you open the file with PowerPoint.

You may be able to use the approach you mention (adding up row heights), but it would only be accurate after opening the presentation with PowerPoint and possibly visiting that slide and perhaps making a small adjustment to the table. You'll have to experiment to see what, if anything, causes PowerPoint to rewrite the table row heights to their rendered values. Note that this behavior may be different between PowerPoint and LibreOffice.

于 2017-07-13T20:52:02.170 回答