尝试将 Apache POI 移植到 Android [英] Trying to port Apache POI to Android

查看:30
本文介绍了尝试将 Apache POI 移植到 Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找 poi-3.8.jar 的轻量级版本,以便在 Android(私人)应用程序中使用它.由于某种原因,我似乎无法在 APK 中放入整个 1.7Mb jar(无论如何这样做都是错误的)并且因为我只是在寻找 doc -> html 和 xls -> html功能,我不太确定我需要整个 jar 文件.

I'm looking for a lightweight version of poi-3.8.jar to use it in an Android (private) app. I don't seem to be able to fit the whole 1.7Mb jar in the APK for some reason (and it would be wrong to do so anyway) and since I'm only looking for the doc -> html and xls -> html functionality, I'm not quite sure I need the whole jar file.

我花了几个小时试图弄清楚如何在 poi/hwpf/converter 中提取 org.apache.poi.hwpf.converter.WordToHtmlExtracter.java,但看起来它使用了很多其他东西.即使这并不让我感到惊讶,我也在想,也许这里有人会知道我可以摆脱哪些包裹来使罐子更小.我很乐意花更多的时间在上面,除非这里有人告诉我这是在浪费时间,而且需要使用源代码中的所有内容才能将 doc 转换为 html 文件.

I've spent a couple hours trying to figure out how to extract org.apache.poi.hwpf.converter.WordToHtmlExtracter.java in poi/hwpf/converter but it looks like it's using a lot of other stuff. Even if this doesn't really surprise me, I was thinking that maybe someone here would know which packages I can get rid of to make the jar smaller. I'll be glad to spend more time on it, unless someone here tells me it's a waste of time and that EVERYTHING in the sources is needed to convert doc to html files.

我不需要任何显示任何内容的东西,我只需要简单"的 doc 到 html(如果可能,xls 到 html)功能.我不需要任何与 PDF、powerpoint、outlook 或其他相关的东西.

I don't need anything that displays anything, I just need the "simple" doc to html (and xls to html if possible) features. I don't need anything related to PDF, powerpoint, outlook or whatever.

我很乐意分享我发现的一切

I'll be glad to share whatever I find out

干杯

推荐答案

好吧,我能够完成我在这里要求的大部分工作.那就是导入jar文件.我至少有两种问题:- Eclipse 上没有足够的内存,这使得我的类在大多数时候崩溃(通过调整 Eclipse.ini 中的 Xmx 和 xms 值来修复)- 每个 DEX 文件的 64k 方法限制使事情变得复杂.我不得不将所有必需的 POI jar 拆分为几个 DEX 文件.(我按照 Android 博客中的教程做到了这一点:http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html )

Well I was able to do most of what I was asking for here. That is importing the jar files. I had at least 2 kinds of problems: - not enough RAM on Eclipse which made dexing my classes crash most of the time (fixed by adjusting the Xmx and xms values in Eclipse.ini) - the 64k method limit for each DEX file made things complicated. I had to split all the required POI jars into several DEX files. (I did that by following the tutorial from the Android blog: http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html )

我的问题的真正答案是:是的,你需要罐子里的所有东西".我使它适用于基本的非打开 xml"文件.我的应用程序可以很好地转换为 html,而且速度也足够快.

The real answer to my question is: "yes you need everything in the jar". I made it work for the basic "non open xml" files. My app does the conversion to html quite well, and it's fast enough too.

顺便说一句,我也试图对打开的 XML"文件做同样的事情,但它要复杂得多.我的小项目没有做它应该做的事情,我在初始化 XMLBeans 类时遇到了一些奇怪的异常.这是我的踪迹(抱歉丑陋):

On a side note, I was also trying to do the same thing with "open XML" files, and it's much more complicated. My little project doesn't do what it's supposed to do, I've got some weird exception when initializing the XMLBeans class. Here's my trace (sorry for the ugliness):

