Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'); 
...
like image 364
user1513756 Avatar asked Dec 04 '25 15:12

user1513756


1 Answers

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.

like image 55
Dabjeil Qutwyngo Avatar answered Dec 06 '25 07:12

Dabjeil Qutwyngo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!