in reply to Re^4: How to get picture in MS excel and insert them into MS word file by the module win32::OLE?
in thread How to get picture in MS excel and insert them into MS word file by the module win32::OLE?

gongcw:

OK, I now understand what you want. It's not really a perl question at all--it's more of an Excel question. As I understand it, you want to be able to ask excel for the list of pictures in a sheet so you can move them to your word document.

I poked around and found a reference to Excel's object model and briefly looked around in it to find the appropriate collection to use. Unfortunately, I didn't find one explicitly for pictures. However, the OLEObjects collection page shows an example of adding a bitmap to a sheet. So you should be able to access the images through the OLEObjects collection.

The problem is that the OLEObjects collection might contain many odd things in it, and unless you know what the object is, you'll find it difficult to work with. In the OLEObjects collection example, though, it shows adding a gif image like this:

Worksheets(1).OLEObjects.Add FileName:="arcade.gif"

So if you iterate over the OLEObjects and check the FileName property of each object, you might find one with a .BMP extension. Be aware that many objects might not have a FileName property, so when you're checking, don't kill your application just because the FileName property doesn't exist.

If you can determine the OLEObject type of the objects you're interested in, then you'll be able to find more information via google on how to communicate with them. Dig through the Excel Object reference (link above) and you may find some good clues. Failing that, I'd post a question on an Excel guru board.

...roboticus

  • Comment on Re^5: How to get picture in MS excel and insert them into MS word file by the module win32::OLE?
  • Download Code

Replies are listed 'Best First'.
Re^6: How to get picture in MS excel and insert them into MS word file by the module win32::OLE?
by gongcw (Initiate) on Jan 08, 2010 at 05:13 UTC
    Hi roboticus,

    Thanks very very much for your kindly help. After exploring some documents about OLEObjects, Pictures, Shapes and their members, this problem has been resolved now.

    Thanks again.:)

      gongcw:

      I'm glad that you've overcome this problem. Sorry I couldn't be more explicit in my help, as I'm very unfamiliar with both Win32::OLE and the Excel object model. It would be helpful to future visitors to the site if you updated the starting message of this thread with the solution, so others won't have to work so hard to find the answer. It doesn't need to be very long, something as simple as "Look through the XYZ list for items with the ABC property set to FOO". Be sure to mark the node as "Updated" so people can tell what you did to change the node.

      ...roboticus

      Update: I added this update to give you an example of how I would do it:

      <p><b>Update:</b> Your update message goes here.</p>

        Hi roboticus,

        Thanks again for your kindly help. Actually, you have given me many improtant information like recording marco in excel, where to find the associated documents, ...
        This message has been updated now. And I post the detailed code above the original question. I think the code is much more clear than description with long long words. :)