Author: fanningpj Date: Tue Jul 2 09:42:02 2024 New Revision: 1918819 URL: http://svn.apache.org/viewvc?rev=1918819&view=rev Log: add dataformatter test
Added: poi/trunk/test-data/spreadsheet/decimal-format.xlsx (with props) Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java poi/trunk/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java?rev=1918819&r1=1918818&r2=1918819&view=diff ============================================================================== --- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java (original) +++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java Tue Jul 2 09:42:02 2024 @@ -31,6 +31,7 @@ import org.apache.poi.ss.usermodel.CellS import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.FormulaEvaluator; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.XSSFITestDataProvider; @@ -148,7 +149,7 @@ public final class TestXSSFDataFormat ex assertEquals("TRUE", df.formatCellValue(cell)); CellStyle cellStyle = wb.createCellStyle(); - cellStyle.setDataFormat((short)14); + cellStyle.setDataFormat((short) 14); cell.setCellStyle(cellStyle); cell.setCellValue(new Date(234092383)); assertEquals("1/3/70", df.formatCellValue(cell)); @@ -159,5 +160,19 @@ public final class TestXSSFDataFormat ex */ } } - + + @Test + public void testGitHub650() throws IOException { + // https://github.com/apache/poi/pull/650 + DataFormatter df = new DataFormatter(); + + try (Workbook wb = _testDataProvider.openSampleWorkbook("decimal-format.xlsx")) { + Sheet sheet = wb.getSheetAt(0); + Cell cell1 = sheet.getRow(0).getCell(0); + assertEquals("1.01", df.formatCellValue(cell1)); + Cell cell2 = sheet.getRow(1).getCell(0); + assertEquals("1.00", df.formatCellValue(cell2)); + } + } + } Modified: poi/trunk/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java?rev=1918819&r1=1918818&r2=1918819&view=diff ============================================================================== --- poi/trunk/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java (original) +++ poi/trunk/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java Tue Jul 2 09:42:02 2024 @@ -38,7 +38,7 @@ public abstract class BaseTestDataFormat protected static final String POUND_FMT = "\"\u00a3\"#,##0;[Red]\\-\"\u00a3\"#,##0"; - private final ITestDataProvider _testDataProvider; + protected final ITestDataProvider _testDataProvider; protected BaseTestDataFormat(ITestDataProvider testDataProvider) { _testDataProvider = testDataProvider; Added: poi/trunk/test-data/spreadsheet/decimal-format.xlsx URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/decimal-format.xlsx?rev=1918819&view=auto ============================================================================== Binary file - no diff available. Propchange: poi/trunk/test-data/spreadsheet/decimal-format.xlsx ------------------------------------------------------------------------------ --- svn:mime-type (added) +++ svn:mime-type Tue Jul 2 09:42:02 2024 @@ -0,0 +1 @@ +application/vnd.openxmlformats-officedocument.spreadsheetml.sheet --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org