MNB PHPExcelDeveloper Guide
v2.0.5

Web workflows examples

Web workflows Excel examples, explained clearly.

Open a focused example to see the implementation path, copy-ready PHP, expected workbook behavior, and the production boundary that matters.

4examples in this category
21focused categories
5implementation paths
01
Validate a spreadsheet upload

Validate the real uploaded file size, extension, MIME information, filename, XLSX ZIP safety, macros, links, and encryption policy.

MediumDirect API
MnbExcel::validateUpload()MnbExcel::safeFileName()
validate-a-spreadsheet-upload.php
<?php

use Mnb\PHPExcel\MnbExcel;

$upload = MnbExcel::validateUpload($_FILES['spreadsheet'] ?? [], [
    'allowed_extensions' => ['xlsx', 'csv', 'tsv'],
    'max_size_mb' => 100,
    'reject_macros' => true,
    'reject_external_links' => true,
    'reject_encrypted' => true,
]);

if (!$upload['valid']) {
    http_response_code(422);
    header('Content-Type: application/json');
    echo json_encode($upload, JSON_THROW_ON_ERROR);
    exit;
}
02
Store an AJAX spreadsheet upload

Validate and atomically store an AJAX upload, then return a safe HTTP-oriented result containing the stored path and digest.

MediumDirect API
MnbExcel::handleAjaxUpload()MnbExcel::storagePath()
store-an-ajax-spreadsheet-upload.php
<?php

use Mnb\PHPExcel\MnbExcel;

header('Content-Type: application/json; charset=UTF-8');

$response = MnbExcel::handleAjaxUpload(
    $_FILES['spreadsheet'] ?? [],
    [
        'directory' => __DIR__ . '/storage/uploads',
        'allowed_extensions' => ['xlsx', 'xls', 'ods', 'csv', 'tsv'],
        'max_size_mb' => 250,
    ]
);

http_response_code((int) ($response['http_status'] ?? 200));
echo json_encode($response, JSON_THROW_ON_ERROR);
03
Import multiple uploaded product files

Process several uploaded product workbooks with one domain schema, shared duplicate rules, and aggregate progress reporting.

AdvancedDirect API
MnbExcel::importDomainFiles()MnbExcel::validateUpload()
import-multiple-uploaded-product-files.php
<?php

use Mnb\PHPExcel\MnbExcel;

$files = [
    __DIR__ . '/storage/uploads/products-east.xlsx',
    __DIR__ . '/storage/uploads/products-west.xlsx',
];

$result = MnbExcel::importDomainFiles(
    'products',
    $files,
    __DIR__ . '/config/database.php',
    'products',
    [
        'stop_on_error' => false,
        'import_options' => [
            'duplicate_strategy' => 'update',
            'unique_by' => ['sku'],
        ],
        'progress' => static function (array $state): void {
            printf(
                "%d/%d files completed\n",
                $state['files_completed'],
                $state['files_total']
            );
        },
    ]
);
04
Queue a product import

Move a long-running domain import out of the request cycle using the built-in durable filesystem queue and worker.

AdvancedDirect API
MnbExcel::queue()enqueueDomainImport()work()MnbExcel::pdoQueue()
queue-a-product-import.php
<?php

use Mnb\PHPExcel\MnbExcel;

$queueDirectory = __DIR__ . '/storage/queue';
$databaseConfig = __DIR__ . '/config/database.php';

$queue = MnbExcel::queue($queueDirectory);
$job = $queue->enqueueDomainImport(
    'products',
    __DIR__ . '/storage/uploads/products.xlsx',
    $databaseConfig,
    'products',
    [
        'duplicate_strategy' => 'update',
        'unique_by' => ['sku'],
    ]
);

printf("Queued job: %s\n", $job->id);

// Run this part from CLI, cron, or a process manager.
$result = $queue->work([
    'max_jobs' => 20,
    'max_attempts' => 3,
    'retry_delay_seconds' => 30,
]);