Ejemplo n.º 1
0
        public void fSpellCheck(RichTextBox tBox, Label lLbl)
        {
            int          iErrorCount = 0;
            _Application app         = new Microsoft.Office.Interop.Word.Application();

            if (tBox.Text.Length > 0)
            {
                app.Visible = false;
                // Setting these variables is comparable to passing null to the function.
                // This is necessary because the C# null cannot be passed by reference.
                object template     = Missing.Value;
                object newTemplate  = Missing.Value;
                object documentType = Missing.Value;
                object visible      = true;
                object optional     = Missing.Value;

                _Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                doc.Words.First.InsertBefore(tBox.Text);
                ProofreadingErrors we = doc.SpellingErrors;

                iErrorCount = we.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);
                //doc.CheckGrammar();
                if (iErrorCount == 0)
                {
                    lLbl.Text = "Spelling OK. No errors corrected ";
                }
                else if (iErrorCount == 1)
                {
                    lLbl.Text = "Spelling OK. 1 error corrected ";
                }
                else
                {
                    lLbl.Text = "Spelling OK. " + iErrorCount + " errors corrected ";
                }
                object first = 0;
                object last  = doc.Characters.Count - 1;

                tBox.Text = doc.Range(ref first, ref last).Text;
            }
            else
            {
                lLbl.Text = "Textbox is empty";
            }

            object saveChanges    = false;
            object originalFormat = Missing.Value;
            object routeDocument  = Missing.Value;

            app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
        }
Ejemplo n.º 2
0
        public string fSpellCheck(ref string text)
        {
            string result = string.Empty;

            int         iErrorCount = 0;
            Application app         = new Application();

            if (text.Length > 0)
            {
                app.Visible = false;

                object template     = Missing.Value;
                object newTemplate  = Missing.Value;
                object documentType = Missing.Value;
                object visible      = true;
                object optional     = Missing.Value;

                _Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                doc.Words.First.InsertBefore(text);
                ProofreadingErrors we = doc.SpellingErrors;
                iErrorCount = we.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);

                if (iErrorCount == 0)
                {
                    result = "Нет ошибок";
                }
                else
                {
                    result = string.Format("Исправлено {0} ошибок.", iErrorCount);
                }
                object first = 0;
                object last  = doc.Characters.Count - 1;

                text = doc.Range(ref first, ref last).Text;
            }
            object saveChanges    = false;
            object originalFormat = Missing.Value;
            object routeDocument  = Missing.Value;

            app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);

            return(result);
        }
Ejemplo n.º 3
0
    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);
    }