Find paragraphs by style in word 2010 using interop

前端 未结 1 1001
生来不讨喜
生来不讨喜 2021-01-15 04:54

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.

相关标签:
1条回答
  • 2021-01-15 05:28

    Try loop like this:

    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);
                    }
            }
    
    0 讨论(0)
提交回复
热议问题