Example #1
0
        public void FindNextSpellingError()
        {
            this.m_CurrentPropertyIndex += 1;
            if (this.m_CurrentPropertyIndex == this.m_SpellCheckList.Count)
            {
                return;
            }
            else
            {
                object value = this.m_SpellCheckList[this.m_CurrentPropertyIndex].Property.GetValue(this.m_DataObject, null);

                Microsoft.Office.Interop.Word._Document document = this.m_WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oFalse);
                document.Words.First.InsertBefore(value.ToString());
                Microsoft.Office.Interop.Word.ProofreadingErrors spellingErrors = document.SpellingErrors;

                if (spellingErrors.Count > 0)
                {
                    document.CheckSpelling(ref oMissing, ref oMissing, ref oMissing,
                                           ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                           ref oMissing, ref oMissing, ref oMissing,
                                           ref oMissing, ref oMissing);

                    object oFirst = 0;
                    object oLast  = document.Characters.Count - 1;

                    string text = document.Range(ref oFirst, ref oLast).Text;
                    this.m_SpellCheckList[this.m_CurrentPropertyIndex].Property.SetValue(this.m_DataObject, text, null);
                }
            }
            this.FindNextSpellingError();
        }
Example #2
0
        public void DoIt()
        {
            string word = null;

            using (System.IO.StreamWriter writeGoodWords = new System.IO.StreamWriter(@"C:\Program Files\Yellowstone Pathology Institute\goodwords.txt"))
            {
                using (System.IO.StreamWriter writeBadWords = new System.IO.StreamWriter(@"C:\Program Files\Yellowstone Pathology Institute\badwords.txt"))
                {
                    System.IO.StreamReader readFile = new System.IO.StreamReader(@"C:\Program Files\Yellowstone Pathology Institute\ypi-custom.dic");
                    while ((word = readFile.ReadLine()) != null)
                    {
                        this.m_Document.Words.First.Delete();
                        this.m_Document.Words.First.InsertBefore(word);

                        Microsoft.Office.Interop.Word.ProofreadingErrors spellingErrors = this.m_Document.SpellingErrors;

                        if (spellingErrors.Count > 0)
                        {
                            writeBadWords.WriteLine(word);
                        }
                        else
                        {
                            writeGoodWords.WriteLine(word);
                        }
                    }
                }
            }
        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Process[] proc = Process.GetProcessesByName("WINWORD");
            foreach (Process proc1 in proc)
            {
                proc1.Kill();
            }
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();

            int errors = 0;

            if (syntaxRichTextBox1.Text.Length > 0)
            {
                app.Visible = true;

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

                Microsoft.Office.Interop.Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                doc1.Words.First.InsertBefore(syntaxRichTextBox1.Text);
                Microsoft.Office.Interop.Word.ProofreadingErrors spellErrorsColl = doc1.SpellingErrors;
                errors = spellErrorsColl.Count;

                object optional = Missing.Value;

                doc1.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);

                toolStripLabelStatus.Text = errors + " errors corrected ";
                object first = 0;
                object last  = doc1.Characters.Count - 1;
                syntaxRichTextBox1.Text = doc1.Range(ref first, ref last).Text.Replace("\r", "\r\n");
                //doc1.Close(ref optional, ref optional, ref optional);
                //doc1 = null;
            }

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

            app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
            //app.Quit();
            app = null;

            //app.Quit(ref originalFormat, ref originalFormat, ref originalFormat);
            Process[] proc3 = Process.GetProcessesByName("WINWORD");
            foreach (Process proc4 in proc3)
            {
                proc4.Kill();
            }
        }
    static void Main()
    {
        Console.WriteLine("Enter a string to spell-check:");
        string stringToSpellCheck = Console.ReadLine();
        string spellingResults;
        int    errors = 0;

        if (stringToSpellCheck.Length == 0)
        {
            spellingResults = "No string to check";
        }
        else
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            Console.WriteLine("\nChecking the string for misspellings ...");
            app.Visible = false;

            Microsoft.Office.Interop.Word._Document tempDoc = app.Documents.Add();

            tempDoc.Words.First.InsertBefore(stringToSpellCheck);
            Microsoft.Office.Interop.Word.ProofreadingErrors spellErrorsColl = tempDoc.SpellingErrors;
            errors = spellErrorsColl.Count;

            // 1. Without using optional parameters
            // object ignoreCase    = true;
            // object alwaysSuggest = false;
            // object optional      = Missing.Value;
            // tempDoc.CheckSpelling( ref optional, ref ignoreCase, ref alwaysSuggest,
            //     ref optional, ref optional, ref optional, ref optional, ref optional,
            //     ref optional, ref optional, ref optional, ref optional );

            //2. Using the "omit ref" feature
            object optional = Missing.Value;
            tempDoc.CheckSpelling(optional, true, false, optional, optional, optional, optional, optional, optional, optional, optional, optional);

            //3. Using "omit ref" and optional parameters tempDoc.CheckSpelling( Missing.Value, true, false );
            app.Quit(false);
            spellingResults = errors + " errors found";
        }

        Console.WriteLine(spellingResults);
        Console.WriteLine("\nPress <Enter> to exit program.");
        Console.ReadLine();
    }
        private static string RevisarOrtografia(string texto)
        {
            var    app            = new Microsoft.Office.Interop.Word.Application();
            int    SpellingErrors = 0;
            string corregido      = string.Empty;

            if (!String.IsNullOrEmpty(texto))
            {
                app.Visible = false;
                object template     = Missing.Value;
                object newTemplate  = Missing.Value;
                object documentType = Missing.Value;
                object visible      = false;
                Microsoft.Office.Interop.Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate,
                                                                                 ref documentType, ref visible);
                doc1.Words.First.InsertBefore(texto);

                Microsoft.Office.Interop.Word.ProofreadingErrors docErrors = doc1.SpellingErrors;
                SpellingErrors = docErrors.Count;

                object optional = Missing.Value;
                doc1.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);
                object first = 0;
                object last  = doc1.Characters.Count - 1;
                corregido = doc1.Range(ref first, ref last).Text;
            }

            if (SpellingErrors == 0)
            {
                MessageBox.Show("No se encontraron errores en el texto");
            }

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

            app.Application.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
            return(corregido);
        }
Example #6
0
        public void DoIt()
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            app.Visible = false;

            int errors = 0;

            if (this.TextBoxSpell.Text.Length > 0)
            {
                object template     = Type.Missing;
                object newTemplate  = Type.Missing;
                object documentType = Type.Missing;
                object visible      = true;

                Microsoft.Office.Interop.Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                doc1.Words.First.InsertBefore(this.TextBoxSpell.Text);
                Microsoft.Office.Interop.Word.ProofreadingErrors spellErrorsColl = doc1.SpellingErrors;
                errors = spellErrorsColl.Count;

                object optional = Type.Missing;

                app.ActiveWindow.Activate();

                doc1.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);

                object first = 0;
                object last  = doc1.Characters.Count - 1;
                this.TextBoxSpell.Text = doc1.Range(ref first, ref last).Text;
            }

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

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