MNB PHPExcelDeveloper Guide

Lookup examples

Lookup 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
21supported categories
5implementation paths
Monolithic library

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

4
examples
2
documented methods
Example 01

VLOOKUP

MnbExcel::formula()MnbExcel::fromWorkbookArray()
vlookup.php
<?php

declare(strict_types=1);

/*
Summary:
    Look up a key in the first column of a vertical table and return a value from another column.

Implementation note:
    Use FALSE for an exact match unless an intentionally sorted approximate lookup table is used.
*/

use Mnb\PHPExcel\MnbExcel;

$orders = [
    ['SKU' => 'P-100', 'Product' => MnbExcel::formula('VLOOKUP(A2,Products!A:C,2,FALSE)', 'Laptop')],
];
$products = [
    ['SKU' => 'P-100', 'Product' => 'Laptop', 'Price' => 1_249],
    ['SKU' => 'P-200', 'Product' => 'Monitor', 'Price' => 349],
];

MnbExcel::fromWorkbookArray(['Orders' => $orders, 'Products' => $products])
    ->withHeader()
    ->save('vlookup.xlsx');