By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,084 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,084 IT Pros & Developers. It's quick & easy.

using SpellChecker from Word

P: n/a
HI all !!
have an appication which should spell check BUT ! I cannot dynamicaly change
language, or set to autodetect
the server in English, but I want it spell check in German or Spanish

here is the code, any suggestion what kind of changes can be done?

//create a utility class for spell checking with MS word
class SpellChecker
{
private ApplicationClass application;

public void Quit()
{
object savenochanges = WdSaveOptions.wdDoNotSaveChanges;
object nothing = System.Reflection.Missing.Value;

if (this.application != null)
this.application.Quit(ref savenochanges,
ref nothing, ref nothing);
this.application = null;
}

~SpellChecker()
{
//quit word, don't save

}

/// <summary>
/// Suggests corrections for a word if misspelled
/// as an array or returns null if the word is
/// spelled correctly.
/// </summary>
/// <param name="word"></param>
/// <returns></returns>
public string[] Suggest(string word)
{
object nothing = System.Reflection.Missing.Value;

object objLanguageEng =
Microsoft.Office.Interop.Word.WdLanguageID.wdEngli shUK;
object objLanguageRus =
Microsoft.Office.Interop.Word.WdLanguageID.wdGerma n;

//ask MS Word to spell check the given word

bool spelledright = application.CheckSpelling(
word,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing
);

if (spelledright) return null;

//if word is spelled wrong, ask MS Word to suggest
//other similar words.
ArrayList words = new ArrayList();

SpellingSuggestions suggestions =
this.application.GetSpellingSuggestions(
word,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing,
ref nothing
);

//add the suggestions to an ArrayList temporarily
foreach (SpellingSuggestion suggestion in suggestions)
words.Add(suggestion.Name);

suggestions = null;

//return the suggestions as a string array
return (string[])words.ToArray(typeof(string));
}

public SpellChecker()
{
object template = "normal.dot";
object newtemplate = false;
object doctype = WdNewDocumentType.wdNewBlankDocument;
object visible = false;

//create an instance of MS word
this.application = new ApplicationClass();

this.application.DisplayAlerts = WdAlertLevel.wdAlertsNone;
this.application.Visible = false;
this.application.Options.SuggestSpellingCorrection s = true;

//create an activate a new document
Document document = this.application.Documents.Add(
ref template, ref newtemplate, ref doctype, ref visible);

document.Activate();
}
}
Sep 28 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.