【发布时间】:2022-08-16 01:57:51
【问题描述】:
我们如何使用 Python-PPTX 删除 PowerPoint 演示文稿表中的特定行?可以循环遍历每一行/列和单元格,但似乎没有办法删除特定行?
标签: python-pptx
我们如何使用 Python-PPTX 删除 PowerPoint 演示文稿表中的特定行?可以循环遍历每一行/列和单元格,但似乎没有办法删除特定行?
标签: python-pptx
没有“内置”方法可以做到这一点,但通过编辑底层 XML,我们可以获得我们想要的结果。
import pptx
from pptx import *
def remove_row(table, row):
tbl = table._tbl
tr = row._tr
tbl.remove(tr)
# Establish read path
in_file_path = "input.pptx"
# Open slide-show presentation
pres = Presentation(in_file_path)
# Get Table
for slide in pres.slides:
for shp in slide.shapes:
if shp.has_table:
table = shp.table
row = table.rows[7]
remove_row(table, row)
pres.save("output.pptx")
【讨论】: