Search code examples
c#winformsdocx

Finding a table in a DOCX file using the DocX library


I have downloaded and started using the DocX library. I have a document called template.docx that is being loaded into memory. I have a table in that document, that has the id = 241. I want to get that table by its id and add rows to it. How can I do this? Here is my code:

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
    }
}

Solution

  • I found a solution myself.

    Since, document.Tables is a list, I can call it like this:

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