No problem, I hope this is of some help to you.
Sudha
At 12:05 PM 5/18/00 -0700, you wrote:
Hi Sudha,
Thanks for the help and detailed information, now I can automate my program
to meet the whole reporting process.
Thanks again, Preethi
- Original Message -
From: "Sudha Natarajan" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, May 17, 2000 1:46 PM
Subject: [perl-win32-gui] File conversion
Hi Preethi,
I don't know if this is of any help to you. Just found this in the
documentation.
Regards
Sudha
How do I extract a series of cells from Microsoft Excel?
If you have a sheet object you can extract the values of a series of cells
through $Sheet-Range-{'Value'}, for example:
my $array = $Sheet-Range("A8:B9")-{'Value'};
Now $array[0][0] contains the value of cell A8, $array[0][1] the value of
cell B8, $array[1][0] the value of cell A9 and $array[1][1] the value of
cell B9.
What is returned is an two-dimensional array (OK, an array with references
to arrays) that contains the values of the requested cells.
A complete example is here:
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;# die on errors...
my $Excel = Win32::OLE-GetActiveObject('Excel.Application')
|| Win32::OLE-new('Excel.Application', 'Quit'); # get already active
Excel
# application or
open
new
my $Book = $Excel-Workbooks-Open("C:\\DOCUMENTS\\test.xls"); # open
Excel
file
my $Sheet = $Book-Worksheets(1); # select worksheet
number 1
my $array = $Sheet-Range("A8:B9")-{'Value'};# get the contents
$Book-Close;
foreach my $ref_array (@$array) { # loop through the
array
# referenced by
$array
foreach my $scalar (@$ref_array) {
print "$scalar\t";
}
print "\n";
}
To retrieve the formatted value of a cell you should use the {'Text'}
property instead of the {'Value'} property. This returns exactly what is
being displayed on the screen though! If the column is not wide enough,
you
get a value of '##':
my $array = $Sheet-Range("A8:B9")-{'Text'};
--
--