none
THe GramaticalErrors property does not list the same errors as Word RRS feed

  • Question

  • Dear MS Support,

      I have a simple docx file containing a single sentence: 'All parts in austenitic stainless steel, whether the have been previously scoured or not.

      If I open this file in Word, it correctly indicates that there is a grammatical error ('the have' should be 'they have'). However if I open the same using Interop and I ask for the list grammatical errors, I  get an empty list

      If it helps, I can send you the sample file with a minimal sample application to  reproduce the issue. The code of my test application is given below.

      Could you advise me on how to get this grammatical error from the interop?

    Best regards,

      Sándor Kolumbán

      31448

                Application docxapp = new Application();
                Document doc = docxapp.Documents.Open(ref filePathO,
                            ref missing, ref readOnly,
                            ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref isVisible);
                
                foreach (Language lang in docxapp.Languages)
                {
                    if (lang.Name == "English (US)")
                    {
                        doc.Content.LanguageID = lang.ID;
                        break;
                    }
                }
                
                // there should be a grammatical error as Word shows that: the -> they
                foreach (Range error in doc.GrammaticalErrors)
                {
                    Console.WriteLine(error.Text);
                }


    Friday, November 10, 2017 6:50 PM

Answers

  • I checked in my sample application and indeed the spelling error collection contains the respective item. But as you can see in the image below, Word marks the range with a blue squiggly line. As far as I know spelling errors are marked with red lines, and blue lines mean grammatical errors.

    Content Word considers an explicit spelling error gets a red squiggly line. Content Word considers an explicit grammar error gets a green squiggly line. Indeterminate errors gets a blue squiggly line. This last group is included as spelling errors in the first instance; correcting the spelling, if required, may generate a grammar error.

    In this case, correcting:
    All parts in austenitic stainless steel, whether the have been previously scoured or not.
    might mean changing it to any of:
    All parts in austenitic stainless steel, whether they have been previously scoured or not.
    or:
    All parts in austenitic stainless steel, whether the parts have been previously scoured or not.
    or:
    All parts in austenitic stainless steel, whether the steel has been previously scoured or not.
    or:
    All parts in austenitic stainless steel, whether a part has been previously scoured or not.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, November 13, 2017 9:16 PM

All replies

  • Hello,

    It is in the spelling error collections.

    Please use 

    using Word = Microsoft.Office.Interop.Word;
                foreach (Word.Range rng in ActiveDocument.SpellingErrors)
                {
                    if (rng.GetSpellingSuggestions().Count>0)
                    {
                        foreach(Word.SpellingSuggestion suggested in rng.GetSpellingSuggestions())
                        {
                            MessageBox.Show(rng.Text + "->" + suggested.Name);
                        }
                    }
                }

    Regards,

    Celeste


    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.

    Monday, November 13, 2017 4:15 AM
    Moderator
  • The 'the' in 'whether the have been' is treated as a spelling error, not as a grammar error. However, if you had 'whether they has been', the whole sentence would be treated as a grammar error.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, November 13, 2017 5:42 AM
  • Dear Celeste,

    I checked in my sample application and indeed the spelling error collection contains the respective item. But as you can see in the image below, Word marks the range with a blue squiggly line. As far as I know spelling errors are marked with red lines, and blue lines mean grammatical errors.

    So to reformulate the original problem more precisely: There is an error in the text that is visualized by word as a grammar issue, but interop offers it as a spelling issue. So the GrammerErros property does not give me all the errors that are shown by Word as grammatical errors.

    Could you offer some insight on how can we figure out from an issue in the SpellingErrors list that Word would mark them with blue squiggles?

    Best regards,

    Sándor Kolumbán


    • Edited by Sándor Kolumbán Monday, November 13, 2017 7:42 PM precision in a statement improed
    Monday, November 13, 2017 1:45 PM
  • I checked in my sample application and indeed the spelling error collection contains the respective item. But as you can see in the image below, Word marks the range with a blue squiggly line. As far as I know spelling errors are marked with red lines, and blue lines mean grammatical errors.

    Content Word considers an explicit spelling error gets a red squiggly line. Content Word considers an explicit grammar error gets a green squiggly line. Indeterminate errors gets a blue squiggly line. This last group is included as spelling errors in the first instance; correcting the spelling, if required, may generate a grammar error.

    In this case, correcting:
    All parts in austenitic stainless steel, whether the have been previously scoured or not.
    might mean changing it to any of:
    All parts in austenitic stainless steel, whether they have been previously scoured or not.
    or:
    All parts in austenitic stainless steel, whether the parts have been previously scoured or not.
    or:
    All parts in austenitic stainless steel, whether the steel has been previously scoured or not.
    or:
    All parts in austenitic stainless steel, whether a part has been previously scoured or not.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, November 13, 2017 9:16 PM
  • Dear Paul,

    This clears things up. So grammatical errors that are also spelling errors appear in the SpellingErrors list. Got it.

    Cheers,

    Sándor Kolumbán

    Wednesday, November 15, 2017 4:00 PM