Hi,
In this tutorial, we will learn how to add spell check functionality in C# using VSTO (Visual Studio Tool for Office). For that you have to install Microsoft Word on your computer.
You have to add reference for the following namespace in the code.
using Microsoft.Office.Interop.Word;
The working code snippet is as follow. It takes string to test spell check in it.
string s1 = textBox1.Text;
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word._Document doc = app.Documents.Add();
doc.Words.First.InsertBefore(s1);
Microsoft.Office.Interop.Word.ProofreadingErrors errors = doc.SpellingErrors;
int errorCount = errors.Count;
doc.CheckSpelling(Missing.Value, true, false);
app.Quit(false);
textBox3.Text = errorCount.ToString();
Demo application is shown with wrong text.
Windows showing wrong word as red highlighted text.
Total error count is being showed at the end.
No comments:
Post a Comment