I'm using the spire.doc version 11.8.18 and .Net 6.0
When I replace text in the StructureDocumentTagInline, an error occured:
Object reference not set to an instance of an object.
at Spire.Doc.Documents.TextSelection.get_SelectedText()
at Spire.Doc.Documents.TextSelection.GetAsOneRange(Boolean IsCopyFormat)
at Spire.Doc.Documents.TextSelection.GetAsRange(Boolean isCopyFormat)
at Spire.Doc.Document.Replace(Regex pattern, String replace)
at Program.<Main>$(String[] args) in E:\Duyen\src\ConsoleApp1\ConsoleApp1\Program.cs:line 13
I'm having a lot of customer complaints about this error. Please let us know the results soon.
Thank you
- Code: Select all
using Spire.Doc;
using System.Text.RegularExpressions;
Console.WriteLine("Hello, World!");
Document document = new Document();
document.LoadFromFile(@"E:\error3.docx");
var matchString = "@@JobNumber@@";
var value = "new value";
// Error when replace with regex
var result1 = document.Replace(new Regex(matchString), value);
// Error when replace string
var result2 = document.Replace(matchString, value, true, true);
document.SaveToFile(@"E:\" + Guid.NewGuid().ToString("N") + ".docx");