我有以下代码.
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestDataRow();
$highestColumn = $sheet->getHighestDataColumn();
for ($row = 2; $row <= $highestRow; $row++){
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn .
$row,NULL,TRUE,FALSE);
}
如果所有列都是空的,我需要忽略行.我已经看到了链接ignore empty columns,但是不确定这是否对我有用.如果它为空,则不需要消除列,但是如果所有列均为空,则不需要消除整个行.
解决方法:
您需要遍历行并检查所有单元格是否为空
样例代码
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestDataRow();
$highestColumn = $sheet->getHighestDataColumn();
for ($row = 2; $row <= $highestRow; $row++){
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,NULL,TRUE,FALSE);
if(isEmptyRow(reset($rowData))) { continue; } // skip empty row
// do something usefull
}
function isEmptyRow($row) {
foreach($row as $cell){
if (null !== $cell) return false;
}
return true;
}