使用apache poi将单元格内容的一部分设置为下划线? [英] Setting a part of the cell contents to Underline using apache poi?
本文介绍了使用apache poi将单元格内容的一部分设置为下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个程序,我必须在Excel表单中设置单元格值,如
I am working on a program in which i have to set cell value in an excel sheet like
这是一个下划线文本
它可以是任何粗体,斜体或下划线。
It can be anything Bold,Italic or Underline.
我正在使用poi 3.9和netbeans,请帮助我这个
I am using poi 3.9 and netbeans, please help me with this
提前感谢
推荐答案
尝试以下:
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屋!
查看全文