0

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);
}
REDMAN
  • 91
  • 9

1 Answers1

0

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

Lucifer
  • 1,594
  • 2
  • 18
  • 32
iamdkrz
  • 21
  • 1
  • Thank you for your help, but I can't find a way to programmatically select the desired column (s.Word is the second column on table), could yo help me? – REDMAN May 29 '18 at 04:44
  • If you need CODE of repetitive Words, then var repetitive = doc.Tables.GroupBy(s => s.Word).SelectMany(grp => grp.Skip(1)).Select(a=>a.Code); – iamdkrz May 29 '18 at 06:45