Adding TextFrames

I apologise if this a silly question, but I can’t seem the find the answer looking at demo code and forum.

What I need to do is add some text to a slide. Now I can read in existing ppt and change the text but that does not help me.

What is the correct/best way to add text to a slide?

I tried to instantiate the TextFrame but there is no AddText method on the Shapes member

Then I though maybe I could add text by creating a rectangle and setting the TextFrame. This did not work because the Text member is read only, as shown below!

“Aspose.PowerPoint.Rectangle aa = slide.Shapes.AddRectangle(20, 20, 500, 30);
aa.TextFrame.Text = “Fred”;” // error Text a read only field


I’m sure its simple, can somebody tell me where I’m going wrong!


Thanks in advance

cwad,
Aspose.PowerPoint uses formatted text, so TextFrame.Text and even Paragraph.Text are readonly properties, mainly useful for debugging purposes. If you want to change text you should get Paragraph from TextFrame.Paragraphs array property, then get Portion from Paragraph.Portions and then change it’s text. I.e., you should write something like “aa.TextFrame.Paragraphs[0].Portions[0].Text = “Fred”;”. But if shape hasn’t textframe (newly created doesn’t), this will couse exception. So, your solution is


Aspose.PowerPoint.Rectangle aa = slide.Shapes.AddRectangle(20, 20, 500, 30);
aa.AddTextFrame(“Fred”);

Please note: if shape already has TextFrame, AddTextFrame() method does nothing.