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
21focused categories
5implementation paths
01Record MacroUse Excel to record the macro in a trusted .xlsm template; PHP supplies fresh data without running the macro.
MediumTrusted template+
Use Excel to record the macro in a trusted .xlsm template; PHP supplies fresh data without running the macro.
preserveAdvancedObjectsFrom()<?php
use Mnb\PHPExcel\MnbExcel;
MnbExcel::fromArray($rows)
->withHeader()
->preserveAdvancedObjectsFrom('templates/monthly-report.xlsm')
->save('monthly-report-output.xlsm');02Edit VBA MacroEdit VBA in Excel or a dedicated VBA tool, then preserve the approved macro project while refreshing workbook data.
AdvancedTrusted template+
Edit VBA in Excel or a dedicated VBA tool, then preserve the approved macro project while refreshing workbook data.
MnbExcel::validateUpload()preserveAdvancedObjectsFrom()<?php
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');03Create User FormCreate the VBA UserForm in a trusted macro-enabled template and preserve it while replacing worksheet data.
AdvancedTrusted template+
Create the VBA UserForm in a trusted macro-enabled template and preserve it while replacing worksheet data.
preserveAdvancedObjectsFrom()<?php
use Mnb\PHPExcel\MnbExcel;
MnbExcel::fromWorkbookArray([
'Data' => $rows,
'Lists' => $dropdownValues,
])
->withHeader()
->preserveAdvancedObjectsFrom('templates/intake-userform.xlsm')
->save('intake-userform-output.xlsm');Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue