tags:

views:

258

answers:

1

I am using openxml WordProcessingDocument to open a Word template and replace placeholder x1 with a string. This works fine unless I need the string to contain a newline. How can I replace x1 with text may contain newlines that word would recognise? I have tried \n \r but these do not work

Just to explain further when the word template is opened I read it into a StreamReader then use .Replace to replace x1.

+1  A: 

To insert newlines, I believe you have to add a Break instance to the Run.

Example:

run.AppendChild(new Text("Hello"));
run.AppendChild(new Break());
run.AppendChild(new Text("world"));

The XML produced will be something like:

<w:r>
  <w:t>Hello</w:t>
  <w:br/>
  <w:t>world</wt>
</w:r>
codeape
I don't think I can use your answer in my situation. I updated my question to explain further
Danny
So you're working with the XML directly? In that case, try inserting XML like the example.
codeape
Were you able to get it to work?
codeape