poi兼容wps一个单元格多种字体
钢翼
编程
/**
* 兼容wps,否则无法设置一个单元格多个字体
* @return
*/
private void fixRichTextString(XSSFRichTextString ts){
String[] boolenanObjectsToUnset = new String[]{"b", "i", "strike"};
for (String boolenanObjectToUnset : boolenanObjectsToUnset) {
XmlObject[] xmlObjects = ts.getCTRst().selectPath(
"declare namespace main='http://schemas.openxmlformats.org/spreadsheetml/2006/main' " +
".//main:" + boolenanObjectToUnset);
for (XmlObject xmlObject : xmlObjects) {
CTBooleanProperty booleanProperty = (CTBooleanProperty)xmlObject;
if (booleanProperty.getVal()){
booleanProperty.unsetVal();
}
}
}
}