[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
This commit is contained in:
PJ Fanning 2024-10-29 18:18:12 +00:00
parent a185d08880
commit 7ea956189d
3 changed files with 18 additions and 1 deletions

View File

@ -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(),

View File

@ -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() + ")");
}

View File

@ -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")));
}
}
}