自动更正文本C#字 [英] AutoCorrect Text C# Word

查看:158
本文介绍了自动更正文本C#字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一句话来自动纠正一些文字,不是英文的问题是,当我使用的拼写检查功能的拼写和语法对话框弹出并等待用户输入和我想要的文本被自动校正。所以我的问题是我如何解决这个问题?

I'm trying to use word to automatically correct some text that is not in English the problem is that when i use the SpellCheck function the "Spell and Grammar" dialog box pop-up and waits for users input and i want the text to be corrected automatically. So my question is how do i solve this ?

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
    }
}

我前几天写了这个codeA和它的工作。问题是卸载校对工具来运行一些测试,现在我不断收到该对话,所以我在想,也许我必须设置一些Word设置或我已经不知道在我的code改变的东西。任何帮助将大大AP preciated。

I wrote this code a few days ago and it worked. The problem is that i uninstall proofing tools to run some tests and now i keep getting that dialog so i'm thinking that may i have to set some Word settings or i've changed something in my code without knowing. Any help would be greatly appreciated.

我使用的Microsoft Office Word 2010中

I am using Microsoft Office Word 2010

推荐答案

有关谁可能会感兴趣,这是我设法解决问题的方法,但它确实需要花费大量的时间,因此任何改进或新的想法都欢迎。

For whoever might be interested this is the way i managed to solve it, but it really takes a lot of time so any improvements or new ideas are welcomed.

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;
        }
    }

这篇关于自动更正文本C#字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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