Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Win::OLE Add image

by Anonymous Monk
on Aug 24, 2004 at 03:34 UTC ( [id://385305]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to add an image (buisness logo) to a excel workbook using Win::OLE?

Replies are listed 'Best First'.
Re: Win::OLE Add image
by blm (Hermit) on Aug 24, 2004 at 07:25 UTC

    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');
Re: Win::OLE Add image
by Anonymous Monk on Sep 06, 2004 at 00:19 UTC
    Thankyou for your help. I encounter a problem when i close the Excel application, then re-run the perl program. It will open Excel, but display no information, just the contents of the background in other applications (eg crash). Do I need to flush buffers, or reset the application? Has any one had these problems? This occurs even running the above supplied code. ps: Using Microsoft Excel 2000 Thanks for your time Digger

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-28 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found