Get all the tables which has 7 columns in a word doc by XML SDK RRS feed

  • Question

  • Hi,

    I am office XML SDK and I want to filter all the tables which has 7 columns and then I want to iterate the data of each cell. First I have got all the tables exists in the doc then i want to filter only those tables which has 7 columns. Can any one please help me how to do that.


     using (WordprocessingDocument doc =
                   WordprocessingDocument.Open(txtICDDoc.Text, true))

    List<Table> tables = doc.MainDocumentPart.Document.Body.Descendants<Table>().ToList();

    //How to filter table those are having 7 columns.


    Monday, August 1, 2011 6:30 AM


  • Hi,


    Thanks I have got the answer and same is given below as reference.


    List<Table> tables = doc.MainDocumentPart.Document.Body.Descendants<Table>().ToList();

                        Predicate<Table> pred= new Predicate<Table>(p => p.Elements<TableGrid>().First().Elements<GridColumn>().Count() == 7);

                        List<Table> final = tables.FindAll(pred);

    • Marked as answer by Shyam Sohane Monday, August 1, 2011 6:50 AM
    Monday, August 1, 2011 6:50 AM