栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java POI 设置字体下划线、方框打勾、字体加粗

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java POI 设置字体下划线、方框打勾、字体加粗

文章目录
    • Java POI 设置字体下划线
      • 1.通过代码设置
      • 2. 通过excel模板,直接字符串替换
    • Java POI 输出方框打勾
      • 1.代码设置
      • 2.直接字符串输出
    • Java POI 设置字体下划线

Java POI 设置字体下划线
1.通过代码设置
// 设置下划线
    private XSSFRichTextString UnderLineIndex(String content, Font font) {
            font.setUnderline((byte)1);
        XSSFRichTextString richString = new XSSFRichTextString(content);
        // 该font应用于那些位置的字符
        richString.applyFont(6, content.length(), font);
        font.setUnderline((byte)0);
        return richString;
    }
2. 通过excel模板,直接字符串替换

private void fillCellValue(XSSFCell cell) {
        String stringCellValue = cell.getStringCellValue().replace("${recuritName}", "余波");
        cell.setCellValue( stringCellValue );
 }
Java POI 输出方框打勾
1.代码设置
 // 设置方框打勾
    private RichTextString fillTextRight(String content, Font font){
        RichTextString richTextString = new XSSFRichTextString("("\u25A1"");
        // 设置字体名称
        font.setFontName("Wingdings 2");
        richTextString.applyFont(, font);
        return richTextString;

    }

2.直接字符串输出
 cell.setStringCellValue("□");
 cell.setStringCellValue("☑");

Java POI 设置字体下划线
// 字体加粗
    private RichTextString blodText(String content, Font font, int start, int end ) {
        RichTextString richTextString = new XSSFRichTextString(content);
        font.setFontName("宋体");
        font.setBold(true);
        // 字体大小
        short fontHeight = font.getFontHeightInPoints();
        font.setFontHeightInPoints((short) 10);
        richTextString.applyFont(start, end , font);
        // 还原为原Font
        font.setFontHeightInPoints(fontHeight);
        font.setBold(false);//粗体显示
        return richTextString;
    }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/298957.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号