]> source.dussan.org Git - poi.git/commitdiff
another dataformatter test
authorPJ Fanning <fanningpj@apache.org>
Tue, 2 Jul 2024 09:08:40 +0000 (09:08 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 2 Jul 2024 09:08:40 +0000 (09:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918817 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java
poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestDataFormat.java

index 4f512a1d55713a04717a758f000fbe598cfbd900..ba89baed3dd30077ac18b53312c9084a5912071d 100644 (file)
@@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.WorkbookEvaluatorProvider;
 import org.apache.poi.ss.usermodel.BaseTestDataFormat;
 import org.apache.poi.ss.usermodel.Cell;
 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.Workbook;
@@ -158,18 +159,5 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat {
             */
         }
     }
-
-    @Test
-    public void testFormatCellValueDecimal() throws IOException {
-        DataFormatter df = new DataFormatter();
-
-        try (Workbook wb = new XSSFWorkbook()) {
-            Cell cell = wb.createSheet("test").createRow(0).createCell(0);
-            assertEquals("", df.formatCellValue(cell));
-
-            cell.setCellValue(1.005);
-            assertEquals("1.005", df.formatCellValue(cell));
-        }
-    }
-
+    
 }
index 98195b11d57e989f67bc5fae65fbff76e2abe18e..610284fbf675b0b37efba525153dc3696583ddcd 100644 (file)
@@ -29,8 +29,11 @@ import org.apache.poi.hssf.HSSFITestDataProvider;
 import org.apache.poi.ss.usermodel.BaseTestDataFormat;
 import org.apache.poi.ss.usermodel.Cell;
 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.Row;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.junit.jupiter.api.Test;
 
 /**
index eed2fd3cc3532163089be2906482835b3b9c879c..77ac9154d7f4adba2a8ae82ac0ee125f8f7f8bce 100644 (file)
@@ -273,4 +273,24 @@ public abstract class BaseTestDataFormat {
             assertEquals("12'345'678", formatter.formatCellValue(lge));
         }
     }
+
+    @Test
+    public void testFormatCellValueDecimal() throws IOException {
+        DataFormatter df = new DataFormatter();
+
+        try (Workbook wb = _testDataProvider.createWorkbook()) {
+            Cell cell = wb.createSheet("test").createRow(0).createCell(0);
+            assertEquals("", df.formatCellValue(cell));
+
+            cell.setCellValue(1.005);
+            assertEquals("1.005", df.formatCellValue(cell));
+
+            DataFormat format = wb.createDataFormat();
+            CellStyle cellStyle = wb.createCellStyle();
+            cellStyle.setDataFormat(format.getFormat("0.00"));
+            cell.setCellStyle(cellStyle);
+            assertEquals("1.01", df.formatCellValue(cell));
+        }
+    }
+
 }