From: PJ Fanning Date: Sun, 8 Aug 2021 14:53:41 +0000 (+0000) Subject: init support for XLOOKUP X-Git-Tag: REL_5_1_0~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=65a2e42a3d1a5d6eb4806ca259c752dfd37c1f2a;p=poi.git init support for XLOOKUP git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892115 13f79535-47bb-0310-9956-ffa450edef68 --- 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 9dad4b8837..940ec64fd0 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 @@ -26,6 +26,9 @@ import java.util.Optional; /** * Implementation of Excel function XLOOKUP() * + * POI does not currently support have return values with multiple columns and just takes the first cell + * right now. + * * Syntax
* XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

* @@ -75,11 +78,9 @@ final class XLookupFunction implements FreeRefFunction { if (matchedRow != -1) { if (returnEval instanceof AreaEval) { AreaEval area = (AreaEval)returnEval; - if (area.getWidth() == 1) { - return area.getRelativeValue(matchedRow, 0); - } else { - return area.getRow(matchedRow); - } + //TODO to fully support XLOOKUP, we should return the full row + //but POI does not currently support functions returning multiple cell values + return area.getRelativeValue(matchedRow, 0); } } if (notFound.isPresent()) { 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 133c0ffa7f..dbf11b7611 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 @@ -49,10 +49,7 @@ public class TestXLookupFunction { try (HSSFWorkbook wb = initWorkbook2()) { HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); HSSFCell cell = wb.getSheetAt(0).getRow(0).createCell(100); - cell.setCellFormula("XLOOKUP(B2,B5:B14,C5:D14)"); - fe.notifyUpdateCell(cell); - CellValue result = fe.evaluate(cell); - //TODO add assertions + assertString(fe, cell, "XLOOKUP(B2,B5:B14,C5:D14)", "Dianne Pugh"); } }