Hello all,
I have a working piece of code that returns all Ranges that are underlined.
The problem is that it takes quite some time (30+ seconds) on 300+ page documents. I'm hopeful there is a faster way to achieve the same goal perhaps using OpenXml maybe (not that good with OpenXml so need help there).
Here is the working code:
public static List<Range> SearchByUnderline(Document document) { List<Range> ranges = new List<Range>(); Word.Range selection = document.Content; selection.Find.ClearFormatting(); selection.Find.Font.Underline = WdUnderline.wdUnderlineSingle; selection.Find.Execute(); List<int> paragraphs = new List<int>(); while (selection.Find.Found) { if (selection.Paragraphs.Count > 0) { if (paragraphs.Where(w => w == selection.Paragraphs[1].Range.Start).Count() == 0) { paragraphs.Add(selection.Paragraphs[1].Range.Start); ranges.Add(selection.Duplicate); } } selection.Find.Execute(); } return ranges; }
Thank you in advance!
Thank you,
Nick Metnik
Please mark my response as helpful if it has helped you in any way or as the answer if it is a valid solution.
Blog
LinkedIn