diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 23e33a2497..0a85c786c7 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -354,12 +354,18 @@ public final class XSSFCell extends CellBase { if(_cell.getT() == STCellType.INLINE_STR) { //set the 'pre-evaluated result _cell.setV(str.getString()); - } else { + } else if (str instanceof XSSFRichTextString) { _cell.setT(STCellType.S); XSSFRichTextString rt = (XSSFRichTextString)str; rt.setStylesTableReference(_stylesSource); int sRef = _sharedStringSource.addSharedStringItem(rt); _cell.setV(Integer.toString(sRef)); + } else { + _cell.setT(STCellType.S); + XSSFRichTextString rt = new XSSFRichTextString(str.getString()); + rt.setStylesTableReference(_stylesSource); + int sRef = _sharedStringSource.addSharedStringItem(rt); + _cell.setV(Integer.toString(sRef)); } } }