*/
@Override
public double getNumericCellValue() {
- CellType cellType = getCellType();
- switch(cellType) {
+ CellType valueType = isFormulaCell() ? getCachedFormulaResultType() : getCellType();
+ switch(valueType) {
case BLANK:
return 0.0;
- case FORMULA:
- // fall-through
case NUMERIC:
if(_cell.isSetV()) {
String v = _cell.getV();
} else {
return 0.0;
}
+ case FORMULA:
+ throw new AssertionError();
default:
- throw typeMismatch(CellType.NUMERIC, cellType, false);
+ throw typeMismatch(CellType.NUMERIC, valueType, false);
}
}
}
}
-
\ No newline at end of file
+
assertEquals(CellType.BOOLEAN, cell.getCellType());
cell.setCellValue(true);
assertTrue(cell.getBooleanCellValue());
- assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING,
+ assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN,
CellType.FORMULA, CellType.ERROR);
cell.setCellValue(factory.createRichTextString("Foo"));
assertEquals(CellType.FORMULA, cell.getCellType());
}
}
+
+ @Test
+ public void testGetNumericCellValueOnABlankCellReturnsZero() {
+ Cell cell = _testDataProvider.createWorkbook().createSheet().createRow(0).createCell(0);
+ assertEquals(CellType.BLANK, cell.getCellType());
+ assertEquals(0, cell.getNumericCellValue(), 0);
+ }
}