-1

I'm using Docx4j with Java/Spring and i've built a service that replaces some placeholders in a document with variable values.

So in my docx I have a "placeholder" like this: [address] that I'm replacing with 5 different variables combined.

My code to do so is:

    Docx4JSRUtil.searchAndReplace(template, Stream.of(new String[][] {
     "[address]", "" + cust_street + " " + " " + cust_locality + " " + cust_cap ""
}

So actually my code replaces the placeholder with all the values on the same line. But what i actually need to accomplish is to write these 3 variables on 2 different lines with a line break.

So instead of a result like: cust street cust locality cust cap

I need a result like:

cust street

cust locality cust cap

Thanks to all in advance :)

1 Answers1

1

Based on the Github of the Docx4JSRUtil, it seems to be used purely for replacement of your defined variables. That said, you may need to edit the template itself so that the utility only replaces with the provided values.

Do not use the utility to alter the format of the template, that breaks the whole purpose of having one.

new_template.docx

${address}
${addressDetails}
Docx4JSRUtil.searchAndReplace(template, Map.of(
        "${address}", cust_street,
        "${addressDetails}", cust_locality + " " + cust_cap
));

That must generate:

new_doc.docx

cust_address
cust_locality cust_cap
squaredcow
  • 149
  • 4