MNB PHPExcelDeveloper Guide
v2.0.5

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
21focused categories
5implementation paths
01
Remove Duplicates

Deduplicate rows by a stable business key before generating the workbook.

EasyPHP preprocessing
MnbExcel::fromArray()
remove-duplicates.php
<?php

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');
02
Text to Columns

Split a delimited source field into independent workbook columns.

EasyPHP preprocessing
array_map()MnbExcel::fromArray()
text-to-columns.php
<?php

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');
03
Flash Fill

Reproduce a predictable Flash Fill transformation in PHP so the rule is explicit and testable.

EasyPHP preprocessing
array_map()MnbExcel::fromArray()
flash-fill.php
<?php

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');
04
Power Query Import

Build a repeatable PHP ETL pipeline that reads source data, transforms it, and writes a clean XLSX output.

AdvancedPHP preprocessing
MnbExcel::read()rows()MnbExcel::fromArray()
power-query-import.php
<?php

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');