Aspose.Words System.ArgumentException:The reference node is not a child of this node.错误解决

男娘i 2023-10-05 08:59 68阅读 0赞

问题描述:

  1. Document doc=new Document("test.doc");
  2. int tableIndex=0;//表格索引
  3. //得到文档中的第一个表格
  4. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  5. //创建段落
  6. Paragraph lastParagraph = new Paragraph(doc);
  7. //复制第一个表格
  8. Table cloneTable = (Table)table.Clone(true);
  9. //在文档末尾段落后面加入复制的表格
  10. 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中。

  1. Document doc=new Document("test.doc");
  2. int tableIndex=0;//表格索引
  3. //得到文档中的第一个表格
  4. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  5. //创建段落
  6. Paragraph lastParagraph = new Paragraph(doc);
  7. //第一个表格末尾加段落
  8. table.ParentNode.InsertAfter(lastParagraph, table);
  9. //复制第一个表格
  10. Table cloneTable = (Table)table.Clone(true);
  11. //在文档末尾段落后面加入复制的表格
  12. table.ParentNode.InsertAfter(cloneTable, lastParagraph);

发表评论

表情:
评论列表 (有 0 条评论,68人围观)

还没有评论,来说两句吧...

相关阅读