Example usage for org.apache.poi.ss.usermodel Row getRowNum

List of usage examples for org.apache.poi.ss.usermodel Row getRowNum

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Row getRowNum.

Prototype

int getRowNum();

Source Link

Document

Get row number this row represents

Usage

From source file:org.dbflute.helper.io.xls.DfTableXlsReader.java

License:Apache License

protected void throwCellValueHandlingException(DfDataTable table, DfDataColumn column, Row row, Cell cell,
        Object value, RuntimeException cause) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Failed to handle the cell value on the xls file.");
    br.addItem("Advice");
    br.addElement("Confirm the exception message.");
    br.addElement("The cell value may be wrong type for the column.");
    br.addElement("So confirm the value on the xls file.");
    br.addItem("RuntimeException");
    br.addElement(cause.getMessage());/*from  w ww .j  a v  a 2s  .co m*/
    br.addItem("Xls File");
    br.addElement(_xlsFile);
    br.addItem("Table");
    br.addElement(table.getTableDbName());
    br.addItem("Column");
    br.addElement(column != null ? column.getColumnDbName() : null);
    br.addItem("Mapping Type");
    final DfDtsColumnType columnType = column.getColumnType();
    br.addElement(columnType != null ? columnType.getType() : null);
    br.addItem("Cell Type");
    if (cell != null) {
        switch (cell.getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:
            br.addElement("CELL_TYPE_NUMERIC");
            break;
        case Cell.CELL_TYPE_STRING:
            br.addElement("CELL_TYPE_STRING");
            break;
        case Cell.CELL_TYPE_FORMULA:
            br.addElement("CELL_TYPE_FORMULA");
            break;
        case Cell.CELL_TYPE_BLANK:
            br.addElement("CELL_TYPE_BLANK");
            break;
        case Cell.CELL_TYPE_BOOLEAN:
            br.addElement("CELL_TYPE_BOOLEAN");
            break;
        case Cell.CELL_TYPE_ERROR:
            br.addElement("CELL_TYPE_ERROR");
            break;
        default:
            br.addElement(cell.getCellType());
            break;
        }
    }
    br.addItem("Cell Value");
    br.addElement(value);
    br.addItem("Row Number");
    br.addElement(column != null ? row.getRowNum() : null);
    final String msg = br.buildExceptionMessage();
    throw new DfXlsReaderReadFailureException(msg, cause);
}

From source file:org.dbflute.helper.io.xls.DfTableXlsReader.java

License:Apache License

protected void throwLargeDataReferenceDataNotFoundException(DfDataTable table, int columnIndex, Row row,
        String str, String dataKey) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Not found the reference data of large data for the column.");
    br.addItem("Xls File");
    br.addElement(_xlsFile);/*from  ww  w . java2  s  .c om*/
    br.addItem("Table Name");
    br.addElement(table.getTableDbName());
    br.addItem("Column");
    br.addElement(table.getColumnName(columnIndex));
    br.addItem("Row Number");
    br.addElement(row.getRowNum());
    br.addItem("Cell Value");
    br.addElement(str);
    br.addItem("Data Key");
    br.addElement(dataKey);
    final String msg = br.buildExceptionMessage();
    throw new DfXlsReaderReadFailureException(msg);
}

From source file:org.dbflute.helper.io.xls.DfTableXlsWriter.java

License:Apache License

protected String resolveLargeDataReferenceIfNeeds(DfDataTable table, int columnIndex, Row row,
        String strValue) {/*from www  .j a  v  a 2  s .c o m*/
    final String mark = "...";
    final int splitLength = getCellLengthLimit() - mark.length();
    if (strValue != null && strValue.length() > splitLength) {
        final String filteredValue;
        if (_largeDataHandling) {
            if (_largeDataMap == null) {
                _largeDataMap = StringKeyMap.createAsFlexibleOrdered();
            }
            final String tableDbName = table.getTableDbName();
            final DfDataColumn column = table.getColumn(columnIndex);
            final String columnDbName = column.getColumnDbName();
            final String columnTitle = tableDbName + "." + columnDbName;
            Map<String, List<String>> dataMap = _largeDataMap.get(columnTitle);
            if (dataMap == null) {
                dataMap = DfCollectionUtil.newLinkedHashMap();
                _largeDataMap.put(columnTitle, dataMap);
            }
            final String plainKey = columnTitle + ":" + row.getRowNum();
            final String dataKey = Integer.toHexString(plainKey.hashCode());
            dataMap.put(dataKey, toLargeDataSplitList(strValue));
            filteredValue = toLargeDataReferenceExp(dataKey);
        } else {
            filteredValue = strValue.substring(0, splitLength) + mark;
        }
        return filteredValue;
    }
    return strValue;
}

