how to replace text with table from other documents in aspose word c#
FindReplaceOptions options2 = new FindReplaceOptions();
options2.Direction = FindReplaceDirection.Backward;
options2.ReplacingCallback = new ReplaceEvaluatorFindAndInsertTable();
wordDocument.Range.Replace(new Regex(“MileStone”), “”, options2);
import event :
private class InsertDocumentAtReplaceHandler : IReplacingCallback
{
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args)
{
//Document subDoc = new Document(“mi.docx”);
Document wordDocument = new Document("mi.docx");
Table table1 = wordDocument.FirstSection.Body.Tables[0];
//Table referenceTable = (Table)wordDocument.GetChild(NodeType.Table, 1, true);
Document _rootDoc = args.MatchNode.Document as Document;
Table importedTab = (Table)_rootDoc.ImportNode(table1, true);
Node dstNode = _rootDoc.ImportNode(importedTab, true, ImportFormatMode.KeepSourceFormatting);
//Node dstNode = _rootDoc.ImportNode(importedTab, true, ImportFormatMode.KeepSourceFormatting);
// Insert a document after the paragraph, containing the match text
Paragraph para = (Paragraph)args.MatchNode.ParentNode;
para.AppendChild(dstNode);
// Remove the paragraph with the match text
para.Remove();
return ReplaceAction.Skip;
}
}
i am getting below error:
Additional information: Cannot insert a node of this type at this location.