简体   繁体   English

Java:使用POI / HWPF解析ms-word文档

[英]Java: parsing ms-word document using POI/HWPF

I have a ms-word document (MS-Office 2003; non-xml). 我有一个ms-word文档(MS-Office 2003;非xml)。 Within this document there is a string associated with a bookmark. 在该文档中,存在与书签相关联的字符串。 Furthermore, the word document contains word-macros. 此外,word文档包含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. 我的目标是使用java读取文档,替换与书签关联的字符串,并将文档保存回字格式。

My first approach was using Apache POI HWPF: 我的第一种方法是使用Apache POI HWPF:

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

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). 此解决方案的问题是生成的文件不再包含宏(原始文档的文件大小:32k;生成的文档19k的文件大小)。

Does anybody now if it's possible to retain all the original info using POI/HWPF? 现在有人可以使用POI / HWPF保留所有原始信息吗?

never found a solution. 从未找到解决方案。 The customer had to pay an Aspose-license (expensive) or refrain from using macros. 客户必须支付Aspose许可证(昂贵)或不使用宏。

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

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