C# docx locating a word into Table

491 Views Asked by At

I have a word document with a huge two columns table, the first column contains a code, and the second one contains a word. In many rows the word of the second column is repeated so I need to locate all rows with repeated words. I'm using findAll() method and getting the index for every occurence of the word but I can't get the table row from that index. Below is the code I'm using.

using (DocX doc = DocX.Load(path/to/file.docx)){
   Table table = doc.Tables[0];
   var ocurrences = doc.FindAll("text", RegexOptions.IgnoreCase);
}
1

There are 1 best solutions below

2
On

You can LinQ for getting repetitive rows as:

var repetitive = doc.Tables.GroupBy(s => s.Word).SelectMany(grp => grp.Skip(1));

Note :- here Word is the second column