【问题标题】:How To Delete A Specific Table Row In PowerPoint Using Python-PPTX如何使用 Python-PPTX 删除 PowerPoint 中的特定表格行
【发布时间】:2022-08-16 01:57:51
【问题描述】:

我们如何使用 Python-PPTX 删除 PowerPoint 演示文稿表中的特定行?可以循环遍历每一行/列和单元格,但似乎没有办法删除特定行?

    标签: python-pptx


    【解决方案1】:

    没有“内置”方法可以做到这一点,但通过编辑底层 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")
    

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 2020-05-29
      • 2017-09-03
      相关资源
      最近更新 更多