none
WordDocument.Words[_index_].Font.Bold returns -1 for Bold text. RRS feed

  • Question

  • Hello everyone.

    I use Visual Studio 2017 and .NET Framework 4.5.

    I tried to identify all words with bold font in word document. First i thought that i would get 1 for Bold, 0 for regular font, but interop word returned -1 for bold font.

    I wonder to know is this case is normal or not.

    Thank you for attention!

    • Moved by CoolDadTx Tuesday, January 30, 2018 2:48 PM Office related
    Tuesday, January 30, 2018 7:43 AM

All replies

  • False = 0
    True = -1

    You might also need to allow for Words that contain some, but not all, characters in a bold font:
    Mixed = 9999999


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Tuesday, January 30, 2018 8:12 PM
  • Hi AllocatedMemory,

    Below is the testing result on my side with VS 2017.

     private void button1_Click(object sender, EventArgs e)
            {
                word.Application page = new word.Application();
                page.Visible = true;
                word.Document doc = null;
               
                    doc = page.Documents.Open(@"C:\Users\v-padee\Desktop\sample.docx");
                    if (doc != null)
                    {
                      
                        textBox1.Text = doc.Words[1].Bold.ToString();
                          
                    }
            }

    Output:

    I hope it clears your doubt.

    Reference:

    Range.Bold Property (Word)

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 1, 2018 2:43 AM
    Moderator