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
preserveAdvancedObjectsFrom()<?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');MnbExcel::validateUpload()preserveAdvancedObjectsFrom()<?php
declare(strict_types=1);
/*
Summary:
Edit VBA in Excel or a dedicated VBA tool, then preserve the approved macro project while
refreshing workbook data.
Implementation note:
The library does not parse, modify, or execute VBA source. Review and sign macro projects
outside the PHP process.
*/
use Mnb\PHPExcel\MnbExcel;
$inspection = MnbExcel::validateUpload('templates/approved-automation.xlsm', [
'allowed_extensions' => ['xlsm'],
'reject_macros' => false,
]);
if (!($inspection['features']['macros'] ?? false)) {
throw new RuntimeException('Expected an approved macro project.');
}
MnbExcel::fromArray($rows)
->withHeader()
->preserveAdvancedObjectsFrom('templates/approved-automation.xlsm')
->save('automation-output.xlsm');preserveAdvancedObjectsFrom()<?php
declare(strict_types=1);
/*
Summary:
Create the VBA UserForm in a trusted macro-enabled template and preserve it while replacing
worksheet data.
Implementation note:
UserForms are VBA components. They cannot be generated by the XLSX builder and must come from a
reviewed template.
*/
use Mnb\PHPExcel\MnbExcel;
MnbExcel::fromWorkbookArray([
'Data' => $rows,
'Lists' => $dropdownValues,
])
->withHeader()
->preserveAdvancedObjectsFrom('templates/intake-userform.xlsm')
->save('intake-userform-output.xlsm');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