且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Apache Poi在Android上阅读.docx

更新时间:2023-02-23 14:22:27

您缺少一些jar.为了使用POI读取Word 2007文件,您还需要以下库(从官方Apache POI站点下载的归档文件中都提供了这些库):

You're missing some jars. In order to read Word 2007 files using POI you also need the following libraries (they're all available in the archive you download from the official Apache POI site):

poi-ooxml-schemas (您遇到错误的那个)

poi-ooxml-schemas (the one you're getting the error about)

xmlbeans

dom4j

stax

根据官方网站,不再需要dom4j和stax,但是我发现没有添加它们时遇到了问题.

According to the official website, dom4j and stax are no longer needed but I found I had problems when I didn't add them.

不幸的是,您一定会发现添加所有这些库将导致Dalvik dex错误(Android classes.dex最多可容纳64k的方法声明,您将对其进行交叉).对此的官方"解释是POI根本不是为Android设计的.不幸的是,我无法找到解决该问题的简单,可管理的解决方案(曾尝试将POI移植到Android,但在某种程度上成功了,但就我的口味而言,它们太麻烦了).我通过将Word 2007文件发送到远程服务器解决了该问题,将其转换为旧格式,然后返回到要由POI打开的移动设备.

Unfortunately, you're bound to discover that adding all of these libraries will result in a Dalvik dex error (an Android classes.dex can hold up to 64k of method declarations, which you will cross). The "official" explanation for this is that POI is simply not designed for Android. Unfortunately I have not been able to find an easy, manageable solution for that problem (there have been attempts, some partially successful, of porting POI to Android, but they're too cumbersome for my taste). I solved that problem by sending the Word 2007 files to a remote server, converted them to the old format and returned to the mobile device to be opened by POI.