aboutsummaryrefslogtreecommitdiffstats
path: root/poi/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-10-10 11:21:41 +0000
committerPJ Fanning <fanningpj@apache.org>2021-10-10 11:21:41 +0000
commit5bcf3c3d734a0034bc2970838cc80cb9e01ec485 (patch)
treefabda3d2e07456773b74fd4e2ed758c70e4d9e23 /poi/src
parent93fb1bf96bad48105208d811e5489fa941cb027b (diff)
downloadpoi-5bcf3c3d734a0034bc2970838cc80cb9e01ec485.tar.gz
poi-5bcf3c3d734a0034bc2970838cc80cb9e01ec485.zip
[bug-62040] quotient function does not support cell references
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894103 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi/src')
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/functions/Quotient.java6
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/functions/TestQuotient.java19
2 files changed, 23 insertions, 2 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Quotient.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Quotient.java
index 19ae7235ed..7a1ff4a9ba 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Quotient.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Quotient.java
@@ -45,14 +45,16 @@ public class Quotient extends Fixed2ArgFunction implements FreeRefFunction {
double enumerator;
try {
- enumerator = OperandResolver.coerceValueToDouble(venumerator);
+ ValueEval ve = OperandResolver.getSingleValue(venumerator, srcRowIndex, srcColumnIndex);
+ enumerator = OperandResolver.coerceValueToDouble(ve);
} catch (EvaluationException e) {
return ErrorEval.VALUE_INVALID;
}
double denominator;
try {
- denominator = OperandResolver.coerceValueToDouble(vedenominator);
+ ValueEval ve = OperandResolver.getSingleValue(vedenominator, srcRowIndex, srcColumnIndex);
+ denominator = OperandResolver.coerceValueToDouble(ve);
} catch (EvaluationException e) {
return ErrorEval.VALUE_INVALID;
}
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestQuotient.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestQuotient.java
index 838beb576a..f742264393 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestQuotient.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestQuotient.java
@@ -16,14 +16,22 @@
==================================================================== */
package org.apache.poi.ss.formula.functions;
+import static org.apache.poi.ss.util.Utils.addRow;
+import static org.apache.poi.ss.util.Utils.assertDouble;
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.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.junit.jupiter.api.Test;
+import java.io.IOException;
+
/**
* Tests for {@link Quotient}
*/
@@ -63,4 +71,15 @@ class TestQuotient {
confirmValueError("dividing by zero", "3.14159", "0", ErrorEval.DIV_ZERO);
}
+
+ @Test
+ void testWithCellRefs() throws IOException {
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ HSSFSheet sheet = wb.createSheet();
+ addRow(sheet, 0, 5, 2);
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ HSSFCell cell = wb.getSheetAt(0).getRow(0).createCell(100);
+ assertDouble(fe, cell, "QUOTIENT(A1, B1)", 2.0);
+ }
+ }
} \ No newline at end of file