MNB PHPExcelDeveloper Guide

Reading examples

Reading Excel examples, explained clearly.

Open a focused example to see the implementation path, copy-ready PHP, expected workbook behavior, and the production boundary that matters.

11examples in this category
21supported categories
5implementation paths
Monolithic library

Reading examples with copy-ready, production-minded PHP.

Each example identifies the exact methods it uses and can be opened independently from the right-side index.

11
examples
26
documented methods
Example 01

Read XLSX rows

MnbExcel::read()sheet()withHeaderRow()toArray()
read-xlsx-rows.php
<?php

declare(strict_types=1);

/*
Summary:
    Read one worksheet into associative PHP rows while skipping empty records and enforcing a safe
    row limit.

Implementation note:
    Use toArray() for small and normal worksheets. Run the large-file preflight before loading an
    unknown or very large workbook into memory.
*/

use Mnb\PHPExcel\MnbExcel;

$workbookPath = __DIR__ . '/fixtures/students.xlsx';

if (!is_file($workbookPath)) {
    throw new RuntimeException(sprintf('Workbook not found: %s', $workbookPath));
}

$rows = MnbExcel::read($workbookPath)
    ->sheet('Students')
    ->withHeaderRow()
    ->toArray([
        'skip_empty_rows' => true,
        'max_rows' => 5_000,
    ]);

foreach ($rows as $row) {
    echo $row['student_id'] . ': ' . $row['name'] . PHP_EOL;
}

Use the monolithic facade when the application needs the complete package.