Copying Paragraph and Portion in PPTX

Copying a Paragraph

The properties of the Paragraph can be accessed in ParagraphFormat instance of Pargraph class. We need to copy all the properties of source paragraph to target paragraph. In the following example, the CopyParagraph method is shared that takes paragraph to be copied as an argument. It copies all the properties of source paragraph to a temporary paragraph and return the same. The target paragraph gets the copied values.

public static void main(String[] args){
//Function Call
IParagraph newPara=CopyParagraph(SourcePara);
}
//Function Definition
public static IParagraph CopyParagraph(IParagraph par)
{
Paragraph temp = new Paragraph();
// use CreateParagraphFormatData !!!
IParagraphFormatEffectiveData paraData = par.createParagraphFormatEffective();
// use ParagraphFormat to set values
temp.getParagraphFormat().setAlignment(paraData.getAlignment());
temp.getParagraphFormat().setDefaultTabSize(paraData.getDefaultTabSize());
temp.getParagraphFormat().setMarginLeft(paraData.getMarginLeft());
temp.getParagraphFormat().setMarginRight(paraData.getMarginRight());
temp.getParagraphFormat().setFontAlignment(paraData.getFontAlignment());
temp.getParagraphFormat().setIndent(paraData.getIndent());
temp.getParagraphFormat().setDepth(paraData.getDepth());
temp.getParagraphFormat().setSpaceAfter(paraData.getSpaceAfter());
temp.getParagraphFormat().setSpaceBefore(paraData.getSpaceBefore());
temp.getParagraphFormat().setSpaceWithin(paraData.getSpaceWithin());
temp.getParagraphFormat().getBullet().setChar(paraData.getBullet().getChar());
temp.getParagraphFormat().getBullet().setHeight(paraData.getBullet().getHeight());
temp.getParagraphFormat().getBullet().setFont(paraData.getBullet().getFont());
temp.getParagraphFormat().getBullet().setNumberedBulletStyle(paraData.getBullet().getNumberedBulletStyle());
temp.getParagraphFormat().setFontAlignment(paraData.getFontAlignment());
return temp;
}

Copying a Portion

The properties of the Portion can be accessed in PortionFormat instance of Portion class. We need to copy all the properties of source portion to target portion . In the following example, the CopyPortion method is shared that takes portion to be copied as an argument. It copies all the properties of source portion to a temporary portion and return the same. The target portion gets the copied values.

public static void main(String[] args){
//Function Call
IPortion newPortion=CopyPortion(SourcePortion);
}
//Function Definition
public static IPortion CopyPortion(IPortion por)
{
Portion temp = new Portion();
//use CreatePortionFormatData!!!
IPortionFormatEffectiveData portData = por.createPortionFormatEffective();
// use PortionFormat to set values
temp.getPortionFormat().setAlternativeLanguageId(portData.getAlternativeLanguageId());
temp.getPortionFormat().setBookmarkId(portData.getBookmarkId());
temp.getPortionFormat().setEscapement(portData.getEscapement());
temp.getPortionFormat().getFillFormat().setFillType(por.getPortionFormat().getFillFormat().getFillType());
temp.getPortionFormat().getFillFormat().getSolidFillColor().setColor(portData.getFillFormat().getSolidFillColor());
if(portData.getFontBold() == true)
temp.getPortionFormat().setFontBold(NullableBool.True);
else
temp.getPortionFormat().setFontBold(NullableBool.False);
temp.getPortionFormat().setFontHeight(portData.getFontHeight());
if(portData.getFontItalic() == true)
temp.getPortionFormat().setFontItalic(NullableBool.True);
else
temp.getPortionFormat().setFontItalic(NullableBool.False);
temp.getPortionFormat().setFontUnderline(portData.getFontUnderline());
temp.getPortionFormat().getUnderlineFillFormat().setFillType(portData.getUnderlineFillFormat().getFillType());
temp.getPortionFormat().getUnderlineFillFormat().getSolidFillColor().setColor(portData.getUnderlineFillFormat().getSolidFillColor());
if(portData.isHardUnderlineFill() == true)
temp.getPortionFormat().isHardUnderlineFill(NullableBool.True);
else
temp.getPortionFormat().isHardUnderlineFill(NullableBool.False);
if(portData.isHardUnderlineLine() == true)
temp.getPortionFormat().isHardUnderlineLine(NullableBool.True);
else
temp.getPortionFormat().isHardUnderlineLine(NullableBool.False);
if(portData.getKumimoji() == true)
temp.getPortionFormat().setKumimoji(NullableBool.True);
else
temp.getPortionFormat().setKumimoji(NullableBool.False);
temp.getPortionFormat().setKerningMinimalSize(portData.getKerningMinimalSize());
temp.getPortionFormat().setLanguageId(portData.getLanguageId());
temp.getPortionFormat().setLatinFont(portData.getLatinFont());
temp.getPortionFormat().setEastAsianFont(portData.getEastAsianFont());
temp.getPortionFormat().setComplexScriptFont(portData.getComplexScriptFont());
temp.getPortionFormat().setSymbolFont(portData.getSymbolFont());
temp.getPortionFormat().setTextCapType(portData.getTextCapType());
temp.getPortionFormat().setSpacing(portData.getSpacing());
temp.getPortionFormat().setStrikethroughType(portData.getStrikethroughType());
if(portData.getProofDisabled() == true)
temp.getPortionFormat().setProofDisabled(NullableBool.True);
else
temp.getPortionFormat().setProofDisabled(NullableBool.False);
if(portData.getNormaliseHeight() == true)
temp.getPortionFormat().setNormaliseHeight(NullableBool.True);
else
temp.getPortionFormat().setNormaliseHeight(NullableBool.False);
temp.getPortionFormat().setHyperlinkMouseOver(portData.getHyperlinkMouseOver());
temp.getPortionFormat().setHyperlinkClick(por.getPortionFormat().getHyperlinkClick());
temp.getPortionFormat().getHighlightColor().setColor(portData.getHighlightColor());
return temp;
}