poi兼容wps一个单元格多种字体

返回
Author Avatar
钢翼
2021-12-13
编程
53
/**
     * 兼容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();
                }
            }
        }
    }