How to set text in a Placeholder

Hi,

I have a question aboutAspose Slides. I want to set the text in a TextHolder respectively Placeholder. I get the right object (test with ‘setAlternativeText’) but I do not know how to go on although I have been trying for hours.

Presentation target = new Presentation(“d:/nmaster.ppt”);
target.getSlideByPosition(1).getPlaceholders().get_Item(0).setAlternativeText(“this one”);
target.write(“d:/erg.ppt”);

For ppts please see attachment. Can you please help me?
I am using Slides 7.6.0 for Java.

Many thanks

Hi Borris,


I have worked with the presentation file shared and like to share that following code is used for setting the placeholder text. You need to typecast Placeholder to Textholder in order to set the text. However, the cast exception is occurring when type casting placeholder to texholder and I have created an issue with ID SLIDESJAVA-34059 to further investigate and resolve it. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

Presentation target = new Presentation(path+“nmaster.ppt”);
target.getSlideByPosition(1).getPlaceholders().get_Item(0).setAlternativeText(“this one”);


TextHolder txtHolder=(TextHolder)target.getSlideByPosition(1).getPlaceholders().get_Item(0);
txtHolder.getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Hello World”);
// target.getSlideByPosition(1).getShapes().get_Item(0).setAlternativeText(“this one”);
target.write(path+“erg2.ppt”);

We are sorry for your inconvenience,

Hi Mudassir,

in this example I want to set title and subtitle of the title slide - it is an important feature.
Do you know a workaround for this topic or can you estimate when this issue is solved?



Many thanks,
Borris

Hi Borris,

I like to share that the issue is probably with your presentation and our development team is investigating the issue. For the time being, I have altered your presentation and generated the sample code that may help in serving the purpose for your needs. Please try using the sample code for the time being on your end.

public static void TestAlternativeText()
{
String path=“D:\Aspose Data\Test2\”;
Presentation target = new Presentation(path+“nmaster2.ppt”);
Slide slide=target.getSlideByPosition(1);

Shape shape=null;
for(int i=0;i<slide.getShapes().size();i++)
{
shape=slide.getShapes().get_Item(i);
TextFrame txt=shape.getTextFrame();
if(shape.getPlaceholder()!=null && txt!=null)
{
int type1=shape.getPlaceholder().getPlaceholderType();
int type2=PlaceholderType.CenteredTitle;

if(shape.getAlternativeText().equals(“Title”))
{

txt.getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Title Text”);


}

else if(shape.getAlternativeText().equals(“SubTitle”))
{
txt.getParagraphs().get_Item(0).getPortions().get_Item(0).setText(“Sub Title Text”);

}
}



}

target.write(path+“erg2.ppt”);
}

Many Thanks,

Hi Mudassir,

thank you, it works fine!
One question left: I think the trick is setting the alt-attribute. Which powerpoint version did you use (in powerpoint 97 there is no alt attribute and I think it is no good idea to use for example powerpoint 2007 in compatibility mode)?


Nice weekend and
many thanks,
Borris

Hi Borris,

I am using PowerPoint 2010 on my end to set the Alt text for the shape. I guess PowerPoint 2007 may also have the provision for setting the alternative text and perhaps installing the compatibility pack may for sure have the provision.

Many Thanks,

The issues you have found earlier (filed as SLIDESJAVA-34059) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.