POI设置Word页边距

本文介绍了如何使用Apache POI库来设置Word文档的页边距,并提供了解决问题的链接,包括CTPageMar类的缺失问题。同时,还推荐了其他资源来参考进行样式设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考资料:http://stackoverflow.com/questions/17787176/spacing-and-margin-settings-in-word-document-using-apache-poi-docx

CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
CTPageMar pageMar = sectPr.addNewPgMar();
pageMar.setLeft(BigInteger.valueOf(720L));
pageMar.setTop(BigInteger.valueOf(1440L));
pageMar.setRight(BigInteger.valueOf(720L));
pageMar.setBottom(BigInteger.valueOf(1440L))

在导入org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar类的时候可能
找不到引用的jar包,提示“The type org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar cannot be resolved

解决办法参考http://stackoverflow.com/questions/10208097/how-to-copy-a-paragraph-of-docx-to-another-docx-withjava-and-retain-the-style

下载ooxml-schemas 1.1 http://repo.maven.apache.org/maven2/org/apache/poi/ooxml-schemas/1.1/

POI 3.8、POI3.9、POI3.10.1和POI 3.11的jar包中都不包含CTPageMar这个类


其他常用的一些样式设置可以参考http://53873039oycg.iteye.com/blog/2153194

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值