使用互操作在 Word 2010 中按样式查找段落 [英] Find paragraphs by style in word 2010 using interop

查看:29
本文介绍了使用互操作在 Word 2010 中按样式查找段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能指出我正确的方向,或者告诉我如何使用 c#.net 中的单词互操作按样式名称查找段落.

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

这篇关于使用互操作在 Word 2010 中按样式查找段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