实现单词的拼写检查在Windows窗体应用程序 [英] Implement Word Spell check in Windows Form App

查看:195
本文介绍了实现单词的拼写检查在Windows窗体应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内部的Windows窗体应用程序,我想使用拼写检查。每个人都有Office 2007的安装,所以我不应该有一个问题存在,但我无法得到这个全面合作。

I have an In-house windows form app that I would like to use Spell Checking in. Everyone has Office 2007 installed so I shouldn't have an issue there but I am having trouble getting this to fully work.

下面是我:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
using System.Reflection;

namespace Refraction.Spelling
{
    public static class SpellCheckers
    {
        public static string CheckSpelling(string text)
        {
            Word.Application app = new Word.Application();
 object nullobj = Missing.Value;
                object template = Missing.Value;
                object newTemplate = Missing.Value;
                object documentType = Missing.Value;
                object visible = true;
                object optional = Missing.Value;
            object savechanges = false;
            Word._Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);

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

        var 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);
        object first = 0;
        object last = doc.Characters.Count - 1;
        var results = doc.Range(ref first, ref last).Text;
        doc.Close(ref savechanges, ref nullobj, ref nullobj);
        app.Quit(ref savechanges, ref nullobj, ref nullobj);

        return results;
    }
}

}

我用这个像这样:

I use this like so:

memDirectionsToAddress.Text = SpellCheckers.CheckSpelling(memDirectionsToAddress.Text);

现在这个成功弹出的对话框拼写检查从Word和检测到任何拼写错误的单词<打击>,但我不能让它改正在WinForm程序

Now this successfully pops up the SpellCheck Dialog from Word and detects any misspelled wordsbut I cannot get it to make the corrections in the WinForm app.

<打击>此外,它留下这个壳一个Word文档的开放与纠正的文本。我怎么不显示,或者至少让它消失?

两件事情:

  • 首先,尽管壳关闭它 每次闪烁。任何解决方案 是什么?
  • 二,拼写检查对话框呢 没有出现在上面,我可以设置为 纠正?
  • First, though the "shell" closes it Flashes everytime. Any solutions to that?
  • Second, the Spell Check Dialog does not appear on TOP, what can I set to correct that?

感谢

推荐答案

接下来的步骤将是:

  1. 拉修正文字背出来的文件。
  2. 关闭文档。 (如果只有在Word中一个文档打开,你可能要关闭或隐藏Word应用程序。)
  3. 返回纠正的文本到调用函数。

更多信息:

  • <一个href="http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ac899e2d-5c2f-4ea9-ada2-b03aa4773664" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ac899e2d-5c2f-4ea9-ada2-b03aa4773664
  • <一个href="http://www.c-sharpcorner.com/UploadFile/Globalking/fileAccessingusingcsharp02242006050207AM/fileAccessingusingcsharp.aspx?ArticleID=44e79e38-0cdc-4e5e-8574-63572d8cc112" rel="nofollow">http://www.c-sharpcorner.com/UploadFile/Globalking/fileAccessingusingcsharp02242006050207AM/fileAccessingusingcsharp.aspx?ArticleID=44e79e38-0cdc-4e5e-8574-63572d8cc112
  • http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ac899e2d-5c2f-4ea9-ada2-b03aa4773664
  • http://www.c-sharpcorner.com/UploadFile/Globalking/fileAccessingusingcsharp02242006050207AM/fileAccessingusingcsharp.aspx?ArticleID=44e79e38-0cdc-4e5e-8574-63572d8cc112

这篇关于实现单词的拼写检查在Windows窗体应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