如何:在文档中检查拼写

更新:2007 年 11 月

适用对象

本主题中的信息仅适用于指定的 Visual Studio Tools for Office 项目和 Microsoft Office 版本。

项目类型

  • 文档级项目

  • 应用程序级项目

Microsoft Office 版本

  • Word 2003

  • Word 2007

有关更多信息,请参见按应用程序和项目类型提供的功能

若要在文档中检查拼写,请使用 CheckSpelling 方法。此方法返回一个布尔值,该值指示所提供的参数是否拼写正确。

检查拼写并在消息框中显示结果

  • 调用 CheckSpelling 方法,并将它传给文本范围,以检查拼写错误。若要使用此代码示例,请从项目内的 ThisDocument 或 ThisAddIn 类中运行此示例。

    Dim result As String = "Spelled incorrectly."
    
    If Me.Application.CheckSpelling(Me.Range.Text) = True Then
        result = "Spelled correctly."
    End If
    
    MessageBox.Show(result)
    
    string result = "Spelled incorrectly.";
    
    object startLocation = this.Content.Start;
    object endLocation = this.Content.End;
    
    bool spellCheck = this.Application.CheckSpelling(
        this.Range(ref startLocation, ref endLocation).Text,
        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
    
    if (spellCheck == true)
    {
        result = "Spelled correctly.";
    }
    
    MessageBox.Show(result);
    

请参见

任务

如何:在文档中定义和选择范围

概念

了解 Office 解决方案中的可选参数