首页 > 其他分享 >poi3.13生成word的页脚

poi3.13生成word的页脚

时间:2023-02-20 18:34:00浏览次数:41  
标签:createRun run 页脚 setXWPFRunStyle fldChar 宋体 paragraph word poi3.13

生成页脚段落

XWPFDocument document = new XWPFDocument();
/*
         * 生成页脚段落
         * 给段落设置宽度为占满一行
         * */
        CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
        XWPFHeaderFooterPolicy headerFooterPolicy = new XWPFHeaderFooterPolicy(document, sectPr);
        XWPFFooter footer = headerFooterPolicy.createFooter(STHdrFtr.DEFAULT);
        System.out.println(footer);
        List<XWPFParagraph> paragraphs = footer.getParagraphs();
        System.out.println(paragraphs);
        XWPFParagraph paragraph = footer.getParagraphArray(0);
        System.out.println(paragraph);
        paragraph.setAlignment(ParagraphAlignment.CENTER);
        paragraph.setVerticalAlignment(TextAlignment.CENTER);
        paragraph.setBorderTop(Borders.THICK);
        CTTabStop tabStop = paragraph.getCTP().getPPr().addNewTabs().addNewTab();
        tabStop.setVal(STTabJc.RIGHT);
        int twipsPerInch = 1440;
        tabStop.setPos(BigInteger.valueOf(6 * twipsPerInch));
/*
         * 给段落创建元素
         * 设置元素字面为公司地址+公司电话
         * */
        XWPFRun run = paragraph.createRun();
        setXWPFRunStyle(run, "宋体", 8);
        run.addTab();
//        String s=run.getFontFamily();
        /*
         * 生成页码
         * 页码右对齐
         * */
        run = paragraph.createRun();
        run.setText("第");
        setXWPFRunStyle(run, "宋体", 8);
        run = paragraph.createRun();
        CTFldChar fldChar = run.getCTR().addNewFldChar();
        fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));
        setXWPFRunStyle(run, "宋体", 8);
        run = paragraph.createRun();
        CTText ctText = run.getCTR().addNewInstrText();
        ctText.setStringValue("PAGE  \\* MERGEFORMAT");
        ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
        setXWPFRunStyle(run, "宋体", 8);

        fldChar = run.getCTR().addNewFldChar();
        fldChar.setFldCharType(STFldCharType.Enum.forString("end"));

        run = paragraph.createRun();
        run.setText("页/共");
        setXWPFRunStyle(run, "宋体", 8);

        run = paragraph.createRun();
        fldChar = run.getCTR().addNewFldChar();
        fldChar.setFldCharType(STFldCharType.Enum.forString("begin"));

        run = paragraph.createRun();
        ctText = run.getCTR().addNewInstrText();
        ctText.setStringValue("NUMPAGES  \\* MERGEFORMAT ");
        ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve"));
        setXWPFRunStyle(run, "宋体", 8);

        fldChar = run.getCTR().addNewFldChar();
        fldChar.setFldCharType(STFldCharType.Enum.forString("end"));

        run = paragraph.createRun();
        run.setText("页");
        setXWPFRunStyle(run, "宋体", 8);


标签:createRun,run,页脚,setXWPFRunStyle,fldChar,宋体,paragraph,word,poi3.13
From: https://blog.51cto.com/u_15973676/6069214

相关文章

  • poi3.13生成多级标题
    自定义标题的层级关系/***增加自定义标题样式。这里用的是stackoverflow的源码**@paramdocxDocument目标文档*@paramstrStyleId样式......
  • poi3.13生成表格
    表格生成和换页方法//创建试验设计表格XWPFTabletableBanBen=document.createTable();//设置表级别单元格边距tableBanBen.setCellMa......
  • pdf转MD、HTML、word网址收集
    PDF转Word,Excel,PPT,JPG的网址:https://smallpdf.com/cn/pdf-to-wordPDF转Markdown的网址:https://pdf2md.morethan.io/PDF转HTML的网址:https://www.pdftohtml.net/......
  • NPOI给word中的表格table动态添加行,并保留表格样式 , 替换文字
    publicclassNPOIHelper{///<summary>///输出模板docx文档///</summary>///<paramname="tempFilePath">模板文件地......
  • pdf转md、word、html、ppt等相互转换
    pdf转md、word、html、ppt等相互转换PDF与Word,Excel,PPT,JPG互转的网址:https://smallpdf.com/cn/pdf-to-wordPDF转Markdown的网址:https://pdf2md.morethan......
  • 关于MySQL 8.0 默认使用了新的身份验证插件 caching_sha2_password,而旧版本的 MySQL C
    要解决这个问题,有以下两种方法:1、使用新版本的MySQLConnector/NET。您可以从MySQL官网下载最新版本的MySQLConnector/NET,它支持新的caching_sha2_password插件。......
  • java便捷的word导出工具(officejj)
    写在最前面officejj不仅支持导出word,它操作excel和pdf也很简单。官方文档:https://doc.javaex.cn/officejj怎么发现它的公司主要是为学校开发管理系统的,然后就经常要导......
  • 给wordpress添加下载按钮
    是不是一直觉得每次写文章,发布下载链接,一串串的网址,或者锚文本都非常不美观。用插件解决,貌似太过小题大做了。显示下载按钮,方法其实很简单,只要把如下代码插入主题目录下的fu......
  • C#/VB.NET 如何在 Word 文档中添加页眉和页脚
    页眉位于文档中每个页面的顶部区域,常用于显示文档的附加信息,可以插入时间、图形、公司微标、文档标题、文件名或作者姓名等;页脚位于文档中每个页面的底部的区域,常用于显示文......
  • word样式多级标题变成黑块/黑线
      我在写文档(客户给的word模板)时,突然发现3级标题内容,变成了竖线。使用网上查询的“按组合键『Ctrl+Shift+S』,打开『应用样式』对话框,点击『重新应用』”,问题虽然......