/** * If cell contains formula, it evaluates the formula, and * puts the formula result back into the cell, in place * of the old formula. * Else if cell does not contain formula, this method leaves * the cell unchanged. * Note that the same instance of HSSFCell is returned to * allow chained calls like: * <pre> * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType(); * </pre> * Be aware that your cell value will be changed to hold the * result of the formula. If you simply want the formula * value computed for you, use {@link #evaluateFormulaCell(Cell)}} */ public HSSFCell evaluateInCell(Cell cell) { if (cell == null) { return null; } HSSFCell result = (HSSFCell) cell; if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { CellValue cv = evaluateFormulaCellValue(cell); setCellValue(cell, cv); setCellType(cell, cv); // cell will no longer be a formula cell } return result; } private static void setCellType(Cell cell, CellValue cv) {
/** * If cell contains formula, it evaluates the formula, and * puts the formula result back into the cell, in place * of the old formula. * Else if cell does not contain formula, this method leaves * the cell unchanged. * Note that the same instance of HSSFCell is returned to * allow chained calls like: * <pre> * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType(); * </pre> * Be aware that your cell value will be changed to hold the * result of the formula. If you simply want the formula * value computed for you, use {@link #evaluateFormulaCell(Cell)}} */ public HSSFCell evaluateInCell(Cell cell) { if (cell == null) { return null; } HSSFCell result = (HSSFCell) cell; if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { CellValue cv = evaluateFormulaCellValue(cell); setCellValue(cell, cv); setCellType(cell, cv); // cell will no longer be a formula cell } return result; } private static void setCellType(Cell cell, CellValue cv) {