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

查看:60
本文介绍了如何使用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 FAQ中有明确说明:

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

要使用新的 OOXML 文件格式,POI 需要一个包含文件格式 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.

来自 FAQ 的 URL 不起作用,但您可以在 中找到所需的 jar中央 Maven 仓库.

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

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

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