We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cannot perform Search and Replace

I have a pptx file with the following text on the first slide:

[this is a test]

I want to use Aspose.Slides to find this string and replace it with something else. I am using code similar to the search/replace code provided by Aspose:

pres = new Presentation(_dto.Document_Template_Path);
ITextFrame[] tb = SlideUtil.GetAllTextFrames(pres, true);
for (int i = 0; i < tb.Length; i++)
{
foreach (Aspose.Slides.Paragraph para in tb[i].Paragraphs)
{
foreach (Portion port in para.Portions)
{
if (port.Text == "[this is test]")
{
// do my replacement here
}
}
}
}

Unfortunately there seems to be an issue with how Portions are parsed. When I step through the code, I see that my string in PowerPoint is respresented as

Aspose.Slides.Portion[0] [this is a test
Aspose.Slides.Portion[1] ]

As you can see, the Aspose parser is incorrectly splitting the text in PowerPoint into two different portions.

This makes search and replace not possible.

Is this a known issue, or is there a different way to do search/replace using Aspose Slides?

Thanks

Hi Dan,


Thank you for your interest in Aspose.Slides.

I have observed your comments and like to share with you that one portion may split into more if its formatting is changed in anyway. In your scenario, I request you to please use the below code, which has only one new method in addition to your code. Please share your input file with us if you still face the issue.

pres = new Presentation(_dto.Document_Template_Path);
pres.JoinPortionsWithSameFormatting();
ITextFrame[] tb = SlideUtil.GetAllTextFrames(pres, true);
for (int i = 0; i < tb.Length; i++)
{
foreach (Aspose.Slides.Paragraph para in tb[i].Paragraphs)
{
foreach (Portion port in para.Portions)
{
if (port.Text == “[this is test]”)
{
// do my replacement here
}
}
}
}

Please let us know if the issue persists. We will be pleased to help you further.

Best Regards,

That worked perfectly. Thanks for the help!