2015-06-15 32 views
1

如何使用Apache POI創建一系列文本粗體文本樣式? 如:如何使用Apache POI在單元格內爲文本範圍應用粗體文本樣式?

enter image description here

代替將作風爲整個小區的。 我用幾行代碼來做到這一點在vb.net:

excellSheet.Range("C2").Value = "Priority: " + priority 
excellSheet.Range("C2").Characters(0, 8).Font.Bold = True 

但我找不到在Java中使用Apache POI做的方式。

任何幫助將不勝感激。謝謝!

回答

3

首先,create your Font with bold styling, using the Workbook object

Font font = workbook.createFont(); 
font.setBoldweight(Font.BOLDWEIGHT_BOLD); 

接下來,抓住從CellRichTextString並調用applyFont overload that takes a range of indexes and the Font to apply

RichTextString rts = cell.getRichStringCellValue(); 
rts.applyFont(0, 8, font); 

,如果你想其他文本轉換工作簿中的大膽你應該重用Font對象。

+0

非常感謝! – pableiros

相關問題