如何获得的Word / Excel文档的页/张数? [英] How to get Page/Sheet Count of Word/Excel documents?

查看:452
本文介绍了如何获得的Word / Excel文档的页/张数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在项目中,我有一个要求来显示页面的Word文档(.doc和.docx)文件在Excel文档数量和张数(为.xls,.xlsx)。我试图读取使用Docx4j .docx文件但性能很差,但我只需要在字数和使用Apache POI尝试。我得到一个错误,是这样的:

In my project I have one requirement to show the number of pages in Word documents (.doc, .docx) files and number of sheets in Excel documents (.xls, .xlsx). I have tried to read the .docx file using Docx4j but the performance is very poor but I need just the word count and tried using Apache POI. I am getting an error, something like:

"trouble writing output: Too many methods: 94086; max is 65536. By package:" 

我想知道是否有可用于Android任何付费/开源库。

I want to know whether there is any paid/open source library available for android.

推荐答案

有只是没有办法显示在MS Word文件页面确切的数字,因为这将是对不同用户的不同。确切的数目取决于打印机设置,纸张设置,字体,可用图像等。

There is just no way to show exact number of pages in MS Word file, because it will be different for different users. The exact number depends on printer settings, paper settings, fonts, available images, etc.

不过,你可以做以下的二进制文件:

Still, you can do the following for binary files:


  • 开启文件使用POIFSFileSystem或NPOIFSFileSystem

  • 因为它是在构造函数中完成只提取FileInformationBlock HWPFDocumentCore

  • ,因为它是在HWPFDocument的constuctor进行使用来自FileInformationBlock信息DocumentProperties

  • 获得DOP财产CPG的值:DocumentProperties :: getCPg()

本场的描述是:一个有符号整数值,指定的主文档中的页面最后计算或估计数,取决于fExactCWords和fIncludeSubdocsInStats的值

The description of this field is: "A signed integer value that specifies the last calculated or estimated count of pages in the main document, depending on the values of fExactCWords and fIncludeSubdocsInStats."

有关DOCX / XLSX文件,您将需要访问相同的(我认为)财产,但使用SAX或StAX的方法。

For DOCX/XLSX documents you will need to access the same (I assume) property but using SAX or StAX methods.

这篇关于如何获得的Word / Excel文档的页/张数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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