Friday, 06 December 2019 08:14

New Method to Replace Text in PowerPoint in C#

Written by  support iceblue
Rate this item
(0 votes)

Spire.Presentation 4.11 and the later versions provide the following methods to replace text in PowerPoint document:

ReplaceFirstText(string matchedString, string newValue, bool caseSensitive): replace the first occurrence of searched text only.

ReplaceAllText(string matchedString, string newValue, bool caseSensitive): replace all the occurrences of searched text.

In the below examples, we will show you how to use the above methods to replace text in a PowerPoint document.

Replace the first occurrence of searched text only

using Spire.Presentation;

namespace ReplaceFirstText
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation ppt = new Presentation();
            //Load the PowerPoint document
            ppt.LoadFromFile("Input.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];

            //Replace the first occurrence of “Spire.Presentation” with “New Text” by using ReplaceFirstText method
            slide.ReplaceFirstText("Spire.Presentation", "New Text", false);

            //Save the resultant document
            ppt.SaveToFile("RplaceFirstText.pptx", FileFormat.Pptx2013);
        }
    }
}

New Method to Replace Text in PowerPoint in C#

Replace all the occurrences of searched text

using Spire.Presentation;

namespace ReplaceAllText
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation ppt = new Presentation();
            //Load the PowerPoint document
            ppt.LoadFromFile("Input.pptx");

            //Get the first slide
            ISlide slide = ppt.Slides[0];

            //Replace all the occurrences of “Spire.Presentation” with “New Text” by using ReplaceAllText method
            slide.ReplaceAllText("Spire.Presentation", "New Text", false);

            //Save the resultant document
            ppt.SaveToFile("RplaceAllText.pptx", FileFormat.Pptx2013);
        }
    }
}

New Method to Replace Text in PowerPoint in C#

Additional Info

  • tutorial_title: