我最近在处理这个问题,并想分享一下我的发现并补充一些已有答案的内容。
您的问题是:
我想检查哪些拼写错误并相应地获得这些错误单词的建议。
(...)
我只想知道所有“ref object”都意味着什么? 我要知道他们的含义。
简短的回答是 - 请参阅
文档。
为了向您展示
GetSpellingSuggestions
方法如何在更完整的上下文中使用,我提供了以下示例程序。 请注意,您可以使用
language
变量更改所需的校对语言。 代码如下:
using System;
using Microsoft.Office.Interop.Word;
namespace WordStack
{
public class Program
{
private static void Main()
{
var wordApplication = new Application() { Visible = false };
var myDocument = wordApplication.Documents.Open(@"C:\...\myDoc.docx");
var language = wordApplication.Languages[WdLanguageID.wdEnglishUS];
const string custDict = "custom.dic";
var suggestions = wordApplication.GetSpellingSuggestions("overfloww", custDict, MainDictionary: language.Name);
foreach (SpellingSuggestion spellingSuggestion in suggestions)
Console.WriteLine("Suggested replacement: {0}", spellingSuggestion.Name);
Console.ReadLine();
wordApplication.Quit();
}
}
}
...这让我得出以下三个建议:overflow、overflows和overflown。
给定的示例是使用.NET 4.5和Word Interop API(Office 2013)的15版本实现的。
请注意,给定的示例也解决了您对已经给出的答案之一的评论,其中说:
(...)它正在工作。但是Microsoft Word应用程序会弹出每个单词。有没有办法获得拼写建议而不让Microsoft应用程序窗口弹出??
就个人而言,我没有遇到过这种行为(无论是在Application
实例上可用的GetSpellingSuggestions
还是CheckSpelling
方法中都没有)。
然而,如果在
Document
实例上调用
CheckSpelling
,它将会在发现一个或多个拼写错误时显示拼写对话框
(如文档中所述)(前提是在构建Word
Application
实例时为
Visible
属性分配了
true
——否则,它将在后台等待输入,导致应用程序“冻结”)。