Hi
Thanks for
your request. You can try to use ReplaceEvaluatur to replace this text. See the
following example.
public void TestReplaceText_95167()
{
Document doc = new
Document(@"200_95167_daithi\in.doc");
Regex regex = new Regex("Text to
replace");
doc.Range.Replace(regex, new ReplaceEvaluator(ReplaceAction1), true);
doc.Save(@"200_95167_daithi\out.doc");
}
ReplaceAction ReplaceAction1(object
sender, ReplaceEvaluatorArgs e)
{
DocumentBuilder builder = new
DocumentBuilder(e.MatchNode.Document);
builder.MoveTo(e.MatchNode);
builder.Write("Replaced");
int index =
e.MatchNode.Document.FirstSection.Body.Paragraphs.IndexOf(builder.CurrentParagraph);
//insert next paragraph content to current paragraph.
foreach (Run run in
e.MatchNode.Document.FirstSection.Body.Paragraphs[index + 1].Runs)
{
builder.CurrentParagraph.AppendChild(run);
}
//remove next paragraph
e.MatchNode.Document.FirstSection.Body.Paragraphs[index + 1].Remove();
return ReplaceAction.Replace;
}
I hope that
it will help you.
Best
regards