Using MS Office's Spellchecking feature with C#

人盡茶涼 提交于 2019-12-06 12:11:46

问题


I wanna do a application with C# ; it will count correct words and wrong words in a text and show me it ... there is a feature in MS Word .. So how can i use this feature in C# if its possible ? (in Turkish language).


回答1:


You can add a reference to Microsoft Word x.0 Object Library. Check out this MSDN article for information: http://msdn.microsoft.com/en-us/library/15s06t57(VS.80).aspx.

Once you have added the reference you should then be able to use the Word.Application object. It would look something like this (untested code!!).

using Word;

public void checkspelling(string text) 
{
    Word.Application app = new Word.Application();
    object template=Missing.Value; 
        object newTemplate=Missing.Value; 
        object documentType=Missing.Value; 
        object visible=true; 
        object optional = Missing.Value; 

        _Document doc = app.Documents.Add(ref template, 
           ref newTemplate, ref documentType, ref visible);

        doc.Words.First.InsertBefore(text); 
        Word.ProofreadingErrors errors = doc.SpellingErrors; 

        ecount = errors.Count; 
        doc.CheckSpelling( ref optional, ref optional, ref optional, 
            ref optional, ref optional, ref optional, ref optional, 
            ref optional, ref optional, ref optional, ref optional, 
        ref optional);

        if (ecount == 0) 
        {
        // no errors
    }
        else
    {
        // errros
    }
}



回答2:


I don't thing it is a good idea to use the MS Office spell checkers. There are several open source libraries out there you can use. One of them is NHunspell, the .NET Version of the open office spell checker Hunspell. It works with the open office directories and yo got support for a lot of languages.




回答3:


http://www.codeproject.com/KB/cs/spellcheckdemo.aspx

Here is an additional older example from CodeProject.



来源:https://stackoverflow.com/questions/975886/using-ms-offices-spellchecking-feature-with-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!