MNB PHPExcelDeveloper Guide

Imports examples

Imports 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.

6examples in this category
21supported categories
5implementation paths
Monolithic library

Imports examples with copy-ready, production-minded PHP.

Each example identifies the exact methods it uses and can be opened independently from the right-side index.

6
examples
14
documented methods
Example 01

Preview import quality

MnbExcel::previewImport()ReadSession::previewImport()
preview-import-quality.php
<?php

declare(strict_types=1);

/*
Summary:
    Inspect missing columns, unexpected columns, duplicate candidates, empty values, and sample rows
    before validation or database writes.

Implementation note:
    ReadSession::previewImport() combines the read and preview steps when the source file is already
    represented by a read session.
*/

use Mnb\PHPExcel\MnbExcel;

$workbookPath = __DIR__ . '/fixtures/students.csv';

if (!is_file($workbookPath)) {
    throw new RuntimeException(sprintf('Workbook not found: %s', $workbookPath));
}

$rows = MnbExcel::read($workbookPath)
    ->withHeaderRow()
    ->toArray();

$preview = MnbExcel::previewImport($rows, [
    'required_columns' => ['student_id', 'name', 'email'],
    'allowed_columns' => ['student_id', 'name', 'email', 'phone'],
    'strict_columns' => true,
    'duplicate_by' => ['student_id'],
]);

print_r([
    'status' => $preview['status'],
    'total_rows' => $preview['total_rows'],
    'total_columns' => $preview['total_columns'],
    'warnings' => $preview['warnings'],
]);