Free Support Forum - aspose.com

Setting Text in PPTX

Do to some issues I was having with the master slides in my previous version (PPT) I had to hack one slide to…

var titleShape = slide.Shapes[0];
var subtitleShape = slide.Shapes[1];
if (titleShape != null && titleShape.IsTextHolder)
{
var paragraph = titleShape.TextFrame.Paragraphs[0];
if (paragraph != null)
{
var port = titleShape.TextFrame.Paragraphs[0].Portions[0];
if (port != null)
{
port.Text = title;
port.FontColor = Color.Orange;
}
}
}

Now with PPTX I am trying to do the same…

var titleShape = slide.Shapes[0];
var subtitleShape = slide.Shapes[1];
titleShape.IsTextHolder;

//
if (titleShape != null && titleShape is AutoShapeEx)
{
var paragraph = ((AutoShapeEx) titleShape).TextFrame.Paragraphs[0];
if (paragraph != null)
{
var port = ((AutoShapeEx) titleShape).TextFrame.Paragraphs[0].Portions[0];
if (port != null)
{
port.Text = title;
port.FontColor = Color.Orange;
}
}
}

Two problems
1) .Fontcolor no longer exists, should I use HighlightColor?
2) My text is not getting written at all?

Any help is appreciated.

Hi,

Your code should add the text. FontColor property is no more available in TextFrameEx for Pptx. HighlightColor can be used to highlight the text with a color using its color property.

Any ideas on why the text isnt being added?

What is the best way to change the font color of text for pptx?

Hi,

Probably, you are not accessing the proper shape. May be you are trying to add text to a GroupShape rather than AutoShape. If you provide the source pptx, i can suggest you better.

There isnt a real source file. It reads in a couple other powerpoints and copies their slides over to a master template. Then it goes through the first slide and puts a title/subtitle on it. I am running into another issue now that I will post into the forums, I will come back to this one once that is resolve (maybe related…)


Thanks for your quick reply

Hi Nick,

With Aspose.Slides for .NET 4.0.1, there is another way to access all the text portions without looping through all the shapes. For more information visit this link. An example for PPT is as under:

Presentation pres = new Presentation("show.ppt");

ITextBox[] tb = PresentationScanner.GetAllTextBoxes(pres, false);

for (int i = 0; i < tb.Length; i++)

{

TextFrame tf=(TextFrame)tb[i];

}