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 ApplicationClas s application;
public void Quit()
{
object savenochanges = WdSaveOptions.w dDoNotSaveChang es;
object nothing = System.Reflecti on.Missing.Valu e;
if (this.applicati on != null)
this.applicatio n.Quit(ref savenochanges,
ref nothing, ref nothing);
this.applicatio n = 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.Reflecti on.Missing.Valu e;
object objLanguageEng =
Microsoft.Offic e.Interop.Word. WdLanguageID.wd EnglishUK;
object objLanguageRus =
Microsoft.Offic e.Interop.Word. WdLanguageID.wd German;
//ask MS Word to spell check the given word
bool spelledright = application.Che ckSpelling(
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();
SpellingSuggest ions suggestions =
this.applicatio n.GetSpellingSu ggestions(
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 (SpellingSugges tion suggestion in suggestions)
words.Add(sugge stion.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 = WdNewDocumentTy pe.wdNewBlankDo cument;
object visible = false;
//create an instance of MS word
this.applicatio n = new ApplicationClas s();
this.applicatio n.DisplayAlerts = WdAlertLevel.wd AlertsNone;
this.applicatio n.Visible = false;
this.applicatio n.Options.Sugge stSpellingCorre ctions = true;
//create an activate a new document
Document document = this.applicatio n.Documents.Add (
ref template, ref newtemplate, ref doctype, ref visible);
document.Activa te();
}
}
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 ApplicationClas s application;
public void Quit()
{
object savenochanges = WdSaveOptions.w dDoNotSaveChang es;
object nothing = System.Reflecti on.Missing.Valu e;
if (this.applicati on != null)
this.applicatio n.Quit(ref savenochanges,
ref nothing, ref nothing);
this.applicatio n = 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.Reflecti on.Missing.Valu e;
object objLanguageEng =
Microsoft.Offic e.Interop.Word. WdLanguageID.wd EnglishUK;
object objLanguageRus =
Microsoft.Offic e.Interop.Word. WdLanguageID.wd German;
//ask MS Word to spell check the given word
bool spelledright = application.Che ckSpelling(
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();
SpellingSuggest ions suggestions =
this.applicatio n.GetSpellingSu ggestions(
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 (SpellingSugges tion suggestion in suggestions)
words.Add(sugge stion.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 = WdNewDocumentTy pe.wdNewBlankDo cument;
object visible = false;
//create an instance of MS word
this.applicatio n = new ApplicationClas s();
this.applicatio n.DisplayAlerts = WdAlertLevel.wd AlertsNone;
this.applicatio n.Visible = false;
this.applicatio n.Options.Sugge stSpellingCorre ctions = true;
//create an activate a new document
Document document = this.applicatio n.Documents.Add (
ref template, ref newtemplate, ref doctype, ref visible);
document.Activa te();
}
}