【问题标题】:Error in CTPageSZ class using Apache POI Java NetBeans Word Document使用 Apache POI Java NetBeans Word 文档的 CTPageSZ 类中的错误
【发布时间】:2016-01-20 10:10:43
【问题描述】:

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

当我尝试输入以下代码时。我遇到了一些问题。我使用 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”的错误。

我遇到来自 NetBeans 的以下错误消息:

  1. 在包 apachetable1 中创建类“CTPageSz”
  2. 在 apachetable1.ApacheTable1 中创建类“CTPageSz”
  3. 配置“Throwable 方法结果被忽略”提示

我搜索了 CTPageSz,但不知道如何修复此错误。我使用 Apache POI 3.13。

有没有更简单的方法可以将方向更改为横向?谢谢。

【问题讨论】:

    标签: java apache netbeans ms-word


    【解决方案1】:

    我在使用 CTPageSz 时遇到了类似的问题!我猜你用错了罐子!

    基本上有 2 个 jar,一个是 poi-ooxml-schemas jar,另一个只是 ooxml-schemas jar。

    我在互联网上看到的是 jar 的 poi 变体更小,并且只包含通常需要的类。当你从他们的网站下载 apache-poi 包时,你会得到这个变体。

    您需要在项目中包含其他变体,即 simple ooxml-jar,可以在 here 找到。 jar 大小为 14.8MB,明显大于 poi 变体。

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

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题,我编译了这个依赖,问题已经解决了

          <dependency>
              <groupId>org.apache.poi</groupId>
              <artifactId>ooxml-schemas</artifactId>
              <version>1.3</version>
          </dependency>
      

      尝试使用它,并告诉我它是否适合你

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-10
        • 1970-01-01
        • 2018-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多