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

#!C:/Perl/bin/perl.exe use strict; sub Report{ use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors... my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $Book = $Excel->Workbooks->Add(); my $Sheet = $Book->Worksheets(1); $Sheet->Cells(1,1)->{'Value'}="Hello"; $Sheet->Cells(1,2)->{'Value'}="Excel Report"; $Book->SaveAs("c:\\tmp\\test_graph123.xls"); $Book->Close(); $Excel->Quit; }
If the above script is executed in the CGI Mode I found the error
Win32::OLE(0.1403) error 0x80070005: "Access is denied" at ...... line 7
It throws the error on creating the Excel Object i.e. on
Win32::OLE->new('Excel.Application', 'Quit');
Whether any Permission has to be provied to access the Excel Application thru Apache under CGI mode.
FYI While Using the SpreadSheet::WriteExcel module I am able to create and write an Excel file in the respective folder "c:\tmp\".
I have spend lot of hrs in this, but I am unable to find the solution.
I am new to the win32Perl. So Kind Comments/Suggestions will be of great helpfull.
  • Comment on Under CGI Mode Unable to access the Excel Application using Win32::OLE
  • Download Code

Replies are listed 'Best First'.
Re: Under CGI Mode Unable to access the Excel Application using Win32::OLE
by NerdMachine (Initiate) on Nov 09, 2005 at 05:30 UTC
    Allow me to offer some debugging suggestions. "thru Apache under CGI" probably translates to "under a different user account with a different path and different permissions." That is probably the key to this puzzle.

    OLE->new() loads a DLL. You can use procexp.exe from sysinternals.com to figure out which DLLs are loaded for a process. Using sleep(), you can slow down your execution and watch as DLLs get loaded. Pay attention to what is loaded when it works. Check that DLL out and see if it can be accessed by the account running apache (again, procexp can help you figure out what that account is). It may even need to be in the path (procexp again).

    If you can't figure it out from that, use filemon.exe from sysinternals.com and filter out all but the apache process. Look and see what file isn't getting loaded correctly and what the reason is.

    --NerdMachine

Re: Under CGI Mode Unable to access the Excel Application using Win32::OLE
by SheridanCat (Pilgrim) on Nov 09, 2005 at 17:42 UTC
    My suspicion is that the default user for Apache on Windows, LocalSystem, doesn't have rights to do what you're asking it to do.

    If you have control of the server Apache is running on, you can go into the Services and change the user to a more privileged user. Obviously, this is a bit more dangerous, so you should probably consult your sysadmin about how to set this properly.