【问题标题】:Spreadsheet::ParseExcel $cell->value() returning undefSpreadsheet::ParseExcel $cell->value() 返回 undef
【发布时间】:2015-08-17 12:39:12
【问题描述】:

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

当我在自己的行上使用 $cell->value() 时,似乎没有问题,但是当我尝试使用它将值插入数组时,它返回 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;返回单元格的内容但打印 Dumper $line;返回 undef

【问题讨论】:

  • 什么是$line?你是说print Dumper (\@line); 吗?
  • 是的!谢谢,我错误地使用了 Dumper 并且 getvalue 实际上正在工作。感谢您的帮助。
  • 正是这样的错误很容易捕获使用:use strict; use warnings;你有一个快乐的一天,因为这是很常见的,比没有人为不包含使用严格和使用警告的问题而烦恼;。

标签: excel perl undef


【解决方案1】:

你必须推送$cell->value而不是$value

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

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

【讨论】:

  • 抱歉 - 错字,现已修复(但是使用 push @line, $cell->value if defined($cell); 也返回 undef)
  • 尝试将$value = $cell->value; 更改为my $value = $cell->value;
  • @JamesJiimmy 你什么时候做push @line, \$value ?
猜你喜欢
  • 2014-11-19
  • 2011-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-12
  • 1970-01-01
  • 2023-03-06
  • 2011-10-25
相关资源
最近更新 更多