Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: How to add an image to Excel/CSV

by bmann (Priest)
on Oct 28, 2005 at 00:41 UTC ( #503520=note: print w/replies, xml ) Need Help??

in reply to How to add an image to Excel/CSV

You can insert an image into an Excel file, but not a csv. Excel will strip the image out and only save the data when it is saved to csv.

To see how it's done in an xls, fire up the macro recorder in Excel then insert your image. Now move the image. Stop the macro recorder and open up Excel's VBA IDE. Take the generated code and convert it to perl.

use strict; use warnings; use Win32::OLE; my $excel = Win32::OLE->CreateObject('Excel.Application'); $excel->{Visible} = 1; my $wb = $excel->Workbooks->Add; $wb->ActiveSheet->Pictures->Insert( "C:\\s\\x.png" )->Select; $excel->Selection->ShapeRange->IncrementLeft( 40 ); $excel->Selection->ShapeRange->IncrementTop( 40 ); __END__ Sub Macro1() ' Macro recorded with Macro Recorder ' Tools -> Macro -> Record new macro ActiveSheet.Pictures.Insert( _ "C:\s\x.png").Select Selection.ShapeRange.IncrementLeft 40 Selection.ShapeRange.IncrementTop 40 End Sub
Voila, done! BTW, you probably want to read the definitive thread on Excel and Win32::OLE, Using Win32::OLE and Excel - Tips and Tricks.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (None)
    As of 2021-10-17 16:29 GMT
    Find Nodes?
      Voting Booth?
      My first memorable Perl project was:

      Results (72 votes). Check out past polls.