Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get Word native format from clipboard ?

158 views
Skip to first unread message

Christian Staffe

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
Hi,

I'm currently extracting the RTF version of a Word document from the
clipboard using the CF_RTF clipboard format and store it in a database (I'm
working in C++). How can I retrieve the Word document in native Word format
instead of RTF and serialize it ?

Thanks.

Christian


Jim Barry

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
Christian Staffe wrote:

You could get the "Embed Source" format, which uses an IStorage medium
that you can easily copy to another storage.

Cheers,

- Jim


Christian Staffe

unread,
Apr 10, 2000, 3:00:00 AM4/10/00
to
Thanks Jim, I tried this but unfortunately it doesn't work. The "Embed
Source" is just the embedded version of the document and when pasted, I get
the word document as an embedded object (what I don't really want). Could it
be that Word is just using RTF when copy/pasting formatted content and does
not offer its native format throught the clipboard ?

Christian

Jim Barry <jim....@bigfoot.com> wrote in message
news:newscache$q6alsf$e8c$1...@firewall.thermoteknix.co.uk...

Dave Rado

unread,
Apr 10, 2000, 3:00:00 AM4/10/00
to
Christian Staffe <IUnk...@Interface.com> wrote

| Could it
| be that Word is just using RTF when copy/pasting formatted content and
does
| not offer its native format throught the clipboard ?

I'm pretty sure Word uses RTF in the clipboard, yes.

Regards

Dave

John Nurick

unread,
Apr 11, 2000, 3:00:00 AM4/11/00
to
On Mon, 10 Apr 2000 17:21:52 +0200, "Christian Staffe"
<IUnk...@Interface.com> wrote:

>Thanks Jim, I tried this but unfortunately it doesn't work. The "Embed
>Source" is just the embedded version of the document and when pasted, I get

>the word document as an embedded object (what I don't really want). Could it


>be that Word is just using RTF when copy/pasting formatted content and does
>not offer its native format throught the clipboard ?

That's how it seemed to me when I investigated this a year or two ago
(though not in great depth): Word puts RTF on the clipboard for other
applications, but doesn't use the Windows clipboard for internal
copy-paste operations. For that matter, I suspect it may be a red
herring in modern versions of Office to think in terms of a "native
format" representation of a document somewhere in RAM. If a document
consists of a main text stream, other text streams (headers, text
boxes, etc), various formatting and numbering and fields and the
tables and pointers that implement them, embedded objects, drawing
objects, and goodness knows what else - it strikes me that it's pretty
hard for Word to decide what should go on the clipboard as "native
format" representation of a selection, and even harder for another app
to decide how to interpret it!

--
John

Please reply to the newsgroup and not by e-mail. That way, more
brain cells get to work on the problem!

Christian Staffe

unread,
Apr 11, 2000, 3:00:00 AM4/11/00
to
John Nurick <j.nu...@dial.pipex.com> wrote in message
news:k094fs0chitk442oj...@4ax.com...

Agree ! My initial point was that I saved Word documents as blobs in
databases using RTF. But it's particularly inefficient in size compared to
the "native" format (the doc file) if Word contains pictures (jpg for
example) even with compression ! So I want to switch to this "native" format
instead of RTF and investigated the clipboard way of doing it. The
conclusion so far is that this won't work.

The question here is finally just : "how do I get a Word document as a byte
stream in memory so I can save it in a database (and reload it later)". For
a lot of reasons (privacy of medical data), I don't want to use the file
system to save/load the file. A memory map file doesn't work because I'm
working as an automation client and the Load/Save methods need a filename as
argument, not a handle. Another way to do it is to use the persistence
interfaces of Word.Document but it seems that OleLoad and OleSave (or direct
access to IPersistStorage) do not work at alle outside of a coumpound
document framework. So far, I have really no idea how to save a Word
document in a database without using the file system !

Christian

Jim Barry

unread,
Apr 11, 2000, 3:00:00 AM4/11/00
to
Christian Staffe wrote:

> Thanks Jim, I tried this but unfortunately it doesn't work.
> The "Embed Source" is just the embedded version of the
> document and when pasted, I get the word document as an
> embedded object (what I don't really want).

But if you have the embed source data saved to a file, you can have
Word either open that file or do an "Insert File" operation. In the
latter case you can use a temporary file when extracting the data from
your database. Then delete the temporary file immediately after
inserting it into Word.

When storing the embed source data in the database, you wouldn't need
to save the data to a file at all. You could save it to an in-memory
storage (using CreateILockBytesOnHGlobal and
StgCreateDocfileOnILockBytes), then write the contents of the HGLOBAL
to the database. Or maybe your database supports IStorage directly.

> Could it be that Word is just using RTF when copy/pasting
> formatted content and does not offer its native format
> throught the clipboard ?

Yes. I don't think there is anything that Word can't store in RTF. As
far as I can tell, RTF pretty much _is_ Word's native fomat; a
text-based representation of it, anyway. Strangely, Word's "Paste
Special" dialog seems to prefer HTML to RTF though.

Cheers,

- Jim


Alexander Nickolov

unread,
Apr 11, 2000, 3:00:00 AM4/11/00
to
I haven't ever tried this, but you may give it a try:

CoGetInstanceFromFile
IPersistStorage::Save
IPersistStorage::SaveCompleted

It is likely not to work, I admit, but...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@geocities.com
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Christian Staffe <IUnk...@Interface.com> wrote in message
news:8cumtm$fhh$1...@news.mch.sbs.de...


> John Nurick <j.nu...@dial.pipex.com> wrote in message
> news:k094fs0chitk442oj...@4ax.com...
> > On Mon, 10 Apr 2000 17:21:52 +0200, "Christian Staffe"

> > <IUnk...@Interface.com> wrote:
> >
> > >Thanks Jim, I tried this but unfortunately it doesn't work. The "Embed
> > >Source" is just the embedded version of the document and when pasted, I
> get
> > >the word document as an embedded object (what I don't really want).

Could
> it
> > >be that Word is just using RTF when copy/pasting formatted content and
> does
> > >not offer its native format throught the clipboard ?
> >

Christian Staffe

unread,
Apr 12, 2000, 3:00:00 AM4/12/00
to
In fact, I already have an interface pointer to a Word Document that I have
instanciated through automation. When calling IPersistStorage::Save it
doesn't work ! In fact to make it work it's necessary to save the document
on the file system at least one time (what I just try to avoid !) before
calling the Save method successfully (but I don't know why !). When calling
IPersistStoreage::Load, it's even worse, HRESULT returned is ok but nothing
happens (the document is not loaded). It looks like the Word.Document object
(and its IPersist interfaces) has only been designed to work as an embedded
document and not to be used from an automation controller :-(

Christian

Alexander Nickolov <agnic...@geocities.com> wrote in message
news:#dUx7w#o$GA.1916@cppssbbsa06...

Christian Staffe

unread,
Apr 12, 2000, 3:00:00 AM4/12/00
to
Jim Barry <jim....@bigfoot.com> wrote in message
news:newscache$2xousf$4si$1...@firewall.thermoteknix.co.uk...

> Christian Staffe wrote:
>
> > Thanks Jim, I tried this but unfortunately it doesn't work.
> > The "Embed Source" is just the embedded version of the
> > document and when pasted, I get the word document as an
> > embedded object (what I don't really want).
>
> But if you have the embed source data saved to a file, you can have
> Word either open that file or do an "Insert File" operation. In the
> latter case you can use a temporary file when extracting the data from
> your database. Then delete the temporary file immediately after
> inserting it into Word.
>
> When storing the embed source data in the database, you wouldn't need
> to save the data to a file at all. You could save it to an in-memory
> storage (using CreateILockBytesOnHGlobal and
> StgCreateDocfileOnILockBytes), then write the contents of the HGLOBAL
> to the database. Or maybe your database supports IStorage directly.

Yes, I have been able to get the embed source and save it in the database
using ILockBytes mechanisms. But is the storage returned by the embed source
format in the clipboard exactly the same as the one you would get by reading
the doc file from the file system (or otherwise stated, if I now save my
embed source storage on disk as a doc file, would Word be abled to load this
file normally ?

Also, even if the saving works, I still want to avoid using the file system
to reload the storage in Word. I'm working with medical applications and we
have strong security requirements about this (what about a crash and the
file remaining in the file system).

> > Could it be that Word is just using RTF when copy/pasting
> > formatted content and does not offer its native format
> > throught the clipboard ?
>

> Yes. I don't think there is anything that Word can't store in RTF. As
> far as I can tell, RTF pretty much _is_ Word's native fomat; a
> text-based representation of it, anyway. Strangely, Word's "Paste
> Special" dialog seems to prefer HTML to RTF though.

With Word97, a paste special is presenting RTF as the "default" pasting
option. This has indeed changed in Word2000, where HTML is now the default !

Christian

Jim Barry

unread,
Apr 12, 2000, 3:00:00 AM4/12/00
to
Christian Staffe wrote:

> if I now save my embed source storage on disk as a doc file,
> would Word be abled to load this file normally ?

Well, it worked when I tried it. :-)

> Also, even if the saving works, I still want to avoid using
> the file system to reload the storage in Word.

It's a tough one. What you need is a way to load a document directly
from an IStorage. If there is a way, I'm afraid I don't know what it
is. :-(

Cheers,

- Jim


Alexander Nickolov

unread,
Apr 12, 2000, 3:00:00 AM4/12/00
to
Exactly what I expected. This is by design. You can only save through
the same type of persistence interface you've been loaded with. I just
hoped Word's persistence is flawed :), but it is not...

Well, sorry I couldn't help you...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@geocities.com
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Christian Staffe <IUnk...@Interface.com> wrote in message
news:8d1ai3$cnb$1...@news.mch.sbs.de...

0 new messages