excelperliiswin32ole

Error when tried to open a excel file from Perl using IIS


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?


Solution

  • 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)