Spreadsheet::ParseExcel $cell->value() 返回 undef

Spreadsheet::ParseExcel $cell->value() returning undef

我是 perl 新手,在使用电子表格 excel 解析器模块时遇到了问题。

当我在自己的行中使用 $cell->value() 时,似乎没有问题,但是当我尝试使用它来将值插入数组时,它 returns undef,代码如下:

for my $row ($row_min .. $row_max) {
    my @line;
        for my $col ( $col_min .. $col_max) {
                my $cell = $worksheet->get_cell( $row, $col );
                $value = $cell->value;
                push @line, $value if defined($cell);
                print $cell->value;
                print Dumper $line;
                }

         }
}

此处打印$cell->value; returns 单元格的内容但打印 Dumper $line; returns未定义

你必须按$cell->value而不是$value

push @line, $cell->value if defined($cell);

您应该在程序的开头添加 use strict,这样在这种情况下您会收到错误消息。