MNB PHPExcelDeveloper Guide
XLS library

Reading Native XLS Files

Read BIFF8 worksheets, Unicode shared strings, dates, formulas, cached values, and projected rows with the native reader.

Updated

LevelIntermediateReading time10 minPackagemnb/mnb-phpexcel-xls
Xls::read()XlsReader::readSheet()XlsReader::sheetNames()ReadSession::rows()

What you will learn

  • Select a sheet by name or one-based index.
  • Choose formula, cached-value, or combined formula results.
  • Apply binary-parser safety limits to untrusted uploads.

Read associative rows#

PHP
use Mnb\PHPExcel\Format\Xls;

foreach (Xls::read('customers.xls')
    ->sheet('Customers')
    ->withHeaderRow()
    ->rows([
        'skip_empty_rows' => true,
        'max_rows' => 5000,
    ]) as $row) {
    echo $row['Name'] . PHP_EOL;
}

Choose a formula result mode#

PHP
$session = Xls::read('calculations.xls')->sheet('Summary');

$formulas = $session->toArray(['formula_cells' => 'formula']);
$cached   = $session->toArray(['formula_cells' => 'cached_value']);
$both     = $session->toArray(['formula_cells' => 'both']);

both returns Mnb\PHPExcel\Reader\State\FormulaResult values containing the formula, cached result, result type, and native BIFF token metadata. Unknown BIFF tokens retain a diagnostic formula representation while their cached values remain readable.

Use direct reader operations when needed#

PHP
use Mnb\PHPExcel\Reader\XlsReader;

$reader = new XlsReader();
$sheetNames = $reader->sheetNames('report.xls');
$rows = $reader->readSheet('report.xls', 1, [
    'start_row' => 2,
    'end_row' => 1000,
    'only_columns' => ['A', 'C', 'F'],
]);

Limit binary parsing for uploads#

PHP
$rows = Xls::read('upload.xls')->toArray([
    'max_file_size' => 64 * 1024 * 1024,
    'max_stream_size' => 32 * 1024 * 1024,
    'max_chain_sectors' => 200000,
    'max_biff_records' => 1000000,
    'max_shared_strings' => 250000,
]);