Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我试图使用Perl';在Excel中设置单元格的值时,为什么会出现异常;是Win32::OLE吗?_Perl_Excel_Win32ole - Fatal编程技术网

当我试图使用Perl';在Excel中设置单元格的值时,为什么会出现异常;是Win32::OLE吗?

当我试图使用Perl';在Excel中设置单元格的值时,为什么会出现异常;是Win32::OLE吗?,perl,excel,win32ole,Perl,Excel,Win32ole,我在第109行的PROPERTYPUT“Value”中得到错误Win32::OLE错误0x80020009:“发生异常” 中的代码是Perl foreach my $ref_array1 (@$array1) { # loop through the array foreach my $col1 (@$ref_array1) { foreach my $ref_array2 (@$array2) { # loop through the array

我在第109行的PROPERTYPUT“Value”中得到错误
Win32::OLE错误0x80020009:“发生异常”

中的代码是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++;
感谢您的任何帮助。
谢谢

以下不完整的示例有效(即,它将5放入单元格
A1
):


另请参见my.

以下不完整示例有效(即,它将5放入单元格
A1
):


另请参见我的。

user402705:我重新格式化了您的问题,使其更具可读性。请看一看,以备将来参考。然后,试着给出一个简短但完整的示例,我们可以运行它,它仍然显示问题。user402705:我重新格式化了您的问题,使其更具可读性。请看一看,以备将来参考。并且,尝试提出一个简短但完整的示例,我们可以运行它,它仍然显示出问题。
#!/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;
}