Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#中使用单词互操作进行拼写检查_C#_Ms Word_Office Interop_Spell Checking - Fatal编程技术网

在C#中使用单词互操作进行拼写检查

在C#中使用单词互操作进行拼写检查,c#,ms-word,office-interop,spell-checking,C#,Ms Word,Office Interop,Spell Checking,我正在用C#编写一个拼写检查应用程序,使用word.dll(单词互操作API) 我想检查哪些拼写是错误的,并相应地得到错误单词的建议 我从网络上获得了一个示例代码,无法理解以下命令的参数: Microsoft.Office.Interop.Word._Application.GetSpellingSuggestions (string, ref object, ref object, ref object, ref object, ref object, ref objec

我正在用C#编写一个拼写检查应用程序,使用
word.dll
(单词互操作API)

我想检查哪些拼写是错误的,并相应地得到错误单词的建议

我从网络上获得了一个示例代码,无法理解以下命令的参数:

Microsoft.Office.Interop.Word._Application.GetSpellingSuggestions
   (string, ref object, ref object, ref object, ref object, ref object, 
       ref object, ref object, ref object, ref object, ref object, ref object, 
       ref object, ref object)
我只想知道所有的
ref对象
s意味着什么?我想知道它们的含义。

更新:
    SpellingSuggestions GetSpellingSuggestions(
        string Word,
        ref Object CustomDictionary,
        ref Object IgnoreUppercase,
        ref Object MainDictionary,
        ref Object SuggestionMode,
        ref Object CustomDictionary2,
        ref Object CustomDictionary3,
        ref Object CustomDictionary4,
        ref Object CustomDictionary5,
        ref Object CustomDictionary6,
        ref Object CustomDictionary7,
        ref Object CustomDictionary8,
        ref Object CustomDictionary9,
        ref Object CustomDictionary10

)
所以你似乎需要从word中获得第一个拼写建议。我查看了这篇文章,我推断您需要这样做:

Word.SpellingSuggestions listOfSuggestions = 
                                  app.GetSpellingSuggestions(searchStr);
listOfSuggestions.Items[0].Name;//should contain the first suggestion
因此,从以下方面:

语法1

expression.GetSpellingSuggestions(CustomDictionary, IgnoreUppercase, 
    MainDictionary, SuggestionMode, CustomDictionary2  CustomDictionary10)
结果:返回SpellingSuggestions集合,该集合表示建议作为指定范围内第一个单词拼写替换的单词

语法2

expression.GetSpellingSuggestions(Word, CustomDictionary, IgnoreUppercase,
 MainDictionary, SuggestionMode, CustomDictionary2  CustomDictionary10)
结果:返回SpellingSuggestions集合,该集合表示建议作为给定单词拼写替换的单词


注意:如果使用的是.NET4之前的任何内容,则必须使用
空/null
参数。从
.NET4
开始,我们已经有了可选参数,当您添加对Office库的引用时,interop包装器将基于可选参数进行重载。

前几天我处理过这个问题,我想与大家分享我的发现,并为已经给出的答案添加一点内容

你问:

我想检查哪些拼写不正确,并相应地得到 对错误单词的建议

(……)

我只是想知道所有的“ref对象”意味着什么?我想要 了解他们的意思

    SpellingSuggestions GetSpellingSuggestions(
        string Word,
        ref Object CustomDictionary,
        ref Object IgnoreUppercase,
        ref Object MainDictionary,
        ref Object SuggestionMode,
        ref Object CustomDictionary2,
        ref Object CustomDictionary3,
        ref Object CustomDictionary4,
        ref Object CustomDictionary5,
        ref Object CustomDictionary6,
        ref Object CustomDictionary7,
        ref Object CustomDictionary8,
        ref Object CustomDictionary9,
        ref Object CustomDictionary10

)
简单的回答是:看里面

为了向您展示如何在更完整的上下文中使用
GetSpellingSuggestions
方法,我在下面提供了一个示例程序。请注意,您可以使用
language
变量更改所需的校对语言。守则如下:

using System;
using Microsoft.Office.Interop.Word;

namespace WordStack
{
    public class Program
    {
        private static void Main()
        {
            // Create a new Word application instance (and keep it invisible)
            var wordApplication = new Application() { Visible = false };

            // A document must be loaded
            var myDocument = wordApplication.Documents.Open(@"C:\...\myDoc.docx");

            // Set the language
            var language = wordApplication.Languages[WdLanguageID.wdEnglishUS];

            // Set the filename of the custom dictionary
            // -- Based on:
            // http://support.microsoft.com/kb/292108
            // http://www.delphigroups.info/2/c2/261707.html
            const string custDict = "custom.dic";

            // Get the spelling suggestions
            var suggestions = wordApplication.GetSpellingSuggestions("overfloww", custDict, MainDictionary: language.Name);

            // Print each suggestion to the console
            foreach (SpellingSuggestion spellingSuggestion in suggestions)
                Console.WriteLine("Suggested replacement: {0}", spellingSuggestion.Name);

            Console.ReadLine();
            wordApplication.Quit();
        }
    }
}
。。。这给了我以下三个建议:溢出、溢出和溢出

给定的示例已使用.NET 4.5和Word Interop API(Office 2013)的版本15实现

请注意,给定的示例还解决了您对已给出答案之一的评论,并表示:

(……)它正在发挥作用。但是微软的Word应用程序正在为我们的用户弹出 每一个字。有没有什么方法可以让你在没有拼写的情况下得到拼写建议 让Microsoft应用程序窗口弹出

就我个人而言,我没有经历过这种行为(无论是
GetSpellingSuggestions
还是
应用程序
实例上可用的
检查拼写
方法)


但是,如果在
文档
实例上调用
检查拼写
,如果发现一个或多个拼写错误的单词,它将显示拼写对话框(假设您在构建Word
应用程序
实例期间,将
Visible
属性指定给
true
——否则,它将等待后台输入,导致应用程序“冻结”).

非常感谢。实际上,我想通过代码获得第一个拼写建议,而不是通过microsoft word打开建议窗口。我如何才能做到这一点?非常感谢……它正在工作。但是microsoft word应用程序正在为每个单词弹出。有没有办法在不让Microsoft应用程序窗口弹出??为什么不参考文档?