XWPFDocument docx = new XWPFDocument();
XWPFHeaderFooterPolicy headerFooterPolicy = docx.getHeaderFooterPolicy();
if (headerFooterPolicy == null) headerFooterPolicy = docx.createHeaderFooterPolicy();
String sealType = "";
sealType = paperTemplate.getPtSealLineType().toLowerCase();
switch (sealType) {
case "once":
//首页
docx.createHeader(HeaderFooterType.FIRST);
break;
case "default":
//每页
headerFooterPolicy.createHeader(STHdrFtr.DEFAULT);
break;
case "odd":
//奇数页
docx.setEvenAndOddHeadings(true);
headerFooterPolicy.createHeader(STHdrFtr.DEFAULT);
headerFooterPolicy.createHeader(STHdrFtr.EVEN);
break;
case "even":
//偶数页
docx.setEvenAndOddHeadings(true);
headerFooterPolicy.createHeader(STHdrFtr.DEFAULT);
headerFooterPolicy.createHeader(STHdrFtr.EVEN);
break;
}
标签:case,docx,word,页脚,headerFooterPolicy,break,STHdrFtr,页眉,createHeader
From: https://www.cnblogs.com/javacoffeenet/p/17798462.html