Example usage for org.apache.poi.ss.usermodel Cell getColumnIndex

List of usage examples for org.apache.poi.ss.usermodel Cell getColumnIndex

Introduction

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

Prototype

int getColumnIndex();

Source Link

Document

Returns column index of this cell

Usage

From source file:at.mukprojects.exclycore.dao.XLSXReader.java

License:Open Source License

private ExclyDouble readDouble(Cell cell, int type) throws Exception {
    ExclyDouble output = null;/*from  w  w  w .  ja v  a  2  s .com*/

    if (type == Cell.CELL_TYPE_STRING) {
        String data = cell.getStringCellValue();
        if (isNumericGerman(data)) {
            Number number = NumberFormat.getNumberInstance(Locale.GERMAN).parse(data);
            output = new ExclyDouble(number.doubleValue());
        } else if (isNumericUK(data)) {
            Number number = NumberFormat.getNumberInstance(Locale.UK).parse(data);
            output = new ExclyDouble(number.doubleValue());
        } else if (data.equals("") || data.equals(" ") || data.equals("-")) {
            output = new ExclyDoubleBlank();
        } else {
            output = new ExclyDoubleError();
            log.warn("The reader has expected a numeric value, but found a string value. [Row, Column] ("
                    + cell.getRowIndex() + ", " + cell.getColumnIndex() + ")");
        }
    } else if (type == Cell.CELL_TYPE_BLANK) {
        output = new ExclyDoubleBlank();
    } else if (type == Cell.CELL_TYPE_FORMULA) {
        int formulaType = cell.getCachedFormulaResultType();
        output = readDouble(cell, formulaType);
    } else if (type == Cell.CELL_TYPE_BOOLEAN) {
        Boolean data = cell.getBooleanCellValue();
        if (data) {
            output = new ExclyDouble(1);
        } else {
            output = new ExclyDouble(0);
        }
    } else if (type == Cell.CELL_TYPE_NUMERIC) {
        double data = cell.getNumericCellValue();
        output = new ExclyDouble(data);
    } else if (type == Cell.CELL_TYPE_ERROR) {
        output = new ExclyDoubleError();
    } else {
        log.warn("The reader was unable to find a valid parser for the cell [Row, Column] ("
                + cell.getRowIndex() + ", " + cell.getColumnIndex() + ")");
        output = new ExclyDoubleError();
    }

    return output;
}

From source file:at.mukprojects.exclycore.dao.XLSXReader.java

License:Open Source License

/**
 * Tries to read the value of the given cell. If it's possible to parse the
 * value into an integer it will return an ExclyInteger with the parsed
 * value. Otherwise a ExclyIntegerError or a ExclyIntegerBlank is returned,
 * depending on the cell value wasn't parsable or blank. Both have a value
 * of zero.//from ww  w .j  a  va  2s  . com
 * 
 * @param cell
 *            The Excel cell.
 * @return Return the parsed value of the cell as an ExclyInteger.
 */
public ExclyInteger readIntegerCellValue(Cell cell) {
    ExclyInteger output = null;

    if (cell == null) {
        return new ExclyIntegerError();
    }

    try {
        output = readInteger(cell, cell.getCellType());
    } catch (Exception e) {
        log.error("The reader was unable to read the data from cell [Row, Column] (" + cell.getRowIndex() + ", "
                + cell.getColumnIndex() + ")", e);
        output = new ExclyIntegerError();
    }

    return output;
}

From source file:at.mukprojects.exclycore.dao.XLSXReader.java

License:Open Source License

private ExclyInteger readInteger(Cell cell, int type) throws Exception {
    ExclyInteger output = null;//  w w  w .j  a va2 s. c o  m

    if (type == Cell.CELL_TYPE_STRING) {
        String data = cell.getStringCellValue();
        if (isNumericGerman(data)) {
            Number number = NumberFormat.getNumberInstance(Locale.GERMAN).parse(data);
            output = new ExclyInteger(number.intValue());
        } else if (isNumericUK(data)) {
            Number number = NumberFormat.getNumberInstance(Locale.UK).parse(data);
            output = new ExclyInteger(number.intValue());
        } else if (data.equals("") || data.equals(" ") || data.trim().equals("-")) {
            output = new ExclyIntegerBlank();
        } else {
            output = new ExclyIntegerError();
            log.warn("The reader has expected a numeric value, but found a string value. [Row, Column] ("
                    + cell.getRowIndex() + ", " + cell.getColumnIndex() + ")");
        }
    } else if (type == Cell.CELL_TYPE_BLANK) {
        output = new ExclyIntegerBlank();
    } else if (type == Cell.CELL_TYPE_FORMULA) {
        int formulaType = cell.getCachedFormulaResultType();
        output = readInteger(cell, formulaType);
    } else if (type == Cell.CELL_TYPE_BOOLEAN) {
        Boolean data = cell.getBooleanCellValue();
        if (data) {
            output = new ExclyInteger(1);
        } else {
            output = new ExclyInteger(0);
        }
    } else if (type == Cell.CELL_TYPE_NUMERIC) {
        double data = cell.getNumericCellValue();
        output = new ExclyInteger(data);
    } else if (type == Cell.CELL_TYPE_ERROR) {
        output = new ExclyIntegerError();
    } else {
        log.warn("The reader was unable to find a valid parser for the cell [Row, Column] ("
                + cell.getRowIndex() + ", " + cell.getColumnIndex() + ")");
        output = new ExclyIntegerError();
    }

    return output;
}

