Skip to content
MNB PHPExcelDeveloper Guide
AI

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.

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.

Example 02

List and select worksheets

Example 03

Detect the header row automatically

Example 04

Read selected rows and columns

Example 05

Read cells, formulas, dates, and metadata

Example 06

Inspect an XLSX workbook without materializing rows

Example 07

List worksheets and inspect their dimensions

Example 08

Find inspection metadata for one worksheet

Example 09

Count rows without building a complete array

Example 10

Select an optional sheet or use the active sheet

Example 11

Check for data rows before collecting an array