Runnable PHP Excel Examples
Preview documented row mapping, chunking, and validation behavior in the browser, then download complete PHP scripts for local execution.
Updated
PHP 8.1+Full packageBrowser previewDownloadable examples
Available sincev2.0.5Version guide
What you will learn
- See expected data transformations before running Composer code locally.
- Download complete scripts using the included sample workbooks.
- Understand the security boundary between a browser preview and real PHP execution.
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”.
02 · Large files
Split streamed rows into fixed-size chunks
foreach ($session->chunk(500) as $batch) {
processBatch($batch);
}
Output
Press “Run preview”.
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”.
Run the downloaded scripts locally#
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.txtThe downloaded scripts expect the documentation sample workbooks under downloads/samples. Adjust the paths when copying them into another project.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue