Copier un paragraphe et une portion dans PPTX

Copier un paragraphe

Les propriétés du Paragraphe peuvent être accessibles dans l’instance ParagraphFormat de la classe Pargraph. Nous devons copier toutes les propriétés du paragraphe source vers le paragraphe cible. Dans l’exemple suivant, la méthode CopyParagraph est partagée, prenant le paragraphe à copier comme argument. Elle copie toutes les propriétés du paragraphe source vers un paragraphe temporaire et retourne ce dernier. Le paragraphe cible reçoit les valeurs copiées.

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;
}

Copier une portion

Les propriétés de la Portion peuvent être accessibles dans l’instance PortionFormat de la classe Portion. Nous devons copier toutes les propriétés de la portion source vers la portion cible. Dans l’exemple suivant, la méthode CopyPortion est partagée, prenant la portion à copier comme argument. Elle copie toutes les propriétés de la portion source vers une portion temporaire et retourne ce dernier. La portion cible reçoit les valeurs copiées.

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;
}