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

Re: How can I get contents of word doc without using the clipboard? by Marco

Marco
Wed Oct 27 02:24:40 CDT 2004

Try the Word.Application.ActiveDocument.Range.Text property?!

Marco

Dave wrote:
> 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



RE: How can I get contents of word doc without using the clipboard? by Sergio

Sergio
Wed Oct 27 06:19:02 CDT 2004

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.

"Dave" wrote:

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

Re: How can I get contents of word doc without using the clipboard? by Dave

Dave
Wed Oct 27 07:57:08 CDT 2004

Yes, I thought of that, but it would be slower, and kind of inelegant.

- Dave

"Sergio" <Sergio@discussions.microsoft.com> wrote in message
news:AF7280DF-3AAE-45E3-95FD-393C326D8B1E@microsoft.com...
> 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.
>
> "Dave" wrote:
>
> > 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
> >
> >
> >



Re: How can I get contents of word doc without using the clipboard? by Dave

Dave
Wed Oct 27 07:56:30 CDT 2004

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

"Marco Singer" <msinger@konplan.com> wrote in message
news:OruGIY$uEHA.1204@TK2MSFTNGP10.phx.gbl...
> Try the Word.Application.ActiveDocument.Range.Text property?!
>
> Marco
>
> Dave wrote:
> > 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
>
>



Re: How can I get contents of word doc without using the clipboard? by Jonathan

Jonathan
Wed Oct 27 09:11:05 CDT 2004


"Dave" <dpt@nospam.eliassen.com> wrote in message
news:O4kFjRCvEHA.3376@TK2MSFTNGP12.phx.gbl...
> 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.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


Re: How can I get contents of word doc without using the clipboard by Sergio

Sergio
Wed Oct 27 10:23:07 CDT 2004

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



"Dave" wrote:



"Dave" wrote:

> Yes, I thought of that, but it would be slower, and kind of inelegant.
>
> - Dave
>
> "Sergio" <Sergio@discussions.microsoft.com> wrote in message
> news:AF7280DF-3AAE-45E3-95FD-393C326D8B1E@microsoft.com...
> > 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.
> >
> > "Dave" wrote:
> >
> > > 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
> > >
> > >
> > >
>
>
>