设置单元格内容的一部分,强调使用Apache POI? [英] Setting a part of the cell contents to Underline using apache poi?

查看:146
本文介绍了设置单元格内容的一部分,强调使用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);
}

会看起来像

Will look like

您可以更改字体颜色以及以同样的方式...是指这里

You can change the font colors as well in the same way... refer here

这篇关于设置单元格内容的一部分,强调使用Apache POI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