Limitation of IReadFilter don't work with xls file

Author: AdryanSignorCreated Sep 18, 2018Updated Apr 8, 2026

Hi, this is:

- [X] a bug report
- [ ] a feature request

What is the expected behavior?

The limitation of reading rows when loading xls file with IReadFilter interface.

What is the current behavior?

Reading all rows when loading xls file with IReadFilter interface.

What are the steps to reproduce?

  1. Create a file with 10 rows.
  2. Implements IReadFilter with row limitation 5.
  3. Create an Xls reader.
  4. Set the class with IReadFilter.
  5. Load the xls file.
  6. Get the highest row, this returns 10, not the expected 5.
php
<?php

use \PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use \PhpOffice\PhpSpreadsheet\IOFactory;
use \PhpOffice\PhpSpreadsheet\Reader\IReadFilter;

class SpreadsheetReadFilter implements IReadFilter {

	const LIMIT_ROW = 10000;

	const LIMIT_COLUMN = 256;

	private static $instance;

	private function __construct() {}

	public static function getInstance() {
		if (self::$instance == null) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	public function readCell($column, $row, $worksheetName = '') {
		//return false; // Also reading all rows
		return ($row <= self::LIMIT_ROW && Coordinate::columnIndexFromString($column) <= self::LIMIT_COLUMN);
	}
}

require __DIR__ . '/vendor/autoload.php';

$spreadsheet = IOFactory::createReader('Xls')
	->setReadFilter(SpreadsheetReadFilter::getInstance())
	->load('./testRead.xls');

/**
 * expected: SpreadsheetReadFilter::LIMIT_ROW // 10000
 * current for Xls:  40001
 * current for Csv:  10000
 * current for Xlsx: 10000
 */
echo $spreadsheet->getActiveSheet()->getHighestRow();

Test files (Csv, Xls, xlsx): testRead.zip

Which versions of PhpSpreadsheet and PHP are affected?

PHP 7.1.21 PhpSpreadsheet ^1.3

Source: PHPOffice/PhpSpreadsheet