]> source.dussan.org Git - poi.git/commitdiff
[bug-66181] support VALUE function where input is a blank cell
authorPJ Fanning <fanningpj@apache.org>
Mon, 14 Nov 2022 17:41:21 +0000 (17:41 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 14 Nov 2022 17:41:21 +0000 (17:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905308 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/ss/formula/functions/Value.java
poi/src/test/java/org/apache/poi/ss/formula/functions/TestValue.java

index b3c6cb3c45a2a790b176d6c50ae14c68070b5a28..451f0a2fab200fe7840c4f5c0b0182aaf1fbef59 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.poi.ss.formula.functions;
 
+import org.apache.poi.ss.formula.eval.BlankEval;
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.EvaluationException;
 import org.apache.poi.ss.formula.eval.NumberEval;
@@ -53,6 +54,9 @@ public final class Value extends Fixed1ArgFunction implements ArrayFunction {
             return e.getErrorEval();
         }
         String strText = OperandResolver.coerceValueToString(veText);
+        if (veText == BlankEval.instance) {
+            return new NumberEval(0.0);
+        }
         if (StringUtil.isBlank(strText)) {
             return ErrorEval.VALUE_INVALID;
         }
index 7166037788d9339678c86322872d209aaf2f2a19..33d1e7bfa42431ba7220c03bda52043506872171 100644 (file)
@@ -19,12 +19,20 @@ package org.apache.poi.ss.formula.functions;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.NumberEval;
 import org.apache.poi.ss.formula.eval.StringEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.ss.util.Utils;
 import org.junit.jupiter.api.Test;
 
+import java.io.IOException;
+
 /**
  * Tests for {@link Value}
  */
@@ -97,4 +105,17 @@ final class TestValue {
         confirmValueError("1e2.5");
         confirmValueError("");
     }
+
+    @Test
+    void testBlank() throws IOException {
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
+            HSSFSheet sheet = wb.createSheet();
+            HSSFRow row = sheet.createRow(0);
+            HSSFCell b1 = row.createCell(1);
+            HSSFCell c1 = row.createCell(2);
+            HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+            Utils.assertDouble(fe, b1, "VALUE(A1)", 0.0);
+            Utils.assertDouble(fe, c1, "VALUE(B1)", 0.0);
+        }
+    }
 }