使用DocX库在DOCX文件中查找表

时间:2013-04-12 17:14:13

标签: c# winforms docx

我已下载并开始使用DocX library。我有一个名为template.docx的文档正在加载到内存中。我在该文档中有一个表,其中包含id = 241。我想通过它的id获取该表并向其添加行。我怎样才能做到这一点?这是我的代码:

using (DocX document = DocX.Load("template.docx"))
{
    int tableId = 241, i = 0;
    Table t = //here I need to find the table

    foreach(DataGridViewRow row in produseFacturate.Rows)
    {
         i++;

         //here I want to add rows to the table
    }
}

1 个答案:

答案 0 :(得分:2)

我自己找到了解决方案。

因为,document.Tables是一个列表,我可以这样称呼它:

Table t = document.Tables[3]; // I found out that the table index is actually 3;