This short tutorial explains how to find and replace text in PowerPoint using Python. It has details to set the IDE, a list of steps, and a sample code to find and replace in PowerPoint using Python. You will learn different techniques to replace strings in a presentation.
Steps to Replace Words in PowerPoint using Python
- Set the environment to use Aspose.Slides for Python via .NET
- Load the aspose.slides library and bind it to the alias
- Define the old and new strings to be searched and replaced
- Load the source PPTX into the Presentation class object to replace the string
- Iterate through all the slides in the presentation and get the collection of text boxes in each slide
- Access all the paragraphs in each text box and get a collection of portions in all the paragraphs
- Check the availability of the target string in the text property of the portion
- If the string is found, replace it with the new string
- Save the updated presentation
These steps summarize how to find and replace text in PowerPoint using Python. Load the presentation into memory, iterate through slides, get all text boxes using SlideUtil in each slide, then iterate through paragraphs and portions, and replace the matching text in each portion. Finally, save the resultant presentation on the disk.
Code to Search and Replace in PowerPoint using Python
This code shows the process to find and replace text in PowerPoint. You can improvise the code by adding find/replace pairs of strings, toggling case sensitivity, and replacing text in tables, speaker notes, and master/layout slides. The Presentation.replace_text() method can be used to directly replace strings in the presentation without parsing slides and respective content for a quick updating of the file.
This article shows various options to replace strings. To extract media i.e. audio or video from a presentation, refer to the article Extract media from PowerPoint using Python.