如何使用 Apache POI 为单元格内的一系列文本应用粗体文本样式?
How to apply bold text style for a range of text inside a cell using Apache POI?
如何使用 Apache POI 将一系列文本设为粗体文本样式?
例如:
而不是为整个单元格应用样式。
我曾经在 vb.net 中使用以下代码行执行此操作:
excellSheet.Range("C2").Value = "Priority: " + priority
excellSheet.Range("C2").Characters(0, 8).Font.Bold = True
但我无法在 Java 中使用 Apache POI 找到执行此操作的方法。
任何帮助将不胜感激。谢谢!
第一,create your Font
with bold styling, using the Workbook
object.
Font font = workbook.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
接下来,从 Cell
中获取 RichTextString
并调用 applyFont
overload that takes a range of indexes and the Font
to apply。
RichTextString rts = cell.getRichStringCellValue();
rts.applyFont(0, 8, font);
如果您想将工作簿中的其他文本转换为粗体,您应该重复使用 Font
对象。
如何使用 Apache POI 将一系列文本设为粗体文本样式? 例如:
而不是为整个单元格应用样式。 我曾经在 vb.net 中使用以下代码行执行此操作:
excellSheet.Range("C2").Value = "Priority: " + priority
excellSheet.Range("C2").Characters(0, 8).Font.Bold = True
但我无法在 Java 中使用 Apache POI 找到执行此操作的方法。
任何帮助将不胜感激。谢谢!
第一,create your Font
with bold styling, using the Workbook
object.
Font font = workbook.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
接下来,从 Cell
中获取 RichTextString
并调用 applyFont
overload that takes a range of indexes and the Font
to apply。
RichTextString rts = cell.getRichStringCellValue();
rts.applyFont(0, 8, font);
如果您想将工作簿中的其他文本转换为粗体,您应该重复使用 Font
对象。