Example usage for org.apache.poi.xwpf.usermodel XWPFDocument setTable

List of usage examples for org.apache.poi.xwpf.usermodel XWPFDocument setTable

Introduction

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

Prototype

public void setTable(int pos, XWPFTable table) 

Source Link

Document

Replace content of table in array tables at position pos with a

Usage

From source file:biz.webgate.dominoext.poi.component.kernel.DocumentProcessor.java

License:Apache License

public XWPFDocument processDocument(ITemplateSource itsCurrent, List<IDocumentBookmark> bookmarks,
        List<DocumentTable> tables, FacesContext context, UIDocument uiDocument) throws POIException {

    Logger logCurrent = LoggerFactory.getLogger(this.getClass().getCanonicalName());

    InputStream is = itsCurrent.getFileStream();
    XWPFDocument dxDocument = getDocument(is);
    itsCurrent.cleanUP();//from   ww w.  j  a v  a2 s  .  c  om
    if (bookmarks != null && bookmarks.size() > 0) {
        processBookmarks2Document(dxDocument, bookmarks);
    }
    logCurrent.finest("Start export Tables");
    if (tables != null && tables.size() > 0) {
        for (DocumentTable tblExport : tables) {
            XWPFTable dxTable = EmbeddedDataSourceExportProcessor.getInstance().processExportTable(tblExport,
                    dxDocument, context, tblExport.getVar(), tblExport.getIndex());
            logCurrent.finest("exportTable created");
            // logCurrent.finer("Start Processing Cells");
            if (tblExport.getDocCellValues() != null && tblExport.getDocCellValues().size() > 0) {
                for (ICellValue iCV : tblExport.getDocCellValues()) {
                    if (iCV instanceof DocCellValue) {
                        DocCellValue cv = (DocCellValue) iCV;
                        if (cv.getRowNumber() <= tblExport.getMaxRow()) {
                            DocumentProcessor.setDocCellValue(dxTable, cv.getRowNumber(), cv.getColumnNumber(),
                                    cv.getValue(), tblExport.getMaxRow(), false);
                        } else {
                            logCurrent.finer("MaxValue < CellValue.getRowNumber()");
                        }
                    }
                }

            }
            if (dxTable != null) {
                logCurrent.finest("Set Table Position");
                if (tblExport.getTableNr() != 0) {
                    dxDocument.setTable(tblExport.getTableNr(), dxTable);
                    dxDocument.removeBodyElement(dxDocument.getPosOfTable(dxTable));
                }
            }
            /*
             * if (dxTable != null) { System.out.println("Insert Table");
             * dxDocument.insertTable(2, dxTable); }
             */
            // System.out.println(dxDocument.getPosOfParagraph(p));

            // logCurrent.finer("Proccess Export Cells - DONE");
        }

    }

    if (uiDocument != null) {
        uiDocument.postGenerationProcess(context, dxDocument);
    }
    return dxDocument;
}