List of usage examples for org.apache.poi.ss.usermodel CreationHelper createFormulaEvaluator
FormulaEvaluator createFormulaEvaluator();
From source file:blanco.commons.calc.parser.AbstractBlancoCalcParser.java
License:Open Source License
public static String getCellValue(Cell cell) { // 2016.01.20 j.amano // ?jxl to poi ????? //------------------------ //??:\-1,000/* w w w . ja v a2 s .c o m*/ //jxl:($1,000)?$????????? //poi:-1000 //------------------------ //??:2016/1/20 //jxl:0020, 1 20, 2016 //poi:2016/01/20 00:00:00 //------------------------ //??:#REF!??? //jxl:#REF! //poi:#REF! //------------------------ //??:1,000 //jxl:" "1,000 //poi:-1000 //------------------------ if (cell != null) { switch (cell.getCellType()) { case Cell.CELL_TYPE_BLANK: return ""; case Cell.CELL_TYPE_STRING: return cell.getRichStringCellValue().getString(); case Cell.CELL_TYPE_BOOLEAN: return String.valueOf(cell.getBooleanCellValue()); case Cell.CELL_TYPE_NUMERIC: // ?? if (DateUtil.isCellDateFormatted(cell)) { // ???? Date dt = cell.getDateCellValue(); // ???? DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); String sDate = df.format(dt); return sDate; } // ???.0 DecimalFormat format = new DecimalFormat("0.#"); return format.format(cell.getNumericCellValue()); case Cell.CELL_TYPE_FORMULA: Workbook wb = cell.getSheet().getWorkbook(); CreationHelper crateHelper = wb.getCreationHelper(); FormulaEvaluator evaluator = crateHelper.createFormulaEvaluator(); return getCellValue(evaluator.evaluateInCell(cell)); case Cell.CELL_TYPE_ERROR: byte errorCode = cell.getErrorCellValue(); FormulaError error = FormulaError.forInt(errorCode); String errorText = error.getString(); return errorText; default: return ""; } } return ""; }
From source file:com.ssy.havefun.f3d.F3DDaoImpl.java
public String getCellValue(Cell cell) { String ret = ""; switch (cell.getCellType()) { case Cell.CELL_TYPE_BLANK: ret = ""; break;//from www . j ava 2 s.c om case Cell.CELL_TYPE_BOOLEAN: ret = String.valueOf(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: ret = null; break; case Cell.CELL_TYPE_FORMULA: Workbook wb = cell.getSheet().getWorkbook(); CreationHelper crateHelper = wb.getCreationHelper(); FormulaEvaluator evaluator = crateHelper.createFormulaEvaluator(); ret = getCellValue(evaluator.evaluateInCell(cell)); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { // Date theDate = cell.getDateCellValue(); // ret = simpleDateFormat.format(theDate); } else { ret = NumberToTextConverter.toText(cell.getNumericCellValue()); } break; case Cell.CELL_TYPE_STRING: ret = cell.getRichStringCellValue().getString(); break; default: ret = null; } return ret; //?trim }
From source file:org.eclipse.lyo.samples.excel.adapter.dao.internal.ExcelDaoImpl.java
License:Open Source License
private String getCellValue(Cell cell) { if (cell != null) { String value = null;//from w w w .j a v a2s . com int type = cell.getCellType(); if (type == Cell.CELL_TYPE_STRING) { value = cell.getStringCellValue(); } else if (type == Cell.CELL_TYPE_NUMERIC) { if (DateUtil.isCellDateFormatted(cell)) { Date date = cell.getDateCellValue(); value = FastDateFormat.getInstance(DEFAULT_OUTPUT_DATE_FORMAT).format(date); } else { double d = cell.getNumericCellValue(); if (d == Math.floor(d)) { // need to consider when d is negative value = "" + (int) d; } else { value = "" + cell.getNumericCellValue(); } } } else if (type == Cell.CELL_TYPE_FORMULA) { // get calculated value if the cell type is formula Workbook wb = cell.getSheet().getWorkbook(); CreationHelper crateHelper = wb.getCreationHelper(); FormulaEvaluator evaluator = crateHelper.createFormulaEvaluator(); // get recursively if the value is still formula value = getCellValue(evaluator.evaluateInCell(cell)); } return value; } return null; }