From source file:org.dhatim.fastexcel.reader.BenchmarksTest.java

License:Apache License

@Benchmark
public long monitorjbl() throws IOException {
    long sum = 0;
    try (InputStream is = openResource(FILE);
            org.apache.poi.ss.usermodel.Workbook workbook = StreamingReader.builder().open(is)) {
        for (org.apache.poi.ss.usermodel.Sheet sheet : workbook) {
            for (org.apache.poi.ss.usermodel.Row r : sheet) {
                if (r.getRowNum() == 0) {
                    continue;
                }//from   ww  w .j a  v a2 s  . co  m
                sum += r.getCell(0).getNumericCellValue();
            }
        }
    }
    assertEquals(RESULT, sum);
    return sum;
}

From source file:org.dhatim.fastexcel.reader.FastExcelReaderTest.java

License:Apache License

@Test
public void testDates() throws IOException, OpenXML4JException {
    ArrayList<RowDates> values = new ArrayList<>();

    try (InputStream inputStream = open(EXCEL_DATES);
            ReadableWorkbook fworkbook = new ReadableWorkbook(inputStream)) {
        try (Stream<Row> stream = fworkbook.getFirstSheet().openStream()) {
            stream.forEach(row -> {/*from   ww  w  .j av  a2 s .  co  m*/
                values.add(new RowDates(row.getRowNum(), row.getCell(0).asDate().toString(),
                        row.getCell(1).asDate().toString()));
            });
        }
    }

    ArrayList<RowDates> wvalues = new ArrayList<>();
    try (InputStream inputStream = open(EXCEL_DATES); Workbook workbook = WorkbookFactory.create(inputStream)) {
        for (org.apache.poi.ss.usermodel.Row row : workbook.getSheetAt(0)) {
            wvalues.add(new RowDates(row.getRowNum() + 1, toODT(row.getCell(0).getDateCellValue()),
                    toODT(row.getCell(1).getDateCellValue())));
        }
    }

    for (int i = 0; i < values.size(); i++) {
        if (!values.get(i).equals(wvalues.get(i))) {
            assertThat(values.get(i)).isEqualTo(wvalues.get(i));
        }
    }
}

From source file:org.diffkit.diff.sns.DKPoiSheet.java

License:Apache License

/**
 * if hasRowNum_, types_[0] will represent the ROW_NUM column
 *//*from w w w  .  jav a 2 s  .  c o  m*/
private static Object[] readRow(Row row_, Type[] types_, boolean hasRowNum_) {
    if (IS_DEBUG_ENABLED) {
        LOG.debug("types_->{}", Arrays.toString(types_));
        LOG.debug("hasRowNum_->{}", hasRowNum_);
    }
    if ((row_ == null) || (types_ == null))
        return null;
    Object[] result = new Object[types_.length];
    if (hasRowNum_)
        result[0] = (Integer) row_.getRowNum() + 1;

    for (int colIdx = (hasRowNum_ ? 1 : 0), cellIdx = 0; colIdx < types_.length; colIdx++, cellIdx++)
        result[colIdx] = readCell(row_.getCell(cellIdx), types_[colIdx]);

    return result;
}

From source file:org.drools.informer.load.spreadsheet.SpreadsheetData.java

License:Apache License

/**
 * Will split the sheet from the workbook up into {@link SpreadsheetRow} and {@link SpreadsheetItem}
 * //from   ww  w. j  a v a2 s .  c om
 * @param sheet
 */
