ruqui has asked for the wisdom of the Perl Monks concerning the following question:

Hello perl wizards, I'd like to add a range of values I have in an array of arrays into a range of cells in an Excel spreadsheet; I wrote the following but it fails:
use Win32::OLE; eval {$excel = Win32::OLE->GetActiveObject('Excel.Application')}; die "Excel not installed" if $@; unless (defined $excel) { $excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel"; } $workbook = $excel->Workbooks->Open(getcwd() . "/test.xlsx"); $worksheet = $workbook->Worksheets(1); @matrix = ( [0, 1], [2, 3] ); $worksheet->Range("B5:C6")->{Value} = @matrix; $worksheet->Save;
The code above updates the cells B5:C6 with (2, 2, 2, 2) instead of (0, 1, 2, 3) ... what I'm doing wrong?

Replies are listed 'Best First'.
Re: Win32::OLE: how to modify a range of values in an excel table
by Anonymous Monk on Nov 05, 2013 at 02:22 UTC
    Try
    $worksheet->Range("B5:C6")->{Value} = \@matrix; #####################################^^^