How to make a range of text bold text style using Apache POI? Eg:
Instead of applying style for the entire cell. I used to do this in vb.net with these lines of code:
excellSheet.Range("C2").Value = "Priority: " + priority
excellSheet.Range("C2").Characters(0, 8).Font.Bold = True
But I can't find the way to do that in Java using Apache POI.
Any help will be much appreciated. Thanks!
First, create your Font
with bold styling, using the Workbook
object .
Font font = workbook.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
Next, grab the RichTextString
from the Cell
and call the applyFont
overload that takes a range of indexes and the Font
to apply .
RichTextString rts = cell.getRichStringCellValue();
rts.applyFont(0, 8, font);
You should reuse the Font
object if you want to convert other text in the workbook to bold.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.