Java Code Examples for org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP#getPPr()

The following examples show how to use org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP#getPPr() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyleUtils.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
public static void styleTableParagraph(XWPFParagraph par, TableStyle style) {
    if (null != par && null != style && null != style.getAlign()) {
        CTP ctp = par.getCTP();
        CTPPr CTPpr = ctp.isSetPPr() ? ctp.getPPr() : ctp.addNewPPr();
        CTJc jc = CTPpr.isSetJc() ? CTPpr.getJc() : CTPpr.addNewJc();
        jc.setVal(style.getAlign());
    }

}
 
Example 2
Source File: StyleUtils.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
public static void styleParagraph(XWPFParagraph paragraph, Style style) {
    if (null == paragraph || null == style) return;
    CTP ctp = paragraph.getCTP();
    CTPPr pPr = ctp.isSetPPr() ? ctp.getPPr() : ctp.addNewPPr();
    CTParaRPr pr = pPr.isSetRPr() ? pPr.getRPr() : pPr.addNewRPr();
    StyleUtils.styleRpr(pr, style);
}
 
Example 3
Source File: NumberingContinue.java    From poi-tl with Apache License 2.0 4 votes vote down vote up
public static NumberingContinue of(BodyContainer bodyContainer, int start, int end, IterableTemplate iterable) {
    if (start + 1 >= end) return new NumberingContinue();

    final List<IBodyElement> elements = bodyContainer.getBodyElements().subList(start + 1, end);
    if (elements.isEmpty()) return new NumberingContinue();

    CTNumPr first = null;
    int firstPos = -1;
    for (IBodyElement element : elements) {
        if (element.getElementType() == BodyElementType.PARAGRAPH) {
            XWPFParagraph paragraph = (XWPFParagraph) element;
            CTP ctp = paragraph.getCTP();
            if (ctp.getPPr() != null && ctp.getPPr().getNumPr() != null) {
                CTNumPr numPr = ctp.getPPr().getNumPr();
                // find first
                if (null == first) {
                    first = numPr;
                    firstPos = bodyContainer.getPosOfParagraphCTP(ctp);
                } else {
                    // first is not unique
                    if ((Objects.equals(numPr.getIlvl().getVal(), first.getIlvl().getVal())
                            && Objects.equals(numPr.getNumId().getVal(), first.getNumId().getVal()))) {
                        first = null;
                        break;
                    }
                }
            }
        }
    }
    if (null == first) return new NumberingContinue();

    // the first is unique, if first inside other iterable section
    List<MetaTemplate> templates = iterable.getTemplates();
    for (MetaTemplate template : templates) {
        if (template instanceof IterableTemplate) {
            CTP startCtp = ((XWPFParagraph) ((IterableTemplate) template).getStartRun().getParent()).getCTP();
            CTP endCtp = ((XWPFParagraph) ((IterableTemplate) template).getEndRun().getParent()).getCTP();

            int startPos = bodyContainer.getPosOfParagraphCTP(startCtp);
            if (startPos >= firstPos) break;

            int endPos = bodyContainer.getPosOfParagraphCTP(endCtp);
            if (firstPos > startPos && firstPos < endPos) { return new NumberingContinue(); }
        }
    }
    return new NumberingContinue(first.getNumId().getVal());
}