使用interop在单词2010中按样式查找段落

时间:2013-05-08 14:30:03

标签: c# ms-word

有人可以指出我正确的方向,或者告诉我如何使用c#.net中的单词interop按照他们的样式名称查找段落。

1 个答案:

答案 0 :(得分:2)

尝试这样的循环:

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