public SpreadsheetData(HSSFSheet sheet) {
    super();
    sheetName = sheet.getSheetName();
    for (Row row : sheet) {
        int rowNumber = row.getRowNum();
        SpreadsheetRow rowItems = new SpreadsheetRow(rowNumber);
        rows.add(rowItems);
        for (Cell cell : row) {
            if ((cell == null) || (cell.getCellType() == Cell.CELL_TYPE_BLANK)) {
                // null check is just in case - should never be!
                continue;
            }
            if ((keyColumn > 0) && (cell.getColumnIndex() < keyColumn)) {
                // comments column
                continue;
            }
            SpreadsheetItem item = new SpreadsheetItem(sheet.getSheetName(), cell);
            if (firstItemOnSheet == null) {
                // The first cell item must be sheet identifier/heading - previous columns will be treated as comments
                // and thus ignored
                firstItemOnSheet = item;
                keyColumn = cell.getColumnIndex();
            }
            String id = item.getCellIdentifier();

            //System.out.println("Sheet:" + sheet.getSheetName() + ", id=" + id + ", toString=" + item.toString());
            data.put(id, item);
            rowItems.addRowItem(item);
            cellList.add(item.getCellIdentifier());
        }
    }
}

From source file:org.drools.scorecards.parser.xls.XLSScorecardParser.java

License:Apache License

private void processSheet(HSSFSheet worksheet) throws ScorecardParseException {
    for (Row row : worksheet) {
        int currentRowCtr = row.getRowNum();
        excelDataCollector.newRow(currentRowCtr);
        for (Cell cell : row) {
            int currentColCtr = cell.getColumnIndex();
            switch (cell.getCellType()) {
            case Cell.CELL_TYPE_STRING:
                excelDataCollector.newCell(currentRowCtr, currentColCtr, cell.getStringCellValue());
                break;
            case Cell.CELL_TYPE_NUMERIC:
                if (DateUtil.isCellDateFormatted(cell)) {
                    excelDataCollector.newCell(currentRowCtr, currentColCtr, cell.getDateCellValue());
                } else {
                    excelDataCollector.newCell(currentRowCtr, currentColCtr,
                            Double.valueOf(cell.getNumericCellValue()));
                }/*w w  w  .  j a  v  a  2  s.  c  o  m*/
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                excelDataCollector.newCell(currentRowCtr, currentColCtr,
                        Boolean.valueOf(cell.getBooleanCellValue()).toString());
                break;
            case Cell.CELL_TYPE_FORMULA:
                break;
            case Cell.CELL_TYPE_BLANK:
                excelDataCollector.newCell(currentRowCtr, currentColCtr, "");
                break;
            }
        }
    }
}

From source file:org.drugepi.table.ExcelUtils.java

License:Mozilla Public License

public static Cell getColumnParentCell(Sheet sheet, Row row, Cell cell) throws Exception {
    if (row.getRowNum() == 0)
        return null;

    if (cell == null)
        return null;

    Row prevRow = sheet.getRow(row.getRowNum() - 1);
    if (prevRow == null)
        return null;

    Cell parentCell = null;/*ww  w. j  a v a  2s.c  om*/
    int lookupIndex = cell.getColumnIndex();
    while (lookupIndex >= 0) {
        parentCell = prevRow.getCell(lookupIndex);

        if (parentCell == null)
            break;

        if ((cellIsColumnDefinition(parentCell)) && (!cellIsEmpty(parentCell)))
            return parentCell;

        lookupIndex--;
    }

    return null;
}

From source file:org.drugepi.table.ExcelUtils.java

License:Mozilla Public License

public static Cell getRowParentCell(Sheet sheet, Row row, Cell cell) throws Exception {
    if (row.getRowNum() == 0)
        return null;

    if (cell == null)
        return null;

    int prevCol = cell.getColumnIndex() - 1;
    if (prevCol < 0)
        return null;

    Cell parentCell = null;//w  w w. j a  v  a2  s.co m
    for (int i = row.getRowNum() - 1; i >= 0; i--) {
        Row searchRow = sheet.getRow(i);
        if (searchRow != null) {
            parentCell = searchRow.getCell(prevCol);

            if ((cellIsRowDefinition(parentCell)) && (!cellIsEmpty(parentCell)))
                return parentCell;
        }
    }

    return null;
}