我想将数组数组中的一系列值添加到 Excel 电子表格中的一系列单元格中;我写了以下内容,但失败了:
use Win32::OLE;
use Cwd;
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;
上面的代码用 (2, 2, 2, 2) 而不是 (0, 1, 2, 3) 更新单元格 B5:C6,我无法弄清楚原因......我做错了什么?