Data examples
Data 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.
4examples in this category
21supported categories
5implementation paths
Monolithic library
Data 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.
- 4
- examples
- 4
- documented methods
MnbExcel::fromArray()<?php
declare(strict_types=1);
/*
Summary:
Deduplicate rows by a stable business key before generating the workbook.
Implementation note:
Choose an explicit key. Comparing entire rows can keep records that are logically duplicates but
differ in whitespace or case.
*/
use Mnb\PHPExcel\MnbExcel;
$unique = [];
foreach ($rows as $row) {
$key = strtolower(trim((string) $row['Email']));
$unique[$key] ??= $row;
}
MnbExcel::fromArray(array_values($unique))
->withHeader()
->save('unique-contacts.xlsx');array_map()MnbExcel::fromArray()<?php
declare(strict_types=1);
/*
Summary:
Split a delimited source field into independent workbook columns.
Implementation note:
Use str_getcsv() rather than explode() when quoted delimiters must be handled.
*/
use Mnb\PHPExcel\MnbExcel;
$expanded = array_map(static function (array $row): array {
[$city, $state] = array_pad(array_map('trim', explode(',', $row['Location'], 2)), 2, '');
return $row + ['City' => $city, 'State' => $state];
}, $rows);
MnbExcel::fromArray($expanded)
->withHeader()
->save('text-to-columns.xlsx');array_map()MnbExcel::fromArray()<?php
declare(strict_types=1);
/*
Summary:
Reproduce a predictable Flash Fill transformation in PHP so the rule is explicit and testable.
Implementation note:
Excel Flash Fill infers a pattern interactively. Server-side exports should use an explicit
transformation instead.
*/
use Mnb\PHPExcel\MnbExcel;
$filled = array_map(static function (array $row): array {
$parts = preg_split('/\s+/', trim($row['Full name'])) ?: [];
$row['Initials'] = implode('', array_map(
static fn (string $part): string => strtoupper(substr($part, 0, 1)),
$parts
));
return $row;
}, $rows);
MnbExcel::fromArray($filled)
->withHeader()
->save('flash-fill-equivalent.xlsx');MnbExcel::read()rows()MnbExcel::fromArray()<?php
declare(strict_types=1);
/*
Summary:
Build a repeatable PHP ETL pipeline that reads source data, transforms it, and writes a clean
XLSX output.
Implementation note:
MNB PHPExcel does not author Power Query M definitions. Use PHP ETL for server workflows or
preserve a trusted workbook that already contains queries.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = MnbExcel::read('supplier.csv')
->sheet(1)
->withHeader()
->rows();
$clean = array_map(static fn (array $row): array => [
'SKU' => strtoupper(trim($row['sku'])),
'Description' => trim($row['description']),
'Price' => (float) $row['price'],
], $rows);
MnbExcel::fromArray($clean)
->withHeader()
->currencyColumns(['Price'], '$')
->save('supplier-import.xlsx');No matching example found.Try a method name, task, or result.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue