I want to add my data stored in 2×2 dimension array in Excel using Perl. I know how to open and add simple data. This I can do using for loop. But how can I do it elegantly?
This is what I am trying to do
$sheet->Range('A1:B'.'$size')->{Value} = @$data; or @data; or {@data}; or {\@data};
where @data is two dimensional array.
# 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 $sheet = $book->Worksheets(1); print 'A1:B'.'$size'; # write a 2 rows by 3 columns range $sheet->Range('A1:B'.'$size')->{Value} = @$data;
I see that you are using Win32::OLE but this sort of thing is also quite easy with Spreadsheet::WriteExcel: