Images into Word via clipboard or via saved file?

P

Petr Prikryl

Hi

Summary: What is the recommended way for inserting
generated images into the generated Word document
from (C++) application? Should I use clipboard or
should I save the (WMF) picture into file and load
it to Word doc from the file?

We neet to suppord export to Word 97 and later.

Details
=======

Cindy Meister answered my previous question on inserting
image directly from OLE Picture object into Word doc (thanks
for the answer)... (microsoft.public.word.oleinterop,
Q: Inserting OLE Picture into generated Word doc?)
As far as I know, this simply isn't possible when automating
a Word document, except over the Clipboard (.Paste method).
Word has to use a converter to "translate" a graphic into a
Word doc's binary file format. And the converters only run
through File/Open or during the Paste operation.

Using clipboard for transfering the images into the automatically
generated Word document conflicts with the following text
from the MSDE Library documentation:

"The clipboard is user-driven. A window should transfer
data to or from the clipboard only in response to a command
from the user. A window must not use the clipboard
to transfer data without the user's knowledge."

Because of that I decided earlier to save the image to a file
and load it into the generated Word document from disk.
However, we have observed some problems with different
versions of Word (see below).

Is there any serious recommendation or document that
describes how the thing should be done?

The text below is a fragment fromt my previous post.
It summarizes our current solution and the problems...

----------------------------------------------------
I was successfull to generate the Word document with
pictures that were created by export into the xxx.wmf
files and insert them into the document using something
like (simplified, C++):

spInlineShapes->AddPicture(imgFileName, False, True, Range);

If interested in details, you can download the sources from
http://www.skil.cz/ExportWord/ExportWord1.zip. (It uses
ChartFX Client Server charting component, so the included
..exe may not work for you. If you want to try the code and
do not have the charting component, just remove the chart
related code from sources and prepare some WMF
image to be inserted into the generated document.)

There are some technical problems with different versions
of Word -- the files with inserted images are locked
for some time and cannot be removed (which does not
spoil the generated Word document, but left some mess
behind). I also feel that it is cleaner not to store the images
to disk only to read them again into memory.

Thanks for your time and experience,
Petr
 
C

Cindy M -WordMVP-

Hi Petr,
What is the recommended way for inserting
generated images into the generated Word document
from (C++) application? Should I use clipboard or
should I save the (WMF) picture into file and load
it to Word doc from the file?
I'd go with saving to file and inserting.

1. It's always chancy, sharing the Clipboard with the user

2. Word won't necessarily take something off the Clipboard
exactly as it was put on. No guarantee when inserting from
a file, either, for that matter. In both cases, you're
going over a converter.

But the InlineShapes.Add or Shapes.Add method is the one
I'd definitely prefer unless something concrete speaks
against it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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