DocX icon indicating copy to clipboard operation
DocX copied to clipboard

ReplaceText on fields preceded by shift+enter fails with an exception

Open sqovsoftware opened this issue 5 years ago • 4 comments

I have a Document. The first few lines look like this:

<FirstName> <LastName>
<Address> <City>

Between these two lines is a soft enter: shift+escape. When I try to replace text:

...

private const RegexOptions _regexOptions = RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant;

...

public void MyMethod(Container container)
{
    container.ReplaceText("<Address>", "MyStreet 123", options: _regexOptions);
}

I get an exception:

"Specified argument was out of the range of valid values."

Why does this happen? It only seems to happen if the previous line was ended with shift+enter. The same text, but with the preceding line ended with a normal enter does not throw an exception.

sqovsoftware avatar Sep 10 '19 14:09 sqovsoftware

Judging from the activity on this issue tracker, this library appears dead, and the support staff non-existent. If your usecase is only about replacing text in docx files, I suggest the OpenXML powertools library. It's free, and while simpler in terms of offered functionality, it always manages to replace any text.

B45man avatar Sep 10 '19 14:09 B45man

Hi, This library is not dead. It is the free version of "Xceed Words for .NET" (https://xceed.com/xceed-words-for-net/). It has less features, slower support and is always a few versions behind the "Plus" version, but this community product is still maintained and will always be.

I was able to reproduce your issue. This issue is already fixed in v1.5 and up. You can try the latest version v1.6 for free for 45 days here : https://xceed.com/xceed-words-for-net/.

If you don't want to try the "Plus" version, you can go in file HelperFunctions, in method ToText() and add the case: case "br": { // Manage only line Breaks. var breakNodeValue = e.HasAttributes ? e.Attribute( DocX.w + "type" ).Value : null; if( ( breakNodeValue == null ) || ( breakNodeValue == "textWrapping" ) ) return "\n";

        return "";
      }

Thank you.

XceedBoucherS avatar Oct 03 '19 17:10 XceedBoucherS

So you'll never support .net core in this free version?

Scylla2020 avatar Oct 08 '21 01:10 Scylla2020

Hi Scylla2020, For now, only the "Plus" version supports a .NET standard and a .NET5 version. But this could change depending on the demand. Thank you

XceedBoucherS avatar Oct 12 '21 17:10 XceedBoucherS