Aspose.Words System.ArgumentException:The reference node is not a child of this node.错误解决
问题描述:
Document doc=new Document("test.doc");
int tableIndex=0;//表格索引
//得到文档中的第一个表格
Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
//创建段落
Paragraph lastParagraph = new Paragraph(doc);
//复制第一个表格
Table cloneTable = (Table)table.Clone(true);
//在文档末尾段落后面加入复制的表格
table.ParentNode.InsertAfter(cloneTable, lastParagraph);
执行table.ParentNode.InsertAfter(cloneTable, lastParagraph);报以下错误:
System.ArgumentException:“The reference node is not a child of this node.”
这是因为lastParagraph没有在插入doc中。
问题解决:
先将lastParagraph插入doc中,再将cloneTable插入doc中。
Document doc=new Document("test.doc");
int tableIndex=0;//表格索引
//得到文档中的第一个表格
Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
//创建段落
Paragraph lastParagraph = new Paragraph(doc);
//第一个表格末尾加段落
table.ParentNode.InsertAfter(lastParagraph, table);
//复制第一个表格
Table cloneTable = (Table)table.Clone(true);
//在文档末尾段落后面加入复制的表格
table.ParentNode.InsertAfter(cloneTable, lastParagraph);
还没有评论,来说两句吧...