MNB PHPExcelDeveloper Guide
Use cases

Migrate from PHPExcel to PHP 8

Replace legacy PHPExcel installation and workbook patterns with Composer packages, the MnbExcel facade, read sessions, and modern workbook builders.

Updated

PHP 8.1+Full packageMigration
LevelIntermediateReading time12 minPackagemnb/mnb-phpexcel
MnbExcel::read()MnbExcel::fromArray()ReadSession::rows()WorkbookBuilder::save()

What you will learn

  • Replace manual includes with Composer autoloading.
  • Translate workbook loading and row iteration to read sessions.
  • Translate array exports to a modern workbook builder.

Install the modern package#

Terminal
composer require mnb/mnb-phpexcel:^2.0

Replace workbook loading and worksheet iteration#

PHP
$objPHPExcel = PHPExcel_IOFactory::load('orders.xlsx');
$worksheet = $objPHPExcel->getSheetByName('Orders');

foreach ($worksheet->getRowIterator() as $row) {
    // Read cell iterators manually.
}

Replace workbook creation from arrays#

PHP
$excel = new PHPExcel();
$sheet = $excel->getActiveSheet();
$sheet->fromArray($rows, null, 'A1');
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$writer->save('report.xlsx');

Migration contract#

Installation
Composer package and Composer autoloading.
Reading model
ReadSession with chainable configuration and explicit terminal methods.
Writing model
WorkbookBuilder with chainable workbook configuration and save().
Return types
Generators, native arrays, structured arrays, scalar values, and builder objects are documented explicitly.
Large files
Use row streaming and chunks instead of materializing a complete workbook object when the job is record-oriented.
Migration strategy
Move one workflow at a time and verify generated workbooks in Excel or LibreOffice.
ReturnsReadSession or WorkbookBuilderShapeOne migrated workflow at a time
Expected output
Legacy loader → MnbExcel::read()
Worksheet iteration → rows()
fromArray + writer → MnbExcel::fromArray()->save()

Preserve regression fixtures so values, formulas, sheet names, formatting, and output files remain verifiable.

Continue the migration#