MNB PHPExcelDeveloper Guide
v2.0.5
XLSX module

Reading XLSX Workbooks

Use read sessions for sheets, headers, projection, ranges, formulas, dates, images, and structured output.

Updated

LevelIntermediateReading time10 minPackagemnb/mnb-phpexcel
sheetNames()activeSheet()sheetIfExists()hasRows()autoDetectHeader()projectColumns()cellDetails()chunks()

What you will learn

  • Select worksheets by index or name and normalize headers.
  • Reduce work through row ranges and source-level column projection.
  • Choose direct cell, row generator, chunk, and structured-output APIs.

Inspect sheets and choose one#

PHP
$session = MnbExcel::read('report.xlsx');

print_r($session->sheetNames());
print_r($session->activeSheetInfo());

$rows = ($session->sheetIfExists('Sales') ?? $session->activeSheet())
    ->autoDetectHeader(sampleRows: 25, minimumConfidence: 0.45)
    ->rows();

Project and stream only what you need#

PHP
$rows = MnbExcel::read('orders.xlsx')
    ->sheet('Orders')
    ->withHeaderRow(1)
    ->projectColumns(['Order ID', 'Customer', 'Amount'])
    ->range(startRow: 1, endRow: 100000)
    ->streaming()
    ->rows();

Projection is applied before the application retains discarded values. For large workbooks, combine projection with the large-file preflight and streaming APIs.

Use direct access for lookup workbooks#

PHP
$total = Xlsx::cell('finance.xlsx', 'D12', 'Summary');
$matrix = Xlsx::rangeValues('finance.xlsx', 'A1:F20', 'Summary');
$details = Xlsx::cellDetails('finance.xlsx', 'B7', 'Review');

print_r([
    'formula' => $details->formula,
    'style' => $details->style,
    'comment' => $details->comment,
    'hyperlink' => $details->hyperlink,
]);

Process batches and preserve failures#

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

foreach ($session->chunks(1000) as $chunk) {
    processOrders($chunk);
}

$errors = $session->rowErrors();

Continue with the dedicated guides for formulas and dates, images and metadata, and large-file streaming.