2

目的: ワード doc の内容を cosole に読み込むこと

使用環境:Windows 7 32bit Eclipse IDE Indigo Android 4.1 API 16 Java 1.6 ライブラリ:docx4j-2.8.0

以下は、Word doc のテキストをコンソールに出力するために使用しているコード スニペットです。

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(Environment.getExternalStorageDirectory().getAbsolutePath(), selectedFromList));

MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); 
System.out.println("file contents --->>>>>" +documentPart.getContent());    

DocPropsCorePart docPropsCorePart = wordMLPackage.getDocPropsCorePart();
CoreProperties coreProps = (CoreProperties)docPropsCorePart.getJaxbElement();

System.out.println("'dc:title' is " + coreProps.getTitle().getValue().getContent().get(0));
System.out.println(coreProps.getTitle().getValue().getClass().getName() );
System.out.println("'dcterms:created' is " + coreProps.getCreated().getClass().getName() );

上記のコードを実行しようとすると、次の問題が発生します eclipse logcat は次のログを表示します

08-10 12:22:37.853: I/dalvikvm(1761): Could not find method javax.xml.bind.JAXBContext.createMarshaller, referenced from method 

org.docx4j.openpackaging.packages.WordprocessingMLPackage.save
08-10 12:22:37.853: W/dalvikvm(1761): VFY: unable to resolve virtual method 7579: Ljavax/xml/bind/JAXBContext;.createMarshaller ()Ljavax/xml/bind/Marshaller;
08-10 12:22:37.853: D/dalvikvm(1761): VFY: replacing opcode 0x6e at 0x0017

08-10 12:22:37.863: I/dalvikvm(1761): Could not find method javax.xml.bind.JAXBContext.createMarshaller, referenced from method 

org.docx4j.openpackaging.packages.WordprocessingMLPackage.transform

08-10 12:22:37.863: W/dalvikvm(1761): VFY: unable to resolve virtual method 7579: Ljavax/xml/bind/JAXBContext;.createMarshaller ()Ljavax/xml/bind/Marshaller;
08-10 12:22:37.863: D/dalvikvm(1761): VFY: replacing opcode 0x6e at 0x000d

08-10 12:22:37.863: I/dalvikvm(1761): Failed resolving Lorg/docx4j/jaxb/JaxbValidationEventHandler; interface 1254 'Ljavax/xml/bind/ValidationEventHandler;'
08-10 12:22:37.863: W/dalvikvm(1761): Link of class 'Lorg/docx4j/jaxb/JaxbValidationEventHandler;' failed

08-10 12:22:37.873: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x46db at 0x1e in Lorg/docx4j/openpackaging/packages/WordprocessingMLPackage;.transform
08-10 12:22:37.873: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x1dba at 0x26 in Lorg/docx4j/openpackaging/packages/WordprocessingMLPackage;.transform

08-10 12:22:37.883: E/dalvikvm(1761): Could not find class 'org.apache.poi.poifs.filesystem.POIFSFileSystem', referenced from method 

org.docx4j.openpackaging.packages.OpcPackage.load

08-10 12:22:37.883: W/dalvikvm(1761): VFY: unable to resolve new-instance 1658 (Lorg/apache/poi/poifs/filesystem/POIFSFileSystem;) in 

Lorg/docx4j/openpackaging/packages/OpcPackage;
08-10 12:22:37.883: D/dalvikvm(1761): VFY: replacing opcode 0x22 at 0x001a

08-10 12:22:37.893: I/dalvikvm(1761): Could not find method javax.xml.bind.JAXBContext.createUnmarshaller, referenced from method 

org.docx4j.openpackaging.packages.OpcPackage.load

08-10 12:22:37.893: W/dalvikvm(1761): VFY: unable to resolve virtual method 7580: Ljavax/xml/bind/JAXBContext;.createUnmarshaller ()Ljavax/xml/bind/Unmarshaller;
08-10 12:22:37.893: D/dalvikvm(1761): VFY: replacing opcode 0x6e at 0x004d

08-10 12:22:37.893: I/dalvikvm(1761): Could not find method javax.xml.bind.JAXBContext.createMarshaller, referenced from method 

org.docx4j.openpackaging.packages.OpcPackage.save

