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

hi all,

I have a perl script that exports an excel chart to a png file. This works fine when I run it through prompt. but it doesn't work If I call it from asp. perl script 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... my $filter = 'PNG'; # can be GIF, JPG, JPEG or PNG $filename = "C:\\graph1.xls"; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); # use the Exc +el application if it's open, otherwise open new my $Book = $Excel->Workbooks->Open( $filename ); # open the fi +le foreach my $Sheet (in $Book->Sheets) { # loop through all shee +ts foreach my $ChartObj (in $Sheet->ChartObjects) { # loop throug +h all chartobjects in the sheet #$pngsave = join("",split(/\s+/,$graphtitle)); $dirpath = "c:\\Tt"; mkdir ("$dirpath", 0777); my $savename = "$dirpath\\test" . ".$filter"; #check out the +variable name # Write image to PNG file $ChartObj->Chart->Export({ FileName => $savename, #check out t +he variable name FilterName => $filter, Interactive => 0}); } }
ASP code is
<html> <body> <form action = "disp.asp" method = post> Enter a Value <input type = "text" name = "fname" size = 20> <input type = "submit" value = "click"> </from> <% dim nm nm = request.form("fname") if nm <> "" then response.write("<center> <br> hi "& nm &"</center>" ) response.write("<center> <br> have a good start </center +>") set shell = Createobject("wscript.shell") shell.run "cmd.exe /c C:\\Perl\\bin\\perl " & nm, 1, 1 set shell = nothing end if %> </body> </html>
This works in some systems & doesn't in some. Its not giving any error.

Do I need to register any activex dll for this? If so what all dll's I need to register?

Thanks in advance

Considered by jdporter - Retitle: "ASP -> Shell -> Perl -> Excel doesn't seem to work"
Unconsidered by castaway - Keep/Edit/Delete: 9/16/0 - Looks fine to me

Replies are listed 'Best First'.
Re: Perl, Win32::OLE, ASP
by gellyfish (Monsignor) on Mar 22, 2005 at 09:11 UTC

    To be honest I am not quite sure why you are shelling out to run a perl program that does OLE Automation from an ASP application when it would probably be easier to automate Excel directly from the ASP, but whatever - you need to read this if you intend to automate office applications on the server side.

    /J\

Re: Perl, Win32::OLE, ASP
by FitTrend (Pilgrim) on Mar 22, 2005 at 14:09 UTC

    Maybe this isn't a code issue, but more of a permissions issue. If your web server doesn't have appropriate permissions to your file, then it can't access it to do what you want. The only other thing I can see (and I have limited ASP experience) is that when I've used cmd.exe /c in other perl scripts, I had to quote the command.

    cmd.exe /c "C:\\perl\\bin\\perl PATH_TO_MY_SCRIPT\\SCRIPT.PL ARGS".</p +>

    Hope this helps