本文整理汇总了Java中org.apache.poi.xwpf.usermodel.XWPFParagraph.getCTP方法的典型用法代码示例。如果您正苦于以下问题:Java XWPFParagraph.getCTP方法的具体用法?Java XWPFParagraph.getCTP怎么用?Java XWPFParagraph.getCTP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xwpf.usermodel.XWPFParagraph
的用法示例。
在下文中一共展示了XWPFParagraph.getCTP方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertMPagination
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
/**
* Insert the given {@link MPagination}.
*
* @param paragraph
* the {@link XWPFParagraph} to modify
* @param run
* the {@link XWPFRun} to insert to
* @param mPagination
* the {@link MPagination}
* @return the last inserted {@link XWPFParagraph}
*/
private XWPFParagraph insertMPagination(XWPFParagraph paragraph, XWPFRun run, MPagination mPagination) {
final XWPFParagraph res;
switch (mPagination) {
case newColumn:
run.addBreak(BreakType.COLUMN);
res = paragraph;
break;
case newParagraph:
res = createNewParagraph(generatedDocument, (XWPFParagraph) run.getParent());
break;
case newPage:
run.addBreak(BreakType.PAGE);
res = paragraph;
break;
case newTableOfContent:
CTP ctP = paragraph.getCTP();
CTSimpleField toc = ctP.addNewFldSimple();
toc.setInstr("TOC \\h");
toc.setDirty(STOnOff.TRUE);
res = paragraph;
break;
case newTextWrapping:
run.addBreak(BreakType.TEXT_WRAPPING);
res = paragraph;
break;
default:
throw new IllegalStateException("Not supported MPagination.");
}
return res;
}
示例2: render
import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
@Override
public void render(ElementTemplate eleTemplate, Object data, XWPFTemplate template) {
NiceXWPFDocument doc = template.getXWPFDocument();
RunTemplate runTemplate = (RunTemplate) eleTemplate;
XWPFRun run = runTemplate.getRun();
if (null == data) return;
NumbericRenderData numbericData = (NumbericRenderData) data;
List<TextRenderData> datas = numbericData.getNumbers();
Pair<Enum, String> numFmt = numbericData.getNumFmt();
Style fmtStyle = numbericData.getFmtStyle();
if (datas == null || datas.isEmpty()) {
runTemplate.getRun().setText("", 0);
return;
} else {
XWPFNumbering numbering = doc.getNumbering();
if (null == numbering) {
numbering = doc.createNumbering();
}
NumberingWrapper numberingWrapper = new NumberingWrapper(numbering);
CTAbstractNum cTAbstractNum = CTAbstractNum.Factory.newInstance();
// if we have an existing document, we must determine the next
// free number first.
cTAbstractNum.setAbstractNumId(
BigInteger.valueOf(numberingWrapper.getAbstractNumsSize() + 10));
Enum fmt = numFmt.getLeft();
String val = numFmt.getRight();
CTLvl cTLvl = cTAbstractNum.addNewLvl();
cTLvl.addNewNumFmt().setVal(fmt);
cTLvl.addNewLvlText().setVal(val);
cTLvl.addNewStart().setVal(BigInteger.valueOf(1));
if (fmt == STNumberFormat.BULLET) {
// cTLvl.setIlvl(BigInteger.valueOf(0));
cTLvl.addNewLvlJc().setVal(STJc.LEFT);
} else {
// cTLvl.setIlvl(BigInteger.valueOf(0));
}
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
BigInteger numID = numbering.addNum(abstractNumID);
// doc.insertNewParagraph(run);
XWPFRun newRun;
for (TextRenderData line : datas) {
XWPFParagraph paragraph = doc.insertNewParagraph(run);
paragraph.setNumID(numID);
CTP ctp = paragraph.getCTP();
CTPPr pPr = ctp.isSetPPr() ? ctp.getPPr() : ctp.addNewPPr();
CTParaRPr pr = pPr.isSetRPr() ? pPr.getRPr() : pPr.addNewRPr();
StyleUtils.styleRpr(pr, fmtStyle);
newRun = paragraph.createRun();
StyleUtils.styleRun(newRun, line.getStyle());
newRun.setText(line.getText());
}
// doc.insertNewParagraph(run);
}
runTemplate.getRun().setText("", 0);
}