使用 Docx 库循环遍历 Word 文档中的每个单词
Looping Through Each Word In Word Document Using Docx Library
我正在尝试制作一个小程序来对现有文档应用自动更正更改。我正在使用 docX 库。我的问题是,如何使用 docX 库迭代(或循环)文档中的每个单词,以检查是否需要更正(我已经在 list<T>
中插入了所有自动更正条目).
试试这个...
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;
}
}
我正在尝试制作一个小程序来对现有文档应用自动更正更改。我正在使用 docX 库。我的问题是,如何使用 docX 库迭代(或循环)文档中的每个单词,以检查是否需要更正(我已经在 list<T>
中插入了所有自动更正条目).
试试这个...
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;
}
}