Finding and replacing text is often used to update the content in PowerPoint presentations. However, in order to perform this operation for a batch of presentations, you need automation. Accordingly, this article covers how to find and replace text in PowerPoint PPTX/PPT programmatically using C#.
C# API to Find and Replace Text in PowerPoint
In order to find and replace text in PowerPoint presentations, we’ll use Aspose.Slides for .NET. It is a feature-rich API that is designed to create and manipulate PowerPoint presentations from within .NET applications. You can either download the API or install it using NuGet.
PM> Install-Package Aspose.Slides.NET
Find and Replace Text in PowerPoint PPTX using C#
The following are the steps to find and replace text in a PPTX presentation using C#.
- Load the PowerPoint presentation using Presentation class.
- Loop through each Slide in the presentation.
- In each iteration, get text frames in an ITextFrame array.
- Loop through array of ITextFrame and in each iteration, perform the following operations:
- Loop through the ParagraphCollection in each text frame.
- Access the PortionCollection in each Paragraph.
- Check if Portion.Text contains the search string.
- If yes, find the position of the search string and replace it by setting Portion.Text property.
- Save the updated presentation using Presentation.Save(string, SaveFormat) method.
The following code sample shows how to find and replace text in a PowerPoint presentation.
Get a Free API License
You can use Aspose.Slides for .NET without evaluation limitations by requesting a temporary license.
Conclusion
The feature of finding and replacing text in PowerPoint presentations is used in various scenarios. In order to automate this operation, the article covered how to find and replace text in PowerPoint presentations programmatically using C#. You can simply install the API in your application and integrate the provided code sample. In addition, you can visit the documentation to explore other features of Aspose.Slides for .NET. Also, you can feel free to let us know about your queries via our forum.