XWPFDocument document= new XWPFDocument();
CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
CTPageMar pageMar = sectPr.addNewPgMar();
pageMar.setTop(BigInteger.valueOf(720L));
pageMar.setBottom(BigInteger.valueOf(720L));
pageMar.setLeft(BigInteger.valueOf(1440L));
pageMar.setRight(BigInteger.valueOf(1440L));
注意 新版本的POI需要引入ooxml-schemas-1.1.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/CTPageMar
at org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTSectPrImpl.addNewPgMar(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more