{
XSSFRichTextString xvalue = (XSSFRichTextString)value;
- if (xvalue != null) {
+ if (xvalue != null && xvalue.getString() != null) {
ensureRichTextStringType();
if (xvalue.length() > SpreadsheetVersion.EXCEL2007.getMaxTextLength()) {
@Override
public void setCellValue(String value)
{
- ensureTypeOrFormulaType(CELL_TYPE_STRING);
-
- if(value != null && value.length() > SpreadsheetVersion.EXCEL2007.getMaxTextLength()){
- throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters");
+ if (value != null) {
+ ensureTypeOrFormulaType(CELL_TYPE_STRING);
+
+ if(value != null && value.length() > SpreadsheetVersion.EXCEL2007.getMaxTextLength()){
+ throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters");
+ }
+
+ if(_value.getType()==CELL_TYPE_FORMULA)
+ ((StringFormulaValue)_value).setPreEvaluatedValue(value);
+ else
+ ((PlainStringValue)_value).setValue(value);
+ } else {
+ setCellType(CELL_TYPE_BLANK);
}
-
- if(_value.getType()==CELL_TYPE_FORMULA)
- ((StringFormulaValue)_value).setPreEvaluatedValue(value);
- else
- ((PlainStringValue)_value).setValue(value);
}
/**
wb.close();
}
+
+ /**
+ * If someone sets a null string as a cell value, treat
+ * it as an empty cell, and avoid a NPE on auto-sizing
+ */
+ @Test
+ public void test57034() throws Exception {
+ Workbook wb = _testDataProvider.createWorkbook();
+ Sheet s = wb.createSheet();
+ Cell cell = s.createRow(0).createCell(0);
+ cell.setCellValue((String)null);
+ assertEquals(Cell.CELL_TYPE_BLANK, cell.getCellType());
+
+ _testDataProvider.trackColumnsForAutosizing(s, 0);
+
+ s.autoSizeColumn(0);
+ assertEquals(2048, s.getColumnWidth(0));
+
+ s.autoSizeColumn(0, true);
+ assertEquals(2048, s.getColumnWidth(0));
+
+ wb.close();
+ }
}