在 Windows 窗体应用程序中实现单词拼写检查
我有一个内部 Windows 窗体应用程序,我想使用拼写检查。每个人都安装了 Office 2007,所以我应该不会有问题,但我无法使其完全正常工作。
这是我所拥有的:
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;
}
}
}
我像这样使用它:
memDirectionsToAddress.Text = SpellCheckers.CheckSpelling(memDirectionsToAddress.Text);
现在,这成功地从 Word 弹出了拼写检查对话框并检测到任何拼写错误的单词,但我无法让它在 WinForm 应用程序中进行更正。
此外,它还会打开包含更正文本的 Word 文档“外壳”。我如何不显示这一点或至少让它消失?
两件事:
- 首先,虽然“外壳”将其关闭 每次都闪一下任何解决方案 那?
- 其次,拼写检查对话框可以 没有出现在TOP上,我可以设置什么 更正吗?
谢谢
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.
Here is what I have:
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);
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.
Also, it leaves this "Shell" of a Word Doc open with the corrected text. How do I not show that or at least make it go away?
Two things:
- 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?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
接下来的步骤是:
更多信息:
The next steps would be:
More info:
我有一个旧脚本,其中所需的功能都被调用,因此单词本身不需要 DLL 引用:
只需向其提供文本,它将返回您批准的任何更正。
I have an old script for this where the required features are all invoked so no DLL ref are required for word itself:
Just feed it the text and it will return with any corrections you approve.