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://*.com/questions/28833418/switch-page-to-landscape-from-portrait-apache-poi.
我尝试使用Apache POI和Java生成一个Microsoft Word文档。我对这个结果非常满意,直到我试图改变文档的朝向。我找到了一些解决方案。其中一个是:https://*.com/questions/28833418/switch-page-to- view -from-portrait-apache-poi。
When I try to enter the codes below. I have encountered some problems. I use Netbeans IDE.
当我试图输入下面的代码时。我遇到了一些问题。我使用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);
Line 9 and 10 gives me error regarding "CTPageSz".
第9行和第10行给了我关于“CTPageSz”的错误。
I encounter the following error messages from NetBeans:
我遇到了以下来自NetBeans的错误消息:
- Create class "CTPageSz" in package apachetable1
- 在包apachetable1中创建类“CTPageSz”。
- Create class "CTPageSz" in apachetable1.ApacheTable1
- 在apachetable1.ApacheTable1中创建类“CTPageSz”。
- Configure "Throwable method result is ignored" Hint
- 配置“可丢弃的方法结果被忽略”提示。
I search about CTPageSz but could not really know how to fix this error. I use Apache POI 3.13.
我搜索了CTPageSz,但不知道如何修正这个错误。我使用Apache POI 3.13。
Are there any simpler ways to change orientation to landscape ? Thank you.
有没有更简单的方法来改变朝向?谢谢你!
1 个解决方案
#1
3
I was facing a similar issue with CTPageSz! I guess you are using the wrong jar!
我正面临着与CTPageSz类似的问题!我猜你用的是错误的罐子!
Basically there are 2 jars, one is the poi-ooxml-schemas jar and the other being simply the ooxml-schemas jar.
基本上有两个罐子,一个是poi-ooxml-schemas jar,另一个是简单的ooxml-schemas jar。
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.
我在internet上看到的是,jar的poi变体更小,并且只包含一个通常需要的类。当你从他们的网站下载apache-poi软件包时,你就会得到这个变种。
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.
您需要在项目i中包含其他变体。在这里可以找到简单的ooxml-jar。这个罐子的大小是14.8MB,比poi的变体大得多。
Hope this helps. All the best :)
希望这个有帮助。所有最好的:)
#1
3
I was facing a similar issue with CTPageSz! I guess you are using the wrong jar!
我正面临着与CTPageSz类似的问题!我猜你用的是错误的罐子!
Basically there are 2 jars, one is the poi-ooxml-schemas jar and the other being simply the ooxml-schemas jar.
基本上有两个罐子,一个是poi-ooxml-schemas jar,另一个是简单的ooxml-schemas jar。
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.
我在internet上看到的是,jar的poi变体更小,并且只包含一个通常需要的类。当你从他们的网站下载apache-poi软件包时,你就会得到这个变种。
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.
您需要在项目i中包含其他变体。在这里可以找到简单的ooxml-jar。这个罐子的大小是14.8MB,比poi的变体大得多。
Hope this helps. All the best :)
希望这个有帮助。所有最好的:)