首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AutoCorrect Text C# Word

AutoCorrect Text C# Word
EN

Stack Overflow用户
提问于 2012-02-16 08:54:01
回答 2查看 5.8K关注 0票数 1

我正在尝试使用word自动更正一些非英文文本的问题是,当我使用SpellCheck函数时,弹出“拼写和语法”对话框,等待用户输入,我希望文本自动更正。所以我的问题是我该如何解决这个问题?

代码语言:javascript
复制
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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-16 21:22:40

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

代码语言:javascript
复制
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;
        }
    }
票数 2
EN

Stack Overflow用户

发布于 2012-02-16 10:25:26

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

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

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

大概是这样的

代码语言:javascript
复制
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

如果这不是你想要的,一定要告诉我。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9304013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档