自动更正文本C#Word

我正在尝试使用word来自动纠正一些不是英文的文本问题是当我使用拼写检查function弹出“拼写和语法”对话框并等待用户输入时我希望文本是自动纠正。 所以我的问题是如何解决这个问题?

using System.Collections.Generic; using Microsoft.Office.Interop.Word; using Word = Microsoft.Office.Interop.Word; using TobyCL.ro.toby.StringOperations; namespace namespace.ro.toby { class WordProofing:IProof { private readonly Word.Application _wordApp; private readonly Word.Document _wordDoc; private static object _oEndOfDoc = "\\endofdoc"; public WordProofing() { _wordApp = new Word.Application {Visible = false}; _wordDoc = _wordApp.Documents.Add(); } public void Close() { object obj = Word.WdSaveOptions.wdDoNotSaveChanges; _wordDoc.Close(ref obj); _wordApp.Quit(ref obj); } #region Implementation of IProof public string Proof(string proofText) { Range wRng = _wordDoc.Bookmarks.get_Item(ref _oEndOfDoc).Range; wRng.Text = proofText; _wordDoc.CheckSpelling(IgnoreUppercase: true,AlwaysSuggest:false); string str = wRng.Text; wRng.Text = ""; return str; } #endregion } } 

我几天前写了这段代码,但它确实奏效了。 问题是我卸载校对工具来运行一些测试,现在我继续得到那个对话框,所以我想我可能必须设置一些Word设置或者我已经在我的代码中更改了一些内容而不知道。 任何帮助将不胜感激。

我使用的是Microsoft Office Word 2010

对于任何可能感兴趣的人来说,这是我设法解决它的方式,但它确实需要花费很多时间,所以欢迎任何改进或新想法。

 using Microsoft.Office.Interop.Word; class WordProofing { private Application _wordApp; private readonly Document _wordDoc; private static object _oEndOfDoc = "\\endofdoc"; public WordProofing() { _wordApp = new Application { Visible = false }; _wordDoc = _wordApp.Documents.Add(); } public void Close() { _wordDoc.Close(WdSaveOptions.wdDoNotSaveChanges); _wordApp.Quit(); } public string Proof(string proofText) { Range wRng = _wordDoc.Bookmarks.get_Item(ref _oEndOfDoc).Range; wRng.Text = proofText; ProofreadingErrors spellingErros = wRng.SpellingErrors; foreach (Range spellingError in spellingErros) { SpellingSuggestions spellingSuggestions = _wordApp.GetSpellingSuggestions(spellingError.Text,IgnoreUppercase:true); foreach (SpellingSuggestion spellingSuggestion in spellingSuggestions) { spellingError.Text = spellingSuggestion.Name; break; } } string str = wRng.Text; wRng.Text = ""; return str; } } 

您使用的是哪个MS Word版本?

默认情况下,拼写检查器会显示对话框。 要禁用该对话框,我知道有两种方法。

1)使用代码,自动从自动修正中选择第一个选项。

就是这样的

 AutoCorrect.Entries.Add Name:="AdSAD", Value:="Assad" 

2)或使用菜单选项。 请参阅此链接。

主题使用主词典中的单词自动更正拼写

链接 : http : //office.microsoft.com/en-us/word-help/automatically-correct-spelling-with-words-from-the-main-dictionary-HA010174790.aspx

如果这不是你想要的,请告诉我吗?