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
21focused categories
5implementation paths
01VLOOKUPLook up a key in the first column of a vertical table and return a value from another column.
+
Look up a key in the first column of a vertical table and return a value from another column.
MnbExcel::formula()MnbExcel::fromWorkbookArray()<?php
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' => 1249],
['SKU' => 'P-200', 'Product' => 'Monitor', 'Price' => 349],
];
MnbExcel::fromWorkbookArray(['Orders' => $orders, 'Products' => $products])
->withHeader()
->save('vlookup.xlsx');02HLOOKUPLook up a value in the first row of a horizontal table.
+
Look up a value in the first row of a horizontal table.
MnbExcel::formula()<?php
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');03XLOOKUPUse a modern exact lookup that separates the lookup range from the return range and supports a not-found value.
+
Use a modern exact lookup that separates the lookup range from the return range and supports a not-found value.
MnbExcel::formula()<?php
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' => 1249],
['SKU' => 'P-200', 'Product' => 'Monitor', 'Price' => 349],
];
MnbExcel::fromWorkbookArray(['Orders' => $orders, 'Products' => $products])
->withHeader()
->currencyColumns(['Price'], '$')
->save('xlookup.xlsx');04INDEX + MATCHCombine MATCH to find a row and INDEX to return a value from a separate column.
+
Combine MATCH to find a row and INDEX to return a value from a separate column.
MnbExcel::formula()<?php
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');Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue