MNB PHPExcelDeveloper Guide
Migration guides

PHPExcel PHP 8 Alternative and Migration Guide

Move historical PHPExcel-style code to a modern PHP 8.1+ spreadsheet API with Composer, native XLSX support and practical migration examples.

Updated

LevelIntermediateReading time12 minPackagemnb/mnb-phpexcel
MnbExcel::read()ReadSession::withHeaderRow()ReadSession::toArray()MnbExcel::fromArray()WorkbookBuilder::save()

What you will learn

  • Install a modern PHP 8.1+ spreadsheet package with Composer.
  • Translate common workbook-reading and report-writing patterns to MNB PHPExcel.
  • Keep migration code explicit about sheets, headers, row types, formulas and unsupported legacy features.

Install the modern PHP 8 package#

Terminal
composer require mnb/mnb-phpexcel:^2.0

The full package provides the MnbExcel facade and all documented modules. The individual XLSX package provides Mnb\PHPExcel\Format\Xlsx for focused XLSX-only projects.

Map familiar workbook tasks to the current API#

Migration taskMNB PHPExcel APIRecommended behavior
Open an XLSX workbookMnbExcel::read($path)Inspect the file and worksheet names before collecting rows.
Select a worksheetsheet(1) or sheet("Orders")Worksheet numbers are 1-based; prefer names for business imports.
Use the first row as headerswithHeaderRow(1)Keep the header-row number explicit in production code.
Read all rowstoArray()Use for bounded files; stream with rows() or largeRead() for large workbooks.
Read one cellcell("B2")Use direct cell access when a workbook acts like a configuration document.
Create an XLSX reportMnbExcel::fromArray($rows)->save($path)Use the workbook builder for styles, charts, validation and protection.

Migrate a common read workflow#

read-orders.php
<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use Mnb\PHPExcel\MnbExcel;
use Mnb\PHPExcel\Support\MnbExcelException;

try {
    $workbook = MnbExcel::read(__DIR__ . '/orders.xlsx');

    $sheet = $workbook->sheetIfExists('Orders')
        ?? $workbook->activeSheet();

    $rows = $sheet
        ->withHeaderRow(1)
        ->withOptions(['skip_empty_rows' => true])
        ->toArray();

    foreach ($rows as $row) {
        echo ($row['Order ID'] ?? '') . PHP_EOL;
    }
} catch (MnbExcelException $exception) {
    print_r($exception->toErrorArray(debug: true));
}

Migrate a common write workflow#

write-orders.php
<?php

use Mnb\PHPExcel\MnbExcel;

$rows = [
    ['Order ID' => 1001, 'Customer' => 'Acme', 'Amount' => 249.95],
    ['Order ID' => 1002, 'Customer' => 'Northwind', 'Amount' => 180.00],
];

MnbExcel::fromArray($rows)
    ->withHeader()
    ->freezeHeader()
    ->autoFilter()
    ->autoWidth()
    ->save(__DIR__ . '/orders-report.xlsx');

Review compatibility before replacing production code#

  • Test representative workbooks from Microsoft Excel and LibreOffice.
  • Verify formulas, dates, number formats, merged ranges and protected files explicitly.
  • Use native XLSX for modern workbooks and the native BIFF8 XLS package only for required legacy files.
  • Run streaming tests with the largest real workbook your application accepts.
  • Keep unsupported legacy features visible in migration notes rather than silently dropping them.

Continue with the PHP Excel reader guide, PHP Excel writer guide, and native PHP XLSX library overview.