您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python-pptx:复制幻灯片

Python-pptx:复制幻灯片

这是我在GitHub上找到的,并且对我有用。我确实为我的项目做了几件事。您将需要导入六个并复制。我正在使用pptx-6.10

def duplicate_slide(pres, index):
    template = pres.slides[index]
    try:
        blank_slide_layout = pres.slide_layouts[12]
    except:
        blank_slide_layout = pres.slide_layouts[len(pres.slide_layouts)]

    copied_slide = pres.slides.add_slide(blank_slide_layout)

    for shp in template.shapes:
        el = shp.element
        newel = copy.deepcopy(el)
        copied_slide.shapes._spTree.insert_element_before(newel, 'p:extLst')

    for _, value in six.iteritems(template.part.rels):
        # Make sure we don't copy a notesSlide relation as that won't exist
        if "notesSlide" not in value.reltype:
            copied_slide.part.rels.add_relationship(
                value.reltype,
                value._target,
                value.rId
            )

    return copied_slide

然后,您可以通过传入演示文稿和模板的幻灯片索引来创建副本:

copied_slide = duplicate_slide(pres, 4)

我仍在编辑复制幻灯片中的形状,一旦我在项目中继续前进,就可以更新

python 2022/1/1 18:38:57 有262人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