问题
How can I do something with text in my word document using button in word add-in? I don't know, how to get text from document after click on the button, because Application is not accessible in Ribbon class.
回答1:
The following code should take the text found in the selection:
string textFromDoc;
textFromDoc = Globals.ThisAddIn.Application.Selection.Text;
You can also specify the Range
by:
textFromDoc = Globals.ThisAddIn.Application.ActiveDocument.Range(0, 20).Text;
This will take the first 20 letters written in the active document. Bottom line, you can access Application by using:
Globals.ThisAddIn.Application
来源:https://stackoverflow.com/questions/19645428/add-in-in-vsto-how-to-get-text-from-word-document-using-ribbon-with-button