user1513756
user1513756

Reputation: 31

Problems reading a .xls file using Perl Win32::OLE under Cygwin

I have been fighting with this one for two days, I cannot find the solution and I'm getting frustrated. While using the code below under Cygwin I get this error

OLE exception from "Microsoft Office Excel": Excel cannot access 'Empty.xls'.
The document may be read-only or encrypted. Win32::OLE(0.1703) error 0x800a03ec in METHOD/PROPERTYGET "Open" at m:/In/make_excel.pl line 24

The thing is that under the DOS prompt it is working perfectly. The file is not readonly of course. I'm guessing there is some problem with the file format interpretation. Any hint? It would be highly appreciated.

#!/usr/bin/perl
use Win32::OLE;
use Win32::OLE::Variant;
use Win32::OLE::Const 'Microsoft Excel';
$Excel = Win32::OLE->GetActiveObject('Excel.Application') ||
   Win32::OLE->new('Excel.Application');
$Excel->{'Visible'} = 0;        #0 is hidden, 1 is visible
$Excel->{DisplayAlerts}=0;  #0 is hide alerts
# Open File and Worksheet
my $Book = $Excel->Workbooks->Open('C:\Empty.xls'); 
...

Upvotes: 3

Views: 4264

Answers (2)

Dabjeil Qutwyngo
Dabjeil Qutwyngo

Reputation: 31

MS Excel requires MS Windows paths.

The problem is in the

my $seedProject = "$ENV{'HOME'}/Empty.xls";

Use '\\' instead of '/' : Excel works only with windows paths. Check path delimeters in $ENV{HOME} also.

Upvotes: 3

Sinan Ünür
Sinan Ünür

Reputation: 118118

It is very important to keep the regular Windows universe and the Cygwin corner of it well insulated when working in Cygwin. It is entirely possible that you actually did not have a Cygwin Win32::OLE installation to begin with and somehow ActiveState's lib directories where being added to the @INC of Cygwin's perl (via an environment setting or something else). That will mostly work for pure Perl modules, but anything that uses XS will be messed up.

By installing Win32::OLE in Cygwin, you may have put it in the @INC ahead of ActiveState's lib directories, and therefore allowed Cygwin's perl to locate the correct module. However, you should run something like:

$ perl -e 'print "@INC\n"'

On the Cygwin prompt to ensure that only Cygwin paths appear in it.

Also, you might want to install Cygwin's perl-libwin32 package via setup.exe, rather than building modules manually.

Upvotes: 1

Related Questions