1
votes

How to make a range of text bold text style using Apache POI? Eg:

enter image description here

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!

1

1 Answers

3
votes

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.