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 ?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.