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
MnbExcel::formula()MnbExcel::fromWorkbookArray()<?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');MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Look up a value in the first row of a horizontal table.
Implementation note:
Horizontal lookup tables are less common than vertical tables but remain useful for compact
parameter sheets.
*/
use Mnb\PHPExcel\MnbExcel;
$summary = [[
'Band' => 'Standard',
'Discount' => MnbExcel::formula('HLOOKUP(A2,Bands!B1:E2,2,FALSE)', 0.05),
]];
$bands = [
['Label' => 'Discount', 'Basic' => 0, 'Standard' => 0.05, 'Premium' => 0.10],
];
MnbExcel::fromWorkbookArray(['Summary' => $summary, 'Bands' => $bands])
->withHeader()
->percentageColumns(['Discount'])
->save('hlookup.xlsx');MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Use a modern exact lookup that separates the lookup range from the return range and supports a
not-found value.
Implementation note:
XLOOKUP requires a recent Excel version. Use INDEX + MATCH when older clients must be supported.
*/
use Mnb\PHPExcel\MnbExcel;
$orders = [[
'SKU' => 'P-200',
'Price' => MnbExcel::formula('XLOOKUP(A2,Products!A:A,Products!C:C,"Unknown")', 349),
]];
$products = [
['SKU' => 'P-100', 'Product' => 'Laptop', 'Price' => 1_249],
['SKU' => 'P-200', 'Product' => 'Monitor', 'Price' => 349],
];
MnbExcel::fromWorkbookArray(['Orders' => $orders, 'Products' => $products])
->withHeader()
->currencyColumns(['Price'], '$')
->save('xlookup.xlsx');MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Combine MATCH to find a row and INDEX to return a value from a separate column.
Implementation note:
INDEX + MATCH can look left or right and works in older Excel releases.
*/
use Mnb\PHPExcel\MnbExcel;
$orders = [[
'SKU' => 'P-100',
'Product' => MnbExcel::formula('INDEX(Products!B:B,MATCH(A2,Products!A:A,0))', 'Laptop'),
]];
$products = [
['SKU' => 'P-100', 'Product' => 'Laptop'],
['SKU' => 'P-200', 'Product' => 'Monitor'],
];
MnbExcel::fromWorkbookArray(['Orders' => $orders, 'Products' => $products])
->withHeader()
->save('index-match.xlsx');No matching example found.Try a method name, task, or result.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue