none
Word 2010 Add-Ins get Paragraph Formatting's RRS feed

  • Question

  • Hi @ all

    I'm about to write a Word 2010 add-in in C# in VS2010, that checks all the Headings ("Heading 1", "Heading 2" and "Heading 3") are correct formatted.

    For example:

    "Heading 1" must be (Font=Verdana, Font-Site=16, FontWeight=Bold)

    "Heading 2" must be (Font=Verdana, Font-Site=14, FontWeight=Bold)

    "Heading 3" must be (Font=Verdana, Font-Site=12, FontWeight=Bold)

    How can I check that?

    foreach( Paragraph p in Paragraphs)
               {
                   var myStyle = p.Format.get_Style();
                   
                                if (myStyle.NameLocal == "Heading 1") // Question-FLAG 1
                                {
    // Question-FLAG 2
                                }
               }

    Question-FLAG 1:  Is there a possibility to write a semantic meaning, instead  a static string ->"Heading 1"

    Question-FLAG 2: How Can I get the actual paragraphs Properties, for example (Fontsize, Bold or Italic, Fontcolor...)

    Thanks in Advance

    Joe


    • Edited by Joe Aiden Thursday, April 5, 2012 12:46 PM
    • Moved by CoolDadTx Thursday, April 5, 2012 1:48 PM Office related (From:Visual C# General)
    Thursday, April 5, 2012 12:00 PM

Answers

  • Hi Joe Aiden,

    Thank you for posting.

    >>Question-FLAG 1:  Is there a possibility to write a semantic meaning, instead  a static string ->"Heading 1"

    I think you can define an Enum for the styles which can use to represent the string.

    >> Question-FLAG 2: How Can I get the actual paragraphs Properties, for example (Fontsize, Bold or Italic, Fontcolor...)

    You can get these properties  from the paragraph's Range object:

                foreach (Paragraph p in Paragraphs)
                {
                    var myStyle = p.Format.get_Style();
     
                    if (myStyle.NameLocal == "Heading 1"// Question-FLAG 1
                    {
                        // Question-FLAG 2
                        MessageBox.Show(p.Range.Font.Size.ToString());
                        MessageBox.Show(p.Range.Font.Name.ToString());
                    }
                }

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Joe Aiden Monday, April 9, 2012 10:52 AM
    Monday, April 9, 2012 8:54 AM

All replies

  • Hi Joe Aiden,

    Thank you for posting.

    >>Question-FLAG 1:  Is there a possibility to write a semantic meaning, instead  a static string ->"Heading 1"

    I think you can define an Enum for the styles which can use to represent the string.

    >> Question-FLAG 2: How Can I get the actual paragraphs Properties, for example (Fontsize, Bold or Italic, Fontcolor...)

    You can get these properties  from the paragraph's Range object:

                foreach (Paragraph p in Paragraphs)
                {
                    var myStyle = p.Format.get_Style();
     
                    if (myStyle.NameLocal == "Heading 1"// Question-FLAG 1
                    {
                        // Question-FLAG 2
                        MessageBox.Show(p.Range.Font.Size.ToString());
                        MessageBox.Show(p.Range.Font.Name.ToString());
                    }
                }

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Joe Aiden Monday, April 9, 2012 10:52 AM
    Monday, April 9, 2012 8:54 AM
  • Hi Bruce Song, thanks for your reply

    The static string "Heading 1" is depending of the Word Language installed on the PC.

    For Example in Spanish is "Título 1".
    Is there a possibility to program it Language neutrally?


    Yes.. it is

    Monday, April 9, 2012 10:51 AM