如何使用apache poi设置Word文档的页边距? [英] how to set page margins for word document using apache poi?

查看:621
本文介绍了如何使用apache poi设置Word文档的页边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为使用apache poi-3.9创建的Word文档设置页边距.我发现可以使用CTPageMar 但是CTPageMar尚未解决.我正在使用apache poi-3.9

I want to set page-margins for word document created using apache poi-3.9. I found it can be done using CTPageMar but CTPageMar is not being resolved. I am using apache poi-3.9

我尝试过

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));

推荐答案

据我了解,该问题与所提供的代码无关,它与缺少的CTPageMar类有关.

As far as I understand, the problem is not related to the provided code, it is connected with missing CTPageMar class.

Apache POI常见问题解答中明确说明了缺少类问题的根源:

The source of missing classes problem is clearly explained in Apache POI FAQ:

要使用新的OOXML文件格式,POI需要一个包含以下内容的jar文件: 文件格式XSD [...]您可以从POI Maven存储库手动下载jar.

To use the new OOXML file formats, POI requires a jar containing the file format XSDs [...] You can download the jar by hand from the POI Maven Repository.

常见问题解答中的URL不起作用,但是您可以在.

URL from FAQ is not working, but you can find required jar in central maven repo.

这篇关于如何使用apache poi设置Word文档的页边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