]> source.dussan.org Git - poi.git/commitdiff
Run Cell-tests on HSSF as well and make handling of null-values consistent across...
authorDominik Stadler <centic@apache.org>
Fri, 28 Dec 2018 19:53:13 +0000 (19:53 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 28 Dec 2018 19:53:13 +0000 (19:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1849881 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

index 4bdb85501dddf4c541c11484d3d48cdb3f8d0c93..35c234a4496615d8e3e613a9f4b262928d913b1e 100644 (file)
@@ -494,6 +494,11 @@ public class HSSFCell implements Cell {
      */
     public void setCellValue(Date value)
     {
+        if(value == null) {
+            setCellType(CellType.BLANK);
+            return;
+        }
+
         setCellValue(HSSFDateUtil.getExcelDate(value, _book.getWorkbook().isUsing1904DateWindowing()));
     }
 
@@ -514,6 +519,11 @@ public class HSSFCell implements Cell {
      */
     public void setCellValue(Calendar value)
     {
+        if(value == null) {
+            setCellType(CellType.BLANK);
+            return;
+        }
+
         setCellValue( HSSFDateUtil.getExcelDate(value, _book.getWorkbook().isUsing1904DateWindowing()) );
     }
 
index 0a471419caeaf5b01a038a4f0bdad103f37fbc3d..28d2d489365ef782b0f3da76314b39cee144daab 100644 (file)
@@ -57,18 +57,4 @@ public abstract class BaseTestXCell extends BaseTestCell {
         assertEquals("???<>\t\n\u00a0 &\"POI\'\u2122", wb2.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
         wb2.close();
     }
-
-    @Test
-    public void testSetNullValues() throws IOException {
-        Workbook wb = _testDataProvider.createWorkbook();
-        Cell cell = wb.createSheet("test").createRow(0).createCell(0);
-
-        cell.setCellValue((Calendar)null);
-        cell.setCellValue((Date)null);
-        cell.setCellValue((String)null);
-        cell.setCellValue((RichTextString) null);
-        cell.setCellValue((String)null);
-
-        wb.close();
-    }
 }
index 31617253df1fa695cccd6ee3f6570d48a9639c0c..c027123a8ac8e9adff8822e7311c81a9ef510df9 100644 (file)
@@ -83,16 +83,4 @@ public class TestSXSSFCell extends BaseTestXCell {
             swb.close();
         }
     }
-
-    @Test
-    public void test62216() throws IOException {
-        try (SXSSFWorkbook wb = new SXSSFWorkbook()) {
-            Cell instance = wb.createSheet().createRow(0).createCell(0);
-            String formula = "2";
-            instance.setCellFormula(formula);
-            instance.setCellErrorValue(FormulaError.NAME.getCode());
-
-            assertEquals(formula, instance.getCellFormula());
-        }
-    }
 }
index 3228bbd0a199c3be977eafd194fc7d94cf4b1b64..304faaadaf39ada4b202b7f8297c630a3a982c18 100644 (file)
@@ -1061,6 +1061,49 @@ public abstract class BaseTestCell {
         }
     }
 
+    @Test
+    public void test62216() throws IOException {
+        try (Workbook wb = _testDataProvider.createWorkbook()) {
+            Cell instance = wb.createSheet().createRow(0).createCell(0);
+            String formula = "2";
+            instance.setCellFormula(formula);
+            instance.setCellErrorValue(FormulaError.NAME.getCode());
+
+            assertEquals(formula, instance.getCellFormula());
+        }
+    }
+
+    @Test
+    public void testSetNullValues() throws IOException {
+        Workbook wb = _testDataProvider.createWorkbook();
+        Cell cell = wb.createSheet("test").createRow(0).createCell(0);
+
+        cell.setCellValue((Calendar)null);
+        assertEquals(CellType.BLANK, cell.getCellType());
+        assertEquals("", cell.getStringCellValue());
+
+        cell.setCellValue((Date)null);
+        assertEquals(CellType.BLANK, cell.getCellType());
+        assertEquals("", cell.getStringCellValue());
+
+        cell.setCellValue((String)null);
+        assertEquals(CellType.BLANK, cell.getCellType());
+        assertEquals("", cell.getStringCellValue());
+
+        assertEquals(CellType.BLANK, cell.getCellType());
+        assertEquals("", cell.getStringCellValue());
+
+        cell.setCellValue((RichTextString) null);
+        assertEquals(CellType.BLANK, cell.getCellType());
+        assertEquals("", cell.getStringCellValue());
+
+        cell.setCellValue((String)null);
+        assertEquals(CellType.BLANK, cell.getCellType());
+        assertEquals("", cell.getStringCellValue());
+
+        wb.close();
+    }
+
     @Test
     public void testFormulaSetValueDoesNotChangeType() throws IOException {
         try (Workbook wb = _testDataProvider.createWorkbook()) {