How to work on a list in a range in a word file using c#

289 Views Asked by At

I am trying to edit a word document using word automation. In the document, there is a list of references that I want to verify and edit one by one. I have selected the references part in a range and now I want to loop through the list.

object start = new Regex(@"(References)\s*:?\s*").Match(wordText).Index;
        object end = wordText.Length;

        Word.Range rngRef = doc.Range(start,end);

This is how I have selected range, now how do I select list and loop through the items?

1

There are 1 best solutions below

0
Luuk On

I depend how the ordered list is exactly 'formatted' in Word. If this is just a number of paragraphs one could do (to get the text from the paragraphs):

int i = 0;
var paragraphs = rngRef.Paragraphs;
foreach (Word.Paragraph item in paragraphs)
{
     Console.WriteLine("{0}: {1}", ++i, item.Range.Text);
}