[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
This commit is contained in:
PJ Fanning 2021-10-10 11:21:41 +00:00
parent 93fb1bf96b
commit 5bcf3c3d73
2 changed files with 23 additions and 2 deletions

View File

@ -45,14 +45,16 @@ public class Quotient extends Fixed2ArgFunction implements FreeRefFunction {
double enumerator; double enumerator;
try { try {
enumerator = OperandResolver.coerceValueToDouble(venumerator); ValueEval ve = OperandResolver.getSingleValue(venumerator, srcRowIndex, srcColumnIndex);
enumerator = OperandResolver.coerceValueToDouble(ve);
} catch (EvaluationException e) { } catch (EvaluationException e) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }
double denominator; double denominator;
try { try {
denominator = OperandResolver.coerceValueToDouble(vedenominator); ValueEval ve = OperandResolver.getSingleValue(vedenominator, srcRowIndex, srcColumnIndex);
denominator = OperandResolver.coerceValueToDouble(ve);
} catch (EvaluationException e) { } catch (EvaluationException e) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -16,14 +16,22 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.ss.formula.functions; 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 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.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.eval.ValueEval;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.IOException;
/** /**
* Tests for {@link Quotient} * Tests for {@link Quotient}
*/ */
@ -63,4 +71,15 @@ class TestQuotient {
confirmValueError("dividing by zero", "3.14159", "0", ErrorEval.DIV_ZERO); 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);
}
}
} }