1
votes

I am running a perl script file from c# application using IIS, in that I want to open a already existing Excel file and I am opening it using the following line:

$ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) 
or die "Oops, cannot start Excel";//upto this working fine

$book = $ex->Workbooks->Open($fileName); //this line only giving error

Now I am getting the error in the open as follows:

OLE exception from "Microsoft Office Excel":

Microsoft Office Excel cannot access the file 'C:\GWATS\Report\Nov-17-2014_10-06-36\GES-11n_IOT_10-06-37.xls'. There are several possible reasons:

• The file name or path does not exist.

• The file is being used by another program.

• The workbook you are trying to save has the same name as a currently open workbook.

Win32::OLE(0.1711) error 0x800a03ec in METHOD/PROPERTYGET "Open" at C:\GWATS\Lib\System\Report.pm line 611.

The file is surely present I verified that.

Also this script is working fine when I directly run that in cmd. What is the problem here, I think the problem is with IIS but I could find what exactly the problem is?

3
Does the user account which IIS is using to run your script have access to the file?Tim Williams
yes Tim I added DefaultAppPool to users and given full control to Report folderrajasekar25
If you run a "file exists" check from perl using that path does it succeed?Tim Williams
when run from cmd prompt it is running fine. It is opening the file and writing the contents without any error.rajasekar25
Even when run as the IIS user account?Tim Williams

3 Answers

1
votes

Try the below perl script. If still some error exists let me know:

Code:

   use Win32::OLE qw(in with);
   use Win32::OLE::Const 'Microsoft Excel'; 

   my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
     || Win32::OLE->new('Excel.Application', 'Quit');
    my $filename = 'C:\GWATS\Report\Nov-17-2014_10-06-36\GES-11n_IOT_10-06-37.xls'
    my $book  = $Excel->Workbooks->Open($filename);
0
votes

Open Windows Explorer

Depending on whether you installed a 32bit or 64bit version of office you will need to do one (or both) of the following:

32bit Office installation: Navigate to C:\Windows\System32\config\systemprofile

64bit Office installation: Navigate to C:\Windows\SysWOW64\config\systemprofile

Verify the folder "Desktop" exists (create it if it's not there)

Right click > Properties

On the security tab: Add the account under which the site is running (eg: DefaultAppPool) with default permissions (Read & execute; List folder contents; Read)

0
votes

i faced similar issue

it worked for me when i gave the absolute path for the files