aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2024-07-02 09:42:02 +0000
committerPJ Fanning <fanningpj@apache.org>2024-07-02 09:42:02 +0000
commit6e07ce50dd2a065eabd12cb203ef9d94d3f73cf6 (patch)
tree36f1408ad049b0219ba0d1b6bd55b578521656dd
parent04c9d0a3c12a828559ae5a5db9e29e881e8f8ef1 (diff)
downloadpoi-6e07ce50dd2a065eabd12cb203ef9d94d3f73cf6.tar.gz
poi-6e07ce50dd2a065eabd12cb203ef9d94d3f73cf6.zip
add dataformatter test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918819 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java19
-rw-r--r--poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java2
-rw-r--r--test-data/spreadsheet/decimal-format.xlsxbin0 -> 9677 bytes
3 files changed, 18 insertions, 3 deletions
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 0000000000..72484c9c31
--- /dev/null
+++ b/test-data/spreadsheet/decimal-format.xlsx
Binary files differ