Hi,
I want to search some specific text in document and then insert merge field at the position of match node. But unfortunately, I found that if there are several matchings, from the second match, the mode node is incorrect. The code I wrote is:
Document doc = new Document("ReplaceDoc.doc");
Regex regex = new Regex(@"ABC\d+", RegexOptions.IgnoreCase);
doc.Range.Replace(regex, new TextFinder(), true);
class TextFinder: IReplacingCallback
{
private DocumentBuilder builder = null;
public ReplaceAction Replacing(ReplacingArgs args)
{
Node currentNode = args.MatchNode;
if (builder == null)
builder = new DocumentBuilder(currentNode.Document as Document);
builder.MoveTo(currentNode);
builder.InsertField(" MERGEFIELD ABC ");
return ReplaceAction.Replace;
}
}
I attached two documents here. One is template the other is output. It is obvious that in output the merge field is inserted at wrong position. Through debug, args.MatchNode is incorrect from second matching(3rd, 4th, and etc.) Could anybody investigate this issue?
thanks.