使用Apache POI Java NetBeans Word文档的CTPageSZ类错误 [英] Error in CTPageSZ class using Apache POI Java NetBeans Word Document

查看:942
本文介绍了使用Apache POI Java NetBeans Word文档的CTPageSZ类错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过使用Apache POI和Java来生成Microsoft Word文档.在尝试将文档的方向更改为横向之前,我对结果感到非常满意.我确实进行了搜索并找到了一些解决方案.其中之一是: https://stackoverflow.com/questions/28833418 /switch-page-to-landscape-fromportrait-apache-poi .

I try to produce a Microsoft Word document by using Apache POI and Java. I was really happy with the result until I try to change the orientation of the document to landscape. I did search and find some solutions. One of them is: https://stackoverflow.com/questions/28833418/switch-page-to-landscape-from-portrait-apache-poi.

当我尝试输入以下代码时.我遇到了一些问题.我使用Netbeans IDE.

When I try to enter the codes below. I have encountered some problems. I use Netbeans IDE.

XWPFDocument document = new XWPFDocument();
CTDocument1 doc = document.getDocument();
CTBody body = doc.getBody();
CTSectPr section = body.addNewSectPr();
XWPFParagraph paragraph = document.createParagraph();
CTP ctp = paragraph.getCTP();
CTPPr br = ctp.addNewPPr();
br.setSectPr(section);
CTPageSz pageSize = section.getPgSz();
pageSize.setOrient(STPageOrientation.LANDSCAPE);

第9行和第10行给我有关"CTPageSz"的错误.

Line 9 and 10 gives me error regarding "CTPageSz".

我从NetBeans遇到以下错误消息:

I encounter the following error messages from NetBeans:

  1. 在软件包apachetable1中创建类"CTPageSz"
  2. 在apachetable1.ApacheTable1中创建类"CTPageSz"
  3. 配置可抛弃的方法结果被忽略"提示

我搜索了有关CTPageSz的信息,但实际上不知道如何解决此错误.我使用Apache POI 3.13.

I search about CTPageSz but could not really know how to fix this error. I use Apache POI 3.13.

有没有更简单的方法可以改变风景的方向?谢谢.

Are there any simpler ways to change orientation to landscape ? Thank you.

推荐答案

我正遇到CTPageSz的类似问题!我猜您使用的Jar错误!

I was facing a similar issue with CTPageSz! I guess you are using the wrong jar!

基本上有2个罐子,一个是poi-ooxml-schemas罐子,另一个是ooxml-schemas罐子.

Basically there are 2 jars, one is the poi-ooxml-schemas jar and the other being simply the ooxml-schemas jar.

我在互联网上读到的是jar的poi变体较小,并且只包含一个通常需要的类.当您从他们的网站下载apache-poi软件包时,就会得到此变体.

What I've read around the internet is that the poi variant of the jar is smaller and contains only classes that one generally requires. And you get this variant when you download the apache-poi package from their website.

您需要在项目中包括其他变体,即简单 ooxml-jar,可以在

You need to include the other variant in your project i.e the simple ooxml-jar which can be found here. The jar is 14.8MB in size, significantly bigger than the poi variant.

希望这会有所帮助.祝一切顺利:)

Hope this helps. All the best :)

这篇关于使用Apache POI Java NetBeans Word文档的CTPageSZ类错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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