Page 1 of 1

How to add new line charcter inside a table cell

PostPosted: Fri Jan 17, 2014 3:58 am
by mukund
Hi,

I have a template docx file. In the template, there is a 10x1 table with placeholders (D1,D2,D3.....D10). I have a replaceTable method to replace the placeholders in this table with records returned by a SQL query. For the placeholder D3 alone, it needs to be replaced with values from 2 String variables (say str1 and str2). The requirement I have is to be able to replace D3 with str1 + newlinecharacter + str2.

str1 = "abc"; str2 = "def"
D3 should be replaced with:
abc

def

Due to obvious reasons, concatenating the st1 and str2 with \r\n and then replacing D3 does not work, as the new line character gets converted to a space during replacement. Any help is appreciated.

Thanks,
Mukund

Re: How to add new line charcter inside a table cell

PostPosted: Fri Jan 24, 2014 9:11 pm
by marcel_cap
+ 1 for this question.

Re: How to add new line charcter inside a table cell

PostPosted: Thu Jan 30, 2014 10:02 am
by jason
As a general comment, you'd probably be better off using content control data binding than string replacement, since content control data binding explicitly supports repeating data (paragraphs, list items, table rows etc).

To your specific question, new line is represented by <w:br>.

See further:

http://webapp.docx4java.org/OnlineDemo/ ... ML/br.html

docx-java-f6/carriage-return-during-a-replacement-t980.html

docx-java-f6/linebreaks-in-strings-t1663.html