2015-06-15 31 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

相关问题