From: PJ Fanning Date: Thu, 29 Jul 2021 18:22:18 +0000 (+0000) Subject: add date test X-Git-Tag: REL_5_1_0~100 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=925688a454c22770c0b6c41b1ff4b83620382d2c;p=poi.git add date test git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891878 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java index d8a54cfa54..944f46dd1c 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -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()) {