private static string RevisarOrtografia(string texto) { var app = new Microsoft.Office.Interop.Word.Application(); 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); 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; } object saveChanges = false; object originalFormat = Missing.Value; object routeDocument = Missing.Value; app.Application.Quit(ref saveChanges, ref originalFormat, ref routeDocument); return(corregido); }
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(); }
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(); } }
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); }