使用互操作在Word 2010中按样式查找段落

问题描述:

有人可以向我指出正确的方向,还是向我展示如何使用c#.net中的单词interop通过其样式名称查找段落.

Could someone point me in the right direction, or show me how to find paragraphs by their style name using word interop in c#.net.

尝试如下循环:

using WN = Microsoft.Office.Interop.Word;
//...
        WN::Application WordApp;
        WordApp = new WN.Application();
//...        
    WN.Document WordDoc = WordApp.Documents.Open(Filename); //open document

        List<string> SelectedParagraphs = new List<string>();
        for(int i=1;i<WordDoc.Paragraphs.Count;i++) //numeration of paragraphs starts from 1
        {
                string WordP = WordDoc.Paragraphs[i].Range.Text; // get paragraph text
                string WordS = ((WN.Style)WordDoc.Paragraphs[i].get_Style()).NameLocal; //get paragraph style name
                if (WordS=="Needed style")
                {
                    SelectedParagraphs.Add(WordP);
                }
        }