Using powershell with openxml I replace values and output the result as .docx file.
I use
[OpenXmlPowerTools.SearchAndReplacer]::SearchAndReplace($original,"John","Jane"+"<w:br/>",$false)
I got
Jane '<w:br/>' next character goes here
I expect
Jane
next character goes here
Does anyone see my mistake?
Line breaks in OpenXML are child nodes of run nodes, and siblings of text nodes.
You're passing in the correct XML node for a break, but it's being inserted into a text node as opposed to being added to the run node.
E.g.
<w:p>
<w:r>
<w:t>
Jane '<w:br/>' next text goes here
<w:t/>
<w:r/>
<w:p/>
Instead of:
<w:p>
<w:r>
<w:t>
Jane
<w:t/>
<w:br/>
<w:t>
next text goes here
<w:t/>
<w:r/>
<w:p/>
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