Hi,
I am using a Aspose.Words evalutation version.
I need to change hundreds of documents which I need to replace the place holders from plain text to merged fiels.
using find a replace somehow I get an exception.
System.NullReferenceException was caught
Message=“Object reference not set to an instance of an object.”
This is the code I am using:
doc = new Document(filepath);
string regExp = Regex.Escape("[") + “%[0-9A-Z-_ öüä]*%” + Regex.Escape("]");
doc.Range.Replace(new Regex(regExp, RegexOptions.IgnoreCase),new ReplaceEvaluator(ReplaceEvaluator1), true);
private ReplaceAction ReplaceEvaluator1(object sender, ReplaceEvaluatorArgs e)
{
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document);
string fieldName = e.Match.Value;
builder.MoveTo(e.MatchNode);
builder.InsertField(string.Format(“MERGEFIELD {0}”, fieldName), string.Format("«{0}»", fieldName));
builder.Write("");
return ReplaceAction.Replace;
}
Please see templates:
Thanks Josue