Java: parsing ms-word document using POI / HWPF

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

My first approach was to use 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 no longer contains a macro (the file size of the source document: 32k; the file size of the generated document is 19k).

Anyone now, if you can save all the original information using POI / HWPF?

+3
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/1712287/


All Articles