Example usage for org.apache.poi.xwpf.usermodel XWPFTable getNumberOfRows

List of usage examples for org.apache.poi.xwpf.usermodel XWPFTable getNumberOfRows

Introduction

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

Prototype

public int getNumberOfRows() 

Source Link

Usage

From source file:apachepoitest.DocumentPropertyEnumerator.java

public static void showTableProperties(List<XWPFTable> lt) {
    for (XWPFTable t : lt) {
        System.out.println("TABLE: ");
        //Not yet needed
        //System.out.println("COL BAND SIZE: " + t.getColBandSize());
        //System.out.println("ROW BAND SIZE: " + t.getRowBandSize());
        System.out.println("NO. OF ROWS: " + t.getNumberOfRows());
        System.out.println("WIDTH: " + t.getWidth());
    }//www  .  j  a v  a  2  s .  c o  m
}

From source file:cn.afterturn.easypoi.word.parse.ParseWord07.java

License:Apache License

/**
 * ?/*from  w  w  w  .ja va 2s.  com*/
 *
 * @param table
 * @param map
 * @author JueYue
 * 2013-11-17
 */
private void parseThisTable(XWPFTable table, Map<String, Object> map) throws Exception {
    XWPFTableRow row;
    List<XWPFTableCell> cells;
    Object listobj;
    for (int i = 0; i < table.getNumberOfRows(); i++) {
        row = table.getRow(i);
        cells = row.getTableCells();
        listobj = checkThisTableIsNeedIterator(cells.get(0), map);
        if (listobj == null) {
            parseThisRow(cells, map);
        } else if (listobj instanceof ExcelListEntity) {
            new ExcelEntityParse().parseNextRowAndAddRow(table, i, (ExcelListEntity) listobj);
            i = i + ((ExcelListEntity) listobj).getList().size() - 1;//??,?
        } else {
            ExcelMapParse.parseNextRowAndAddRow(table, i, (List) listobj);
            i = i + ((List) listobj).size() - 1;//??,?
        }
    }
}

From source file:com.qihang.winter.poi.word.parse.ParseWord07.java

License:Apache License

/**
 * ?/*from w  w  w.ja  va 2 s.c  o m*/
 * 
 * @author Zerrion
 * @date 2013-11-17
 * @param table
 * @param map
 */
private void parseThisTable(XWPFTable table, Map<String, Object> map) throws Exception {
    XWPFTableRow row;
    List<XWPFTableCell> cells;
    Object listobj;
    ExcelEntityParse excelEntityParse = new ExcelEntityParse();
    for (int i = 0; i < table.getNumberOfRows(); i++) {
        row = table.getRow(i);
        cells = row.getTableCells();
        if (cells.size() == 1) {
            listobj = checkThisTableIsNeedIterator(cells.get(0), map);
            if (listobj == null) {
                parseThisRow(cells, map);
            } else if (listobj instanceof ExcelListEntity) {
                table.removeRow(i);// 
                excelEntityParse.parseNextRowAndAddRow(table, i, (ExcelListEntity) listobj);
            } else {
                table.removeRow(i);// 
                ExcelMapParse.parseNextRowAndAddRow(table, i, (List) listobj);
            }
        } else {
            parseThisRow(cells, map);
        }
    }
}

From source file:com.validation.manager.core.tool.table.extractor.TableExtractor.java

License:Apache License

private File writeTablesToFile() throws IOException {
    File temp = createTempFile("table", null);
    temp.createNewFile();/* www  .java  2  s.c om*/
    temp.deleteOnExit();
    List<DefaultTableModel> tables = new ArrayList<>();
    for (XWPFTable table : extractTablesFromWord()) {
        //Build the table
        int rows = table.getNumberOfRows();
        int columns = table.getRow(0).getTableCells().size();
        Object[][] data = new Object[rows][columns];
        String[] title = new String[columns];
        for (int i = 0; i < columns; i++) {
            title[i] = format("Column {0}", i + 1);
        }
        //Row 0 for mapping field
        int rowNum = 0;
        int columnNum;
        for (XWPFTableRow row : table.getRows()) {
            columnNum = 0;
            for (XWPFTableCell cell : row.getTableCells()) {
                data[rowNum][columnNum] = cell.getText();
                columnNum++;
            }
            rowNum++;
        }
        //Rebuild the table model to fit this table
        tables.add(new DefaultTableModel(data, title));
    }
    FileOutputStream fileOut = null;
    ObjectOutputStream output = null;
    try {
        fileOut = new FileOutputStream(temp);
        output = new ObjectOutputStream(fileOut);
        output.writeObject(tables);
        output.flush();
    } finally {
        if (output != null) {
            output.close();
        }
        if (fileOut != null) {
            fileOut.close();
        }
    }
    return temp;
}

From source file:File.DOCX.ReadDocx.java

