MNB PHPExcelDeveloper Guide
v2.0.5
Large files

Stream Large Exports

Write database-sized XLSX or partitioned CSV ZIP exports without building a complete workbook in memory.

Updated

LevelAdvancedReading time11 minPackagemnb/mnb-phpexcel
MnbExcel::largeExport()largeExportFromSql()LargeXlsxWriteSession::save()saveCsvZip()

What you will learn

  • Export from generators or PDO cursors.
  • Split sheets before Excel row limits.
  • Use CSV ZIP when table volume is more important than workbook formatting.

Export a generator#

PHP
MnbExcel::largeExport($rowGenerator)
    ->sheetName('Orders')
    ->withHeader()
    ->freezeHeader()
    ->autoFilter()
    ->formatColumn('Amount', 'currency')
    ->autoSplitSheets(true)
    ->progress($progressCallback, 5000)
    ->save('orders.xlsx');

Export directly from SQL#

PHP
MnbExcel::largeExportFromSql(
    $pdo,
    'SELECT id, customer, amount, created_at FROM orders ORDER BY id'
)
    ->formatColumn('amount', 'decimal')
    ->save('orders.xlsx');

Use partitioned CSV ZIP for extreme table exports#

PHP
MnbExcel::largeExport($rowGenerator)
    ->withHeader()
    ->csvRowsPerFile(500000)
    ->saveCsvZip('orders-parts.zip');

CSV ZIP sacrifices styles, images, formulas, and workbook objects in exchange for simple, scalable table delivery.