Use the Main Facade and Specialized APIs
Use MnbExcel by default, then move to read sessions, workbook builders, or specialized format classes when needed.
Updated
What you will learn
- Start with the MnbExcel facade for normal application code.
- Use specialized format classes only for format-specific operations.
- Recognize the objects returned by each API.
Use MnbExcel as the default entry point#
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#
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#
$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#
$workbook = MnbExcel::fromWorkbookArray([
'Data' => $rows,
'Summary' => [],
]);
$workbook
->withHeader()
->addChart(/* ... */)
->encryptWithPassword($password)
->save('report.xlsx');Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue