自学内容网 自学内容网

java给word设置复选框

poi设置

使用"Wingdings 2" 字体

WordUtil.appendText(paragraph, "\uF052", "Wingdings 2",null);
WordUtil.appendText(paragraph, "□", null);

选中的复选框:

  • poi导出pdf的时候正常
  • 使用aspose-words导出pdf就空了

使用默认字体

WordUtil.appendText(paragraph, "☑", null,null);
WordUtil.appendText(paragraph, "□", null);

选中的复选框:

  • poi导出pdf的时候是空,
  • 使用aspose-words导出pdf正常
    在这里插入图片描述

又是心态爆炸的一天o(╥﹏╥)o

工具方法


    /**
     * 在一行中追加文本
     *
     * @param text
     * @param fontName
     * @param paragraph
     */
    public static XWPFRun appendText(XWPFParagraph paragraph, String text, String fontName, Integer position) {
        XWPFRun run = paragraph.createRun();
        CTRPr ctrPr = run.getCTR().addNewRPr();
        CTFonts font = ctrPr.addNewRFonts();
        // ASCII 第一优先级(这个能匹配直接用这个,不行用下面的字体)
        if (StringUtils.isNotBlank(fontName)) {
            font.setAscii(fontName);    //上一种方法setFontFamily() 其实只调用了这个方法
        } else {
            font.setAscii("宋体");    //上一种方法setFontFamily() 其实只调用了这个方法

        }

        //中文
        font.setEastAsia("Arial");

// 其他字符(有想法可以自己去研究一下是什么字符的):
        font.setCs("宋体");
        //最低优先级
        font.setHAnsi("宋体");
        if (position != null) {
            ctrPr.addNewPosition().setVal(BigInteger.valueOf(position));
        }
        run.setText(text);

        return run;
    }


原文地址:https://blog.csdn.net/qq_36254947/article/details/142660598

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!