12-19 12:07:10.790: W/dalvikvm(13385): Exception
Ljava/lang/RuntimeException; thrown while initializing
Lorg/apache/xmlbeans/impl/regex/SchemaRegularExpression;
12-19 12:07:10.790: W/dalvikvm(13385): Exception
Ljava/lang/ExceptionInInitializerError; thrown while initializing
Lorg/apache/xmlbeans/impl/schema/BuiltinSchemaTypeSystem;
12-19 12:07:10.790: D/dalvikvm(13385): Method.invoke() on bad class
Lorg/apache/xmlbeans/impl/schema/BuiltinSchemaTypeSystem; failed
12-19 12:07:10.790: W/dalvikvm(13385): Exception
Ljava/lang/ExceptionInInitializerError; thrown while initializing
Lorg/apache/xmlbeans/XmlBeans;
12-19 12:07:10.790: W/System.err(13385):
java.lang.reflect.InvocationTargetException
12-19 12:07:10.790: W/System.err(13385):    at
java.lang.reflect.Method.invokeNative(Native Method)
12-19 12:07:10.790: W/System.err(13385):    at
java.lang.reflect.Method.invoke(Method.java:491)
12-19 12:07:10.790: W/System.err(13385):    at
t.fze.TestOfficeAndroidActivity.onCreate(TestOfficeAndroidActivity.java:55)
12-19 12:07:10.790: W/System.err(13385):    at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
12-19 12:07:10.790: W/System.err(13385):    at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
12-19 12:07:10.790: W/System.err(13385):    at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
12-19 12:07:10.790: W/System.err(13385):    at
android.app.ActivityThread.access$1500(ActivityThread.java:122)
12-19 12:07:10.790: W/System.err(13385):    at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
12-19 12:07:10.790: W/System.err(13385):    at
android.os.Handler.dispatchMessage(Handler.java:99)
12-19 12:07:10.790: W/System.err(13385):    at
android.os.Looper.loop(Looper.java:132)
12-19 12:07:10.790: W/System.err(13385):    at
android.app.ActivityThread.main(ActivityThread.java:4025)
12-19 12:07:10.790: W/System.err(13385):    at
java.lang.reflect.Method.invokeNative(Native Method)
12-19 12:07:10.790: W/System.err(13385):    at
java.lang.reflect.Method.invoke(Method.java:491)
12-19 12:07:10.790: W/System.err(13385):    at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
12-19 12:07:10.790: W/System.err(13385):    at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
12-19 12:07:10.790: W/System.err(13385):    at
dalvik.system.NativeStart.main(Native Method)
12-19 12:07:10.790: W/System.err(13385): Caused by:
org.apache.poi.POIXMLException:
java.lang.reflect.InvocationTargetException
12-19 12:07:10.790: W/System.err(13385):    at
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
12-19 12:07:10.790: W/System.err(13385):    at
org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:414)
12-19 12:07:10.790: W/System.err(13385):    at
org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
12-19 12:07:10.790: W/System.err(13385):    at
org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:174)
12-19 12:07:10.790: W/System.err(13385):    at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:63)
12-19 12:07:10.790: W/System.err(13385):    at
org.apache.poi.ss.examples.html.ToHtml.create(ToHtml.java:139)
12-19 12:07:10.790: W/System.err(13385):    at
org.apache.poi.ss.examples.html.ToHtml.create(ToHtml.java:123)
12-19 12:07:10.790: W/System.err(13385):    ... 16 more
12-19 12:07:10.790: W/System.err(13385): Caused by:
java.lang.reflect.InvocationTargetException
12-19 12:07:10.790: W/System.err(13385):    at
java.lang.reflect.Constructor.constructNative(Native Method)
12-19 12:07:10.790: W/System.err(13385):    at
java.lang.reflect.Constructor.newInstance(Constructor.java:416)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)
12-19 12:07:10.800: W/System.err(13385):    ... 22 more
12-19 12:07:10.800: W/System.err(13385): Caused by:
java.lang.ExceptionInInitializerError
12-19 12:07:10.800: W/System.err(13385):    at
org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(ThemeDocument.java:71)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:38)
12-19 12:07:10.800: W/System.err(13385):    ... 25 more
12-19 12:07:10.800: W/System.err(13385): Caused by:
java.lang.ExceptionInInitializerError
12-19 12:07:10.800: W/System.err(13385):    at
java.lang.reflect.Method.invokeNative(Native Method)
12-19 12:07:10.800: W/System.err(13385):    at
java.lang.reflect.Method.invoke(Method.java:491)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.XmlBeans.getNoType(XmlBeans.java:856)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.XmlBeans.<clinit>(XmlBeans.java:881)
12-19 12:07:10.800: W/System.err(13385):    ... 27 more
12-19 12:07:10.800: W/System.err(13385): Caused by:
java.lang.ExceptionInInitializerError
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem.fillInType(BuiltinSchemaTypeSystem.java:1025)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem.<clinit>(BuiltinSchemaTypeSystem.java:223)
12-19 12:07:10.800: W/System.err(13385):    ... 31 more
12-19 12:07:10.800: W/System.err(13385): Caused by:
java.lang.RuntimeException: Installation Problem???  Couldn't load
messages: Can't find resource for bundle
'org.apache.xmlbeans.impl.regex.message_fr_FR', key ''
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.RegexParser.setLocale(RegexParser.java:88)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.RegexParser.<init>(RegexParser.java:78)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.ParserForXMLSchema.<init>(ParserForXMLSchema.java:28)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.RegularExpression.setPattern(RegularExpression.java:2996)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.RegularExpression.setPattern(RegularExpression.java:3009)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.RegularExpression.<init>(RegularExpression.java:2975)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.SchemaRegularExpression.<init>(SchemaRegularExpression.java:27)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.SchemaRegularExpression.<init>(SchemaRegularExpression.java:23)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.SchemaRegularExpression$1.<init>(SchemaRegularExpression.java:44)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.SchemaRegularExpression.buildKnownPatternMap(SchemaRegularExpression.java:43)
12-19 12:07:10.800: W/System.err(13385):    at
org.apache.xmlbeans.impl.regex.SchemaRegularExpression.<clinit>(SchemaRegularExpression.java:38)
12-19 12:07:10.800: W/System.err(13385):    ... 33 more

这篇关于尝试将 Apache POI 移植到 Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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