arjansh commented on a change in pull request #234: MM-82 Detect Column Types URL: https://github.com/apache/metamodel/pull/234#discussion_r354717979
########## File path: excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java ########## @@ -281,6 +348,51 @@ private static String getFormulaCellValue(Workbook wb, Cell cell) { return cell.getCellFormula(); } + private static Object getFormulaCellValueAsObject(final Workbook workbook, final Cell cell) { + // first try with a cached/precalculated value + try { + return getDoubleAsNumber(cell.getNumericCellValue()); + } catch (final Exception e) { + if (logger.isInfoEnabled()) { + logger.info("Failed to fetch cached/precalculated formula value of cell: " + cell, e); + } + } + + // evaluate cell first, if possible + try { + if (logger.isInfoEnabled()) { + logger + .info("cell {} is a formula. Attempting to evaluate: {}", getCellCoordinates(cell), cell + .getCellFormula()); + } + + final FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); + + // calculates the formula and puts it's value back into the cell + final Cell evaluatedCell = evaluator.evaluateInCell(cell); + + return getCellValueAsObject(workbook, evaluatedCell); + } catch (final FormulaParseException e) { + logger.error("Parse exception occurred while evaluating cell formula: " + cell, e); Review comment: I would consider logging these messages at "warning" level instead of "error" level, because the use case here is not that some major part of the mechanism is breaking down, we're just not able to handle one particular cell in a nice manner and we do have a fallback option handle that. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services