我希望使用Perl将存储在2x2维数组中的数据添加到Excel中。我知道如何打开和添加简单的数据,可以使用for循环来实现。但是如何更加优雅地完成呢?
这就是我想要做的事情。
$sheet->Range("A1:B"."$size")->{Value} = @$data;
or @data;
or {@data};
or {\@data};
其中@data
是一个二维数组。
# 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;