Skip to content
MNB PHPExcelDeveloper Guide
AI

Getting started

Use the Main Facade and Specialized APIs

Use MnbExcel by default, then move to read sessions, workbook builders, or specialized format classes when needed.

Level
Beginner
Reading time
6 min
Package
mnb/mnb-phpexcel
Updated

Use MnbExcel as the default entry point#

PHP
use Mnb\PHPExcel\MnbExcel;

$session = MnbExcel::read('orders.xlsx');
MnbExcel::fromArray($rows)->save('orders-copy.xlsx');

The direct format class is optional and is included in the same main package.

Use MnbExcel for complete application workflows#

PHP
use Mnb\PHPExcel\MnbExcel;

MnbExcel::importProducts('products.xlsx', $pdo, 'products');
MnbExcel::emailGeneratedExcel($report, $to, $subject);
MnbExcel::runScheduler($scheduler);

The facade is installed by the main package and coordinates all supported formats and workflows.

Use ReadSession for a read pipeline#

PHP
$session = MnbExcel::read('orders.xlsx')
    ->sheet('Orders')
    ->autoDetectHeader()
    ->range(2, null, 'A', 'H')
    ->projectColumns(['Order ID', 'Amount'])
    ->streaming();

foreach ($session->chunks(1000) as $chunk) {
    // Process a consistent batch.
}

Use WorkbookBuilder for output composition#

PHP
$workbook = MnbExcel::fromWorkbookArray([
    'Data' => $rows,
    'Summary' => [],
]);

$workbook
    ->withHeader()
    ->addChart(/* ... */)
    ->encryptWithPassword($password)
    ->save('report.xlsx');