C# DocX克隆表并在索引处插入

C# DocX克隆表并在索引处插入,c#,docx,novacode-docx,C#,Docx,Novacode Docx,我正在使用C#制作一个简单的Windows应用程序,使用Novacode操作Word文档 我的Word文档中有一个要克隆的源表。我可以使用以下代码找到源表: Table sourceTable = document.Tables[3]; 我可以通过行和列看出,这实际上是我要克隆的表 我的Word文档中有一个字符串,在它之后我想插入克隆的源表。事实上,我可能需要多次插入它 我不知道如何找到我的字符串及其索引,然后在该索引处插入一个或多个克隆表 谢谢。我是这样做的,我使用一个标签插入并替换为表:

我正在使用C#制作一个简单的Windows应用程序,使用Novacode操作Word文档

我的Word文档中有一个要克隆的源表。我可以使用以下代码找到源表:

Table sourceTable = document.Tables[3]; 
我可以通过行和列看出,这实际上是我要克隆的表

我的Word文档中有一个字符串,在它之后我想插入克隆的源表。事实上,我可能需要多次插入它

我不知道如何找到我的字符串及其索引,然后在该索引处插入一个或多个克隆表


谢谢。

我是这样做的,我使用一个标签插入并替换为表:

// Add a Table to this document.
var table = document.AddTable(2, 3);

// Specify some properties for this Table.
table.Alignment = Alignment.center;

// Add content to this Table.
table.Rows[0].Cells[0].Paragraphs.First().Append("A");
table.Rows[0].Cells[1].Paragraphs.First().Append("B");
table.Rows[0].Cells[2].Paragraphs.First().Append("C");
table.Rows[1].Cells[0].Paragraphs.First().Append("D");
table.Rows[1].Cells[1].Paragraphs.First().Append("E");
table.Rows[1].Cells[2].Paragraphs.First().Append("F");

// Insert table at index where tag #TABLE# is in document.
document.InsertTable(table));
foreach (var paragraph in document.Paragraphs)
{
    paragraph.FindAll("#TABLE#").ForEach(index => paragraph.InsertTableAfterSelf((table)));
}

//Remove tag
document.ReplaceText("#TABLE#", "");