Spreadsheet::ParseXLSX 和空白单元格
Spreadsheet::ParseXLSX and blank cells
我正在尝试使用 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..."
尝试预测或处理我尝试过的空单元格:
- 在上面的代码后面加上一个"or $thisCell = ''"
将上面的代码包装在一个 if 子句中,例如:
if ($worksheet->get_cell($currentRow, $currentCol)->unformatted()) {
$thisCell = $worksheet->get_cell($currentRow, $currentCol)->unformatted();
else {
$thisCell = "";
}
我真的被困在这个问题上了,我确信这是我正在搞砸的基本问题。任何帮助将不胜感激。
my $cell = $worksheet->get_cell($currentRow, $currentCol);
my $value = $cell ? $cell->value : undef;
我正在尝试使用 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..."
尝试预测或处理我尝试过的空单元格:
- 在上面的代码后面加上一个"or $thisCell = ''"
将上面的代码包装在一个 if 子句中,例如:
if ($worksheet->get_cell($currentRow, $currentCol)->unformatted()) { $thisCell = $worksheet->get_cell($currentRow, $currentCol)->unformatted(); else { $thisCell = ""; }
我真的被困在这个问题上了,我确信这是我正在搞砸的基本问题。任何帮助将不胜感激。
my $cell = $worksheet->get_cell($currentRow, $currentCol);
my $value = $cell ? $cell->value : undef;