]> source.dussan.org Git - poi.git/commitdiff
add date test
authorPJ Fanning <fanningpj@apache.org>
Thu, 29 Jul 2021 18:22:18 +0000 (18:22 +0000)
committerPJ Fanning <fanningpj@apache.org>
Thu, 29 Jul 2021 18:22:18 +0000 (18:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891878 13f79535-47bb-0310-9956-ffa450edef68

poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java

index d8a54cfa5451ab97d1663d944cc17d372a137a1d..944f46dd1c7c68da428bdff325b87b4b3f629f8c 100644 (file)
@@ -1386,6 +1386,26 @@ public abstract class BaseTestCell {
         }
     }
 
+    @Test
+    void setCellFormulaWithDateArithmetic() throws IOException {
+        try (Workbook wb = _testDataProvider.createWorkbook()) {
+            Cell cellA1 = getInstance(wb);
+            cellA1.setCellFormula("B1+1");
+
+            LocalDate date = LocalDate.parse("2021-07-31");
+            Cell cellB1 = cellA1.getRow().createCell(1);
+            cellB1.setCellValue(date);
+
+            assertEquals(CellType.FORMULA, cellA1.getCellType());
+            assertEquals(CellType.NUMERIC, cellA1.getCachedFormulaResultType());
+
+            FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
+            CellValue valueA1 = fe.evaluate(cellA1);
+            assertEquals(CellType.NUMERIC, valueA1.getCellType());
+            assertEquals(DateUtil.getExcelDate(date.plusDays(1)), valueA1.getNumberValue());
+        }
+    }
+
     @Test
     void setCellType_FORMULA_onAnArrayFormulaCell_doesNothing() throws IOException {
         try (Workbook wb = _testDataProvider.createWorkbook()) {