Java 如何在android应用程序中读取xlsx文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21278813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to read xlsx file in an android application?
提问by benleung
I know there's many same questions on stackoverflow, but it seems that I can't see any possible solution for reading the content of xlsx.
我知道在 stackoverflow 上有很多相同的问题,但似乎我看不到任何可能的解决方案来阅读 xlsx 的内容。
What I have try:
我尝试过的:
I have try to put the whole Apache POI library to an android application and try to read the xlsx file. However, the problem is that the Apache POI library is too heavy to put into an android application. An error message shows that the Dalvik VM cannot execute an app with more than 65536 methods.
我尝试将整个 Apache POI 库放到一个 android 应用程序中,并尝试读取 xlsx 文件。然而,问题是 Apache POI 库太重,无法放入 android 应用程序中。一条错误消息显示 Dalvik VM 无法执行具有超过 65536 个方法的应用程序。
It there any way to read the content of the xlsx file (could be the content only, other formatting such as color/width of the cell is not important) in an android app? Or it there any one tried to trim down the apache poi library so that Dalvik VM can execute it? As I saw that QuickOffice from Google Play are also using Apache POI, but I really don't know how to put the POI into an app. Thanks so much.
有什么方法可以在Android应用程序中读取xlsx文件的内容(可能只是内容,其他格式如单元格的颜色/宽度并不重要)?或者有人试图减少 apache poi 库以便 Dalvik VM 可以执行它?我看到 Google Play 的 QuickOffice 也在使用 Apache POI,但我真的不知道如何将 POI 放入应用程序中。非常感谢。
回答by Digvesh Patel
回答by Andrew Kondratev
Just committed XSSF Android usage demo on github:
刚刚在 github 上提交了 XSSF Android 使用演示:
https://github.com/andruhon/AndroidReadXLSX
https://github.com/andruhon/AndroidReadXLSX
The core idea is just to remove from poi-ooxml and poi-ooxml-schemas all files which are seems to be not necessary to read XLSX. For example xslf and xwpf from poi-ooxml, schemas presentationml and wordrpocessingml from poi-ooxml-schemas and other stuff...
核心思想只是从 poi-ooxml 和 poi-ooxml-schemas 中删除所有似乎不需要读取 XLSX 的文件。例如来自 poi-ooxml 的 xslf 和 xwpf,来自 poi-ooxml-schemas 的 schemas presentationml 和 wordrpocessingml 和其他东西......
After that, build your project and try to read XLSX, read log after that fails and see which dependency caused this fail, copy missed file from original poi-ooxml-schemas jar. Do it again and again unless it is working.
之后,构建您的项目并尝试读取 XLSX,读取失败后的日志并查看导致此失败的依赖项,从原始 poi-ooxml-schemas jar 中复制丢失的文件。一次又一次地做,除非它有效。
UPD: no more need in --core-library option!
http://blog.kondratev.pro/2014/09/reading-xlsx-on-android-3.html
UPD:不再需要 --core-library 选项!
http://blog.kondratev.pro/2014/09/reading-xlsx-on-android-3.html
Demo mentioned above already contains reduced poi-ooxml and poi-ooxml-schemas.
上面提到的 Demo 已经包含了简化的 poi-ooxml 和 poi-ooxml-schemas。