I am replacing text in the textframe of a shape.
Here is some sample code I am using…
Hi Jason,
Thanks for inquiring Aspose.Slides.
I have observed your requirements of replacing text. Actually, you are replacing text on TextFrame level and when you do so the text formatting properties are lost. In order to retain the text properties, you need to change the text on portion level which will ensure the text formatting properties as per requirement. Please try using following alternate on your end.
public static void ReplaceTextInShape(string documentNameAndPath, int slideNumber, string shapeName, string oldText, string newText)
{
Aspose.Slides.Presentation presentation = new Presentation(documentNameAndPath);
Aspose.Slides.ISlide slide = presentation.Slides[slideNumber];
Aspose.Slides.IShape shape = slide.Shapes.FirstOrDefault(t => t.Name == shapeName);
if (shape != null)
{
IAutoShape ashp=(IAutoShape)shape;
if(ashp.TextFrame!=null)
{
ITextFrame text = ashp.TextFrame;
foreach (IParagraph para in text.Paragraphs)
{
foreach (IPortion port in para.Portions)
{
port.Text.Replace(oldText, newText);
}
}
}
}
presentation.Save(documentNameAndPath, Aspose.Slides.Export.SaveFormat.Pptm);
presentation.Dispose();
}
Many Thanks,