469,929 Members | 1,381 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

using SpellChecker from Word

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
0 1504

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Nathan Sokalski | last post: by
3 posts views Thread by noridotjabi | last post: by
5 posts views Thread by beary | last post: by
reply views Thread by Armen Kirakosyan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.