Java 如何使用 docx4j 将 HTML 转换为 .docx?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20461239/
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 convert HTML to .docx using docx4j?
提问by Jalal Sordo
I read some articles about the conversion of html
to .docx
and I found out that docx4j
gives pretty decent results. I wonder if anyone could provide me the following info:
我阅读了一些关于html
to转换的文章.docx
,我发现它docx4j
给出了相当不错的结果。我想知道是否有人可以向我提供以下信息:
- Needed
jars
and versions. - Sample code for conversion from
html
to.docx
.
- 需要
jars
和版本。 - 从
html
到 的转换示例代码.docx
。
Sorry I couldn't post anything I tried because I haven't tried anything on this task yet, although I use Apache POI
to convert the bytes[]
I get from datatabse
to html
to output in a rich text editor
on a jsf
application. Please enlighten me, I'm lost in stress and confusion...!
抱歉,我无法发布我尝试过的任何内容,因为我还没有在此任务上尝试过任何内容,尽管我曾经在应用程序Apache POI
中将bytes[]
I 从datatabse
到转换html
为输出。请赐教,我迷失在压力和困惑中......!rich text editor
jsf
采纳答案by JasonPlutext
To import XHTML, use
要导入 XHTML,请使用
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-ImportXHTML</artifactId>
<version>3.0.0</version>
</dependency>
See further http://www.docx4java.org/blog/2013/11/docx4j-3-0-and-maven/
进一步查看http://www.docx4java.org/blog/2013/11/docx4j-3-0-and-maven/
For sample code, see https://github.com/plutext/docx4j-ImportXHTML/tree/master/src/samples/java/org/docx4j/samples
示例代码见https://github.com/plutext/docx4j-ImportXHTML/tree/master/src/samples/java/org/docx4j/samples
Note that your input needs to be well-formed XML, so if you have HTML, you'll need to tidy it first (with one of the many java libraries which can do this for you).
请注意,您的输入需要是格式良好的 XML,因此如果您有 HTML,则需要先整理它(使用许多可以为您完成此操作的 Java 库之一)。