Example usage for org.apache.poi.xwpf.usermodel IBody getPartType

List of usage examples for org.apache.poi.xwpf.usermodel IBody getPartType

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel IBody getPartType.

Prototype

public BodyType getPartType();

Source Link

Document

get the PartType of the body, for example DOCUMENT, HEADER, FOOTER, FOOTNOTE,

Usage

From source file:fr.opensagres.poi.xwpf.converter.core.utils.StylesHelper.java

License:Open Source License

public static XWPFTableCell getEmbeddedTableCell(XWPFParagraph paragraph) {
    IBody body = paragraph.getBody();
    if (body != null && body.getPartType() == BodyType.TABLECELL) {
        return (XWPFTableCell) body;
    }//from   w  ww  .  j  a  v a 2  s .  c o m
    return null;
}

From source file:fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.java

License:Open Source License

/**
 * Returns true if the given paragraph which is empty (none <w:r> run) must generate new line and false otherwise.
 * //from w  w  w .j av  a  2 s . co m
 * @param paragraph
 * @param index
 * @return
 */
private boolean isAddNewLine(XWPFParagraph paragraph, int index) {
    // a new line must be generated if :
    // - there is next paragraph/table
    // - if the body is a cell (with none vMerge) and contains just this paragraph
    IBody body = paragraph.getBody();
    List<IBodyElement> bodyElements = body.getBodyElements();
    if (body.getPartType() == BodyType.TABLECELL && bodyElements.size() == 1) {
        XWPFTableCell cell = (XWPFTableCell) body;
        STMerge.Enum vMerge = stylesDocument.getTableCellVMerge(cell);
        if (vMerge != null && vMerge.equals(STMerge.CONTINUE)) {
            // here a new line must not be generated because the body is a cell (with none vMerge) and contains just
            // this paragraph
            return false;
        }
        // Loop for each cell of the row : if all cells are empty, new line must be generated otherwise none empty
        // line must be generated.
        XWPFTableRow row = cell.getTableRow();
        List<XWPFTableCell> cells = row.getTableCells();
        for (XWPFTableCell c : cells) {
            if (c.getBodyElements().size() != 1) {
                return false;
            }
            IBodyElement element = c.getBodyElements().get(0);
            if (element.getElementType() != BodyElementType.PARAGRAPH) {
                return false;
            }
            return ((XWPFParagraph) element).getRuns().size() == 0;
        }
        return true;

    }
    // here a new line must be generated if there is next paragraph/table
    return bodyElements.size() > index + 1;
}