This short tutorial explains how to find and replace text in PowerPoint using Python. Includi dettagli per configurare l’IDE, un elenco di passaggi e un codice di esempio per trovare e sostituire in PowerPoint usando Python. Imparerai diverse tecniche per sostituire stringhe in una presentazione.
Steps to replace words in PowerPoint using Python
- Set up the environment to use Aspose.Slides for Python via .NET
- Carica la libreria aspose.Diapositive e associarle all’alias.
- Define the old and new strings to search for and replace.
- Upload the original PPTX into the class object Presentation to replace the string.
- Scroll through all the slides of the presentation and retrieve the collection of text boxes on each slide.
- Access all the paragraphs in each text box and get a collection of parts in all paragraphs.
- Check the availability of the target string in the text property of the segment.
- If the string is found, replace it with the new string.
- Salva la presentazione aggiornata
These steps summarize how to find and replace text in PowerPoint using Python. Load the presentation into memory, iterate through the slides, get all text boxes using SlideUtil on each slide, then iterate through the paragraphs and runs, and replace the corresponding text in each run. Infine, salva la presentazione risultante sul disco.
Code to search and replace in PowerPoint using Python
This code shows the process to find and replace text in PowerPoint. It is possible to improvise the code by adding find/replace string pairs, enabling case sensitivity, and replacing text in tables, speaker notes, and master/layout slides. Il metodo Presentazione.replace_text() può essere usato per sostituire direttamente le stringhe nella presentazione senza analizzare le diapositive e il relativo contenuto, per un aggiornamento rapido del file.
Questo articolo mostra varie opzioni per sostituire le stringhe. Per estrarre media, ad esempio audio o video, da una presentazione, fare riferimento all’articolo Extract media from PowerPoint using Python.