From 6ca520e32d673c060253d840f6d846f9ad61e6a5 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sun, 5 Dec 2021 21:26:30 +0000 Subject: [PATCH] initial work on example 5 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895604 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/formula/atp/XLookupFunction.java | 19 ++++++------------- .../ss/formula/atp/TestXLookupFunction.java | 6 ++---- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/ss/formula/atp/XLookupFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/atp/XLookupFunction.java index 5f9b1528db..7841e9cce5 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/atp/XLookupFunction.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/atp/XLookupFunction.java @@ -49,15 +49,15 @@ final class XLookupFunction implements FreeRefFunction, ArrayFunction { public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { int srcRowIndex = ec.getRowIndex(); int srcColumnIndex = ec.getColumnIndex(); - return _evaluate(args, srcRowIndex, srcColumnIndex, ec.isSingleValue()); + return _evaluate(args, srcRowIndex, srcColumnIndex); } @Override public ValueEval evaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { - return _evaluate(args, srcRowIndex, srcColumnIndex, false); + return _evaluate(args, srcRowIndex, srcColumnIndex); } - private ValueEval _evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex, boolean isSingleValue) { + private ValueEval _evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { if (args.length < 3) { return ErrorEval.VALUE_INVALID; } @@ -96,12 +96,12 @@ final class XLookupFunction implements FreeRefFunction, ArrayFunction { return ErrorEval.VALUE_INVALID; } } - return evaluate(srcRowIndex, srcColumnIndex, args[0], args[1], args[2], notFound, matchMode, searchMode, isSingleValue); + return evaluate(srcRowIndex, srcColumnIndex, args[0], args[1], args[2], notFound, matchMode, searchMode); } private ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval lookupEval, ValueEval indexEval, ValueEval returnEval, ValueEval notFound, LookupUtils.MatchMode matchMode, - LookupUtils.SearchMode searchMode, boolean isSingleValue) { + LookupUtils.SearchMode searchMode) { try { ValueEval lookupValue = OperandResolver.getSingleValue(lookupEval, srcRowIndex, srcColumnIndex); TwoDEval tableArray = LookupUtils.resolveTableArrayArg(indexEval); @@ -120,7 +120,7 @@ final class XLookupFunction implements FreeRefFunction, ArrayFunction { if (returnEval instanceof AreaEval) { AreaEval area = (AreaEval)returnEval; int width = area.getWidth(); - if (isSingleValue || width <= 1) { + if (width <= 1) { return notFound; } return notFoundAreaEval(notFound, width); @@ -135,13 +135,6 @@ final class XLookupFunction implements FreeRefFunction, ArrayFunction { } if (returnEval instanceof AreaEval) { AreaEval area = (AreaEval)returnEval; - if (isSingleValue) { - if (tableArray.isColumn()) { - return area.getRelativeValue(matchedIdx, 0); - } else { - return area.getRelativeValue(0, matchedIdx); - } - } if (tableArray.isColumn()) { return area.offset(matchedIdx, matchedIdx,0, area.getWidth() - 1); } else { diff --git a/poi/src/test/java/org/apache/poi/ss/formula/atp/TestXLookupFunction.java b/poi/src/test/java/org/apache/poi/ss/formula/atp/TestXLookupFunction.java index d81fb516a4..b549a59bbe 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/atp/TestXLookupFunction.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/atp/TestXLookupFunction.java @@ -75,7 +75,7 @@ public class TestXLookupFunction { assertError(fe, cell, "XLOOKUP(B2,B5:B14,C5:D14)", FormulaError.NA); String formulaText = "XLOOKUP(B2,B5:B14,C5:D14,\"not found\")"; - assertString(fe, cell, formulaText, "not found"); + assertString(fe, cell, "XLOOKUP(B2,B5:B14,C5:C14,\"not found\")", "not found"); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row1 = sheet.getRow(1); @@ -105,9 +105,7 @@ public class TestXLookupFunction { HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFCell cell = wb.getSheetAt(0).getRow(2).createCell(3); assertDouble(fe, cell, "XLOOKUP(D2,$B6:$B17,$C6:$C17)", 25000); - assertDouble(fe, cell, "XLOOKUP($C3,$C5:$G5,$C6:$G17)", 50000); - //TODO next test fails - //assertDouble(fe, cell, "XLOOKUP(D2,$B6:$B17,XLOOKUP($C3,$C5:$G5,$C6:$G17))", 25000); + assertDouble(fe, cell, "XLOOKUP(D2,$B6:$B17,XLOOKUP($C3,$C5:$G5,$C6:$G17))", 25000); } }