How to get selected text from Word Document in C# based Word Add-In?

旧城冷巷雨未停 提交于 2019-12-13 18:39:41

问题


I am developing a MS Word Add-In. For which, I would like to know how to get the text that is currently selected in the word document and then perform my application specific action on it.

Thank you, for your help.


回答1:


In your Word add-in project in Visual studio use the following code on your trigger event to get the selected text:

        string selectText = string.Empty;
        Word.Selection wordSelection = this.Application.Selection;
        if (wordSelection != null && wordSelection.Range != null)
        {
            selectText = wordSelection.Text;
        }

note: the above code hasn't been tested.



来源:https://stackoverflow.com/questions/11023296/how-to-get-selected-text-from-word-document-in-c-sharp-based-word-add-in

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