We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Range.Replace and paragraph format

I have an issue with the Range.Replace method. When I replace a text that is horizontally aligned to the center and replace it with a text that has a newline (&p), only the last line is center aligned and the rest are left aligned. If I use Environment.NewLine instead of &p all lines are aligned correctly to the center but the line-spacing is wrong.

After some debugging I discovered that this behaviour can be changed with the FindReplaceOptions.ApplyParagraphFormat.Alignment option. By giving it another value all lines but the bottom one are aligned like the value was set. The problem for me is that I want to keep the alignment of the text and that I’m replacing multiple times and I don’t know the alignment of the texts I replace.

Is there any way to tell the ReplaceOptions to not apply any format and keep that of the original text?

In the attached example you see the the outcome of a multiline replacement using either &p or Environment.NewLine.
WordReplace.zip (4.9 MB)

Best regards

Wolfgang

@wknauf

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-19439. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-19439) have been fixed in this Aspose.Words for .NET 19.11 update and this Aspose.Words for Java 19.11 update.

Perfect! I can confirm that it works now.

Many thanks for this quick fix!

Wolfgang

@wknauf

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.