MNB PHPExcelDeveloper Guide

XLSX · Security

XLSX security examples.

Package-local, copy-ready examples organized like the classes and methods reference. Open one example at a time, search by method, and jump from the right-side index.

Packagemnb/mnb-phpexcel-xlsx:^2.0Reference1 examples · 4 methods
XLSX individual library

Security examples with copy-ready, production-minded PHP.

Every snippet uses mnb/mnb-phpexcel-xlsx or its declared Core dependency. Each copied snippet includes strict typing, a concise summary, implementation guidance, readable limits, and a safe fixture check.

1
examples
4
documented methods
Example 01

Detect, encrypt, and decrypt XLSX files

Open related guide
Xlsx::encryptFile()Xlsx::isEncrypted()Xlsx::encryptionMode()Xlsx::decryptFile()
detect-encrypt-and-decrypt-xlsx-files.php
<?php

declare(strict_types=1);

/*
Summary:
    Check Office encryption, inspect its mode, and create or remove password-to-open protection.

Implementation note:
    Keep passwords outside source control and logs. Password-to-open encryption is separate from
    worksheet or workbook editing protection.
*/

use Mnb\PHPExcel\Format\Xlsx;

$source = __DIR__ . '/confidential.xlsx';
$encrypted = __DIR__ . '/confidential-protected.xlsx';
$decrypted = __DIR__ . '/confidential-open.xlsx';

Xlsx::encryptFile($source, $encrypted, getenv('WORKBOOK_PASSWORD'), [
    'mode' => 'agile',
]);

var_dump(Xlsx::isEncrypted($encrypted));
var_dump(Xlsx::encryptionMode($encrypted));

Xlsx::decryptFile($encrypted, $decrypted, getenv('WORKBOOK_PASSWORD'));