public void ReadTable(String path, String filename) {
    try {//  w ww  .  j  a  va 2 s.  co m
        FileInputStream fis = new FileInputStream(path + filename + ".docx");
        XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis));
        Iterator<IBodyElement> bodyElementIterator = xdoc.getBodyElementsIterator();
        while (bodyElementIterator.hasNext()) {
            IBodyElement element = bodyElementIterator.next();
            if ("TABLE".equalsIgnoreCase(element.getElementType().name())) {
                List<XWPFTable> tableList = element.getBody().getTables();
                for (XWPFTable table : tableList) {
                    System.out.println("Total Number of Rows of Table:" + table.getNumberOfRows());
                    System.out.println(table.getText());
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

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

License:Open Source License

public static XWPFTableRow getFirstRow(XWPFTable table) {
    int numberOfRows = table.getNumberOfRows();
    if (numberOfRows > 0) {
        return table.getRow(0);
    }/*ww  w.  j  a  v  a2  s  .c  o m*/
    return null;
}

From source file:offishell.word.WordHeleper.java

License:MIT License

/**
 * <p>//from w w w .j a v a2s. c o  m
 * Helper method to clone {@link XWPFTable}.
 * </p>
 * 
 * @param in
 * @param out
 * @param converter
 */
public static void copy(XWPFTable in, XWPFTable out, UnaryOperator<String> converter) {
    // copy context
    CTTbl outCT = out.getCTTbl();

    CTTblPr outPR = outCT.getTblPr() != null ? outCT.getTblPr() : outCT.addNewTblPr();
    outPR.set(in.getCTTbl().getTblPr());

    // copy children
    for (XWPFTableRow inRow : in.getRows()) {
        copy(inRow, out.insertNewTableRow(out.getNumberOfRows()), converter);
    }
}

From source file:org.articleEditor.insertContent.POIDocxReader.java

License:Apache License

protected void processTable(XWPFTable table) throws BadLocationException {
    int rowCount = table.getNumberOfRows();
    int columnCount = 0;
    for (XWPFTableRow row : table.getRows()) {
        columnCount = Math.max(columnCount, row.getTableCells().size());
    }//from w w  w.jav  a2 s .  c o m
    int[] rowsHeight = new int[rowCount];
    int[] columnsWidth = new int[columnCount];
    for (int i = 0; i < rowCount; i++) {
        rowsHeight[i] = 1;
    }
    for (int i = 0; i < columnCount; i++) {
        List<CTTblGridCol> colList = table.getCTTbl().getTblGrid().getGridColList();
        columnsWidth[i] = colList.get(i).getW().intValue() / INDENTS_MULTIPLIER;
    }
    SimpleAttributeSet tableAttrs = new SimpleAttributeSet();
    document.insertTable(currentOffset, rowCount, columnCount, tableAttrs, columnsWidth, rowsHeight);
    for (XWPFTableRow row : table.getRows()) {
        for (XWPFTableCell cell : row.getTableCells()) {
            iteratePart(cell.getBodyElements());
            currentOffset++;
        }
    }
}

From source file:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

public void tableA1AnnualReportStyle(XWPFTable table) {
    /* horizontal merge, From format tables A1 */

    for (int x = 0; x < table.getNumberOfRows(); x++) {
        XWPFTableRow row = table.getRow(x);
        for (int y = 0; y < row.getTableCells().size(); y++) {
            XWPFTableCell cell = row.getCell(y);
            CTTblWidth cellWidth = cell.getCTTc().addNewTcPr().addNewTcW();

            CTTcPr pr = cell.getCTTc().addNewTcPr();
            // pr.addNewNoWrap();
            cellWidth.setW(BigInteger.valueOf(100));
        }//from   w  ww.jav a 2  s  .c om
    }
}

From source file:org.cgiar.ccafs.marlo.utils.POISummary.java

License:Open Source License

public void tableAStyle(XWPFTable table) {
    /* Horizontal merge, From format tables A */
    CTVMerge vmerge = CTVMerge.Factory.newInstance();
    CTVMerge vmerge1 = CTVMerge.Factory.newInstance();

    for (int x = 0; x < table.getNumberOfRows(); x++) {
        if (x > 0) {
            XWPFTableRow row = table.getRow(x);
            for (int y = 0; y < 2; y++) {
                XWPFTableCell cell = row.getCell(y);

                if (cell.getCTTc() == null) {
                    ((CTTc) cell).addNewTcPr();
                }//from ww w.  j a v  a 2  s  . co  m

                if (cell.getCTTc().getTcPr() == null) {
                    cell.getCTTc().addNewTcPr();
                }
                if (x == 1 && !(cell.getText().trim().length() > 0)) {
                    break;
                }
                if (cell.getText().trim().length() > 0) {
                    if (y == 0) {
                        cell.getCTTc().getTcPr().addNewTcW().setW(BigInteger.valueOf(1500));
                    }
                    vmerge.setVal(STMerge.RESTART);
                    cell.getCTTc().getTcPr().setVMerge(vmerge);
                } else {
                    if (y == 0) {
                        cell.getCTTc().getTcPr().addNewTcW().setW(BigInteger.valueOf(1500));
                    }
                    vmerge1.setVal(STMerge.CONTINUE);
                    cell.getCTTc().getTcPr().setVMerge(vmerge1);
                }
            }

        }
    }
}