Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Word Interop - Spell Checking in a Certain Language

For a customer of mine I need to force the spell checking in a certain language.

I have explored the MSDN documentation and found that when calling the CheckSpelling() method in the active document, it will invoke the spelling check. This method has parameters for custom dictionaries.

My problem is that I can't find anything about those dictionaries or how to use them.

Also there is still the possibility that there is of course another way to do this.

Can anybody boost me in the right direction?

like image 889
Tom Ceuppens Avatar asked Feb 21 '23 00:02

Tom Ceuppens


2 Answers

Found my solution:

foreach (Range range in activeDocument.Words)
{
    range.LanguageID = WdLanguageID.wdFrenchLuxembourg;
}

Edit after comment

Since my activedocument is in a variable I seem to lose the static Range property. I found a work arround by doing the following. (lan is my variable where i keep my WdLanguageId)

object start = activeDocument.Content.Start;
object end = activeDocument.Content.End;

activeDocument.Range(ref start, ref end).LanguageID = lan;

thanks @Adrianno for all the help!

like image 97
Tom Ceuppens Avatar answered Mar 07 '23 16:03

Tom Ceuppens


The Spell Checker uses the language of the text to select rules and dictionaries (look here to check how it works).

You have to set the text language to what you need and then SC will use that language. Follow this link for more details:

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.language.aspx

like image 20
Adriano Repetti Avatar answered Mar 07 '23 17:03

Adriano Repetti