MNB PHPExcelDeveloper Guide
v2.0.5
XLSX module

XLSX Inspection and Security

Inspect file and sheet information without loading rows, then validate encryption, uploads, and package integrity.

Updated

LevelIntermediateReading time9 minPackagemnb/mnb-phpexcel
ReadSession::inspect()ReadSession::sheetNames()ReadSession::countRows()Xlsx::isEncrypted()MnbExcel::validateXlsx()

What you will learn

  • Build a lightweight upload preview before reading records.
  • Choose declared or accurate row-count modes.
  • Distinguish encrypted files, unsafe uploads, and invalid packages.

Inspect workbook metadata without row arrays#

PHP
$session = MnbExcel::read('orders.xlsx');
$inspection = $session->inspect();
$sheetNames = $session->sheetNames();

$orders = null;
foreach ($inspection['sheets'] as $sheet) {
    if ($sheet['name'] === 'Orders') {
        $orders = $sheet;
        break;
    }
}

$filledRows = $session
    ->sheet('Orders')
    ->withHeaderRow()
    ->countRows(['skip_empty_rows' => true]);

inspect() reads package structure, workbook relationships, worksheet dimensions, visibility, warnings, and security signals without materializing row arrays. countRows() then streams normalized rows for the selected worksheet when an application needs a populated-record count.

Choose a row-count meaning#

ModeMeaningCost
declared_last_rowLast row from the worksheet dimension stored in inspection metadata.Fastest; relies on producer metadata.
row_tag_countPhysical <row> elements found in worksheet XML.Fast package inspection.
countRows()Rows yielded by the normal reader after header, empty-row, range, and projection options.Streams cell data; does not build a complete row array.

Detect and handle encryption#

PHP
if (Xlsx::isEncrypted('finance.xlsx')) {
    printf("Mode: %s\n", Xlsx::encryptionMode('finance.xlsx') ?? 'unknown');
}

$rows = MnbExcel::read('finance.xlsx', [
    'password' => getenv('XLSX_PASSWORD'),
])->sheet('Summary')->rows();

Validate untrusted workbooks before processing#

  • Apply file-size, ZIP-entry, compression-ratio, path, macro, external-link, and encryption policies.
  • Keep uploaded files outside the public root and use application-generated filenames.
  • Limit formulas, source rows, columns, shared strings, and processing time before large imports.
  • Run XLSX integrity validation after generating critical reports.

See the security overview and production checklist for complete controls.