DocX
DocX copied to clipboard
ReplaceText on fields preceded by shift+enter fails with an exception
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.
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.
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.
So you'll never support .net core in this free version?
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