Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Win::OLE Add image

by blm (Hermit)
on Aug 24, 2004 at 07:25 UTC ( #385346=note: print w/replies, xml ) Need Help??


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');

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2023-03-24 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (60 votes). Check out past polls.

    Notices?