From source file:at.mukprojects.exclycore.dao.XLSXReader.java

License:Open Source License

/**
 * Tries to read the value of the given cell. If it's possible to parse the
 * value into a long it will return an ExclyLong with the parsed value.
 * Otherwise a ExclyLongError or a ExclyLongBlank is returned, depending on
 * the cell value wasn't parsable or blank. Both have a value of zero.
 * //from  w  ww.j av  a2s  .c  o  m
 * @param cell
 *            The Excel cell.
 * @return Return the parsed value of the cell as an ExclyLong.
 */
public ExclyLong readLongCellValue(Cell cell) {
    ExclyLong output = null;

    if (cell == null) {
        return new ExclyLongError();
    }

    try {
        output = readLong(cell, cell.getCellType());
    } catch (Exception e) {
        log.error("The reader was unable to read the data from cell [Row, Column] (" + cell.getRowIndex() + ", "
                + cell.getColumnIndex() + ")", e);
        output = new ExclyLongError();
    }

    return output;
}

From source file:at.mukprojects.exclycore.dao.XLSXReader.java

License:Open Source License

private ExclyLong readLong(Cell cell, int type) throws Exception {
    ExclyLong output = null;//  w w  w  .j  a v a  2s.  co m

    if (type == Cell.CELL_TYPE_STRING) {
        String data = cell.getStringCellValue();
        if (isNumericGerman(data)) {
            Number number = NumberFormat.getNumberInstance(Locale.GERMAN).parse(data);
            output = new ExclyLong(number.intValue());
        } else if (isNumericUK(data)) {
            Number number = NumberFormat.getNumberInstance(Locale.UK).parse(data);
            output = new ExclyLong(number.intValue());
        } else if (data.equals("") || data.equals(" ") || data.equals("-")) {
            output = new ExclyLongBlank();
        } else {
            output = new ExclyLongError();
            log.warn("The reader has expected a numeric value, but found a string value. [Row, Column] ("
                    + cell.getRowIndex() + ", " + cell.getColumnIndex() + ")");
        }
    } else if (type == Cell.CELL_TYPE_BLANK) {
        output = new ExclyLongBlank();
    } else if (type == Cell.CELL_TYPE_FORMULA) {
        int formulaType = cell.getCachedFormulaResultType();
        output = readLong(cell, formulaType);
    } else if (type == Cell.CELL_TYPE_BOOLEAN) {
        Boolean data = cell.getBooleanCellValue();
        if (data) {
            output = new ExclyLong(1);
        } else {
            output = new ExclyLong(0);
        }
    } else if (type == Cell.CELL_TYPE_NUMERIC) {
        double data = cell.getNumericCellValue();
        output = new ExclyLong(data);
    } else if (type == Cell.CELL_TYPE_ERROR) {
        output = new ExclyLongError();
    } else {
        log.warn("The reader was unable to find a valid parser for the cell [Row, Column] ("
                + cell.getRowIndex() + ", " + cell.getColumnIndex() + ")");
        output = new ExclyLongError();
    }

    return output;
}

From source file:at.mukprojects.exclycore.dao.XLSXReader.java

License:Open Source License

/**
 * Tries to read the value of the given cell. If it's possible to parse the
 * value into a date it will return an ExclyDate with the parsed value.
 * Otherwise a ExclyDateError or a ExclyDateBlank is returned, depending on
 * the cell value wasn't parsable or blank. Both have a value of null.
 * //from w w  w  .java 2  s .  com
 * @param cell
 *            The Excel cell.
 * @return Return the parsed value of the cell as an ExclyDate.
 */
public ExclyDate readDateCellValue(Cell cell) {
    ExclyDate output = null;

    if (cell == null) {
        return new ExclyDateError();
    }

    try {
        output = readDate(cell, cell.getCellType());
    } catch (Exception e) {
        log.error("The reader was unable to read the data from cell [Row, Column] (" + cell.getRowIndex() + ", "
                + cell.getColumnIndex() + ")", e);
        output = new ExclyDateError();
    }

    return output;
}

From source file:at.mukprojects.exclycore.dao.XLSXReader.java

License:Open Source License

