I just followed approach No 2 in the VariableReplace example from docx4j 2.8.1 and everything it does, is to remove the variable markers ${}.
The steps I did:
I'd expect 'TEST' solely, and get just 'variable' without the markers in the output document.
No doubt Word is splitting your "variable" across runs, with grammar or spelling flags.
Fix it up with VariablePrepare
Put this line in after you instantiate the WordprocessingMLPackage:
VariablePrepare.prepare(wordMLPackage);
Then you can use your mappings to replace the variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With