mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
2b8200f7d7
commit
22bdfcf399
|
@ -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()) );
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in New Issue