Looping Through Each Word In Word Document Using Docx Library

筅森魡賤 提交于 2019-12-08 04:03:45

问题


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>).


回答1:


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;
  }
}


来源:https://stackoverflow.com/questions/28422248/looping-through-each-word-in-word-document-using-docx-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!