MNB PHPExcelDeveloper Guide
Reading workbooks

Choose the Right Excel Reading Method

Compare row streaming, native arrays, first-row access, counts, structured summaries, selected columns, and direct cells before choosing an API.

Updated

Full packageIndividual XLSXLow memory
Available sincev2.0.3Last API changev2.0.5Version guide
LevelBeginnerReading time8 minPackagemnb/mnb-phpexcel or mnb/mnb-phpexcel-xlsx
ReadSession::rows()ReadSession::toArray()ReadSession::first()ReadSession::countRows()ReadSession::hasRows()ReadSession::toStructuredSheetArray()ReadSession::cell()

What you will learn

  • Choose a method based on output shape and memory behavior.
  • Know the correct empty check for each return type.
  • Avoid extra worksheet passes in large workflows.

Reading-method decision table#

RequirementRecommended APIReturnsMemory profileEmpty check
Process a large worksheet row by rowrows()GeneratorLow / forward-onlyTrack whether the loop yielded or call hasRows() first.
Need every returned row as PHP datatoArray()arrayRows retained in memory$rows === []
Need only the first data rowfirst()?arrayStops after first row$row === null
Need only a yes/no data checkhasRows()boolStops after first rowThe returned Boolean is the check.
Need the final normalized row countcountRows()intStreams the selected rows$count === 0
Need physical/empty/header/returned countstoStructuredSheetArray()arrayStructured rows retained$result["rows"] === []
Need one fixed XLSX coordinatecell("B2")mixedTargeted lookupApplication-specific null/value check.
Need fewer columnsselectColumns(...) then a terminal methodReadSession until terminal callLower normalization/application memoryDepends on the terminal method.

Three common choices#

PHP
foreach ($session->rows() as $row) {
    processRow($row);
}

Performance rule#