@awais.hafeez Thank you for additional information. This is interesting one. Actually Aspose.Words behaves the same for both content in table and outside the table. If you unzip output document and inspect document.xml
, you will see the following:
<w:p w:rsidR="00CC540C" w14:paraId="7CA404BB" w14:textId="1150A7E6">
<w:r>
<w:t>test with CR</w:t>
<w:cr />
<w:t>
with NL
with CR+NL
</w:t>
<w:cr />
<w:t>
with NL+CR
</w:t>
<w:cr />
<w:t>The end.</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00677ACE" w14:paraId="5E45DDD2" w14:textId="395BB521" />
<w:tbl>
.....................
<w:tr w14:paraId="3EEFA81A" w14:textId="77777777" w:rsidTr="00677ACE">
..........................
<w:tc>
...............................
<w:p w:rsidR="00677ACE" w14:paraId="6B127A6D" w14:textId="0B424245">
<w:r>
<w:t>test with CR</w:t>
<w:cr />
<w:t>
with NL
with CR+NL
</w:t>
<w:cr />
<w:t>
with NL+CR
</w:t>
<w:cr />
<w:t>The end.</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
As you can see internal representation of content inside and outside the table is identical.
The actual problem is that using '\r'
and '\n'
characters in the replacement is not a good idea. If you need to have a line break in the replacement you can use either a soft line break '\u000b'
character, or paragraph break - to achieve this you should use special "&p"
metacharacter. So you can use either the following code:
doc.getRange().replace(p, "test with CR\u000bwith NL\u000bwith CR+NL\u000bwith NL+CR\u000bThe end.")
or
doc.getRange().replace(p, "test with CR&pwith NL&pwith CR+NL&pwith NL+CR&pThe end.")