Skip to content
MNB PHPExcelDeveloper Guide
AI

Interactive tools

Runnable PHP Excel Examples

Preview documented row mapping, chunking, and validation behavior in the browser, then download complete PHP scripts for local execution.

Level
Beginner to intermediate
Reading time
10 min
Package
mnb/mnb-phpexcel
Updated
PHP 8.1+Full packageBrowser previewDownloadable examples
Available sincev2.0.5Version guide

Run safe previews#

Safe browser previewThe controls run predefined JavaScript data transformations that mirror the PHP examples. No PHP code is evaluated in the browser.
01 · Reading

Map a header row and skip empty records

$rows = MnbExcel::read($path)
    ->sheet('Customers')
    ->withHeaderRow(1)
    ->toArray(['skip_empty_rows' => true]);
Output
Press “Run preview”.
Download complete PHP example
02 · Large files

Split streamed rows into fixed-size chunks

foreach ($session->chunk(500) as $batch) {
    processBatch($batch);
}
Output
Press “Run preview”.
Download complete PHP example
03 · Imports

Validate required fields before import

foreach ($rows as $index => $row) {
    if (($row['sku'] ?? '') === '') {
        $errors[$index + 2][] = 'SKU is required';
    }
}
Output
Press “Run preview”.
Download complete PHP example

Run the downloaded scripts locally#

Terminal
composer require mnb/mnb-phpexcel:^2.0
php downloads/examples/read-customers.php.txt
php downloads/examples/stream-chunks.php.txt
php downloads/examples/validate-import.php.txt

The downloaded scripts expect the documentation sample workbooks under downloads/samples. Adjust the paths when copying them into another project.