[Python] create new pptx using existing pptx Python-Pptx

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create new.pptx using an old.pptx . old.pptx is having 4 slides in it . I want to create the new.pptx with almost same content with few text modifications in 4 slides . I skipped the modification part from the below code, you can take an example like converting lower cases to upper case..Need to do these things in run time, so that if i just pass the old.pptx it will do the required operation and then write it to new pptx with same no. of slides..I am not sure how to tweak below, may be need to change it completely . Please have a look to below code..

    from pptx import Presentation

    prs1 = Presentation()

    prs = Presentation('old.pptx')

    title_slide_layout = prs1.slide_layouts[0]
    for slide in prs.slides:
    for shape in slide.shapes:
    if not shape.has_text_frame:
    continue
    for paragraph in shape.text_frame.paragraphs:
    #print(paragraph.text)
    prs1.slides.add_slide(paragraph.text)
    prs1.save('new.pptx')

    Continue reading...

Compartilhe esta Página