ReaderOptions and Read Pipelines
Compose immutable read behavior for ranges, columns, headers, formulas, passwords, progress, and errors.
Updated
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#
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#
$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#
$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#
| Concern | Methods |
|---|---|
| Physical range | withRange() |
| Source projection | withColumns() |
| Execution mode | withMode() |
| Header discovery | withAutoHeader() |
| Encrypted input | withPassword() |
| Formula representation | withFormulaMode() |
| Bad-row behavior | withRowErrorPolicy() |
| Progress reporting | withProgress() |
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue