C# 使用C识别ms word文档中的标题#

C# 使用C识别ms word文档中的标题#,c#,ms-word,vsto,ms-office,C#,Ms Word,Vsto,Ms Office,我需要分别识别ms word文档中的标题和普通文本,并将它们放在excel工作表的两个不同列中。这是一个使用C#的VSTO应用程序 这是单词部分的一个简短循环。获取段落样式的名称,并检查其名称。名称将根据文档模板中定义的内容而有所不同 foreach (Paragraph paragraph in this.Application.ActiveDocument.Paragraphs) { Style style = paragraph.get_Style() as Style;

我需要分别识别ms word文档中的标题和普通文本,并将它们放在excel工作表的两个不同列中。这是一个使用C#的VSTO应用程序

这是单词部分的一个简短循环。获取段落样式的名称,并检查其名称。名称将根据文档模板中定义的内容而有所不同

foreach (Paragraph paragraph in this.Application.ActiveDocument.Paragraphs)
{
    Style style = paragraph.get_Style() as Style;
    string styleName = style.NameLocal;
    string text = paragraph.Range.Text;
    if( styleName == "Normal" ) // do something
    else if( styleName == "Heading 1" ) // do something
}

以下是避免使用本地化样式名称的方法:

if(style.NameLocal == Doc.Styles[Word.WdBuiltinStyle.wdStyleHeading1].NameLocal){

}

我已经准备好了程序的结构。我唯一需要的是确定标题。