private Object getNumericCellValue(final Cell cell) { Object cellValue; if (DateUtil.isCellDateFormatted(cell)) { cellValue = new Date(cell.getDateCellValue().getTime()); } else { cellValue = cell.getNumericCellValue(); } return cellValue; }
/** * Returns a string representation of the cell * * <p>Formula cells return the formula string, rather than the formula result. Dates are displayed * in dd-MMM-yyyy format Errors are displayed as #ERR<errIdx> */ public String toString() { switch (getCellType()) { case CELL_TYPE_BLANK: return ""; case CELL_TYPE_BOOLEAN: return getBooleanCellValue() ? "TRUE" : "FALSE"; case CELL_TYPE_ERROR: return ErrorEval.getText(getErrorCellValue()); case CELL_TYPE_FORMULA: return getCellFormula(); case CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(this)) { DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy"); return sdf.format(getDateCellValue()); } return getNumericCellValue() + ""; case CELL_TYPE_STRING: return getRichStringCellValue().toString(); default: return "Unknown Cell Type: " + getCellType(); } }
/** * 获得指定位置的值,返回object,可为数值,字符串,布尔类型,null类型 * * @param column * @return */ public Object getCellValueObject(int rowNum, int column) { // 定义返回的数组 Object tempObject = null; row = sheet.getRow(rowNum); cell = row.getCell(column); // 判断值类型 switch (cell.getCellType()) { // 字符串类型 case Cell.CELL_TYPE_STRING: tempObject = cell.getRichStringCellValue().getString(); // System.out.println(cell.getRichStringCellValue().getString()); break; // 数值类型 case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { tempObject = cell.getDateCellValue(); // System.out.println(cell.getDateCellValue()); } else { tempObject = cell.getNumericCellValue(); // System.out.println(cell.getNumericCellValue()); } break; // 布尔类型 case Cell.CELL_TYPE_BOOLEAN: tempObject = cell.getBooleanCellValue(); // System.out.println(cell.getBooleanCellValue()); break; // 数学公式类型 case Cell.CELL_TYPE_FORMULA: tempObject = cell.getCellFormula(); // System.out.println(cell.getCellFormula()); break; default: System.out.println(); } return tempObject; }