如何使用docx4j将HTML转换为.docx? [英] how to convert HTML to .docx using docx4j?

查看:1050
本文介绍了如何使用docx4j将HTML转换为.docx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一些关于将 html 转换为 .docx 的文章,我发现 docx4j 给出相当不错的结果。我想知道是否有人可以向我提供以下信息:


  1. 需要 jars 和版本。

  2. html 转换为 .docx 的示例代码。
  3. li>

对不起,我无法发布任何我尝试过的,因为我还没有尝试过任何任务,尽管我使用 Apache POI datatabse 转换为字节[] jsf 应用程序中输出到富文本编辑器中的$ c> html 请赐教,我迷失在压力和困惑中......!

解决方案

要导入XHTML,请使用

 < dependency> 
< groupId> org.docx4j< / groupId>
< artifactId> docx4j-ImportXHTML< / artifactId>
< version> 3.0.0< / version>
< /依赖关系>

更多 http://www.docx4java.org/blog/2013/11/docx4j-3-0-and-maven/



有关示例代码,请参阅 https://github.com/plutext/docx4j-ImportXHTML/tree/master/src/samples/java/org/docx4j/samples



请注意,您的输入必须是格式良好的XML,因此如果您使用的是HTML,则需要先清理它(使用可为您执行此操作的许多Java库之一)。

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:

  1. Needed jars and versions.
  2. Sample code for conversion from html to .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...!

解决方案

To import XHTML, use

<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/

For sample code, see 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).

这篇关于如何使用docx4j将HTML转换为.docx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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