Retrieving the text from an open document, how to?
Hello!
I want to retrieve the text (and only the text) from the document that the
user is writing right now.
That means the text from Word, Excel and more apps (not just Office, maybe
OpenOffice as well...).
Anyone knows how to do this using c#?
thanks
:wave:
Re: Retrieving the text from an open document, how to?
For your Office apps you could do something for each app but there would be allot of issues. Why does it need to be real-time? If it wasnt you could probably search documents etc. for any text your looking for.
Re: Retrieving the text from an open document, how to?
I think that your best bet would be to use API functions, although I'm not sure it would be escpecially easy. I use a dictionary called WordWeb that allows you to select a word in any app and the press Ctrl+Alt+W to have WordWeb open with that word and its definition displayed. The way to do this in .NET would be to create a keyboard hook (a forum search will turn up info) to trap the desired key combination even when your app is not active, then use API functions to get the selected text from the active window in the active application. Note that active window means any window, not just a form. You would certainly use the GetForegroundWindow function, but beyond that I couldn't say for sure.
Re: Retrieving the text from an open document, how to?
GetForegroundWindow, and then it depends on the control. If it is a text box it will probably respond to a SendMessage with WM_GETTEXT. For Excel I have no idea.