MNB PHPExcelDeveloper Guide
v2.0.5
Core concepts

ReaderOptions and Read Pipelines

Compose immutable read behavior for ranges, columns, headers, formulas, passwords, progress, and errors.

Updated

LevelIntermediateReading time10 minPackagemnb/mnb-phpexcel
ReaderOptions::defaults()withRange()withColumns()withMode()withPassword()withRowErrorPolicy()

What you will learn

  • Build reusable immutable read configuration.
  • Know when fluent ReadSession methods are equivalent.
  • Pass options consistently to format-specific entry points.

Build options without mutating shared state#

ReaderOptions.php
use Mnb\PHPExcel\Reader\Options\ReadMode;
use Mnb\PHPExcel\Reader\Options\ReaderOptions;
use Mnb\PHPExcel\Reader\Options\RowErrorPolicy;

$options = ReaderOptions::defaults()
    ->withRange(startRow: 2, endRow: 100000, startColumn: 'A', endColumn: 'H')
    ->withColumns(['Order ID', 'Customer', 'Amount'])
    ->withMode(ReadMode::Streaming)
    ->withFormulaMode('cached')
    ->withRowErrorPolicy(RowErrorPolicy::Collect)
    ->withProgress($progressCallback, everyRows: 1000);

Pass options at the entry point#

PHP
$session = MnbExcel::read('orders.xlsx', $options)
    ->sheet('Orders')
    ->withHeaderRow(1);

The options object is immutable, so it can be reused as a baseline and safely modified for another read.

Use session methods for local changes#

PHP
$session = MnbExcel::read('orders.xlsx')
    ->sheet('Orders')
    ->range(2, 100000, 'A', 'H')
    ->projectColumns(['Order ID', 'Amount'])
    ->streaming()
    ->onProgress($progressCallback, 1000)
    ->onRowError('collect');

Know the main option groups#

ConcernMethods
Physical rangewithRange()
Source projectionwithColumns()
Execution modewithMode()
Header discoverywithAutoHeader()
Encrypted inputwithPassword()
Formula representationwithFormulaMode()
Bad-row behaviorwithRowErrorPolicy()
Progress reportingwithProgress()