none
Get The maximum number of rows and columns in a Word document table. RRS feed

  • Question

  • Hello everybody!,

    I am quite new using this library and I am developing a tool to extract information from tables in a Word document.
    I would like to know if is there any way to get the maximum number of rows and columns of the table.

    Thanks a lot in advance for your help.

    Monday, March 6, 2017 10:24 AM

All replies

  • Hi Chema,

    According to your describtion,i think what you want is getting row/column count of the a table,right?
    You could get row count by Elements<TableRow>().Count() and get column by Elements<GridColumn>().Count()

    Here is an example.

    using (WordprocessingDocument doc =
            WordprocessingDocument.Open(filepath, true))
                {
                   // Find the first table in the document.
                    Table table =
                        doc.MainDocumentPart.Document.Body.Elements<Table>().First();
    
                    // Find the second row in the table.
                    int row = table.Elements<TableRow>().Count();
    
                    int col = table.Elements<TableGrid>().First().Elements<GridColumn>().Count();
    
                    MessageBox.Show("RowCount:" + row + "\r" +
                        "ColmunCount:" + col);
                }

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 7, 2017 7:09 AM