08-10 12:22:37.893: W/dalvikvm(1761): VFY: unable to resolve virtual method 7579: Ljavax/xml/bind/JAXBContext;.createMarshaller ()Ljavax/xml/bind/Marshaller;
08-10 12:22:37.893: D/dalvikvm(1761): VFY: replacing opcode 0x6e at 0x0017

08-10 12:22:37.905: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x2654 at 0x1c in Lorg/docx4j/openpackaging/packages/OpcPackage;.load
08-10 12:22:37.905: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x2651 at 0x21 in Lorg/docx4j/openpackaging/packages/OpcPackage;.load

08-10 12:22:37.905: I/dalvikvm(1761): Failed resolving Lorg/docx4j/jaxb/JaxbValidationEventHandler; interface 1254 'Ljavax/xml/bind/ValidationEventHandler;'
08-10 12:22:37.905: W/dalvikvm(1761): Link of class 'Lorg/docx4j/jaxb/JaxbValidationEventHandler;' failed

08-10 12:22:37.905: D/dalvikvm(1761): DexOpt: unable to opt direct call 0x46db at 0x53 in Lorg/docx4j/openpackaging/packages/OpcPackage;.load
08-10 12:22:37.963: W/System.err(1761): org.docx4j.openpackaging.exceptions.Docx4JException: Error reading from the stream

08-10 12:22:37.963: W/System.err(1761):     at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:239)
08-10 12:22:37.963: W/System.err(1761):     at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:195)
08-10 12:22:37.963: W/System.err(1761):     at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:178)
08-10 12:22:37.963: W/System.err(1761):     at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
08-10 12:22:37.975: W/System.err(1761):     at com.reader.MainActivity$2.onItemClick(MainActivity.java:125)
08-10 12:22:37.975: W/System.err(1761):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
08-10 12:22:37.975: W/System.err(1761):     at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
08-10 12:22:37.975: W/System.err(1761):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
08-10 12:22:37.975: W/System.err(1761):     at android.widget.AbsListView$1.run(AbsListView.java:3529)
08-10 12:22:37.984: W/System.err(1761):     at android.os.Handler.handleCallback(Handler.java:615)
08-10 12:22:37.984: W/System.err(1761):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-10 12:22:37.984: W/System.err(1761):     at android.os.Looper.loop(Looper.java:137)
08-10 12:22:37.984: W/System.err(1761):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-10 12:22:37.984: W/System.err(1761):     at java.lang.reflect.Method.invokeNative(Native Method)
08-10 12:22:37.993: W/System.err(1761):     at java.lang.reflect.Method.invoke(Method.java:511)
08-10 12:22:37.993: W/System.err(1761):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-10 12:22:37.993: W/System.err(1761):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-10 12:22:37.993: W/System.err(1761):     at dalvik.system.NativeStart.main(Native Method)
08-10 12:22:38.085: W/System.err(1761): Caused by: java.io.IOException: Mark has been invalidated.
08-10 12:22:38.085: W/System.err(1761):     at java.io.BufferedInputStream.reset(BufferedInputStream.java:350)
08-10 12:22:38.093: W/System.err(1761):     at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:237)

08-10 12:22:38.923: I/Choreographer(1761): Skipped 107 frames!  The application may be doing too much work on its main thread.
4

2 に答える 2

2

開示:私はdocx4jプロジェクトに取り組んでいます

docx4jの Android 固有のブランチを使用する必要があります。

jaxb-can-be-made-to-run-on-android を参照してください

最初にAndroidDocxToHtmlを機能させてから、そこから先に進むことをお勧めします。

于 2012-08-11T00:20:56.230 に答える
0

回答は IOException "Mark has been invalidated" を参照しています: docx4j の Android ブランチを使用していますが、テンプレート DOCX を読み込もうとすると同じエラーが発生します。次の方法でdocxファイルをロードするように変更し、問題を解決しました。

        final LoadFromZipNG loader = new LoadFromZipNG();
        mypackage= (WordprocessingMLPackage)loader.get(is);

DOCX4J-Sample から取得: https://github.com/plutext/AndroidDocxToHtml

于 2012-12-09T10:49:36.830 に答える