http://qs321.pair.com?node_id=385346


in reply to Win::OLE Add image

Yes. I would say so.

Look for the answer in Using Win32::OLE and Excel - Tips and Tricks. You are looking for:

#$Excel->ActiveSheet­->Pictures->Insert(<­PATH TO THE PIC>);

I don't know why it is commented out

I would read that whole node as it seems to be a juicy source of information about perl, Win32::OLE and Excel.

Also, when wanting to work out how to automate Office apps with perl, it is often helpful to use the macro recorder functions in the Office application then open the macro with Visual Basic Editor (Menus ->Tools -> Macro -> Visual Basic Editor) This will give you a rough idea of what objects and methods are used to perform the desired function. You can then easily translate the macro to Perl.

In this instance the macro recorder created the following in VBA:

ActiveSheet.Pictures.Insert( _ "C:\Documents and Settings\tech\My Documents\My Pictures\Sampl +e.jpg").Select
Here is my tested code:
#!c:/perl/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; my $excelfile = 'c:/ben.xls'; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $Book = $Excel->Workbooks->Add(); $Book->SaveAs($excelfile); #Good habit when working with OLE, save +often. my $Sheet = $Book->Worksheets("Sheet1"); $Sheet->Activate(); $Sheet->{Name} = "DidItInPerl"; $Sheet->Pictures->Insert('C:\Documents and Settings\tech\My Documents\ +My Pictures\Sample.jpg');