我正在尝试使用word自动更正一些非英文文本的问题是,当我使用SpellCheck函数时,弹出“拼写和语法”对话框,等待用户输入,我希望文本自动更正。所以我的问题是我该如何解决这个问题?
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
发布于 2012-02-16 21:22:40
对于任何可能感兴趣的人,这是我设法解决它的方法,但它真的需要很多时间,所以欢迎任何改进或新想法。
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;
}
}发布于 2012-02-16 10:25:26
您使用的是哪个MS Word版本?
默认情况下,拼写检查器将显示该对话框。要禁用该对话框,我知道有两种方法。
1)使用代码,从自动更正中自动选择第一个选项。
大概是这样的
AutoCorrect.Entries.Add Name:="AdSAD", Value:="Assad"2)或使用菜单选项。请参考此链接。
Topic:自动更正主词典中单词的拼写
链接:http://office.microsoft.com/en-us/word-help/automatically-correct-spelling-with-words-from-the-main-dictionary-HA010174790.aspx
如果这不是你想要的,一定要告诉我。
https://stackoverflow.com/questions/9304013
复制相似问题