Java:使用 POI/HWPF 解析 ms-word 文档 [英] Java: parsing ms-word document using POI/HWPF

查看:37
本文介绍了Java:使用 POI/HWPF 解析 ms-word 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ms-word 文档(MS-Office 2003;非 xml).在这文档中有一个与书签相关联的字符串.此外,word文档包含word宏.我的目标是阅读用java文档,替换与书签关联的字符串,并将文档保存回 Word 格式.

I have a ms-word document (MS-Office 2003; non-xml). Within this document there is a string associated with a bookmark. Furthermore, the word document contains word-macros. My goal is to read the document with java, replace the string associated with the bookmark, and save the document back to word format.

我的第一种方法是使用 Apache POI HWPF:

My first approach was using Apache POI HWPF:

HWPFDocument doc = new HWPFDocument(new FileInputStream("Test.doc"));
doc.write(new FileOutputStream("Test_generated.doc"));

这个方案的问题是生成的文件没有不再包含宏(原始文档的文件大小:32k;生成的文档的文件大小 19k).

The problem with this solution is that the generated file does not contain the macro anymore (File size of the original document: 32k; file size of the generated document 19k).

现在有没有人可以保留所有原始信息使用 POI/HWPF?

Does anybody now if it's possible to retain all the original info using POI/HWPF?

推荐答案

从未找到解决方案.客户必须支付 Aspose 许可证(昂贵)或避免使用宏.

never found a solution. The customer had to pay an Aspose-license (expensive) or refrain from using macros.

这篇关于Java:使用 POI/HWPF 解析 ms-word 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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