Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Excel 2003 + Perl

by Nalina (Monk)
on Aug 22, 2005 at 09:21 UTC ( #485642=perlquestion: print w/replies, xml ) Need Help??

Nalina has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
I am opening excel application through Win32::OLE & drawing a chart. Then trying to export the chart to PNG file. This works fine when executed directly. But if I Execute it through shell object from ASP throughs an error saying
Win32::OLE(0.1403) error 0x800a03ec in METHOD/PROPERTYGET "Export" at C:\\timken_project\\export.pl li +ne 35
Earlier I had the same problem & had posted it in perlmonks. This problem was solved after installing Office XP with SP1. But now I need to make the same thing working on Office 2003. I tried installing SP1 for Office 2003, but it didn't work. Why is it working on Office XP but not on Office 2003. Though it is not a perl problem any suggestions will be of great help.
The perl code to export the graph is
use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); use Win32::OLE; use Win32::OLE::Const; $Win32::OLE::Warn = 3; # die on errors... $file = "C:\\testw.txt"; open (TTT, ">$file") || die "error"; print TTT "test"; $filename = "C:\\book1.xls"; $filter = 'PNG'; # 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 my $Book = $Excel->Workbooks->Open( $filename ); # open the file foreach my $Sheet (in $Book->Sheets) { # loop through all sheets foreach my $ChartObj (in $Sheet->ChartObjects) { # loop through all chartobjects in the sheet #$datewk = join("".split(/\s+/, $Date)); $savename = "$pngnm" . ".$filter"; #$savename = "$dirpath\\$pngnm" . ".$filter"; # Write image to PNG file $ChartObj->Chart->Export({ FileName => $savename, FilterName => $filter, Interactive => 0 }); } } $Book->Close({SaveChanges=>0}); }; $err = $@; print TTT $err;
Thanks in advance

Replies are listed 'Best First'.
Re: Excel 2003 + Perl
by davidrw (Prior) on Aug 22, 2005 at 12:53 UTC
    Since this works logged in but not under ASP, it seems like it may be a permissions problem with the (i presume) IIS user account not being able to write to the path you're saving in (or maybe not having full rights to Excel/libraries.

    Side note: you might want (if for nothing else just to be explicit in the code) to hide the excel window (it miught be by default).. it's something similar to $Excel->{Visible} = 0 (don't have exact syntax right in fron of me at the moment)
Re: Excel 2003 + Perl
by Roger (Parson) on Aug 22, 2005 at 09:33 UTC
    Office 2003 and Office XP are not "really" compatible. Damn Microsoft with the infinite number of variations and patches for their products. I have Visio 2003 and Visio XP. The file I save in Vision XP can be read from Visio 2003, but not the other way round. So I guess that the 2003 suite is actually newer than the XP suite.

    I am no Office expert so I can not help you. Good luck with your quest for the truth nevertheless!

Re: Excel 2003 + Perl
by puploki (Hermit) on Aug 22, 2005 at 12:02 UTC
    Have you considered using the Office Web Components at all?

    I've not interfaced to them with Perl before, but as they're just COM objects it should be fairly straightforward with Win32::OLE. They're designed to render graphs and excel spreadsheets to a web client so that they don't need any office components installed - maybe this will do what you're after?

    If you were on a Unix/Linux OS, I'd recommend the GD::Graph module - I've used it before and it's pretty flexible at generating any sort of graph you like. I don't believe the GD library works on Windows yet though (I could be wrong...).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://485642]
Approved by holli
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2023-02-08 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (42 votes). Check out past polls.

    Notices?