简体   繁体   English

使用java将docx转换为doc

[英]convert docx to doc with java

I have a legacy software which produces a xml and then with help of docx4j a docx document . 我有一个遗留软件,它生成一个xml,然后在docx4j的帮助下生成一个docx文档。 I must also create a microsoft doc document from the xml file with java. 我还必须使用java从xml文件创建一个microsoft doc文档。 How can I do that. 我怎样才能做到这一点。 I'd really appreciate for any help. 我真的很感激任何帮助。 Thanks 谢谢

Look into poi . 看看poi It's pretty much the defacto standard for modifying Microsoft documents with Java. 它几乎是使用Java修改Microsoft文档的事实标准。

docx4j has POI as a dependency, and POI has reasonable support for the legacy binary doc format (hwpf). docx4j将POI作为依赖关系,POI对遗留二进制文档格式(hwpf)有合理的支持。 So you could use that to convert to doc without introducing additional dependencies. 因此,您可以使用它转换为doc而不引入其他依赖项。 Basically, iterate through your content, and emit each paragraph/table/image in doc format. 基本上,遍历您的内容,并以doc格式发出每个段落/表格/图像。 That would be the reverse of convert/in/Doc.java . 那将与convert / in / Doc.java相反

However, the devil is in the detail, and it would be a lot of work if your documents contain a variety of features. 然而,魔鬼是详细的,如果你的文档包含各种功能,那将是很多工作。 This assertion stands whether you were doing docx4j to binary doc (hwpf), or POI's own xwpf to hwpf, since POI doesn't have a common interface across the two of them. 这个断言代表你是在做docx4j到二进制doc(hwpf),还是POI自己的xwpf到hwpf,因为POI 没有跨越这两个的公共接口

So instead of using POI for this, I'd use JODConverter to drive LibreOffice (or OpenOffice, their docx features are a bit different) to convert docx to legacy binary .doc. 因此,我没有使用POI,而是使用JODConverter驱动LibreOffice(或OpenOffice,他们的docx功能有点不同)将docx转换为传统的二进制.doc。

The JODConverter approach is definitely the path of least resistance, and will generally give good results. JODConverter方法肯定是阻力最小的路径,通常会产生良好的结果。 The downside with it is that if you find something which isn't supported properly, you'll have to wait for the LO/OO guys to fix it, which wouldn't be the case if you did decide to build binary doc output for docx4j using POI. 它的缺点是,如果你找到一些不正确支持的东西,你将不得不等待LO / OO人员修复它,如果你决定构建二进制doc输出,那就不是这种情况了。 docx4j使用POI。 If you did build this, we'd happily accept it as a contribution :-) 如果您确实构建了这个,我们很乐意接受它作为贡献:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM