MNB PHPExcelDeveloper Guide

Security examples

Security 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
21supported categories
5implementation paths
Monolithic library

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

4
examples
12
documented methods
Example 01

Prevent spreadsheet formula injection

MnbExcel::scanCells()cellSafety()formulaPolicy()MnbExcel::text()
prevent-spreadsheet-formula-injection.php
<?php

declare(strict_types=1);

/*
Summary:
    Scan untrusted rows for formula-like text, escape dangerous CSV cells, and block risky explicit
    formulas before writing.

Implementation note:
    Explicit formulas created with MnbExcel::formula() are checked by the formula guard.
    Formula-like untrusted text is escaped according to the output policy.
*/

use Mnb\PHPExcel\MnbExcel;

$rows = [
    [
        'name' => 'Ava',
        'phone' => MnbExcel::text('0987654321'),
        'note' => '=HYPERLINK("https://evil.example","Open")',
    ],
];

$scan = MnbExcel::scanCells($rows);

if ($scan['total_issues'] > 0) {
    print_r($scan['issues']);
}

MnbExcel::fromArray($rows)
    ->withHeader()
    ->cellSafety(['max_text_length' => 32_767])
    ->formulaPolicy('safe')
    ->save(__DIR__ . '/output/safe-contacts.csv');