Re: processing XL using Win32::OLE
- From: prabu.ayyappan@xxxxxxxxx (Prabu Ayyappan)
- Date: Thu, 28 Jun 2007 22:53:55 -0700 (PDT)
Hi Alok,
Hope the examples in the below links help your needs.
For opening and reading an XL(Excel)
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on errors...
# get already active Excel application or open new
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
# open Excel file
my $Book = $Excel->Workbooks->Open("test.xls");
my $Sheet = $Book->Worksheets(1);
# select work*** number 1 (you can also select a work*** by name)
my $Sheet = $Book->Worksheets(1);
foreach my $row (1..4)
{
foreach my $col (1..3)
{
# skip empty cells
next unless defined $***->Cells($row,$col)->{'Value'};
# print out the contents of a cell
printf "At ($row, $col) the value is %s and the formula is %s\n",
$***->Cells($row,$col)->{'Value'},
$***->Cells($row,$col)->{'Formula'};
}
}
# clean up after ourselves
$Book->Close;
Refer the Below link...You can find More examples
http://www.ibm.com/developerworks/library/l-pexcel/
Regards,
Prabu.M.A
alok nath <aloknathlight@xxxxxxxxx> wrote:
Hi,
Can anybody tell how to open an already existing xL file
and then probabaly do some processing using Win32::OLE
I found quite a few examples but none of them open an
existing excel file.
Or is there some better module for XL processing ?
Here is my code ..
use strict ;
use warnings ;
use Win32::OLE;
use Win32::OLE::Const;
my $file = "Matrix.xls" ;
my $ex ;
eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $ex) {
$ex = Win32::OLE->new($file, sub {$_[0]->Quit;})
or die "Oops, cannot start Excel";
}
# get a new workbook
my $book = $ex->Workbooks->Add;
my $Sheet = $book->Worksheets(1);
$***->{Name} = 'Candle';
$book->Close;
Thanks
Alok.
____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
---------------------------------
Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search.
- References:
- processing XL using Win32::OLE
- From: Alok Nath
- processing XL using Win32::OLE
- Prev by Date: processing XL using Win32::OLE
- Next by Date: Spread*** IO::Scalar v. PerlIO::Scalar confusion
- Previous by thread: processing XL using Win32::OLE
- Next by thread: Re: processing XL using Win32::OLE
- Index(es):