Example usage for org.apache.poi.xwpf.usermodel XWPFHeaderFooter getTables

List of usage examples for org.apache.poi.xwpf.usermodel XWPFHeaderFooter getTables

Introduction

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

Prototype

public List<XWPFTable> getTables() throws ArrayIndexOutOfBoundsException 

Source Link

Document

Return the table(s) that holds the text of the header or footer, for complex cases where a paragraph isn't used.

Usage

From source file:org.obeonetwork.m2doc.generator.M2DocEvaluator.java

License:Open Source License

@Override
public IConstruct caseTable(Table table) {
    // Create the table structure in the destination document.

    CTTbl copy = (CTTbl) table.getTable().getCTTbl().copy();
    copy.getTrList().clear();//from   w  ww. ja  va 2 s . com
    if (generatedDocument instanceof XWPFDocument) {
        currentGeneratedTable = ((XWPFDocument) generatedDocument).createTable();
        if (currentGeneratedTable.getRows().size() > 0) {
            currentGeneratedTable.removeRow(0);
        }
        currentGeneratedTable.getCTTbl().set(copy);
    } else if (generatedDocument instanceof XWPFHeaderFooter) {
        final XWPFHeaderFooter headerFooter = (XWPFHeaderFooter) generatedDocument;
        final int index = headerFooter._getHdrFtr().getTblArray().length;
        final CTTbl cttbl = headerFooter._getHdrFtr().insertNewTbl(index);
        XWPFTable newTable = new XWPFTable(cttbl, headerFooter);
        if (newTable.getRows().size() > 0) {
            newTable.removeRow(0);
        }
        headerFooter.insertTable(index, newTable);
        currentGeneratedTable = headerFooter.getTables().get(index);
        currentGeneratedTable.getCTTbl().set(copy);
    } else if (generatedDocument instanceof XWPFTableCell) {
        XWPFTableCell tCell = (XWPFTableCell) generatedDocument;
        int tableRank = tCell.getTables().size();
        XWPFTable newTable = new XWPFTable(copy, tCell, 0, 0);
        if (newTable.getRows().size() > 0) {
            newTable.removeRow(0);
        }
        tCell.insertTable(tableRank, newTable);
        currentGeneratedTable = tCell.getTables().get(tableRank);
    } else {
        throw new UnsupportedOperationException("unknown type of IBody : " + generatedDocument.getClass());
    }
    // iterate on the row
    for (Row row : table.getRows()) {
        doSwitch(row);
    }

    return table;
}