Setting a part of the cell contents to bold using apache poi?

前端 未结 3 1223
悲&欢浪女
悲&欢浪女 2021-01-11 14:08

How can i put this string in to a cell using java apache poi?
The string is \"Hello world Hello\"
As u can see i need to make a part of the text bol

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-11 14:19

    cell.setValue(value);
    RichTextString rts = cell.getRichStringCellValue();
    rts.applyFont(value.indexOf(subValue), value.length(), boldFonts);
    cell.setCellValue(rts);
    

    Where value=something+subValue. Here subValue contents will be with bold fonts. for example if we have someting="Hello" and subValue="world" we will print:

    Hello world

    in the cell.

提交回复
热议问题