问题
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