From 0a467f10c3bc311691484b37d3ffb0788e5be2d0 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Tue, 5 Jul 2016 07:24:14 +0000 Subject: [PATCH] Add a unit-test to verify that DataFormatter.formatCellValue() does format formula-results correctly git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751400 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/usermodel/TestDataFormatter.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java index c4903214a0..f5e79c8c90 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java +++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java @@ -32,10 +32,12 @@ import java.util.Calendar; import java.util.Date; import java.util.Locale; +import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter; import org.apache.poi.ss.format.CellFormat; import org.apache.poi.ss.format.CellFormatResult; +import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.NumberToTextConverter; import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.SuppressForbidden; @@ -775,4 +777,22 @@ public class TestDataFormatter { wb.close(); } } + + @Test + public void testFormulaEvaluation() throws IOException { + Workbook wb = HSSFTestDataSamples.openSampleWorkbook("FormulaEvalTestData.xls"); + + CellReference ref = new CellReference("D47"); + + Cell cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol()); + //noinspection deprecation + assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); + assertEquals("G9:K9 I7:I12", cell.getCellFormula()); + + DataFormatter formatter = new DataFormatter(); + FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + assertEquals("5.6789", formatter.formatCellValue(cell, evaluator)); + + wb.close(); + } }