docx4j-search-and-replace-util icon indicating copy to clipboard operation
docx4j-search-and-replace-util copied to clipboard

Line breaks in replacement text

Open thepigeonoftime opened this issue 5 years ago • 4 comments

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)?

thepigeonoftime avatar Sep 17 '20 11:09 thepigeonoftime

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?

Bildschirmfoto 2020-09-17 um 18 03 37

PS: In case you want to use this in your project: I try to add this to Maven central in the next hours.

phip1611 avatar Sep 17 '20 16:09 phip1611

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.)

thepigeonoftime avatar Sep 18 '20 08:09 thepigeonoftime

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

phip1611 avatar Sep 18 '20 12:09 phip1611

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

kadtaras avatar Mar 01 '23 14:03 kadtaras