#!perl
use Win32::OLE;
# use existing instance if Excel is already running
eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $ex)
{
$ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start Excel";
}
# get a new workbook
# $book = $ex->Workbooks->Add;
$book = $ex->Workbooks->Open({FileName => "trainees.xls", ReadOnly=>1});
#$ws = $book->Worksheets(train)->Name;
$ws = $book->Worksheets(1);
$wsN = $ws->Name;
print "Name = $wsN\n";
$a1 = $ws->Range("A1")->{Value};
print "A1 = $a1\n";
$ws->Range("A109")->{Value}="Fellows";
# write to a particular cell
#$sheet = $book->Worksheets(1);
#$sheet->Cells(1,1)->{Value} = "foo";
# write a 2 rows by 3 columns range
#@firstRow = ('number', 'Xyzzy', 'Plugh');
#@secondRow = ("42",'Perl',"3.1415" );
# $sheet->Range("A2:C3")->{Value} = [[ 'number', 'Xyzzy', 'Plugh' ],
# [ 42, 'Perl', 3.1415 ]];
#$sheet->Range("A2:C3")->{Value} = [[@firstRow],
# [@secondRow]];
# print "XyzzyPerl"
#$array = $sheet->Range("A2:C3")->{Value};
#for (@$array)
# {
# for (@$_)
# {
# print defined($_) ? "$_|" : "<undef>|";
# }
# print "\n";
# }
# save and exit
#$book->SaveAs( 'c:\temp\test.xls' );
undef $book;
undef $ex;