为什么当我尝试使用Perl的Win32 :: OLE在Excel中设置单元格的值时出现exception?

我得到错误Win32::OLE<0.1709> error 0x80020009: "Exception occurred" in PROPERTYPUT "Value"在109行中Win32::OLE<0.1709> error 0x80020009: "Exception occurred" in PROPERTYPUT "Value"

代码是Perl。

 foreach my $ref_array1 (@$array1) { # loop through the array foreach my $col1 (@$ref_array1) { foreach my $ref_array2 (@$array2) { # loop through the array foreach my $col2 (@$ref_array2) { if ($col1 eq $col2) { this is line 109: **$worksheet1->Cells($j,1)->{'Value'} = $col1;** $j++; 

任何forms的帮助表示赞赏。 谢谢

下面的不完整的例子工作(即它在单元格A1放5):

 #!/usr/bin/perl use strict; use warnings; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; my $excel = get_excel(); $excel->{Visible} = 1; my $book = $excel->Workbooks->Add; my $sheet = $book->Worksheets->Add; $sheet->{Name} = 'Perl Win32-OLE Example'; my $range = $sheet->Cells(1,1); $range->{Value} = 5; $range->AutoFormat; sub get_excel { my $excel; unless ( eval { $excel = Win32::OLE->GetActiveObject('Excel.Application') }) { die $@, "\n"; } unless(defined $excel) { $excel = Win32::OLE->new('Excel.Application', sub { $_[0]->Quit }) or die "Oops, cannot start Excel: ", Win32::OLE->LastError, "\n"; } return $excel; } 

另请参阅我的Perl Win32 :: OLE示例 。