以编程方式检查文档中的拼写
若要检查文档中的拼写,请使用该方法CheckSpelling。 此方法返回一个布尔值,该值指示是否正确拼写提供的参数。
适用于: 本主题中的信息适用于 Word 的文档级项目和 VSTO 外接程序项目。 有关详细信息,请参阅办公室应用程序和项目类型提供的功能。
在消息框中检查拼写和显示结果
CheckSpelling调用该方法并将一系列文本传递给检查拼写错误。 若要使用此代码模板,请从项目中的
ThisDocument
或ThisAddIn
类运行它。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);