docx4j-search-and-replace-util
docx4j-search-and-replace-util copied to clipboard
Line breaks in replacement text
Hi,
I'm looking for a way to include line breaks in the replacement text (with special placeholders like \n or ${break}).
So far, wherever I perform a sub-replacement to insert "</w:t><w:br/><w:t>" for those break-placeholders, it just gets printed as characters into the document. Any chance to point me to a good place to add something like that (if possible at all)?
Hi @timepigeon
Hm, for me it works to add "\n" into the replaced text.
placeholderMap.put("${NAME}", "Phi\nlipp");
With the .docx-File in src/test/resources the output has a line break. I think this should work for you too, if I understand you right?
PS: In case you want to use this in your project: I try to add this to Maven central in the next hours.
Hm, for some reason \n gets converted to space for me. I will check this out over the weekend and report back. (I've added the package as a Github dependency in Maven, no rush on publishing it to central from my side. Although it deserves to be on there.)
Okay I have an update on this. \n works when I view the docx document in Pages on my Macbook. Neither \n nor \r\n works when I view the document in Microsoft Word. @timepigeon
I have the same problem. When I open my generated .docx file in Pages, it shows okay, but it \n doesn't work in Microsoft Word