【问题标题】:Spreadsheet::ParseXLSX and blank cells电子表格::ParseXLSX 和空白单元格
【发布时间】:2018-10-31 06:03:39
【问题描述】:

我正在尝试使用 Spreadsheet::ParseXLSX 解析 XLSX 文件(逐行获取每个单元格的值)。在遍历每一行的循环中,我尝试使用以下代码提取值:

$thisCell = $worksheet->get_cell($currentRow, $currentCol)->value();

还有:

$thisCell = $worksheet->get_cell($currentRow, $currentCol)->unformatted();

但是,如果遇到空单元格,脚本总是会中断。我得到的错误方法是“Can't call method [value|unformatted] on an undefined value...”

尝试预测或处理我尝试过的空单元格:

  • 在上述代码后添加“或 $thisCell = ''”
  • 将上述代码包装在 if 子句中,例如:

    if ($worksheet->get_cell($currentRow, $currentCol)->unformatted()) {
        $thisCell = $worksheet->get_cell($currentRow, $currentCol)->unformatted();
    else {
        $thisCell = "";
    }
    

我真的被困在这个问题上,而且我确信这是我在搞砸的基本问题。任何帮助将不胜感激。

【问题讨论】:

    标签: perl parsing xlsx


    【解决方案1】:
    my $cell = $worksheet->get_cell($currentRow, $currentCol);
    
    my $value = $cell ? $cell->value : undef;
    

    【讨论】:

    • 工作就像一个魅力 - 感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-01
    相关资源
    最近更新 更多