若要在文档中检查拼写,请使用 CheckSpelling 方法。 此方法返回一个布尔值,该值指示所提供的参数是否拼写正确。
**适用于:**本主题中的信息适用于 Word 2007 和 Word 2010 的文档级项目和应用程序级项目。有关更多信息,请参见按 Office 应用程序和项目类型提供的功能。
检查拼写并在消息框中显示结果
调用 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); if (spellCheck == true) { result = "Spelled correctly."; } MessageBox.Show(result);