Apache Poi:在DOC文档中获取页数 [英] Apache Poi: get page count in DOC document

查看:2612
本文介绍了Apache Poi:在DOC文档中获取页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Apache Poi获取DOC文档中的页数?

How to get page count in DOC document using Apache Poi?

我尝试使用以下代码:

HWPFDocument wordDoc = new HWPFDocument(new FileInputStream(lowerFilePath));
Integer pageCount = wordDoc.getSummaryInformation().getPageCount();

但是出现了异常(Apache Poi版本:3.13)

But got exception (version of Apache Poi: 3.13)

    java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.toByteArray(Ljava/io/InputStream;I)[B
at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:95)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:174)

推荐答案

您的代码应该可以正常工作.发生此非常常见的POI错误的原因是,您的类路径上的库的旧版本尚不存在该方法.库中的某些版本的零件也不兼容.

Your code should work properly. The reason of this very common POI error is that an older version of the library on your classpath in which the method didn't exist yet. And also some versions of parts from the library are incompatible.

如果您使用maven,则此代码段仅需要这些依赖项:

If you use maven you need only these dependencies for this piece of code:

<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi</artifactId>
  <version>${poi.version}</version>
</dependency>
<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi-scratchpad</artifactId>
  <version>${poi.version}</version>
</dependency>

确保您没有其他版本的罐子.

Make sure you do not have extra versions of jars.

这篇关于Apache Poi:在DOC文档中获取页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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