Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for your inquiry. I think that you would like to put replacement into ReplaceEvaluator parameters. You can try using code like the following.
public void Test258()
{
// Open document
Document doc = new Document(@"Test258\in.doc");
//Create regex that will match the first paragraph of range
Regex regex = new Regex(Regex.Escape("<%\tIs this PSUR for a Centrally Authorized Product?"));
//execute raplace
ReplaceParagraphs replacePar = new ReplaceParagraphs();
replacePar.Replacement = "this is my replacement";
doc.Range.Replace(regex, new ReplaceEvaluator(replacePar.Replace), false);
//Save result
doc.Save(@"Test258\out.doc");
}
class ReplaceParagraphs
{
private string _replacement = string.Empty;
public string Replacement
{
get { return _replacement; }
set { _replacement = value; }
}
public ReplaceAction Replace(object sender, ReplaceEvaluatorArgs e)
{
//Remove content
Node currentParagraph = e.MatchNode.GetAncestor(NodeType.Paragraph);
while (!currentParagraph.Range.Text.Contains("%>"))
{
currentParagraph = currentParagraph.NextSibling;
currentParagraph.PreviousSibling.Remove();
}
(currentParagraph as CompositeNode).RemoveAllChildren();
//Insert new content
//You can use also InsertHtml method etc
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document);
builder.MoveTo(currentParagraph);
builder.Write(_replacement);
return ReplaceAction.Skip;
}
}
Hope this helps.
Best regards.