]> source.dussan.org Git - poi.git/commitdiff
More helpful exception on the wrong cell type
authorNick Burch <nick@apache.org>
Fri, 31 Jul 2015 21:44:56 +0000 (21:44 +0000)
committerNick Burch <nick@apache.org>
Fri, 31 Jul 2015 21:44:56 +0000 (21:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1693656 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java

index e3cba3caf7a6db9cd920146dd56d2ede427d0495..6f2390b3aee4739a7fe7e900e7e041d66c0b6fba 100644 (file)
@@ -153,7 +153,7 @@ public class XSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
      *  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
+     * Note that the same instance of XSSFCell is returned to
      * allow chained calls like:
      * <pre>
      * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
@@ -164,16 +164,16 @@ public class XSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
      * @param cell
      */
     public XSSFCell evaluateInCell(Cell cell) {
-        if (cell == null) {
-            return null;
-        }
-        XSSFCell result = (XSSFCell) cell;
+        doEvaluateInCell(cell);
+        return (XSSFCell)cell;
+    }
+    protected void doEvaluateInCell(Cell cell) {
+        if (cell == null) return;
         if (cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) {
             CellValue cv = evaluateFormulaCellValue(cell);
             setCellType(cell, cv); // cell will no longer be a formula cell
             setCellValue(cell, cv);
         }
-        return result;
     }
     private static void setCellType(Cell cell, CellValue cv) {
         int cellType = cv.getCellType();