如何使用 python-pptx 删除 pptx 中 table 中不需要的行空间?

How to remove unwanted row spaces in a table in pptx using python-pptx?

我想删除行之间不需要的空格,使其变得紧凑,如下图所示:

我尝试使用 space_before 和 space_after 但没有用。有什么建议吗?

bdy_cells[i].text_frame.paragraphs[0].space_before = Pt(2)
bdy_cells[i].text_frame.paragraphs[0].space_after = Pt(2)

下面显示的是包含空格的箭头

python-pptx 允许指定 _Cell 边距:https://python-pptx.readthedocs.io/en/latest/api/table.html#pptx.table._Cell.margin_top

所以你可能有这样的东西:

from pptx.util import Inches

for cell in row.cells:
    cell.margin_top = Inches(0)
    cell.margin_bottom = Inches(0)

默认情况下,单元格的顶部和底部边距为 0.05 英寸。