Hi,
I am writing a word document using C#. At some point, I have to see if a heading is already archived in word, so that I can skip writing it again. My problem is
1. I can not iterate through headings in a word document.
2. If I iterate through paragraph and try to compare if its heading is same Word.WdBuiltinStyle.wdStyleHeading1, it returns me an error that unboxing in this format is not possible.
Below is the code:
Code:
object headingStyle = Microsoft.Office.Interop.Word.WdBuiltinStyle.wdStyleHeading1;
foreach (Word.Paragraph para in mTdbDoc.Paragraphs)
{
Word.WdBuiltinStyle style = (Word.WdBuiltinStyle)para.get_Style(); //Error here
if (style.Equals(headingStyle))
if (para.Range.Text.StartsWith(aCompareString))
return para.Range.End;
}
return -1;
I do not want to do it with Syle.NameLocal because it differs on different machines depending on the word language.
Any hint will be helpful.
Regards
Ricky