private string CheckText(string text) { _WordDoc.SelectAllEditableRanges(ref _Missing); _WordApp.Selection.Text = text; Word.Dialog spellDialog = _WordApp.Dialogs[Word.WdWordDialog.wdDialogToolsSpellingAndGrammar]; // Keep the dialog in front of the current process (ArcMap) var hwndSpellDialog = FindWindow("OpusApp", null); SetParent(hwndSpellDialog, System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); int dialogReturn = spellDialog.Show(ref _Missing); _CancelSpellChecking = (dialogReturn == 0 || dialogReturn == -2); _WordDoc.SelectAllEditableRanges(ref _Missing); return(_WordApp.Selection.Text); }
static void Main(string[] args) { string finalHTML; List<string> listString = new List<string>(); object True = true; Word.Application app = new Word.Application(); Word.Document doc = new Word.Document(); string fileName = @"D:\Programming\C#\Word To Markup Converter\hello world.docx"; doc = app.Documents.Open(fileName, Type.Missing, True); //foreach (Word.Paragraph para in doc.Paragraphs) //{ // para.Range.Copy(); // stripClasses(Clipboard.GetText(TextDataFormat.Html)); //} Word.ListParagraphs listpara = doc.ListParagraphs; IEnumerator ienum = doc.ListParagraphs.GetEnumerator(); List<Tuple<string, Word.WdListType, int>> items = new List<Tuple<string, Word.WdListType, int>>(); while (ienum.MoveNext()) { Word.Range r = ((Word.Paragraph)ienum.Current).Range; items.Add(new Tuple<string, Word.WdListType, int>(r.Text, r.ListFormat.ListType, r.ListFormat.ListLevelNumber)); } items.Reverse(); if (items.Count > 0) { listString = createList(items); } doc.SelectAllEditableRanges(); doc.Range().Copy(); string returnHTMLText = null; if (Clipboard.ContainsText(TextDataFormat.Html)) { Console.WriteLine("html"); returnHTMLText = Clipboard.GetText(TextDataFormat.Html); //Console.WriteLine(returnHTMLText); stripClasses(returnHTMLText, listString); } else { Console.WriteLine("no html"); //Console.WriteLine(doc.); //returnHTMLText = Clipboard.GetText(TextDataFormat.Html); } doc.Close(); app.Quit(); Console.WriteLine("closed"); while (true) ; }
static void Main(string[] args) { string finalHTML; List <string> listString = new List <string>(); object True = true; Word.Application app = new Word.Application(); Word.Document doc = new Word.Document(); string fileName = @"D:\Programming\C#\Word To Markup Converter\hello world.docx"; doc = app.Documents.Open(fileName, Type.Missing, True); //foreach (Word.Paragraph para in doc.Paragraphs) //{ // para.Range.Copy(); // stripClasses(Clipboard.GetText(TextDataFormat.Html)); //} Word.ListParagraphs listpara = doc.ListParagraphs; IEnumerator ienum = doc.ListParagraphs.GetEnumerator(); List <Tuple <string, Word.WdListType, int> > items = new List <Tuple <string, Word.WdListType, int> >(); while (ienum.MoveNext()) { Word.Range r = ((Word.Paragraph)ienum.Current).Range; items.Add(new Tuple <string, Word.WdListType, int>(r.Text, r.ListFormat.ListType, r.ListFormat.ListLevelNumber)); } items.Reverse(); if (items.Count > 0) { listString = createList(items); } doc.SelectAllEditableRanges(); doc.Range().Copy(); string returnHTMLText = null; if (Clipboard.ContainsText(TextDataFormat.Html)) { Console.WriteLine("html"); returnHTMLText = Clipboard.GetText(TextDataFormat.Html); //Console.WriteLine(returnHTMLText); stripClasses(returnHTMLText, listString); } else { Console.WriteLine("no html"); //Console.WriteLine(doc.); //returnHTMLText = Clipboard.GetText(TextDataFormat.Html); } doc.Close(); app.Quit(); Console.WriteLine("closed"); while (true) { ; } }