MNB PHPExcelDeveloper Guide

Basic examples

Basic 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.

9examples in this category
21supported categories
5implementation paths
Monolithic library

Basic 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.

9
examples
21
documented methods
Example 01

Create a workbook

MnbExcel::fromArray()withHeader()save()
create-a-workbook.php
<?php

declare(strict_types=1);

/*
Summary:
    Create an XLSX workbook from associative PHP rows and use the array keys as the header row.

Implementation note:
    The output contains one worksheet named Sheet1. Use fromWorkbookArray() when several worksheets
    are required.
*/

use Mnb\PHPExcel\MnbExcel;

$rows = [
    ['ID' => 1_001, 'Product' => 'Laptop', 'Price' => 1_249],
    ['ID' => 1_002, 'Product' => 'Monitor', 'Price' => 349],
];

MnbExcel::fromArray($rows)
    ->withHeader()
    ->save('products.xlsx');