The simpliest way to create template is using of master styles. You can
define formatting (including font properties, alignment, offsets and
bullets) for different textholder type (title, body etc) and then
simple use setText() method in your app. Without explicit formatting
PowerPoint will get formatting from the master. Of course, this method
doesn’t suite you if your template must have different formatting for
textboxes of same type.
The complex way isn’t so hard too. You can add something like:
private static Pattern splitter = Pattern.compile("[\n\r]");
static public void replaceText(Paragraphs paragraphs, String text)
{
try
{
while(paragraphs.size() > 1)
paragraphs.remove(1);
if(paragraphs.size() == 1)
{
Portions portions = paragraphs.get(0).getPortions();
while(portions.size() > 1)
portions.remove(1);
if(portions.size() == 0)
portions.add(new Portion());
}
else
{
paragraphs.add(new Paragraph());
paragraphs.get(0).getPortions().add(new Portion());
}
Paragraph first = paragraphs.get(0);
String[] newParagraphs = splitter.split(text, -1);
first.getPortions().get(0).setText(newParagraphs.length > 0? newParagraphs[0] : "");
for(int i = 1; i < newParagraphs.length; i++)
{
Paragraph newParagraph = new Paragraph(first);
newParagraph.getPortions().get(0).setText(newParagraphs[ i ]);
paragraphs.add(newParagraph);
}
}
catch(PptEditException exp)
{
// handle exception
}
}
and then call replaceText(textFrame.getParagraphs(), newText) anywhere you need it.