[Python] python-pptx duplicate slide PPT will be damaged

Discussão em 'Python' iniciado por Stack, Março 13, 2025.

  1. Stack

    Stack Membro Participativo

    I found that when using the method of duplicate slide, if there is a chart on the page, PPT will be damaged, so I used this method to copy a slide with a chart and modify the title of the chart on one page, and the title of the chart on the other page is also modified inexplicably

    def duplicate_slide(pres,index):

    template = pres.slides[index]
    blank_slide_layout = pres.slide_layouts[index]
    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

    Continue reading...

Compartilhe esta Página