Hey, except for the cryptic error this code is really neat. I didn't realize you could export embedded charts to .gifs like that. I suppose I will hang onto this.
At any rate, your code bombs out because you are trying to use the Windows handle when you really do not need to. Here is a slightly modified version of your code:
...
$file = "C:\\testw.txt";
open (TTT, ">$file") || die "error";
$filename = "C:\\temp\\frufru.xls";
$filter = 'gif'; # can be GIF, JPG, JPEG or PNG
$pngnm = "C:\\test";
eval{
my $Excel = Win32::OLE->new('Excel.Application', 'Quit'); # use the Ex
+cel application if it's open, otherwise open new
#why in the hell would you want to do this?
#$hwnd = $Excel->{"Hwnd"};
#Hell no
print TTT $hwnd;
die "Cannot find $filename" unless (-e $filename);
my $Book = $Excel->Workbooks->Open( $filename ); # open the file
foreach my $Sheet (in $Book->Sheets)
{
...
I created a single workbook with three spreadsheets and two charts (on the first and second sheet). I debugged all the way until it created the first chart and got bored. Looks like it will work. What's different? Well, notice I commented out the following line:
#$hwnd = $Excel->{"Hwnd"};
Grabbing the Windows handle to Excel is unnecessary since you already have a working one. I suspect you are using some deprecated example code.
I also noticed some people made a few style points about this code. I will add a few also:
You have lots of hard coded paths in this. You might try using the GetOpt::Long module to make is reusable.
You didn't check to see if the .xls file actually existed before trying to open and work with it.
Are you certain you want one big eval() around this whole thing or wouldn't you rather have a few evals around different areas that are likely to fail so that you can recover? For instance, you may want to look for a given file in an alternative location?
And yes, you REALLY must use strict. Really.
Celebrate Intellectual Diversity
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.