]> source.dussan.org Git - poi.git/commitdiff
add xlookup test
authorPJ Fanning <fanningpj@apache.org>
Mon, 6 Dec 2021 10:10:16 +0000 (10:10 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 6 Dec 2021 10:10:16 +0000 (10:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895613 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/test/java/org/apache/poi/xssf/TestXLookupFunction.java [deleted file]
poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFXLookupFunction.java [new file with mode: 0644]
test-data/spreadsheet/xlookup.xlsx [new file with mode: 0644]

diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXLookupFunction.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXLookupFunction.java
deleted file mode 100644 (file)
index 16122cf..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.xssf;
-
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.xssf.usermodel.*;
-import org.junit.jupiter.api.Test;
-
-import java.io.IOException;
-import java.util.Locale;
-
-import static org.apache.poi.ss.util.Utils.*;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-/**
- * Testcase for function XLOOKUP()
- */
-public class TestXLookupFunction {
-
-    //https://support.microsoft.com/en-us/office/xlookup-function-b7fd680e-6d10-43e6-84f9-88eae8bf5929
-
-    @Test
-    void testMicrosoftExample2() throws IOException {
-        String formulaText = "XLOOKUP(B2,B5:B14,C5:D14)";
-        try (XSSFWorkbook wb = initWorkbook2()) {
-            XSSFFormulaEvaluator fe = new XSSFFormulaEvaluator(wb);
-            XSSFSheet sheet = wb.getSheetAt(0);
-            XSSFRow row1 = sheet.getRow(1);
-            String col1 = CellReference.convertNumToColString(2);
-            String col2 = CellReference.convertNumToColString(3);
-            String cellRef = String.format(Locale.ENGLISH, "%s2:%s2", col1, col2);
-            sheet.setArrayFormula(formulaText, CellRangeAddress.valueOf(cellRef));
-            fe.evaluateAll();
-            assertEquals("Dianne Pugh", row1.getCell(2).getStringCellValue());
-            assertEquals("Finance", row1.getCell(3).getStringCellValue());
-        }
-    }
-
-
-    private XSSFWorkbook initWorkbook2() {
-        XSSFWorkbook wb = new XSSFWorkbook();
-        XSSFSheet sheet = wb.createSheet();
-        addRow(sheet, 0, null, "Emp Id", "Employee Name", "Department");
-        addRow(sheet, 1, null, 8389);
-        addRow(sheet, 3, null, "Emp Id", "Employee Name", "Department");
-        addRow(sheet, 4, null, 4390, "Ned Lanning", "Marketing");
-        addRow(sheet, 5, null, 8604, "Margo Hendrix", "Sales");
-        addRow(sheet, 6, null, 8389, "Dianne Pugh", "Finance");
-        addRow(sheet, 7, null, 4937, "Earlene McCarty", "Accounting");
-        addRow(sheet, 8, null, 8299, "Mia Arnold", "Operation");
-        addRow(sheet, 9, null, 2643, "Jorge Fellows", "Executive");
-        addRow(sheet, 10, null, 5243, "Rose Winters", "Sales");
-        addRow(sheet, 11, null, 9693, "Carmela Hahn", "Finance");
-        addRow(sheet, 12, null, 1636, "Delia Cochran", "Accounting");
-        addRow(sheet, 13, null, 6703, "Marguerite Cervantes", "Marketing");
-        return wb;
-    }
-
-}
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFXLookupFunction.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFXLookupFunction.java
new file mode 100644 (file)
index 0000000..dbe7c95
--- /dev/null
@@ -0,0 +1,89 @@
+
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.xssf;
+
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xssf.usermodel.*;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.Locale;
+
+import static org.apache.poi.ss.util.Utils.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Testcase for function XLOOKUP()
+ */
+public class TestXSSFXLookupFunction {
+
+    //https://support.microsoft.com/en-us/office/xlookup-function-b7fd680e-6d10-43e6-84f9-88eae8bf5929
+
+    @Test
+    void testMicrosoftExample2() throws IOException {
+        String formulaText = "XLOOKUP(B2,B5:B14,C5:D14)";
+        try (XSSFWorkbook wb = initWorkbook2()) {
+            XSSFFormulaEvaluator fe = new XSSFFormulaEvaluator(wb);
+            XSSFSheet sheet = wb.getSheetAt(0);
+            XSSFRow row1 = sheet.getRow(1);
+            String col1 = CellReference.convertNumToColString(2);
+            String col2 = CellReference.convertNumToColString(3);
+            String cellRef = String.format(Locale.ENGLISH, "%s2:%s2", col1, col2);
+            sheet.setArrayFormula(formulaText, CellRangeAddress.valueOf(cellRef));
+            fe.evaluateAll();
+            assertEquals("Dianne Pugh", row1.getCell(2).getStringCellValue());
+            assertEquals("Finance", row1.getCell(3).getStringCellValue());
+        }
+    }
+
+    @Test
+    void testXLookupFile() throws Exception {
+        try (XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("xlookup.xlsx")) {
+            XSSFSheet sheet = workbook.getSheetAt(0);
+            XSSFFormulaEvaluator fe = new XSSFFormulaEvaluator(workbook);
+            XSSFRow row1 = sheet.getRow(1);
+            assertEquals("Dianne Pugh", row1.getCell(2).getStringCellValue());
+            assertEquals("Finance", row1.getCell(3).getStringCellValue());
+            fe.evaluateAll();
+            row1 = sheet.getRow(1);
+            assertEquals("Dianne Pugh", row1.getCell(2).getStringCellValue());
+            assertEquals("Finance", row1.getCell(3).getStringCellValue());
+        }
+    }
+
+    private XSSFWorkbook initWorkbook2() {
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFSheet sheet = wb.createSheet();
+        addRow(sheet, 0, null, "Emp Id", "Employee Name", "Department");
+        addRow(sheet, 1, null, 8389);
+        addRow(sheet, 3, null, "Emp Id", "Employee Name", "Department");
+        addRow(sheet, 4, null, 4390, "Ned Lanning", "Marketing");
+        addRow(sheet, 5, null, 8604, "Margo Hendrix", "Sales");
+        addRow(sheet, 6, null, 8389, "Dianne Pugh", "Finance");
+        addRow(sheet, 7, null, 4937, "Earlene McCarty", "Accounting");
+        addRow(sheet, 8, null, 8299, "Mia Arnold", "Operation");
+        addRow(sheet, 9, null, 2643, "Jorge Fellows", "Executive");
+        addRow(sheet, 10, null, 5243, "Rose Winters", "Sales");
+        addRow(sheet, 11, null, 9693, "Carmela Hahn", "Finance");
+        addRow(sheet, 12, null, 1636, "Delia Cochran", "Accounting");
+        addRow(sheet, 13, null, 6703, "Marguerite Cervantes", "Marketing");
+        return wb;
+    }
+
+}
diff --git a/test-data/spreadsheet/xlookup.xlsx b/test-data/spreadsheet/xlookup.xlsx
new file mode 100644 (file)
index 0000000..58b6ae9
Binary files /dev/null and b/test-data/spreadsheet/xlookup.xlsx differ