Skip to content
MNB PHPExcelDeveloper Guide
AI

Imports

Stream Large XLSX Files into a Database

Use the optional database-XLSX integration package for bounded-memory worksheet chunks, PDO batches, resume manifests, and failed rows.

Level
Advanced
Reading time
13 min
Package
mnb/mnb-phpexcel
Updated
LargeExcelDatabaseImportEngine::importToSql()importWorkbookToSql()MnbExcel::largeImportToSql()

Use the direct integration API#

PHP
use Mnb\PHPExcel\Large\LargeExcelDatabaseImportEngine;

$result = (new LargeExcelDatabaseImportEngine())->importToSql(
    'products.xlsx',
    $pdo,
    'products',
    [
        'sheet' => 'Products',
        'with_header' => true,
        'chunk_size' => 2000,
        'batch_size' => 500,
        'duplicate_strategy' => 'update',
        'unique_by' => ['sku'],
        'resume' => true,
        'manifest_path' => __DIR__ . '/storage/products-import.json',
        'failed_rows_csv' => __DIR__ . '/storage/products-failed.csv',
    ]
);

Use the application facade when installed#

PHP
$result = MnbExcel::largeImportToSql(
    'products.xlsx',
    $pdo,
    'products',
    [
        'sheet' => 'Products',
        'chunk_size' => 2000,
        'batch_size' => 500,
        'resume' => true,
    ]
);

MnbExcel belongs to mnb/mnb-phpexcel; it is not available from an isolated XLSX or Database installation.

Keep the generic package independent#