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');
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|