我正在尝试使用 DocX nuget 包创建/操作 Word .docx 文件。
在文档中,他们提供了以下示例:
// Place holder for a Table.
Table t;
// Load document a.
using (DocX documentA = DocX.Load(@"C:\Example\a.docx"))
{
// Get the first Table from this document.
t = documentA.Tables[0];
}
// Load document b.
using (DocX documentB = DocX.Load(@"C:\Example\b.docx"))
{
/*
* Insert the Table that was extracted from document a, into document b.
* This creates a new Table that is now associated with document b.
*/
Table newTable = documentB.InsertTable(t);
// Save all changes made to document b.
documentB.Save();
}// Release this document from memory.
当代码执行时,我在插入表格时收到错误: Table newTable = documentB.InsertTable(t);
错误:System.InvalidOperationException {“序列不包含元素”}
我不知道为什么会发生这种情况。我查看了正在插入的表“t”,它似乎填充了所有属性。我不清楚是什么导致了错误。
任何帮助将不胜感激。