From 6e07ce50dd2a065eabd12cb203ef9d94d3f73cf6 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 2 Jul 2024 09:42:02 +0000 Subject: [PATCH] add dataformatter test git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918819 13f79535-47bb-0310-9956-ffa450edef68 --- .../xssf/usermodel/TestXSSFDataFormat.java | 19 ++++++++++++++++-- .../poi/ss/usermodel/BaseTestDataFormat.java | 2 +- test-data/spreadsheet/decimal-format.xlsx | Bin 0 -> 9677 bytes 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 test-data/spreadsheet/decimal-format.xlsx diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java index ba89baed3d..63faef0c91 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java @@ -31,6 +31,7 @@ import org.apache.poi.ss.usermodel.CellStyle; 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 extends BaseTestDataFormat { 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 extends BaseTestDataFormat { */ } } - + + @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)); + } + } + } diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java index 77ac9154d7..e037b83f98 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java @@ -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; diff --git a/test-data/spreadsheet/decimal-format.xlsx b/test-data/spreadsheet/decimal-format.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..72484c9c311d84d9f098b30b82af40638e97b7f4 GIT binary patch literal 9677 zcmeHtbyQW|);AqehY+MYq+7Zh>29R^&>`I*ARHR$E(MelknWb0ZUqFS}}h+H+22d04ndQ1>ldaZTj@{_lnic`yT-Dmw!mU09SM zWH^u)NI%KIC|-B`&`?l77$_*f-^pG$Ix>6O+hxWN%fYhYgq{cO13px4$3`Tk;fQv} zXje7Hrt#Yw(;zo|$vxFs_z3WU)oO_eihW@L<3``; zGZOO|comQd8)h#rlL%)UvSZ%3e(CqCsT|JDa1Eq$54IOwi|Aoq?NEmI)ELpoF$$pd zU3pEuN|Ukk7%Jw{M{j(D;Le_U{I={zCdD!a#o>+G2Hu}Q^IJRRK7#-)2mu=N??9UZ zoz3r&_64cPce3JyF2mo6_j{)o7;GZhBhq_2lWD8?p!6?l+KtCaG~IY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