MNB PHPExcelDeveloper Guide
v2.0.5
Database module

Column Mapping and Validation

Preview headers, suggest mappings, normalize values, validate records, and preserve original source row numbers.

Updated

LevelIntermediateReading time10 minPackagemnb/mnb-phpexcel
ImportQualityAnalyzer::suggestColumnMap()DomainImporter::preview()ArrayValidator::validate()

What you will learn

  • Preview source columns before database writes.
  • Combine explicit maps, aliases, and confidence-based suggestions.
  • Report failures using the original source row number.

Install the source reader you need#

DomainImporter resolves files through the shared reader registry. Install the format module for the incoming file, such as CSV, XLS, or XLSX, in addition to Database.

Preview before import#

PHP
use Mnb\PHPExcel\Import\DomainImporter;
use Mnb\PHPExcel\Domain\DomainImportType;

$importer = DomainImporter::create();
$preview = $importer->preview(DomainImportType::Products, 'products.xlsx', [
    'preview_rows' => 20,
    'header_row' => 'auto',
    'header_detection_rows' => 25,
    'mapping_min_confidence' => 0.60,
]);

print_r($preview['mapping']);
print_r($preview['sample_rows']);

Override mappings and validation#

PHP
$result = $importer->importProducts('products.xlsx', $pdo, 'products', [
    'column_map' => [
        'Product Code' => 'sku',
        'Item Name' => 'name',
        'Unit Price' => 'price',
    ],
    'rules' => [
        'sku' => ['required'],
        'name' => ['required'],
        'price' => ['required', 'numeric', 'min:0'],
    ],
    'strict_mapping' => true,
    'skip_invalid_rows' => true,
]);