Table Cell Replace with multiline text CRLF line endings

Hi, we’re using Aspose.Words for .NET 20.10.0.0.
Mainly we’re using a Range.Replace for replacing tags in document like your MailMerge or LIQN reporting engine do.

In Table Cells elements we experiencing 3 different behavior of replacing tag with multiline text value.
In word document we got a Table with Cell containing tag {Description} wich will be replaced by value holding multiline text with CRLF line endings.

1] If Cell contains only tag {Description} the line endings CRLF will be replaced by SPACE character.
2] If Cell contains tag {Description} and paragraph (eq. your metacharacter &p) no matter where is placed the line endings will be reaplaced as paragraph (&p). This is behavior we will expect as is done in all other parts of the document with using Range.Raplace.
3] If the document will be created in code by DocumentBuilder and builder Write string tag “{Description}” into the cell and then we use Range.Replace the line endings will be with no change in result document - CRLF.

Here si example console application including docx template to demostrate different behaviors.
TableCellLineBreak.zip (5.7 MB)

So the issue is why the Table Cell Range.Raplce for multiline text works different to other parts of document? (As you can try in example TextArea on inline text). It’s a bug or we just miss something with word document options? Or how we can use a Range.Replace to reach same behavior in all cases?

Thanks in advance

@stedrys

Please replace “\r\n” with “&p” as shown below to get the desired output. Hope this helps you.

 string text = @"First line of text
Second line of text
Third line of long long long text    with tab
Last line";

with

string text = @"First line of text
Second line of text
Third line of long long long text    with tab
Last line".Replace("\r\n", "&p");

We have logged this problem in our issue tracking system as WORDSNET-22202. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@stedrys

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-22202) as ‘Not a Bug’.

Aspose.Words produces the same result as MS Word does. You can use the solution shared in this post to get the desired output.