Compare Paragraph Styles
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Compare Paragraph Styles

  1. #1
    Join Date
    Aug 2008

    Question Compare Paragraph Styles


    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:
    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.


  2. #2
    Join Date
    Jul 2011

    Re: Compare Paragraph Styles

    How about method this post shows?

    Hope helpful!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)