add-in in VSTO - How to get text from Word document using Ribbon with button

馋奶兔 提交于 2020-01-01 10:49:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!