private ExclyDate readDate(Cell cell, int type) throws Exception {
    ExclyDate output = null;/*from  w ww  .j av  a2 s.co m*/

    if (type == Cell.CELL_TYPE_STRING) {
        String data = cell.getStringCellValue();
        if (isNumericGerman(data)) {
            Number number = NumberFormat.getNumberInstance(Locale.GERMAN).parse(data);
            output = new ExclyDate(DateUtil.getJavaDate(number.intValue()));
        } else if (isNumericUK(data)) {
            Number number = NumberFormat.getNumberInstance(Locale.UK).parse(data);
            output = new ExclyDate(DateUtil.getJavaDate(number.intValue()));
        } else if (data.equals("") || data.equals(" ") || data.trim().equals("-")) {
            output = new ExclyDateBlank();
        } else {
            ExclyDate parsedDate = parse(cell.getStringCellValue());
            output = parsedDate;
        }
    } else if (type == Cell.CELL_TYPE_BLANK) {
        output = new ExclyDateBlank();
    } else if (type == Cell.CELL_TYPE_FORMULA) {
        int formulaType = cell.getCachedFormulaResultType();
        output = readDate(cell, formulaType);
    } else if (DateUtil.isCellDateFormatted(cell)) {
        Date data = cell.getDateCellValue();
        output = new ExclyDate(data);
    } else if (type == Cell.CELL_TYPE_NUMERIC) {
        double data = cell.getNumericCellValue();
        output = new ExclyDate(DateUtil.getJavaDate(data));
    } else if (type == Cell.CELL_TYPE_ERROR) {
        output = new ExclyDateError();
    } else {
        log.warn("The reader was unable to find a valid parser for the cell [Row, Column] ("
                + cell.getRowIndex() + ", " + cell.getColumnIndex() + ")");
        output = new ExclyDateError();
    }

    return output;
}

From source file:at.nhmwien.schema_mapping_tool.fileProcessors.XlsxProcessor.java

License:Apache License

public void prepareFileRead() throws Exception {
    this.fieldNames = new HashMap<String, Integer>();

    this.readBook = new XSSFWorkbook(new FileInputStream(this.operateFile));
    this.readSheet = this.readBook.getSheetAt(0);

    Iterator<Cell> cellIt = this.readSheet.getRow(0).cellIterator();
    while (cellIt.hasNext()) {
        Cell currCell = cellIt.next();

        if (currCell.getCellType() != Cell.CELL_TYPE_STRING)
            continue;

        this.fieldNames.put(currCell.getStringCellValue(), currCell.getColumnIndex());
    }/*from w w  w  . ja  va 2 s  .c  o m*/

    this.currRow = 1;
}

From source file:b01.officeLink.excel.FocExcelDocument.java

License:Apache License

public void exportLocally(FocObject object) {
    try {/*from  www . j a va2  s . c o  m*/
        Sheet sheet = workbook.getSheetAt(0);
        // Iterate over each row in the sheet
        Iterator rows = sheet.rowIterator();
        while (rows.hasNext()) {
            Row row = (Row) rows.next();
            System.out.println("Row #" + row.getRowNum());
            // Iterate over each cell in the row and print out the cell's content
            Iterator cells = row.cellIterator();
            while (cells.hasNext()) {
                Cell cell = (Cell) cells.next();
                System.out.println("Cell #" + cell.getColumnIndex());
                /* System.out.println(String.valueOf(cell.getRichStringCellValue())); */
                String str = null;
                try {
                    str = String.valueOf(cell.getRichStringCellValue());
                } catch (Exception e) {
                    Globals.logExceptionWithoutPopup(e);
                    str = "";
                }
                String result = analyseContent(str, object);
                if (result != null) {

                    if (getWorkbook() != null) {
                        cell.setCellValue(getWorkbook().getCreationHelper().createRichTextString(result));
                    }
                }
                /*
                 * switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_NUMERIC:
                 * System.out.println(cell.getNumericCellValue()); String result =
                 * analyseContent(String.valueOf(cell.getNumericCellValue()), object);
                 * if (result != null){ cell.setCellValue(Double.valueOf(result)); }
                 * break; case HSSFCell.CELL_TYPE_STRING:
                 * System.out.println(cell.getRichStringCellValue()); result =
                 * analyseContent(String.valueOf(cell.getRichStringCellValue()),
                 * object); if (result != null){ cell.setCellValue(new
                 * HSSFRichTextString(result)); } break; default:
                 * System.out.println("unsuported cell type"); break; }
                 */}
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:bad.robot.excel.cell.BlankCell.java

License:Apache License

@Override
public void update(Cell cell, Workbook workbook) {
    ColumnIndex column = column(ExcelColumnIndex.from(cell.getColumnIndex()));
    this.getStyle().applyTo(cell, workbook);
    addTo(cell.getRow(), column, workbook);
}