Replacing the contents of a DOCX file.

I am using version 3.7 of Apache POI and would like to know how to replace
and save a file modified using the API.

I used the substitution model with a DOC file with HSSF, but the API had a
bug and prevented me from using it altogether.

So I decided to leave for the implementation of a code that uses XWPF.

By the time I got the following:

A DOCX file containing a header and a footer and a "body".

In the header, footer and body are one species of tags should I extract the
file and replaces it by a relevant data dynamically in my project.

I've managed to display (via console) the text in the header and footer.

I tried to modify the content using "XWPFRun", but without success.

does anyone know what to do? follows the code of what I'm trying to do:

*                       XWPFDocument docx = new XWPFDocument(new 
FileInputStream(new
File("Document.docx")));
                        for (XWPFHeader h : docx.getHeaderList()) {
                                for (XWPFParagraph p : h.getListParagraph()) {
                                        XWPFRun r = p.createRun();
                                                String a = 
r.getParagraph().getParagraphText();
                                                a="aaaaaaaaaaaa";
                                                p.addRun(r);
                                                
docx.enforceCommentsProtection();
                                                System.out.println(p.getText());
                                }
                        }
                        for (XWPFFooter f : docx.getFooterList()) {
                        }*

the paragraph it does not change the text.

or in some cases it adds the text after each line of the paragraph.

how I do it?

--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Replacing-the-contents-of-a-DOCX-file-tp4783849p4783849.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to