thanks for this lovely article but i need this spell checking coding in C#.NET and im demn new to it.
however, i tried but it raise error at some point .. i think it's quiet easy for u
thankswaiting for quick replay..Code:namespace SpellCheck { public class CheckAndCorrect { Microsoft.Office.Interop.Word._Application MSOfficeApp; private bool mbKillMe; protected bool Property KillMe { get { InitializeMe(); KillMe = mbKillMe; return KillMe; } set { mbKillMe = Value; } } public void InitializeMe() { try { //<INITIALIZE WORD> MSOfficeApp = DirectCast(GetObject(, "Word.Application"), Word.Application); } catch (Exception e) { if (TypeName(MSOfficeApp) = "Nothing") { MSOfficeApp = DirectCast(CreateObject("Word.Application"), Word.Application); mbKillMe = True; } else { MessageBox.Show(ex.Message, "SpellChecker™.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } protected string SpellMe(string Text) { Microsoft.Office.Interop.Word.Document oDoc; int iWSE,iWGE,iResp; string sReplace; if (Text = String.Empty) { } else { try { InitializeMe(); switch(MSOfficeApp.Version) { case "9.0" : case "10.0" : case "11.0" : oDoc = MSOfficeApp.Documents.Add(,,,1,true); break; case "8.0" : oDoc = MSOfficeApp.Documents.Add(); break; default: return; } oDoc.Words.First.InsertBefore(Text); iWSE = oDoc.SpellingErrors.Count; iWGE = oDoc.GrammaticalErrors.Count; //<CHECK SPELLING AND GRAMMER DIALOG BOX> if (iWSE > 0 || iWGE > 0) { // <HIDE MAIN WORD WINDOW> MSOfficeApp.Visible = False; if (MSOfficeApp.WindowState = Word.WdWindowState.wdWindowStateNormal ||MSOfficeApp.WindowState = Word.WdWindowState.wdWindowStateMaximize) MSOfficeApp.WindowState = Word.WdWindowState.wdWindowStateMinimize; else MSOfficeApp.WindowState = Word.WdWindowState.wdWindowStateMinimize; //</HIDE MAIN WORD WINDOW> //<PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)> MSOfficeApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.CheckGrammarWithSpelling = True; MSOfficeApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.SuggestSpellingCorrections = True; MSOfficeApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreUppercase = False; MSOfficeApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreInternetAndFileAddresses = True; MSOfficeApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.IgnoreMixedDigits = False; MSOfficeApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Application.Options.ShowReadabilityStatistics = False; //</PREP CHECK SPELLING OPTIONS DIALOG BOX (MODIFY TO YOUR PREFERENCES)> //<DO ACTUAL SPELL CHECKING> MSOfficeApp.Visible = True; MSOfficeApp.Activate(); iResp = MSOfficeApp.Dialogs(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar).Display; //</DO ACTUAL SPELL CHECKING> if (iResp < 0 ) { MSOfficeApp.Visible = True; MessageBox.Show("Corrections Being Updated!", "VB/Office Guru™ SpellChecker™", MessageBoxButtons.OK, MessageBoxIcon.Information); oDoc.Select(); oDoc.Range.Copy(); sReplace = DirectCast(Clipboard.GetDataObject.GetData("System.String", True), String); //<FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT> if ((InStrRev(sReplace, Chr(13) & Chr(10))) = (Len(sReplace) - 1)) { sReplace = String.Mid(sReplace, 1, Len(sReplace) - 2); } //</FIX FOR POSSIBLE EXTRA LINE BREAK AT END OF TEXT> SpellMe = sReplace; } else if (iResp = 0 ) { MessageBox.Show("Spelling Corrections Have Been Canceled!", "VB/Office Guru™ SpellChecker™.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); SpellMe = Text; } } else { MessageBox.Show("No Spelling Errors Found" & Environment.NewLine & "Or No Suggestions Available!", "VB/Office Guru™ SpellChecker™.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); SpellMe = Text; } //</CHECK SPELLING AND GRAMMER DIALOG BOX> oDoc.Close(False); oDoc = Nothing; //<HIDE WORD IF THERE ARE NO OTHER INSTANCES> if (KillMe = True) { MSOfficeApp.Visible = False; } } catch (Exception e) { MessageBox.Show(ex.Message, "SpellChecker™.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } }




Reply With Quote