DocumentBase.GrammaticalErrors 属性

定义

获取一个 ProofreadingErrors 集合,该集合表示文档中未通过语法检查的句子。

public Microsoft.Office.Interop.Word.ProofreadingErrors GrammaticalErrors { get; }

属性值

ProofreadingErrors

一个 ProofreadingErrors 集合,表示文档中未通过语法检查的句子。

示例

下面的代码示例将 ungrammatical 文本添加到第一个段落,然后检查是否有任何错误。 若要使用此示例,请在 ThisDocument 文档级项目的类中运行它。

private void DocumentGrammaticalErrors()
{
    this.Paragraphs[1].Range.InsertParagraphAfter();
    this.Paragraphs[1].Range.Text = "This is a ungrammatical sentence.";
    this.CheckGrammar();
    System.Windows.Forms.Application.DoEvents();
    if (this.GrammaticalErrors.Count == 0 )
    {
        MessageBox.Show("There are no grammatical errors.");
    }
    else
    {
        this.CheckGrammar();
    }
}
Private Sub DocumentGrammaticalErrors()
    Me.Paragraphs(1).Range.InsertParagraphAfter()
    Me.Paragraphs(1).Range.Text = "This is a ungrammatical sentence."
    Me.CheckGrammar()
    System.Windows.Forms.Application.DoEvents()
    If Me.GrammaticalErrors.Count = 0 Then
        MessageBox.Show("There are no grammatical errors.")
    Else
        Me.CheckGrammar()
    End If
End Sub

注解

每个句子只能有一个错误。

如果没有语法错误,则 Count ProofreadingErrors 由属性返回的对象的属性将 GrammaticalErrors 返回0(零)。

适用于