mnb/mnb-phpexcel-xlsx

Native XLSX reader/writer with password encryption, document protection, formulas, pivots, and low-memory streaming for MNB PHPExcel.

Maintainers

Package info

github.com/mnagendrababu23/mnb-phpexcel-xlsx

pkg:composer/mnb/mnb-phpexcel-xlsx

Transparency log

Statistics

Installs: 16

Dependents: 2

Suggesters: 1

Stars: 0

Open Issues: 0

v2.0.3 2026-07-29 12:03 UTC

This package is auto-updated.

Last update: 2026-07-29 12:08:36 UTC


README

Independent native XLSX reader/writer with streaming, formulas, styles, charts, pivots, comments, hyperlinks, protection, and Office password encryption.

composer require mnb/mnb-phpexcel-xlsx:^2.0

For an XLSX-only installation, use Mnb\PHPExcel\Format\Xlsx—the MnbExcel facade belongs to the application package.

use Mnb\PHPExcel\Format\Xlsx;

$rows = Xlsx::read('report.xlsx')
    ->sheet('Data')
    ->withHeaderRow()
    ->toArray();

Xlsx::write($rows, 'report-copy.xlsx', ['with_header' => true]);

Import templates are also package-local and do not require the application package:

Xlsx::writeImportTemplate([
    'name' => ['header' => 'Name', 'required' => true],
    'status' => ['header' => 'Status', 'list' => ['Active', 'Inactive']],
], 'import-template.xlsx');

This package does not require, suggest, or call PhpSpreadsheet. It requires ext-iconv, ext-openssl, ext-libxml, and ext-zlib. ext-zip and ext-xmlreader remain optional performance extensions; package-local fallbacks are included.

Worksheet selection and errors

Worksheet numbers are 1-based. The first worksheet is selected automatically when sheet() is omitted.

$session = Xlsx::read('report.xlsx');

$session->sheet(1);        // first worksheet
$session->sheet('Data');   // worksheet by name
$session->sheetNames();    // inspect available names

Do not call sheet() without an argument. The library throws a SheetSelectionException with an actionable message, workbook path, caller location, and stable error code for missing, invalid, or unknown selections.

use Mnb\PHPExcel\Support\MnbExcelException;

try {
    $rows = Xlsx::read('report.xlsx')
        ->sheet('Missing')
        ->withHeaderRow()
        ->toArray();
} catch (MnbExcelException $e) {
    print_r($e->toErrorArray(debug: true));
}

Sheet discovery, active sheet, and empty worksheets

$session = Xlsx::read('report.xlsx');

if (!$session->hasSheet('Orders')) {
    $session = $session->activeSheet();
} else {
    $session = $session->sheet('Orders');
}

echo $session->activeSheetName();
print_r($session->activeSheetInfo());

$data = $session->withHeaderRow(1);
if ($data->isEmpty()) {
    // The worksheet has zero data rows after the header/options are applied.
    return;
}

$data->assertHasRows();
foreach ($data->rows() as $row) {
    // Process data.
}

inspect() now includes an active_sheet entry with a 1-based index and worksheet name. XLSX active-sheet detection reads the workbook's activeTab; workbooks without that metadata safely fall back to the first worksheet.