MNB PHPExcelDeveloper Guide
Core concepts

Normal vs Streaming Reads

Choose the correct read mode for memory, random access, metadata, and throughput.

Updated

LevelIntermediateReading time9 minPackagemnb/mnb-phpexcel
ReadSession::normal()ReadSession::streaming()ReadSession::rows()ReadSession::chunks()

What you will learn

  • Choose mode by access pattern rather than file extension.
  • Understand what “streaming” guarantees with and without native extensions.
  • Avoid accidental full-workbook materialization.

Choose by the operation you need#

RequirementRecommended mode
Random cell access, styles, images, metadataNormal
One-pass database importStreaming
Preview first 25 recordsNormal or streaming with limit
Millions of rowsLarge reader / native streaming
Read a small configuration workbookNormal

Normal mode favors convenience#

PHP
$sheet = MnbExcel::read('report.xlsx')
    ->sheet('Summary')
    ->normal();

$value = $sheet->cell('D12');
$style = $sheet->cellStyle('D12');
$images = $sheet->images();

Streaming mode favors one-pass processing#

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

foreach ($sheet->chunks(1000) as $rows) {
    // Validate, transform, and insert this batch.
}

Watch for materializing terminal methods#

Methods such as toArray() intentionally collect rows. Prefer rows(), chunks(), eachRow(), or chunk() when the result does not need to live in memory at once.