Finding and replacing text is often used to update the content in PowerPoint presentations. However, to perform this operation for a batch of presentations, you need automation. Accordingly, this article covers how to find and replace text in PowerPoint PPT in C#.
C# API to Find and Replace Text in PowerPoint PPT
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 PPT 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.
C# Replace Text in PowerPoint PPT - Get a Free License
You can replace text in PowerPoint presentations without evaluation limitations by requesting a temporary license.
Conclusion
The feature of finding and replacing text in PowerPoint presentations is used in various scenarios. 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.
C# API to Replace Text in PPTX - Read More
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.