Syncfusion Feedback

Find and Replace Text Using Syncfusion .NET PowerPoint Library

The Syncfusion® .NET PowerPoint Library allows users to find and replace text in PowerPoint slides and elements, such as shapes, text boxes, tables, and SmartArt, without relying on Microsoft PowerPoint or interop dependencies. It provides options to find text by matching case and whole words.

Find and replace text in PowerPoint using C#

Learn how to find and replace text in PowerPoint presentations programmatically using C# with the Syncfusion .NET PowerPoint Library. This guide demonstrates searching for specific text and replacing it throughout the presentation.

Step 1: Create a new project

Start by creating a new C# Console Application project.

Step 2: Install the NuGet package

Add the Syncfusion.Presentation.Net.Core package to your project from NuGet.org.

Step 3: Add required namespaces to find and replace text

Add the following namespaces to your Program.cs file:

using Syncfusion.Presentation;

Step 4: Open the PowerPoint presentation

Open a PowerPoint file from a file stream.

//Load or open an PowerPoint Presentation
FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Open an existing PowerPoint presentation
IPresentation pptxDoc = Presentation.Open(inputStream);

Step 5: Perform find and replace text

Search for specific text in the PowerPoint presentation and replace it with new text.

Run

//Find all the occurrences of a particular text in the PowerPoint presentation
ITextSelection[] textSelections = pptxDoc.FindAll("product", false, false);
foreach (ITextSelection textSelection in textSelections)
{
	//Get the found text as a single text part
	ITextPart textPart = textSelection.GetAsOneTextPart();
	//Replace the text
	textPart.Text = "Service";
}

Step 6: Save the PowerPoint presentation

Save the modified presentation to a file stream.

FileStream outputStream = new(Path.GetFullPath(@"Output/Result.pptx"), FileMode.Create, FileAccess.ReadWrite);
pptxDoc.Save(outputStream);
// Explicitly close streams and presentation
outputStream.Close();
pptxDoc.Close();
inputStream.Close();

Get started quickly by downloading the installer and checking license information on the Downloads page.

Syncfusion .NET PowerPoint Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.