aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2024-10-29 18:18:12 +0000
committerPJ Fanning <fanningpj@apache.org>2024-10-29 18:18:12 +0000
commit7ea956189d4de9bf38194c69839c6d17f95ed148 (patch)
tree6fcfe6a2ff6f94b907c0ab369df11692f72d3b97
parenta185d08880978054081a43428db32e01a3ce6056 (diff)
downloadpoi-7ea956189d4de9bf38194c69839c6d17f95ed148.tar.gz
poi-7ea956189d4de9bf38194c69839c6d17f95ed148.zip
[bug-69418] Issue when evaluating WORKDAY function that has a cell ref as 2nd param
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921651 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/LazyRefEval.java8
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java9
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/functions/TestWorkdayFunc.java2
3 files changed, 18 insertions, 1 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/LazyRefEval.java b/poi/src/main/java/org/apache/poi/ss/formula/LazyRefEval.java
index 709756da66..9e81aa9b0e 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/LazyRefEval.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/LazyRefEval.java
@@ -39,6 +39,14 @@ public final class LazyRefEval extends RefEvalBase {
return _evaluator.getEvalForCell(sheetIndex, getRow(), getColumn());
}
+ /**
+ * @return the Eval of the first sheet associated with this LazyRefEval
+ * @since POI 5.3.1
+ */
+ public ValueEval getInnerValueEvalForFirstSheet() {
+ return _evaluator.getEvalForCell(_evaluator.getFirstSheetIndex(), getRow(), getColumn());
+ }
+
public AreaEval offset(int relFirstRowIx, int relLastRowIx, int relFirstColIx, int relLastColIx) {
AreaI area = new OffsetArea(getRow(), getColumn(),
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java b/poi/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java
index 710c9f7713..545db9fa36 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/eval/OperandResolver.java
@@ -18,6 +18,7 @@
package org.apache.poi.ss.formula.eval;
import org.apache.poi.ss.formula.EvaluationCell;
+import org.apache.poi.ss.formula.LazyRefEval;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.util.CellRangeAddress;
@@ -267,6 +268,14 @@ public final class OperandResolver {
}
return dd;
}
+ if (ev instanceof LazyRefEval) {
+ final LazyRefEval lre = (LazyRefEval) ev;
+ final ValueEval innerValueEval = lre.getInnerValueEvalForFirstSheet();
+ if (innerValueEval == ev) {
+ throw new IllegalStateException("Circular lazy reference " + lre);
+ }
+ return coerceValueToDouble(innerValueEval);
+ }
throw new IllegalStateException("Unexpected arg eval type (" + ev.getClass().getName() + ")");
}
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestWorkdayFunc.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestWorkdayFunc.java
index 96260443f6..63014ed734 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestWorkdayFunc.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestWorkdayFunc.java
@@ -46,7 +46,7 @@ class TestWorkdayFunc {
cellB1.setCellValue(5);
Cell cellResult = sheet.createRow(1).createCell(0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
- assertDouble(fe, cellResult, "WORKDAY(A1,5)", DateUtil.getExcelDate(LocalDate.parse("2024-11-05")));
+ assertDouble(fe, cellResult, "WORKDAY(A1,B1)", DateUtil.getExcelDate(LocalDate.parse("2024-11-05")));
}
}
}