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

Free Support Forum - aspose.com

Shape's TextFrame is null

hi,

I’m creating a ppt dynamically (no existing ppt). I created a master slide with a header and body placeholders with alternative text.

I clone this master slide and add contents as needed. When I try to access to header shape, I get the reference to it, but the textframe property of the shape returns null. Hence, I’m unable to write text in the header.

Is there a better way to do it? below is my code

Shape shape = FindShape(slide, “Header”);
if (shape != null && shape.TextFrame != null)
{
Paragraph para = new Paragraph(shape.TextFrame.Paragraphs[0]);
para.Portions[0].Text = “question text”;
shape.TextFrame.Paragraphs.Add(para);
shape.TextFrame.Paragraphs.RemoveAt( 0 );
}

I fond the shape, but shape.TextFrame returns null

Dear Sarath,

I have observed the code snippet shared by you. Actually, you are trying to access the text frame using shapes. The shapes return the default text frame that is read only. You may please access the placeholders in the slide and use the textholders to add the text. Please use the following code snippet. Hopefully, it will fulfill your requirement.

Presentation pTest = new Presentation();

Slide slide = pTest.AddBodySlide();

//Adding title text

TextHolder thTitle = (TextHolder)slide.Placeholders[0];

Paragraph pPara = new Paragraph();

Portion pPortion = new Portion("Welcome to Aspose.Slides");

pPara.Portions.Add(pPortion);

thTitle.Paragraphs.Add(pPara);

//Adding body text

TextHolder thBody = (TextHolder)slide.Placeholders[1];

pPara = new Paragraph();

pPortion = new Portion("This is body text");

pPara.Portions.Add(pPortion);

thBody.Paragraphs.Add(pPara);

pTest.Write("D:\\Test.ppt");

Thanks and Regards,