问题
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