我用过这里的例子: http://msdn.microsoft.com/ru-ru/library/ms173188(v=vs.80).aspx
它有点好用,除了一件事 - 它不会检查标点符号,而Word本身会检查它。
我尝试在演示中的弹出窗口中更改设置,但它仍然没有检查逗号,我没有在代码中看到任何可能影响此设置的设置。
using System.Reflection;
using Word = Microsoft.Office.Interop.Word;
namespace WordSpell
{
public partial class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
public Form1() //constructor
{
InitializeComponent();
}
private void button1_Click(object sender, System.EventArgs e)
{
Word.Application app = new Word.Application();
int errors = 0;
if (textBox1.Text.Length > 0)
{
app.Visible = false;
// Setting these variables is comparable to passing null to the function.
// This is necessary because the C# null cannot be passed by reference.
object template = Missing.Value;
object newTemplate = Missing.Value;
object documentType = Missing.Value;
object visible = true;
Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
doc1.Words.First.InsertBefore(textBox1.Text);
Word.ProofreadingErrors spellErrorsColl = doc1.SpellingErrors;
errors = spellErrorsColl.Count;
object optional = Missing.Value;
doc1.CheckSpelling(
ref optional, ref optional, ref optional, ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);
label1.Text = errors + " errors corrected ";
object first = 0;
object last = doc1.Characters.Count - 1;
textBox1.Text = doc1.Range(ref first, ref last).Text;
}
object saveChanges = false;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
}
}
}
答案 0 :(得分:2)
需要使用doc1.CheckGrammar();
代替doc1.CheckSpelling(..);