Package org.apache.poi.xwpf.usermodel

Examples of org.apache.poi.xwpf.usermodel.XWPFTableRow


        if (columnDataList == null) {
            return;
        }
        // iterate rows
        for (int rowC = 0; rowC < ctTbl.sizeOfTrArray(); rowC++) {
            XWPFTableRow tabRow = getTable().getRow(rowC);
            CTRow ctRow = tabRow.getCtRow();

            // if it is specified in meta tag get reference column
            // otherwise it is the last column of row
            int tempCellC = tabRow.getTableCells().size() - 1;
            if (dynamicColumnIndex != -1) {
                tempCellC = dynamicColumnIndex;
            }

            // we need to backup static columns of cell

            // TODO what will we do if colstart index bigger than column index?
            if (tempCellC > tabRow.getCtRow().sizeOfTcArray()) {
                continue;
            }

            // create dynamic columns
            int dynamicColumnAddIndex = 0;
            try {
                dynamicColumnAddIndex = getDynamicColumnAddIndex(tabRow, dynamicColumnIndex);
            } catch (OrcaReportRendererException e) {
                e.printStackTrace();
            }

            //check if row needs to be iterated or stretched.
            if (tabRow.getCell(dynamicColumnAddIndex).getCTTc().getTcPr().isSetGridSpan()) {
                BigInteger gridSpanVal = tabRow.getCell(dynamicColumnAddIndex).getCTTc().getTcPr().getGridSpan().getVal();
                tabRow.getCell(dynamicColumnAddIndex).getCTTc().getTcPr().getGridSpan().setVal(gridSpanVal.add(BigInteger.valueOf(columnDataList.size() - 1)));
            } else {
                XWPFTableCell tempCell = tabRow.getCell(dynamicColumnAddIndex);
                //add new cells to the row.
                for (int colC = 0; colC < columnDataList.size() - 1; colC++) {
                    XWPFTableCell tableCell = new XWPFTableCell(ctRow.insertNewTc(dynamicColumnAddIndex + colC), tabRow, getTable().getBody());
                    tabRow.getTableCells().add(dynamicColumnAddIndex + colC, tableCell);
                    DocXEngine.copyCell(tempCell, tableCell);
                }
            }
        }
    }
View Full Code Here


        }

        // we need to backup static rows of table
        int dynamicRowAddC = tempRowC + 1;

        XWPFTableRow tempRow = getTable().getRow(tempRowC);

        // create dynamic columns
        for (int rowC = 0; rowC < (rowDataList.size() - 1); rowC++) {
            //XWPFTableRow newRow = new XWPFTableRow(tempRow.getCtRow(), getTable());
            XWPFTableRow newRow = getTable().insertNewTableRow(dynamicRowAddC);
            for (XWPFTableCell cell : tempRow.getTableCells()) {
                XWPFTableCell newCell = newRow.createCell();
                DocXEngine.copyCell(cell, newCell);
            }
        }
        dynamicRowIndex = tempRowC;
    }
View Full Code Here

  {
    XWPFDocument document = new XWPFDocument();
   
    // New 2x2 table
    XWPFTable tableOne = document.createTable();
    XWPFTableRow tableOneRowOne = tableOne.getRow(0);
    tableOneRowOne.getCell(0).setText("Hello");
    tableOneRowOne.addNewTableCell().setText("World");
   
    XWPFTableRow tableOneRowTwo = tableOne.createRow();
    tableOneRowTwo.getCell(0).setText("This is");
    tableOneRowTwo.getCell(1).setText("a table");
   
    // Add a break between the tables
    document.createParagraph().createRun().addBreak();
   
    // New 3x3 table
    XWPFTable tableTwo = document.createTable();
    XWPFTableRow tableTwoRowOne = tableTwo.getRow(0);
    tableTwoRowOne.getCell(0).setText("col one, row one");
    tableTwoRowOne.addNewTableCell().setText("col two, row one");
    tableTwoRowOne.addNewTableCell().setText("col three, row one");
   
    XWPFTableRow tableTwoRowTwo = tableTwo.createRow();
    tableTwoRowTwo.getCell(0).setText("col one, row two");
    tableTwoRowTwo.getCell(1).setText("col two, row two");
    tableTwoRowTwo.getCell(2).setText("col three, row two");
   
    XWPFTableRow tableTwoRowThree = tableTwo.createRow();
    tableTwoRowThree.getCell(0).setText("col one, row three");
    tableTwoRowThree.getCell(1).setText("col two, row three");
    tableTwoRowThree.getCell(2).setText("col three, row three");
   
    FileOutputStream outStream = new FileOutputStream("data/Apache_CreateTable.doc");
    document.write(outStream);
    outStream.close();
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.xwpf.usermodel.XWPFTableRow

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.