
fashimpaur
User
Sep 21, 2000, 10:07 PM
Post #2 of 3
(7045 views)
|
Re: Problem using scalar vs number in Win32::OLE
[In reply to]
|
Can't Post
|
|
I think the problem is the referencing/dereferencing. Here is an example that works ok using your requested methodology. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> 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; # write to a particular cell $num = 1; $sheet = $book->Worksheets($num); $sheet->Cells(1,1)->{Value} = "foo"; # write a 2 rows by 3 columns range $sheet->Range("A8:C9")->{Value} = [[ undef, 'Xyzzy', 'Plugh' ], [ 42, 'Perl', 3.1415 ]]; # print "XyzzyPerl" $array = $sheet->Range("A8:C9")->{Value}; for (@$array) { for (@$_) { print defined($_) ? "$_|" : "<undef>|"; } print "\n"; } # save and exit $book->SaveAs( glob "./test.xls" ); undef $book; undef $ex; </pre><HR></BLOCKQUOTE> HTH, Dennis
|