Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
laziness, impatience, and hubris

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.

Comment on Re: How to add an image to Excel/CSV
Download Code

Log In?

What's my password?
Create A New User
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 avoiding work at the Monastery: (6)
As of 2014-04-19 15:17 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (482 votes), past polls