Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find and Replace Text in PowerPoint Presentation using C#
// Load presentation
Presentation pres = new Presentation("mytextone.pptx");
string strToFind = "search string";
string strToReplaceWith = "replace string";
// Loop through each slide
foreach (Slide slide in pres.Slides)
{
// Get all text frames in the slide
ITextFrame[] tf = SlideUtil.GetAllTextBoxes(slide);
for (int i = 0; i < tf.Length; i++)
foreach (Paragraph para in tf[i].Paragraphs)
foreach (Portion port in para.Portions)
// Find text to be replaced
if (port.Text.Contains(strToFind))
{
// Replace exisitng text with the new text
string str = port.Text;
int idx = str.IndexOf(strToFind);
string strStartText = str.Substring(0, idx);
string strEndText = str.Substring(idx + strToFind.Length, str.Length - 1 - (idx + strToFind.Length - 1));
port.Text = strStartText + strToReplaceWith + strEndText;
}
}
// Save the presentation
pres.Save("myTextOneAspose.pptx", SaveFormat.Pptx);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment