views:

73

answers:

1

I need to identify the headings and normal texts in a ms word document separately and put them in two different columns of an excel sheet. This is a VSTO application using C#.

A: 

Here's a short loop for the word part. Get the name of the style for a paragraph, and check it's name. The name will differ according to what is defined in your document template.

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
}
Mikael Svenson