aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2018-12-28 19:53:13 +0000
committerDominik Stadler <centic@apache.org>2018-12-28 19:53:13 +0000
commit22bdfcf39996980ab46cbfb3340a58861a89097a (patch)
tree69de91d76ee31480b0599664ed7d1aba117110c0
parent2b8200f7d701ea6ff9638f629f0bd81d2e48410c (diff)
downloadpoi-22bdfcf39996980ab46cbfb3340a58861a89097a.tar.gz
poi-22bdfcf39996980ab46cbfb3340a58861a89097a.zip
Run Cell-tests on HSSF as well and make handling of null-values consistent across implementations
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1849881 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFCell.java10
-rw-r--r--src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java14
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java12
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java43
4 files changed, 53 insertions, 26 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
index 4bdb85501d..35c234a449 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
@@ -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()) );
}
diff --git a/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java b/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
index 0a471419ca..28d2d48936 100644
--- a/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
+++ b/src/ooxml/testcases/org/apache/poi/ss/usermodel/BaseTestXCell.java
@@ -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();
- }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java
index 31617253df..c027123a8a 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java
@@ -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());
- }
- }
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
index 3228bbd0a1..304faaadaf 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
@@ -1062,6 +1062,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()) {
Sheet sheet = wb.createSheet();