List of usage examples for org.apache.poi.ss.usermodel Cell getRowIndex
int getRowIndex();
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 string it will return an ExclyString with the parsed value. * Otherwise an ExcelStringError is returned. An ExcelStringError has the * value of an empty string ("").//from www .j a v a2s . c o m * * @param cell * The Excel cell. * @return Return the parsed value of the cell as an ExclyString. */ public ExclyString readStringCellValue(Cell cell) { ExclyString output = null; if (cell == null) { return new ExclyStringError(); } try { output = readString(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 ExclyStringError(); } return output; }
From source file:at.mukprojects.exclycore.dao.XLSXReader.java
License:Open Source License
private ExclyString readString(Cell cell, int type) throws Exception { ExclyString output = null;//from ww w . j a va2 s . co m if (type == Cell.CELL_TYPE_STRING) { output = new ExclyString(cell.getStringCellValue()); } else if (type == Cell.CELL_TYPE_ERROR) { output = new ExclyStringError(); } else if (type == Cell.CELL_TYPE_FORMULA) { int formulaType = cell.getCachedFormulaResultType(); output = readString(cell, formulaType); } else if (type == Cell.CELL_TYPE_BLANK) { output = new ExclyString(""); } else if (type == Cell.CELL_TYPE_BOOLEAN) { Boolean data = cell.getBooleanCellValue(); if (data) { output = new ExclyString("WAHR"); } else { output = new ExclyString("FALSCH"); } } else if (DateUtil.isCellDateFormatted(cell)) { Date data = cell.getDateCellValue(); output = new ExclyString(data.toString()); } else if (type == Cell.CELL_TYPE_NUMERIC) { double cellValue = cell.getNumericCellValue(); String data = String.valueOf(cellValue); if (cellValue % 1 == 0 && data.endsWith(".0")) { data = data.substring(0, data.length() - 2); } output = new ExclyString(data); } else { log.warn("The reader was unable to find a valid parser for the cell [Row, Column] (" + cell.getRowIndex() + ", " + cell.getColumnIndex() + ")"); output = new ExclyStringError(); } 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 double it will return an ExclyDouble with the parsed value. * Otherwise a ExcelDoubleError or a ExclyDoubleBlank is returned, depending * on the cell value wasn't parsable or blank. Both have a value of zero. * // ww w.ja v a 2 s . c o m * @param cell * The Excel cell. * @return Return the parsed value of the cell as an ExclyDouble. */ public ExclyDouble readDoubleCellValue(Cell cell) { ExclyDouble output = null; if (cell == null) { return new ExclyDoubleError(); } try { output = readDouble(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 ExclyDoubleError(); } return output; }
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 ww w. java2 s .c om*/ 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 w ww. ja va 2 s. c om * * @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;// www.ja va2s . c om 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 w w. j av a2 s . co 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 .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 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 ww w . j a v a 2s . co m * @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 ww w .ja v a 2 s . c om 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; }