Spellchecking in C # using Word Interop

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

I want to check which entries are incorrect and get sentences for the wrong words accordingly.

I got a sample code from the network and I can not understand the parameters for the following command:

 Microsoft.Office.Interop.Word._Application.GetSpellingSuggestions (string, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object) 

I just wanted to know what all ref object means? I want to know their meaning.

+3
source share
3 answers

Update: So it looks like you need to get the first spelling sentence from a word. I checked this article and I conclude that you will need to do something like this:

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

So from msdn docs :

Syntax 1

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

Result : returns the SpellingSuggestions collection, which represents the words offered as spelling replacements for the first word in the specified range.

Syntax 2

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

Result : returns the SpellingSuggestions collection, which represents the words offered as spelling substitutes for the word.

Note If you are using anything earlier than .NET4 , you will need to use Missing.Value for the parameters you want empty/null . Starting with .NET4 , we have additional parameters, and when you add a link to the Office library, the interop shell will have overloads based on optional parameters.

+3
source

I worked with this the other day and thought I wanted to share my conclusions and add a little to the answers already provided.

You're asking:

I want to check which spelling is incorrect and, accordingly, get suggestions for incorrect words.

(...)

I just wanted to know what the whole β€œref object” means? I want to find out their meaning.

The short answer to this question is to look at the documentation .

To show you how the GetSpellingSuggestions method can be used in a more complete context, I included the following program in it. Please note that you can change the desired verification language using the language variable. The code is as follows:

 using System; using Microsoft.Office.Interop.Word; namespace WordStack { public class Program { private static void Main() { // Create a new Word application instance (and keep it invisible) var wordApplication = new Application() { Visible = false }; // A document must be loaded var myDocument = wordApplication.Documents.Open(@"C:\...\myDoc.docx"); // Set the language var language = wordApplication.Languages[WdLanguageID.wdEnglishUS]; // Set the filename of the custom dictionary // -- Based on: // http://support.microsoft.com/kb/292108 // http://www.delphigroups.info/2/c2/261707.html const string custDict = "custom.dic"; // Get the spelling suggestions var suggestions = wordApplication.GetSpellingSuggestions("overfloww", custDict, MainDictionary: language.Name); // Print each suggestion to the console foreach (SpellingSuggestion spellingSuggestion in suggestions) Console.WriteLine("Suggested replacement: {0}", spellingSuggestion.Name); Console.ReadLine(); wordApplication.Quit(); } } } 

... which give me the following three sentences: overflow, overflow and overflow.

This example was implemented using .NET 4.5 and version 15 of the Word Interop API (Office 2013).

Note that this sample also solves your comment on one of the answers already received, saying:

(...) He works. But Microsoft Word app appears every word. Is there a way to get a spelling suggestion without allowing a popup of a Microsoft application?

Personally, I have not experienced this behavior (either using the GetSpellingSuggestions methods or the CheckSpelling available in the Application instance).

However, if you call CheckSpelling on an instance of Document , it will be as described in the documentation , it will display the Spelling dialog box if one or more words with errors are found (provided that during the construction of the instance Word Application to Visible for true ), otherwise it will wait for input in the background, which will cause the application to β€œfreeze”,).

+2
source
  SpellingSuggestions GetSpellingSuggestions( string Word, ref Object CustomDictionary, ref Object IgnoreUppercase, ref Object MainDictionary, ref Object SuggestionMode, ref Object CustomDictionary2, ref Object CustomDictionary3, ref Object CustomDictionary4, ref Object CustomDictionary5, ref Object CustomDictionary6, ref Object CustomDictionary7, ref Object CustomDictionary8, ref Object CustomDictionary9, ref Object CustomDictionary10 ) 
0
source

Source: https://habr.com/ru/post/1403825/


All Articles