]> source.dussan.org Git - poi.git/commitdiff
add data-formatter test
authorPJ Fanning <fanningpj@apache.org>
Wed, 8 Dec 2021 19:27:09 +0000 (19:27 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 8 Dec 2021 19:27:09 +0000 (19:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895706 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java
test-data/spreadsheet/formula-eval.xlsx [new file with mode: 0644]

index 5147e1f84335a023407aa140ea5f97d7d1a7c7f3..fe4aa0a00ab9657a63a9e959a9df169c5b0cd5ea 100644 (file)
@@ -107,4 +107,17 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat {
             assertEquals("1000", formatter.formatCellValue(cell, evaluator));
         }
     }
+
+    @Test
+    void testSetUseCachedValuesForFormulaCells() throws Exception {
+        try (XSSFWorkbook wb = openSampleWorkbook("formula-eval.xlsx")) {
+            final DataFormatter formatter = new DataFormatter();
+            XSSFSheet sheet = wb.getSheetAt(0);
+            XSSFRow row = sheet.getRow(0);
+            XSSFCell d1 = row.getCell(3);
+            assertEquals("SUM(A1:C1)", formatter.formatCellValue(d1));
+            formatter.setUseCachedValuesForFormulaCells(true);
+            assertEquals("6.75", formatter.formatCellValue(d1));
+        }
+    }
 }
diff --git a/test-data/spreadsheet/formula-eval.xlsx b/test-data/spreadsheet/formula-eval.xlsx
new file mode 100644 (file)
index 0000000..198c6b5
Binary files /dev/null and b/test-data/spreadsheet/formula-eval.xlsx differ