【发布时间】: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 = ""; }
我真的被困在这个问题上,而且我确信这是我在搞砸的基本问题。任何帮助将不胜感激。
【问题讨论】: