从旧幻灯片布局生成新幻灯片布局

时间:2019-06-19 18:08:18

标签: python powerpoint python-pptx

我想生成一张新幻灯片,使用与旧幻灯片相同的布局,但是新幻灯片的内容。

幻灯片1 幻灯片2

我需要幻灯片2将其设计更改为幻灯片1的设计,同时保留其txt内容。我设法用下面的代码复制了精确的幻灯片,但是它并不完美,并且覆盖了所有内容。

def copy_external(external, new):

    # copy from external presentation all objects into the existing presentation
    external_pres = external

    # specify the slide you want to copy the contents from
    ext_slide = external_pres.slides[1]

    # Define the layout you want to use from your generated pptx
    # slide_layout = new.slide_layouts[0]
    # lay = external.slide_layouts.index()
    # lay = external.slide_layouts.get_by_name()
    slide_layout = new.slide_layouts[6]

    # create now slide, to copy contents to
    curr_slide = new.slides.add_slide(slide_layout)

    # now copy contents from external slide, but do not copy slide properties
    # e.g. slide layouts, etc., because these would produce errors, as diplicate
    # entries might be generated

    for shp in ext_slide.shapes:
        el = shp.element
        newel = copy.deepcopy(el)
        curr_slide.shapes._spTree.insert_element_before(newel, 'p:extLst')
        #curr_slide.SlideShapes.add_shape(new_shape)

    return new.save('test1.pptx')

0 个答案:

没有答案