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

本文关键字:DOCX 查找 文件 库在 使用 | 更新日期: 2023-09-27 18:08:58

我已经下载并开始使用DocX库。我有一个叫做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
    }
}

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

我自己找到了解决办法。

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

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