DocX icon indicating copy to clipboard operation
DocX copied to clipboard

Is it possible to get text from currently opened word document ?

Open kcvinker opened this issue 5 years ago • 3 comments

Hi, I know that we can get text from currently opened word document with System.Runtime.InteropServices.Marshal.GetActiveObject function. Is it possible to get the same thing in DocX ? All i need to get the text from currently opened word document in MS Word.

kcvinker avatar Aug 19 '20 16:08 kcvinker

Hi, Yes. With DocX, you have access to all the paragraphs of the document. You can parse them to get their text data. But just to make sure, if the document is currently opened with MS Word while you use DocX to open the same document, it won't work, saying the document is already in use by another process.

XceedBoucherS avatar Aug 26 '20 19:08 XceedBoucherS

Thanks for the answer. So you mean, if i opened a document with "Load" method in DocX, i can get the text. I am aware about that. But what i need is to get the text from a document which is already opened without using DocX.

kcvinker avatar Aug 26 '20 21:08 kcvinker

Hi, As explained earlier, if the document is opened with MS Word, and you want to use DocX to open and parse the same document, it won't work, saying the document is already in use by another process.

XceedBoucherS avatar Aug 27 '20 15:08 XceedBoucherS