import org.docx4j.Docx4J;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
public class Main {
public static void main(String[] args) throws Docx4JException,
String inputfilepath = "myfilepathhere";
OutputStream os = new FileOutputStream(inputfilepath + ".html");
WordprocessingMLPackage wordMLPackage = Docx4J
.load(new FileInputStream(inputfilepath));
}
}
Docx4j源代码可在https://github.com/plutext/Docx4j获得。
异常跟踪:
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't get [Content_Types].xml from ZipFile
at org.docx4j.openpackaging.io3.Load3.get(Load3.java:134)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:454)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:371)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:337)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:302)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:170)
at org.docx4j.Docx4J.load(Docx4J.java:195)
at Main.main(Main.java:29)
Caused by: org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:713)
at org.docx4j.openpackaging.io3.Load3.get(Load3.java:132)
... 7 more
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:679)
... 8 more
docx文档很好(由Word2010创建)。我甚至解压了它,看看是否有content_types.xml。就在那儿。
JAXBContext.newInstance("org.docx4j.openpackaging.contenttype");
Exception in thread "main" javax.xml.bind.JAXBException: Provider org.eclipse.persistence.jaxb.JAXBContextFactory not found
- with linked exception:
[java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory]
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at Main.main(Main.java:26)
Caused by: java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at javax.xml.bind.ContextFinder.safeLoadClass(Unknown Source)
... 6 more
docx4j支持几种不同的JAXB实现:
如果你想使用MOXy,你需要:
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-MOXy-JAXBContext</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.5.1</version>
</dependency>
我正在尝试使用docx4j API强制使用docx文件的权限。 文件有两个文档保护选项。
(*来自http://www.docx4java.org/forums/xhtml-import-f28/html-docx-html-inserts-a-lot-of-space-t1966.html#p6791?sid=78b64a02482926c4dbdbbafbf50d0a914将在应答时更新) 我已经创建了一个html测试文档,其内容如下: 然后,我的代码从这个html创建一个docx
我在将HTML转换为docx时遇到了新问题,它引发了异常: 组织。xml。萨克斯。SAXS异常;行号:4;栏目号:73;实体“nbsp”已被引用,但未被声明 正如我所理解的,这是因为docx4j认为我的文件是XML,并希望将其转换为docx但XML中只有5个预定义的实体,而nbsp等实体没有在XML中定义。如何让docx4j将超文本标记语言转换为doc,而无需在doctype中声明实体nbsp?
我正在尝试创建一个表,并使用docx4j库将其添加到MainDocumentPart,如下所示,但它会破坏文档,并且无法打开(我使用MS Word 2010和docx格式)
我正在尝试从google drive下载一个带有PyDrive的文件。我听从指示http://pythonhosted.org/PyDrive/filemanagement.html#download-文件内容。它在我自己的领域正常工作。 日志如下。 我正在尝试从我的客户的域相同的事情,它给出以下错误 我的代码下载。py在下面 是否有一些设置缺失?我能够列出我客户的谷歌驱动器中的所有文件。然而错误