demand : Add page number
<properties> <easypoi.version>4.0.0</easypoi.version> </properties> <!--
easypoi--> <dependency> <groupId>cn.afterturn</groupId> <artifactId>easypoi-base
</artifactId> <version>${easypoi.version}</version> </dependency> <dependency> <
groupId>cn.afterturn</groupId> <artifactId>easypoi-web</artifactId> <version>${
easypoi.version}</version> </dependency> <dependency> <groupId>cn.afterturn</
groupId> <artifactId>easypoi-annotation</artifactId> <version>${easypoi.version}
</version> </dependency> package; import org.
apache.poi.xwpf.model.XWPFHeaderFooterPolicy; import org.apache.poi.xwpf.
usermodel.*; import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import*; /** * ClassName FooterTest * Description add footer to word
with poi * Author Kalinda * Date 2020/7/1 13:54 * Version 1.0 */ public class
FooterTest { public static void main(String[] args) { try { // file path File is
= new File("D:/test.docx"); FileInputStream fis = new FileInputStream(is); //
document object XWPFDocument doc = new XWPFDocument(fis); // calling method
createFooter(doc); // or this method both ok! // createFooter(doc); // output
OutputStream os= new FileOutputStream("D:\\Test1.docx"); doc.write(os); } catch
(Exception e) { e.printStackTrace(); } } public static void createFooter(
XWPFDocument doc) { // create footer XWPFHeaderFooterPolicy policy = doc.
getHeaderFooterPolicy(); CTP ctpFooter = CTP.Factory.newInstance();
XWPFParagraph[] parsFooter; // add style ( CTPPr ctppr = ctpFooter.
addNewPPr(); CTString pst = ctppr.addNewPStyle(); pst.setVal("style21"); CTJc
ctjc= ctppr.addNewJc(); ctjc.setVal(STJc.CENTER); ctppr.addNewRPr(); // add
everything from the footerXXX.xml you need CTR ctr = ctpFooter.addNewR(); ctr.
addNewRPr(); CTFldChar fch = ctr.addNewFldChar(); fch.setFldCharType(
STFldCharType.BEGIN); ctr = ctpFooter.addNewR(); ctr.addNewInstrText().
setStringValue(" PAGE "); ctpFooter.addNewR().addNewFldChar().setFldCharType(
STFldCharType.SEPARATE); ctpFooter.addNewR().addNewT().setStringValue("1");
XWPFParagraph footerParagraph= new XWPFParagraph(ctpFooter, doc); parsFooter =
new XWPFParagraph[1]; parsFooter[0] = footerParagraph; policy.createFooter(
XWPFHeaderFooterPolicy.DEFAULT, parsFooter); } public static void
createDefaultFooter(final XWPFDocument document) { CTP pageNo = CTP.Factory.
newInstance(); XWPFParagraph footer = new XWPFParagraph(pageNo, document);
CTPPr begin= pageNo.addNewPPr(); begin.addNewPStyle().setVal("style21"); begin.
addNewJc().setVal(STJc.CENTER); pageNo.addNewR().addNewFldChar().setFldCharType(
STFldCharType.BEGIN); pageNo.addNewR().addNewInstrText().setStringValue("PAGE
\\* MERGEFORMAT"); pageNo.addNewR().addNewFldChar().setFldCharType(STFldCharType
.SEPARATE); CTR end = pageNo.addNewR(); CTRPr endRPr = end.addNewRPr(); endRPr.
addNewNoProof(); endRPr.addNewLang().setVal("zh-CN"); end.addNewFldChar().
setFldCharType(STFldCharType.END); CTSectPr sectPr = document.getDocument().
getBody().isSetSectPr() ? document.getDocument().getBody().getSectPr() : docx.
getDocument().getBody().addNewSectPr(); XWPFHeaderFooterPolicy policy = new
XWPFHeaderFooterPolicy(document, sectPr); policy.createFooter(STHdrFtr.DEFAULT,
new XWPFParagraph[] { footer }); } }

©2019-2020 Toolsou All rights reserved,
Final review of database : Summary of comprehensive application questions Laplance operator ( Second derivative ) Simple learning of computer composition principle pyqt Button call python program _PyQt: Link button to function in program How much can you go up once you change jobs ? Today, I saw the ceiling of job hopping python in str Function usage _python in str Usage Summary of built-in functions MySQL trigger web The server nginx---linux Installation and deployment C++ Chapter V polymorphism exercises :( It's coming to an end )python Check built-in functions , How to check python Built in function