I have been using PhpSpreadsheet filters for years and now after install on the new machine the function no longer works. Specifically, I created ReadFilter class which implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter.
class ReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter {
private $startRow = 0;
private $endRow = 0;
private $columns = [];
public function __construct($startRow, $endRow, $columns) {
$this->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;
}
}
Then I want to read data using the filter above:
$filterSubset = new ReadFilter(1, 3427, range('A', 'A'));
$inputFileType = 'Xlsx';
$inputFileName = './file_name.xlsx';
$worksheet='Sheet 1';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$reader->setReadFilter($filterSubset);
$spreadsheet = $reader->load($inputFileName);
$sheetData = $spreadsheet->getSheetByName($worksheet)->toArray();
However, I get an error:
PHP Fatal error: Declaration of ReadFilter::readCell($column, $row, $worksheetName = '') must be compatible with PhpOffice\PhpSpreadsheet\Reader\IReadFilter::readCell(string $columnAddress, int $row, string $worksheetName = ''): bool
Php is not happy with the public function readCell in my ReadFilter class. But the error is not self explanatory. Anybody can help?