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#.
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
}
This is how You avoid using localized style name:
if(style.NameLocal == Doc.Styles[Word.WdBuiltinStyle.wdStyleHeading1].NameLocal){
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With