user3150255
user3150255

Reputation: 121

Looping Through Each Word In Word Document Using Docx Library

I am trying to make a small program to apply autocorrect changes to an exiting document. I am using the docX library. My question is, how do you iterate (or loop) through each word in the document, using the docX library, to check if it needs to be corrected or not (I have already inserted all auto correct entries in a list<T>).

Upvotes: 1

Views: 869

Answers (1)

xwpdev
xwpdev

Reputation: 168

try this...

DocX document = DocX.Load( <document path> );

foreach(Novacode.Paragraph item in document.Paragraphs) {
  
  // use this if you need whole text of a paragraph
  string paraText = item.Text;
  
  // use this if you need word by word
  foreach(var data in item.MagicText) {
    
    string word = data.text;
  }
}

Upvotes: 2

Related Questions