How can I get contents of word doc without using the clipboard?

D

Dave

I have a C# application that has need to open a word document by automating
word, using COM, and extract the contents of the word document and insert it
into a rich text box in a form. I can easily do this by having Word copy
the contents of the doc to the clipboard, and then pasting the contents into
the rich text box. The problem is that this trashes the previous contents
of the clipboard in the process. I went down the road of trying to save and
restore the clipboard, but had problems with the interaction with the
"Office Clipboard". There may be a way to get that to work (saving and
restoring the clipboard), but it seems like there must be an easier way -
just extracting the contents of the word doc directly. How do you do that?
I see the "Text" property can be used to extract the contents as plain ASCII
text, but what if I want to extract the rich text formatted text?

- Dave
 
S

Sergio

Don't know if you can get formatted text directly in RTF format.
But if you want to preserve the clipboard you may try to save it to a
temporary file in RTF format, read the file content and than delete it.
 
D

Dave

Marco:

No, that's what I said I tried. That only gives you plain ASCII. I need RTF.
There must be a way to do this!


- Dave
 
J

Jonathan West

Dave said:
Marco:

No, that's what I said I tried. That only gives you plain ASCII. I need
RTF.
There must be a way to do this!

Then I think all you can do is convert the document to RTF and work with
that, perhaps not using Word directly. As far as I am aware, there is no
means other than the clipboard for transferring formatted text out of a Word
document to a rich text control.
 
S

Sergio

Of course it will be a little slower, so you've got to consider overall
performance too, but in my opinion much less inelegant than using the
clipboard.

The point is that the object model lets you use the Word more or less as if
your application were another user.

So, if you are Word user, what would you do to convert a document to RTF?
I've found no direct way for conversions. I would either use the clipboard
or save to a file.

In an application I would avoid the clipboard because there are too many
variables to keep under control if you want your application to be trasparent
for the user, but last choice is your...

let us know if you manage with the clipboard or you find a third way

Sergio



:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top