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
You could get the "Embed Source" format, which uses an IStorage medium
that you can easily copy to another storage.
Cheers,
- Jim
Christian
Jim Barry <jim....@bigfoot.com> wrote in message
news:newscache$q6alsf$e8c$1...@firewall.thermoteknix.co.uk...
I'm pretty sure Word uses RTF in the clipboard, yes.
Regards
Dave
>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!
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
> 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
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
Alexander Nickolov <agnic...@geocities.com> wrote in message
news:#dUx7w#o$GA.1916@cppssbbsa06...
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
> 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
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...