https://issues.apache.org/bugzilla/show_bug.cgi?id=55658
Bug ID: 55658
Summary: SXSSFCell.convertCellValueToString() incorrectly
implemented for CELL_TYPE_NUMERIC
Product: POI
Version: 3.9
Hardware: All
OS: All
Status: NEW
Severity: blocker
Priority: P2
Component: SXSSF
Assignee: [email protected]
Reporter: [email protected]
When you call cell.setValue( myValue ) for a numeric cell when using SXSSF the
call fails with the following error:
java.lang.IllegalStateException: Cannot get a error value from a numeric cell
at org.apache.poi.xssf.streaming.SXSSFCell.typeMismatch(SXSSFCell.java:841)
at
org.apache.poi.xssf.streaming.SXSSFCell.getErrorCellValue(SXSSFCell.java:487)
at
org.apache.poi.xssf.streaming.SXSSFCell.convertCellValueToString(SXSSFCell.java:891)
at org.apache.poi.xssf.streaming.SXSSFCell.setType(SXSSFCell.java:760)
at
org.apache.poi.xssf.streaming.SXSSFCell.ensureTypeOrFormulaType(SXSSFCell.java:744)
at org.apache.poi.xssf.streaming.SXSSFCell.setCellValue(SXSSFCell.java:235)
Looking at the code in
org.apache.poi.xssf.streaming.SXSSFCell.convertCellValueToString it has an
incorrect case for CELL_TYPE_NUMERIC. There is no implementation and it just
uses the same code as CELL_TYPE_ERROR, which is obviously incorrect:
private String convertCellValueToString() {
int cellType = getCellType();
switch (cellType) {
case CELL_TYPE_BLANK:
return "";
case CELL_TYPE_BOOLEAN:
return getBooleanCellValue() ? "TRUE" : "FALSE";
case CELL_TYPE_STRING:
return getStringCellValue();
case CELL_TYPE_NUMERIC:
case CELL_TYPE_ERROR:
byte errVal = getErrorCellValue();
return FormulaError.forInt(errVal).getString();
case CELL_TYPE_FORMULA:
return "";
default:
throw new IllegalStateException("Unexpected cell type (" +
cellType + ")");
}
}
What should this code be? Is there an existing patch I can apply? This bug
makes using SXSSF un-useable. I have a project that I have big memory issues
with when using XSSF and need this implementation.
If this is just a case of converting the NumericCell value to a string, then
why not just do:
case CELL_TYPE_NUMERIC:
return Double.toString( getNumericCellValue() );
Or to be more OO, why not override toString() on the class NumericValue?
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]