diff options
author | PJ Fanning <fanningpj@apache.org> | 2021-12-08 19:03:30 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2021-12-08 19:03:30 +0000 |
commit | ea9883af5500f5f92f3c3b3d056f82fc52b2ff16 (patch) | |
tree | 1dbead5244d00fb3c8a3d680ff5ce5ec05f436f7 /poi | |
parent | 548dfb37f5ef1e3bc770e47cb10e0206daea9c09 (diff) | |
download | poi-ea9883af5500f5f92f3c3b3d056f82fc52b2ff16.tar.gz poi-ea9883af5500f5f92f3c3b3d056f82fc52b2ff16.zip |
update tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895705 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r-- | poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java b/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java index 21744b9b88..8d420462c1 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java @@ -827,19 +827,34 @@ class TestDataFormatter { @Test void testFormulaEvaluation() throws IOException { - Workbook wb = HSSFTestDataSamples.openSampleWorkbook("FormulaEvalTestData.xls"); + try (Workbook wb = HSSFTestDataSamples.openSampleWorkbook("FormulaEvalTestData.xls")) { + CellReference ref = new CellReference("D47"); - CellReference ref = new CellReference("D47"); + Cell cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol()); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals("G9:K9 I7:I12", cell.getCellFormula()); - Cell cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol()); - assertEquals(CellType.FORMULA, cell.getCellType()); - assertEquals("G9:K9 I7:I12", cell.getCellFormula()); - - DataFormatter formatter = new DataFormatter(); - FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); - assertEquals("5.6789", formatter.formatCellValue(cell, evaluator)); + DataFormatter formatter = new DataFormatter(); + FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + assertEquals("5.6789", formatter.formatCellValue(cell, evaluator)); + } + } - wb.close(); + @Test + void testFormulaEvaluationWithoutFormulaEvaluator() throws IOException { + String formula = "G9:K9 I7:I12"; + try (Workbook wb = HSSFTestDataSamples.openSampleWorkbook("FormulaEvalTestData.xls")) { + CellReference ref = new CellReference("D47"); + + Cell cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol()); + assertEquals(CellType.FORMULA, cell.getCellType()); + assertEquals(formula, cell.getCellFormula()); + + DataFormatter formatter = new DataFormatter(); + assertEquals(formula, formatter.formatCellValue(cell)); + formatter.setUseCachedValuesForFormulaCells(true); + assertEquals("5.6789", formatter.formatCellValue(cell)); + } } @Test |