MNB PHPExcelDeveloper Guide

Automation examples

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

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

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

3
examples
2
documented methods
Example 01

Record Macro

preserveAdvancedObjectsFrom()
record-macro.php
<?php

declare(strict_types=1);

/*
Summary:
    Use Excel to record the macro in a trusted .xlsm template; PHP supplies fresh data without
    running the macro.

Implementation note:
    MNB PHPExcel never records or executes macros. Treat macro-enabled templates as executable
    content and allow only approved files.
*/

use Mnb\PHPExcel\MnbExcel;

MnbExcel::fromArray($rows)
    ->withHeader()
    ->preserveAdvancedObjectsFrom('templates/monthly-report.xlsm')
    ->save('monthly-report-output.xlsm');