Spell Checking in C# Using Word Interop

后端 未结 3 1384
灰色年华
灰色年华 2020-12-16 07:09

I am writing a spell check application in C# using word.dll (the Word Interop API).

I want to check which spellings are incorrect and accordingly get s

3条回答
  •  执笔经年
    2020-12-16 07:42

    Update: So it seems you need to get the first spelling suggestion from word. I checked this article and I deduce you would need to do something like this:

    Word.SpellingSuggestions listOfSuggestions = 
                                      app.GetSpellingSuggestions(searchStr);
    listOfSuggestions.Items[0].Name;//should contain the first suggestion
    

    So from the msdn docs:

    Syntax 1

    expression.GetSpellingSuggestions(CustomDictionary, IgnoreUppercase, 
        MainDictionary, SuggestionMode, CustomDictionary2  CustomDictionary10)
    

    Result: Returns a SpellingSuggestions collection that represents the words suggested as spelling replacements for the first word in the specified range.

    Syntax 2

    expression.GetSpellingSuggestions(Word, CustomDictionary, IgnoreUppercase,
     MainDictionary, SuggestionMode, CustomDictionary2  CustomDictionary10)
    

    Result:Returns a SpellingSuggestions collection that represents the words suggested as spelling replacements for a given word.

    Note: If you use anything earlier than .NET4 then you'll have to use Missing.Value for the parameters you want empty/null. As of .NET4 we've got optional parameters and when you add a reference to the Office Library, the interop wrapper will have overloads based on the optional parameters.

提交回复
热议问题