请先引用Microsoft.Office.Interop.Word.dll
调用Word里的拼写检查方法,注意需要先安装了Word.
CODE:
using System;
using System.Reflection;
using Microsoft.Office.Interop.Word;
namespace CsStudy
{
class Pro
{
static void Main()
{
string str = Console.ReadLine();
string res;
int errs = 0;
if (str.Length == 0)
res = "No string";
else
{
Application app = new Application();
Console.WriteLine("\nChecking the string for misspellings... ");
app.Visible = false;
Document tmpDoc = app.Documents.Add();
tmpDoc.Words.First.InsertBefore(str);
ProofreadingErrors spellErr = tmpDoc.SpellingErrors;
errs = spellErr.Count;
tmpDoc.CheckSpelling(Missing.Value, true, false);//COM方法
app.Quit(false);
res = errs + " errors found";
}
Console.WriteLine(res);
Console.ReadKey();
}
}
}
显示: