Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: How to add an image to Excel/CSV by bmann
in thread How to add an image to Excel/CSV by johnnywang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-18 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found