Back to Devexpress

DevExpress Presentation API: Search, Replace, Remove, and Highlight Text in a Slide or Presentation

officefileapi-405628-presentation-api-search-replace-remove-text.md

latest8.5 KB
Original Source

DevExpress Presentation API: Search, Replace, Remove, and Highlight Text in a Slide or Presentation

  • Nov 13, 2025
  • 4 minutes to read

The Presentation API library supports the following text-related operations on the presentation or slide level:

  • Search for text in shapes, notes, and tables
  • Replace text
  • Remove specified text
  • Change character formatting

The same operations are available on the shape level. For more information, refer to the following help topic: Work with Shape Text.

Replace Text

Call the Presentation.ReplaceText or Slide.ReplaceText method to replace text in a presentation or slide:

csharp
using DevExpress.Docs.Presentation;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        //...
        presentation.ReplaceText("com", "info", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });

        Slide slide = presentation.Slides[0];
        slide.ReplaceText("com", "info", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });
    }
}
vb
Imports DevExpress.Docs.Presentation

Namespace PresentationApiSample
    Public Class Program
        Public Shared Sub Main(args As String())
            '...
            presentation.ReplaceText("com", "info", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })
            Dim slide As Slide = presentation.Slides(0)
            slide.ReplaceText("com", "info", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })
        End Sub
    End Class
End Namespace

Find Text

Call the Presentation.FindText or Slide.FindText method to obtain text that matches the search query. The method returns a list of TextSearchInfo objects. Each object contain the found text ranges and the parent text area.

csharp
using DevExpress.Docs.Presentation;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        //...
        IList<TextSearchInfo> textRangeInfos = presentation.FindText("com", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });

        Slide slide = presentation.Slides[0];
        IList<TextSearchInfo> slideTextRangeInfos = slide.FindText("com", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });
    }
}
vb
Imports DevExpress.Docs.Presentation

Namespace PresentationApiSample
    Public Class Program
        Public Shared Sub Main(args As String())
            '...
            Dim textRangeInfos As IList(Of TextSearchInfo) = presentation.FindText("com", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })
            Dim slide As Slide = presentation.Slides(0)
            Dim slideTextRangeInfos As IList(Of TextSearchInfo) = slide.FindText("com", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })
        End Sub
    End Class
End Namespace

Apply Custom Formatting to Specified Text Ranges

Call the Presentation.ModifyTextProperties or Slide.ModifyTextProperties method to apply custom formatting to specified text ranges. For example, you can highlight text (change text or background color).

The following code sample searches for occurrences of the “com” string and changes the font color to red. Method calls for both presentation and slides are included.

csharp
using DevExpress.Docs.Presentation;
using System.Drawing;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        // ...

        IList<TextSearchInfo> textRangeInfos = presentation.FindText("com", new 
        TextSearchOptions { MatchCase = true, WholeWordOnly = true });
        presentation.ModifyTextProperties(textRangeInfos, new TextProperties { Fill = new SolidFill(Color.Red) });

        Slide slide = presentation.Slides[0];
        IList<TextSearchInfo> slideTextRangeInfos = slide.FindText("com", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });

        slide.ModifyTextProperties(slideTextRangeInfos, new TextProperties { Fill = new SolidFill(Color.Red) });

    }
}
vb
Imports DevExpress.Docs.Presentation
Imports System.Drawing

Namespace PresentationApiSample
    Public Class Program
        Public Shared Sub Main(args As String())
            '...

            Dim textRangeInfos As IList(Of TextSearchInfo) = presentation.FindText("com", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })

            presentation.ModifyTextProperties(textRangeInfos, New TextProperties With {
                .Fill = New SolidFill(Color.Red)
            })
            Dim slide As Slide = presentation.Slides(0)
            Dim slideTextRangeInfos As IList(Of TextSearchInfo) = slide.FindText("com", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })

            slide.ModifyTextProperties(slideTextRangeInfos, New TextProperties With {
                .Fill = New SolidFill(Color.Red)
            })

        End Sub
    End Class
End Namespace

Remove Text

Call the Presentation.RemoveText or Slide.RemoveText method to remove specified text ranges from a presentation or slide:

csharp
using DevExpress.Docs.Presentation;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        //...
        IList<TextSearchInfo> textRangeInfos = presentation.FindText("com", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });
        presentation.RemoveText(textRangeInfos);

        Slide slide = presentation.Slides[0];
        IList<TextSearchInfo> slideTextRangeInfos = slide.FindText("com", new TextSearchOptions { MatchCase = true, WholeWordOnly = true });
        slide.RemoveText(slideTextRangeInfos);
    }
}
vb
Imports DevExpress.Docs.Presentation

Namespace PresentationApiSample
    Public Class Program
        Public Shared Sub Main(args As String())
            '...
            Dim textRangeInfos As IList(Of TextSearchInfo) = presentation.FindText("com", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })

            presentation.RemoveText(textRangeInfos)

            Dim slide As Slide = presentation.Slides(0)
            Dim slideTextRangeInfos As IList(Of TextSearchInfo) = slide.FindText("com", New TextSearchOptions With {
                .MatchCase = True,
                .WholeWordOnly = True
            })
        End Sub
    End Class
End Namespace

Extract Text

For more information on how to extract text from presentations, refer to the following help topic: Extract Presentation Content.