如何解决apache poi 禁用第一页的默认页脚
我正在尝试创建一个 Word 文档,其中只有第一页没有页脚,其余页面有页脚。我编写了以下代码(我还尝试更改 - 反转 - footer
和 footerFirst
对象的创建顺序),但这没有帮助。我仍然在所有页面上使用默认页脚。
我应该如何从第一页禁用页脚?提前致谢。
private XWPFDocument initDocument(String FILE) throws Exception{
XWPFDocument document = new XWPFDocument();
XWPFheaderfooterPolicy headerfooterPolicy = document.getheaderfooterPolicy();
if (headerfooterPolicy == null) headerfooterPolicy = document.createheaderfooterPolicy();
// create header start
XWPFFooter footer = headerfooterPolicy.createFooter(XWPFheaderfooterPolicy.DEFAULT);
//XWPFParagraph paragraph = footer.createParagraph();
XWPFParagraph paragraph = footer.getParagraphArray(0);
if (paragraph == null)
paragraph = footer.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run = paragraph.createRun();
run.setFontSize(11);
run.setFontFamily("Times New Roman");
run.setText("Some company info in the footer");
XWPFFooter footerFirst = headerfooterPolicy.createFooter(XWPFheaderfooterPolicy.FirsT);
paragraph = footerFirst.getParagraphArray(0);
if (paragraph == null)
paragraph = footerFirst.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
run = paragraph.createRun();
run.setText(" ");
return document;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。