复制 PPTX 中的段落和部分
Contents
[
Hide
]
为了格式化演示文稿文本,我们需要在 段落 和 部分 级别上进行格式化。一些文本属性可以在段落级别上设置,而一些则在部分级别上设置。如果文本中有需要复制到新添加的段落或部分的段落或部分,我们需要将相应段落或部分的所有属性复制到新添加的段落或部分。
复制段落
段落 的属性可以通过 Paragraph 类的 ParagraphFormat 实例访问。我们需要将源段落的所有属性复制到目标段落。在以下示例中,分享了 CopyParagraph 方法,该方法将要复制的段落作为参数。它将源段落的所有属性复制到一个临时段落并返回该段落。目标段落获取复制的值。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
复制部分
部分 的属性可以通过 Portion 类的 PortionFormat 实例访问。我们需要将源部分的所有属性复制到目标部分。在以下示例中,分享了 CopyPortion 方法,该方法将要复制的部分作为参数。它将源部分的所有属性复制到一个临时部分并返回该部分。目标部分获取复制的值。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |