Overwrite word templates with Apache POI

0

I have a template created in word and what I want is that using Apache POI replace variables in that template. For example: in my template word I put the tag $ {address} and in my code java I do the following:

try (XWPFDocument template = new XWPFDocument(new FileInputStream("e:/plantilla/plantillademopoidoc.docx"))) {
        for (XWPFParagraph paragraph: template.getParagraphs()){
            for (XWPFRun run : paragraph.getRuns()) {
                if (run.text().contains("${direccion}")) {
                    run.setText(run.text().replace("${direccion}", "las doce casas el santuario"), 0);
                }   
            }
        }

        template.write(new FileOutputStream(new File("e:/plantilla/outputdemopoidoc.docx")));

It generates me the document but without making the changes I want. If someone has an example or can tell me where the error of my code is, I would appreciate it.

Greetings Cesar

    
asked by cpasco 06.09.2018 в 01:23
source

0 answers