Additional unit tests for HLOOKUP() and VLOOKUP() and Examples for VLOOKUP()
This commit is contained in:
parent
3540a275b9
commit
70a518981c
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
|
||||
require __DIR__ . '/../../Header.php';
|
||||
|
||||
$helper->log('Searches for a value in the top row of a table or an array of values,
|
||||
and then returns a value in the same column from a row you specify
|
||||
in the table or array.');
|
||||
|
||||
// Create new PhpSpreadsheet object
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$worksheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$data = [
|
||||
['ID', 'First Name', 'Last Name', 'Salary'],
|
||||
[72, 'Emily', 'Smith', 64901, null, 'ID', 53, 66, 56],
|
||||
[66, 'James', 'Anderson', 70855, null, 'Salary'],
|
||||
[14, 'Mia', 'Clark', 188657],
|
||||
[30, 'John', 'Lewis', 97566],
|
||||
[53, 'Jessica', 'Walker', 58339],
|
||||
[56, 'Mark', 'Reed', 125180],
|
||||
[79, 'Richard', 'Lopez', 91632],
|
||||
];
|
||||
|
||||
$worksheet->fromArray($data, null, 'B2');
|
||||
|
||||
$worksheet->getCell('H4')->setValue('=VLOOKUP(H3, B3:E9, 4, FALSE)');
|
||||
$worksheet->getCell('I4')->setValue('=VLOOKUP(I3, B3:E9, 4, FALSE)');
|
||||
$worksheet->getCell('J4')->setValue('=VLOOKUP(J3, B3:E9, 4, FALSE)');
|
||||
|
||||
for ($column = 'H'; $column !== 'K'; ++$column) {
|
||||
$cell = $worksheet->getCell("{$column}4");
|
||||
$helper->log("{$column}4: {$cell->getValue()} => {$cell->getCalculatedValue()}");
|
||||
}
|
||||
|
|
@ -1,304 +1,94 @@
|
|||
<?php
|
||||
|
||||
function orderGrid()
|
||||
{
|
||||
return [
|
||||
['Order ID', 10247, 10249, 10250, 10251, 10252, 10253],
|
||||
['Unit Price', 14.00, 18.60, 7.70, 16.80, 16.80, 64.80],
|
||||
['Quantity', 12, 9, 10, 6, 20, 40],
|
||||
];
|
||||
}
|
||||
|
||||
function partsGrid()
|
||||
{
|
||||
return [
|
||||
['Axles', 'Bearings', 'Bolts'],
|
||||
[4, 4, 9],
|
||||
[5, 7, 10],
|
||||
[6, 8, 11],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
[
|
||||
16.800000000000001,
|
||||
16.80,
|
||||
10251,
|
||||
[
|
||||
[
|
||||
'Order ID',
|
||||
10247,
|
||||
10249,
|
||||
10250,
|
||||
10251,
|
||||
10252,
|
||||
10253,
|
||||
],
|
||||
[
|
||||
'Unit Price',
|
||||
14.0,
|
||||
18.600000000000001,
|
||||
7.7000000000000002,
|
||||
16.800000000000001,
|
||||
16.800000000000001,
|
||||
64.799999999999997,
|
||||
],
|
||||
[
|
||||
'Quantity',
|
||||
12,
|
||||
9,
|
||||
10,
|
||||
6,
|
||||
20,
|
||||
40,
|
||||
],
|
||||
],
|
||||
orderGrid(),
|
||||
2,
|
||||
false,
|
||||
],
|
||||
[
|
||||
6.0,
|
||||
10251,
|
||||
[
|
||||
[
|
||||
'Order ID',
|
||||
10247,
|
||||
10249,
|
||||
10250,
|
||||
10251,
|
||||
10252,
|
||||
10253,
|
||||
],
|
||||
[
|
||||
'Unit Price',
|
||||
14.0,
|
||||
18.600000000000001,
|
||||
7.7000000000000002,
|
||||
16.800000000000001,
|
||||
16.800000000000001,
|
||||
64.799999999999997,
|
||||
],
|
||||
[
|
||||
'Quantity',
|
||||
12,
|
||||
9,
|
||||
10,
|
||||
6,
|
||||
20,
|
||||
40,
|
||||
],
|
||||
],
|
||||
orderGrid(),
|
||||
3,
|
||||
false,
|
||||
],
|
||||
[
|
||||
'#N/A',
|
||||
10248,
|
||||
[
|
||||
[
|
||||
'Order ID',
|
||||
10247,
|
||||
10249,
|
||||
10250,
|
||||
10251,
|
||||
10252,
|
||||
10253,
|
||||
],
|
||||
[
|
||||
'Unit Price',
|
||||
14.0,
|
||||
18.600000000000001,
|
||||
7.7000000000000002,
|
||||
16.800000000000001,
|
||||
16.800000000000001,
|
||||
64.799999999999997,
|
||||
],
|
||||
[
|
||||
'Quantity',
|
||||
12,
|
||||
9,
|
||||
10,
|
||||
6,
|
||||
20,
|
||||
40,
|
||||
],
|
||||
],
|
||||
orderGrid(),
|
||||
2,
|
||||
false,
|
||||
],
|
||||
[
|
||||
14.0,
|
||||
10248,
|
||||
[
|
||||
[
|
||||
'Order ID',
|
||||
10247,
|
||||
10249,
|
||||
10250,
|
||||
10251,
|
||||
10252,
|
||||
10253,
|
||||
],
|
||||
[
|
||||
'Unit Price',
|
||||
14.0,
|
||||
18.600000000000001,
|
||||
7.7000000000000002,
|
||||
16.800000000000001,
|
||||
16.800000000000001,
|
||||
64.799999999999997,
|
||||
],
|
||||
[
|
||||
'Quantity',
|
||||
12,
|
||||
9,
|
||||
10,
|
||||
6,
|
||||
20,
|
||||
40,
|
||||
],
|
||||
],
|
||||
orderGrid(),
|
||||
2,
|
||||
true,
|
||||
],
|
||||
[
|
||||
4,
|
||||
'Axles',
|
||||
[
|
||||
[
|
||||
'Axles',
|
||||
'Bearings',
|
||||
'Bolts',
|
||||
],
|
||||
[
|
||||
4,
|
||||
4,
|
||||
9,
|
||||
],
|
||||
[
|
||||
5,
|
||||
7,
|
||||
10,
|
||||
],
|
||||
[
|
||||
6,
|
||||
8,
|
||||
11,
|
||||
],
|
||||
],
|
||||
partsGrid(),
|
||||
2,
|
||||
true,
|
||||
],
|
||||
[
|
||||
7,
|
||||
'Bearings',
|
||||
[
|
||||
[
|
||||
'Axles',
|
||||
'Bearings',
|
||||
'Bolts',
|
||||
],
|
||||
[
|
||||
4,
|
||||
4,
|
||||
9,
|
||||
],
|
||||
[
|
||||
5,
|
||||
7,
|
||||
10,
|
||||
],
|
||||
[
|
||||
6,
|
||||
8,
|
||||
11,
|
||||
],
|
||||
],
|
||||
partsGrid(),
|
||||
3,
|
||||
false,
|
||||
],
|
||||
[
|
||||
5,
|
||||
'B',
|
||||
[
|
||||
[
|
||||
'Axles',
|
||||
'Bearings',
|
||||
'Bolts',
|
||||
],
|
||||
[
|
||||
4,
|
||||
4,
|
||||
9,
|
||||
],
|
||||
[
|
||||
5,
|
||||
7,
|
||||
10,
|
||||
],
|
||||
[
|
||||
6,
|
||||
8,
|
||||
11,
|
||||
],
|
||||
],
|
||||
partsGrid(),
|
||||
3,
|
||||
true,
|
||||
],
|
||||
[
|
||||
5,
|
||||
'B',
|
||||
[
|
||||
[
|
||||
'Axles',
|
||||
'Bearings',
|
||||
'Bolts',
|
||||
],
|
||||
[
|
||||
4,
|
||||
4,
|
||||
9,
|
||||
],
|
||||
[
|
||||
5,
|
||||
7,
|
||||
10,
|
||||
],
|
||||
[
|
||||
6,
|
||||
8,
|
||||
11,
|
||||
],
|
||||
],
|
||||
partsGrid(),
|
||||
3,
|
||||
null,
|
||||
],
|
||||
[
|
||||
11,
|
||||
'Bolts',
|
||||
[
|
||||
[
|
||||
'Axles',
|
||||
'Bearings',
|
||||
'Bolts',
|
||||
],
|
||||
[
|
||||
4,
|
||||
4,
|
||||
9,
|
||||
],
|
||||
[
|
||||
5,
|
||||
7,
|
||||
10,
|
||||
],
|
||||
[
|
||||
6,
|
||||
8,
|
||||
11,
|
||||
],
|
||||
],
|
||||
partsGrid(),
|
||||
4,
|
||||
],
|
||||
[
|
||||
'c',
|
||||
3,
|
||||
[
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
[
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
],
|
||||
[
|
||||
'd',
|
||||
'e',
|
||||
'f',
|
||||
],
|
||||
[1, 2, 3],
|
||||
['a', 'b', 'c'],
|
||||
['d', 'e', 'f'],
|
||||
],
|
||||
2,
|
||||
true,
|
||||
|
|
@ -307,11 +97,7 @@ return [
|
|||
3,
|
||||
3,
|
||||
[
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
[1, 2, 3],
|
||||
],
|
||||
1,
|
||||
true,
|
||||
|
|
|
|||
|
|
@ -1,293 +1,54 @@
|
|||
<?php
|
||||
|
||||
function densityGrid()
|
||||
{
|
||||
return [
|
||||
['Density', 'Viscosity', 'Temperature'],
|
||||
[0.457, 3.55, 500],
|
||||
[0.525, 3.25, 400],
|
||||
[0.616, 2.93, 300],
|
||||
[0.675, 2.75, 250],
|
||||
[0.746, 2.57, 200],
|
||||
[0.835, 2.38, 150],
|
||||
[0.946, 2.17, 100],
|
||||
[1.090, 1.95, 50],
|
||||
[1.290, 1.71, 0],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
[
|
||||
'#N/A',
|
||||
1,
|
||||
[
|
||||
[
|
||||
'Density',
|
||||
'Viscosity',
|
||||
'Temperature',
|
||||
],
|
||||
[
|
||||
0.45700000000000002,
|
||||
3.5499999999999998,
|
||||
500,
|
||||
],
|
||||
[
|
||||
0.52500000000000002,
|
||||
3.25,
|
||||
400,
|
||||
],
|
||||
[
|
||||
0.61599999999999999,
|
||||
2.9300000000000002,
|
||||
300,
|
||||
],
|
||||
[
|
||||
0.67500000000000004,
|
||||
2.75,
|
||||
250,
|
||||
],
|
||||
[
|
||||
0.746,
|
||||
2.5699999999999998,
|
||||
200,
|
||||
],
|
||||
[
|
||||
0.83499999999999996,
|
||||
2.3799999999999999,
|
||||
150,
|
||||
],
|
||||
[
|
||||
0.94599999999999995,
|
||||
2.1699999999999999,
|
||||
100,
|
||||
],
|
||||
[
|
||||
1.0900000000000001,
|
||||
1.95,
|
||||
50,
|
||||
],
|
||||
[
|
||||
1.29,
|
||||
1.71,
|
||||
0,
|
||||
],
|
||||
],
|
||||
densityGrid(),
|
||||
2,
|
||||
false,
|
||||
],
|
||||
[
|
||||
100,
|
||||
1,
|
||||
[
|
||||
[
|
||||
'Density',
|
||||
'Viscosity',
|
||||
'Temperature',
|
||||
],
|
||||
[
|
||||
0.45700000000000002,
|
||||
3.5499999999999998,
|
||||
500,
|
||||
],
|
||||
[
|
||||
0.52500000000000002,
|
||||
3.25,
|
||||
400,
|
||||
],
|
||||
[
|
||||
0.61599999999999999,
|
||||
2.9300000000000002,
|
||||
300,
|
||||
],
|
||||
[
|
||||
0.67500000000000004,
|
||||
2.75,
|
||||
250,
|
||||
],
|
||||
[
|
||||
0.746,
|
||||
2.5699999999999998,
|
||||
200,
|
||||
],
|
||||
[
|
||||
0.83499999999999996,
|
||||
2.3799999999999999,
|
||||
150,
|
||||
],
|
||||
[
|
||||
0.94599999999999995,
|
||||
2.1699999999999999,
|
||||
100,
|
||||
],
|
||||
[
|
||||
1.0900000000000001,
|
||||
1.95,
|
||||
50,
|
||||
],
|
||||
[
|
||||
1.29,
|
||||
1.71,
|
||||
0,
|
||||
],
|
||||
],
|
||||
densityGrid(),
|
||||
3,
|
||||
true,
|
||||
],
|
||||
[
|
||||
'#N/A',
|
||||
0.69999999999999996,
|
||||
[
|
||||
[
|
||||
'Density',
|
||||
'Viscosity',
|
||||
'Temperature',
|
||||
],
|
||||
[
|
||||
0.45700000000000002,
|
||||
3.5499999999999998,
|
||||
500,
|
||||
],
|
||||
[
|
||||
0.52500000000000002,
|
||||
3.25,
|
||||
400,
|
||||
],
|
||||
[
|
||||
0.61599999999999999,
|
||||
2.9300000000000002,
|
||||
300,
|
||||
],
|
||||
[
|
||||
0.67500000000000004,
|
||||
2.75,
|
||||
250,
|
||||
],
|
||||
[
|
||||
0.746,
|
||||
2.5699999999999998,
|
||||
200,
|
||||
],
|
||||
[
|
||||
0.83499999999999996,
|
||||
2.3799999999999999,
|
||||
150,
|
||||
],
|
||||
[
|
||||
0.94599999999999995,
|
||||
2.1699999999999999,
|
||||
100,
|
||||
],
|
||||
[
|
||||
1.0900000000000001,
|
||||
1.95,
|
||||
50,
|
||||
],
|
||||
[
|
||||
1.29,
|
||||
1.71,
|
||||
0,
|
||||
],
|
||||
],
|
||||
0.70,
|
||||
densityGrid(),
|
||||
3,
|
||||
false,
|
||||
],
|
||||
[
|
||||
'#N/A',
|
||||
0.10000000000000001,
|
||||
[
|
||||
[
|
||||
'Density',
|
||||
'Viscosity',
|
||||
'Temperature',
|
||||
],
|
||||
[
|
||||
0.45700000000000002,
|
||||
3.5499999999999998,
|
||||
500,
|
||||
],
|
||||
[
|
||||
0.52500000000000002,
|
||||
3.25,
|
||||
400,
|
||||
],
|
||||
[
|
||||
0.61599999999999999,
|
||||
2.9300000000000002,
|
||||
300,
|
||||
],
|
||||
[
|
||||
0.67500000000000004,
|
||||
2.75,
|
||||
250,
|
||||
],
|
||||
[
|
||||
0.746,
|
||||
2.5699999999999998,
|
||||
200,
|
||||
],
|
||||
[
|
||||
0.83499999999999996,
|
||||
2.3799999999999999,
|
||||
150,
|
||||
],
|
||||
[
|
||||
0.94599999999999995,
|
||||
2.1699999999999999,
|
||||
100,
|
||||
],
|
||||
[
|
||||
1.0900000000000001,
|
||||
1.95,
|
||||
50,
|
||||
],
|
||||
[
|
||||
1.29,
|
||||
1.71,
|
||||
0,
|
||||
],
|
||||
],
|
||||
0.100,
|
||||
densityGrid(),
|
||||
2,
|
||||
true,
|
||||
],
|
||||
[
|
||||
1.71,
|
||||
2,
|
||||
[
|
||||
[
|
||||
'Density',
|
||||
'Viscosity',
|
||||
'Temperature',
|
||||
],
|
||||
[
|
||||
0.45700000000000002,
|
||||
3.5499999999999998,
|
||||
500,
|
||||
],
|
||||
[
|
||||
0.52500000000000002,
|
||||
3.25,
|
||||
400,
|
||||
],
|
||||
[
|
||||
0.61599999999999999,
|
||||
2.9300000000000002,
|
||||
300,
|
||||
],
|
||||
[
|
||||
0.67500000000000004,
|
||||
2.75,
|
||||
250,
|
||||
],
|
||||
[
|
||||
0.746,
|
||||
2.5699999999999998,
|
||||
200,
|
||||
],
|
||||
[
|
||||
0.83499999999999996,
|
||||
2.3799999999999999,
|
||||
150,
|
||||
],
|
||||
[
|
||||
0.94599999999999995,
|
||||
2.1699999999999999,
|
||||
100,
|
||||
],
|
||||
[
|
||||
1.0900000000000001,
|
||||
1.95,
|
||||
50,
|
||||
],
|
||||
[
|
||||
1.29,
|
||||
1.71,
|
||||
0,
|
||||
],
|
||||
],
|
||||
densityGrid(),
|
||||
2,
|
||||
true,
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue