PhpSpreadsheet Reader Example #10
Simple File Reader Using a Configurable Read Filter
_startRow = $startRow;
$this->_endRow = $endRow;
$this->_columns = $columns;
}
public function readCell($column, $row, $worksheetName = '')
{
if ($row >= $this->_startRow && $row <= $this->_endRow) {
if (in_array($column, $this->_columns)) {
return true;
}
}
return false;
}
}
$filterSubset = new MyReadFilter(9, 15, range('G', 'K'));
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
';
$reader = IOFactory::createReader($inputFileType);
echo 'Loading Sheet "',$sheetname,'" only
';
$reader->setLoadSheetsOnly($sheetname);
echo 'Loading Sheet using configurable filter
';
$reader->setReadFilter($filterSubset);
$spreadsheet = $reader->load($inputFileName);
echo '
';
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>