scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.47k stars 530 forks source link

I need move a slide from one ppt to another ppt #696

Open Lirioooo opened 3 years ago

Lirioooo commented 3 years ago

I've a project and one of the requirements is to move a slide from one presentation to another, but i can't to find a solution and i think to doesn't exists one, i need to do this with this code

prs = Presentation('ppt2.pptx')

for slide in prs.slides:
    for shape in slide.shapes:
        if hasattr(shape, "text"):
            for paragraph in shape.text_frame.paragraphs:
                for run in paragraph.runs:
                    if "Nuestra experiencia en su industria" in run.text:
                        url = "ppt2.pptx"
                        prsIndustria = Presentation(url)
                        slideAn = prsIndustria.slides[0]
                        slide = slideAn

I know that doesn't works like this but its a example. So help me with this please.

mszbot commented 3 years ago

Not possible with this library.

qirh commented 3 years ago

I've solved this problem by iterating over the shapes in the source slide, copying them one by one and creating them in the dest slide. It's not an easy approach as you have to do a lot of manual work like copying over styles and contents and things like that, but for my use case it has worked just fine

albertocalderari commented 1 month ago

Do you have a working code snippet by any chance @mszbot please?

mszbot commented 1 month ago

There is no free library that provides this functionality, it's not simple. You can try aspose.com, powerpointgeneratorapi.com.