using Microsoft.Office.Interop.Word;
Object wordObject = null; Microsoft.Office.Interop.Word.Application word = null; Document document = null; try { wordObject = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application"); word = (Microsoft.Office.Interop.Word.Application)wordObject; word.Visible = false; word.ScreenUpdating = false; string fullPath = word.ActiveDocument.FullName; document = word.Documents.Open(fullPath); int count = document.Words.Count; for(int k = 1; k <= count; k++) { string text = document.Words[k].Text; MessageBox.Show(text); } if (document.Paragraphs.Count > 0) { var paragraph = document.Paragraphs.First; var lastCharPos = paragraph.Range.Sentences.First.End - 1; MessageBox.Show(lastCharPos.ToString()); } word.Quit(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); }
How to get the cursor position in microsoft.interop.word?
document = word.Documents.Open(fullPath);
document = word.ActiveDocument;
word.Quit();
word_application.Selection.Range
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)