使用 Apache POI 将单元格内容的一部分设置为下划线? [英] Setting a part of the cell contents to Underline using Apache POI?
本文介绍了使用 Apache POI 将单元格内容的一部分设置为下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个程序,我必须在其中设置像
I am working on a program in which I have to set cell value in an Excel spreadsheet like
这是一个下划线文本".
可以是粗体、斜体或下划线.
It can be anything Bold, Italic, or Underline.
我使用的是 Apache POI 3.9
I am using Apache POI 3.9
推荐答案
尝试以下操作:
public static void differentFontTypeInSameCell(){
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("TestSheet");
Cell cell = sheet.createRow(0).createCell(0);
Font underlineFont = wb.createFont();
underlineFont.setUnderline(HSSFFont.U_DOUBLE);
Font boldFont = wb.createFont();
boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
Font italicFont = wb.createFont();
italicFont.setItalic(true);
CellStyle style = wb.createCellStyle();
style.setFont(underlineFont);
cell.setCellStyle(style);
RichTextString richString = new HSSFRichTextString("Underline, Bold, Italic");
richString.applyFont(11, 15, boldFont);
richString.applyFont(17, 23, italicFont);
cell.setCellValue(richString);
}
看起来像
您也可以以相同的方式更改字体颜色...请参阅此处
You can change the font colors as well in the same way... refer here
这篇关于使用 Apache POI 将单元格内容的一部分设置为下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文