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

Hello Perl Monks, I have written a perl code in cygwin perl. Here i need to read the excel file for which i am using Win32::OLE. I have used Win32::OLE for perl in past on DOS/Windows. However, this the the first time in cygwin envt & i am facing some issues. Basically i am just not able to open/access the workbook. It dies with the error. My question is, would Win32::OLE work on cygwin evnt ? If so, are there any specific settings required to do that ? Below is the code that i have written. Note that the code & the excel file both are in the same directory. Help is much appreciated.
#!/usr/bin/perl use strict; use warnings FATAL => qw( all ) ; use Win32::OLE; use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; our $Excel = undef ; my $file = 'template_001.xlsx' ; $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application'); $Excel->{DisplayAlerts}=0; #0 is hide alerts # Open File and Worksheet my $Book = $Excel->Workbooks->Open($file) or die "Can't open workbook\ +n" ; print ("The excel book is $Book\n") ;

Original content restored above by GrandFather

Thanks Jim & Rob for your responses. The change i have to make is to provide the absolute path like below.
my $file = 'c:\path\subpath\template_001.xlsx' ;
This solved the problem. Previously as Jim pointed out i was specifying only the spreadsheet & assuming that the file would be picked up from the Cwd, but seem else-wise. This did solve the issue, however just for information purpose i have read at multiple places that Win32::OLE cannot be used on Cygwin domain. Is that true ?

Replies are listed 'Best First'.
Re: Using Win32::OLE on cygwin
by Jim (Curate) on Nov 13, 2013 at 04:09 UTC

    Try anchoring the file to the current working directory.

    my $file = './template_001.xlsx';

    Just a guess. I know that directories and file access work differently under Cygwin than they do under plain old Windows.

    UPDATE:  Your script works for me without modification under Cygwin.

Re: Using Win32::OLE on cygwin
by syphilis (Archbishop) on Nov 13, 2013 at 09:03 UTC
    It dies with the error.

    If Jim's suggestion hasn't helped, then it would be helpful if we knew what the error was.

    If Jim's suggestion *did* solve the issue, then it would be helpful if you told us so.

    Cheers,
    Rob
Re: Using Win32::OLE on cygwin
by Jim (Curate) on Nov 13, 2013 at 19:39 UTC

    (You overwrote your original inquiry with a new inquiry. You shouldn't do that. Now, our responses to your original question don't make any sense in the new, changed context.)

    No, I don't know why OLE automation using Perl and Win32::OLE doesn't work under Cygwin. But more importantly, I don't understand what you gain by using Cygwin, "a Unix-like environment and command-line interface for Microsoft Windows" (Wikipedia), in tandem with a Perl script to manipulate Windows-only software. What Unix software do you need to use with OLE automation? To me, the two technologies are discordant, but I admit I don't fully understand either Cygwin or what it is you're trying to accomplish with it.

    Jim