How to read empty cells in PHPExcel without skipping values?

跟風遠走 提交于 2019-12-06 08:11:46

By default, the cell iterator will only iterate over cells that actually exist

$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);

$item = array();
foreach ($cellIterator as $cell) {
    array_push($item, $cell->getCalculatedValue());
}

However, if all you're doing is building an array of calculated values for each row, then you might find that using the worksheet's rangeToArray() method is more efficient.

EDIT

To get only cells matching your read filter column list:

foreach ($cellIterator as $cell) {
    $item[$cell->getColumn()] = $cell->getCalculatedValue();
}
$item = array_intersect_key($item, array_flip($filter->valid_columns));

or

foreach ($cellIterator as $cell) {
    if(in_array($cell->getColumn(), $filter->valid_columns)) {
        array_push($item, $cell->getCalculatedValue());
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!