mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-26 18:38:32 +00:00
070ceef5d0
Fix #64 (really!), closed as stale in December 2017, another in our "better late than never" series. Excel's INDEX function doesn't really behave quite as described. If a single row is used as an argument, either in literal form `{item1, item2, item3}` or expressed as a range `A1:A6`, INDEX is happy to evaluate the array as if each entry were a row rather than a single item. PhpSpreadsheet is changed to do likewise. INDEX also returned `#REF!` when it would normally return an array (which would often be reduced to its leftmost topmost entry later). This code is deleted, invalidating one existing test, and INDEX will now operate like other functions which can return arrays.
237 lines
4.1 KiB
PHP
237 lines
4.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
return [
|
|
'Single Cell' => [
|
|
1, // Expected
|
|
[
|
|
[1],
|
|
],
|
|
0,
|
|
],
|
|
'Row Number omitted' => [
|
|
'exception', // Expected
|
|
[
|
|
[1],
|
|
],
|
|
],
|
|
'Negative Row' => [
|
|
'#VALUE!', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
-1,
|
|
],
|
|
'Row > matrix rows' => [
|
|
'#REF!', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
10,
|
|
],
|
|
'Row is not a number' => [
|
|
'#NAME?', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
'NaN',
|
|
],
|
|
'Row is reference to non-number' => [
|
|
'#VALUE!', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
'ZZ98',
|
|
],
|
|
'Row is quoted non-numeric result' => [
|
|
'#VALUE!', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
'"string"',
|
|
],
|
|
'Row is Error' => [
|
|
'#N/A', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
'#N/A',
|
|
],
|
|
'Return row 2 only one column' => [
|
|
'xyz', // Expected
|
|
[
|
|
['abc'],
|
|
['xyz'],
|
|
],
|
|
2,
|
|
],
|
|
'Return row 1 col 2' => [
|
|
'def', // Expected
|
|
[
|
|
['abc', 'def'],
|
|
['xyz', 'tuv'],
|
|
],
|
|
1,
|
|
2,
|
|
],
|
|
'Column number omitted from 2-column matrix' => [
|
|
'abc', // Expected
|
|
[
|
|
['abc', 'def'],
|
|
['xyz', 'tuv'],
|
|
],
|
|
1,
|
|
],
|
|
'Column number omitted from 1-column matrix' => [
|
|
'xyz', // Expected
|
|
[
|
|
['abc'],
|
|
['xyz'],
|
|
],
|
|
2,
|
|
],
|
|
'Return row 2 from larger matrix (Phpspreadsheet flattens expected [2,4] to single value)' => [
|
|
2, // Expected
|
|
// Input
|
|
[
|
|
[1, 3],
|
|
[2, 4],
|
|
],
|
|
2,
|
|
0,
|
|
],
|
|
'Negative Column' => [
|
|
'#VALUE!', // Expected
|
|
[
|
|
[1, 3],
|
|
[2, 4],
|
|
],
|
|
0,
|
|
-1,
|
|
],
|
|
'Column > matrix columns' => [
|
|
'#REF!', // Expected
|
|
[
|
|
[1, 3],
|
|
[2, 4],
|
|
],
|
|
2,
|
|
10,
|
|
],
|
|
'Column is not a number' => [
|
|
'#NAME?', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
1,
|
|
'NaN',
|
|
],
|
|
'Column is reference to non-number' => [
|
|
'#VALUE!', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
1,
|
|
'ZZ98',
|
|
],
|
|
'Column is quoted non-number' => [
|
|
'#VALUE!', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
1,
|
|
'"string"',
|
|
],
|
|
'Column is Error' => [
|
|
'#N/A', // Expected
|
|
[
|
|
[1],
|
|
[2],
|
|
],
|
|
1,
|
|
'#N/A',
|
|
],
|
|
'Row 2 Column 2' => [
|
|
4, // Expected
|
|
[
|
|
[1, 3],
|
|
[2, 4],
|
|
],
|
|
2,
|
|
2,
|
|
],
|
|
'Row 2 Column 2 Alphabetic' => [
|
|
'Pears',
|
|
[
|
|
['Apples', 'Lemons'],
|
|
['Bananas', 'Pears'],
|
|
],
|
|
2,
|
|
2,
|
|
],
|
|
'Row 2 Column 1 Alphabetic' => [
|
|
'Bananas',
|
|
[
|
|
['Apples', 'Lemons'],
|
|
['Bananas', 'Pears'],
|
|
],
|
|
2,
|
|
1,
|
|
],
|
|
'Row 2 Column 0 (PhpSpreadsheet flattens result)' => [
|
|
'Bananas',
|
|
[
|
|
['Apples', 'Lemons'],
|
|
['Bananas', 'Pears'],
|
|
],
|
|
2,
|
|
0,
|
|
],
|
|
'Row 5 column 2' => [
|
|
3,
|
|
[
|
|
[4, 6],
|
|
[5, 3],
|
|
[6, 9],
|
|
[7, 5],
|
|
[8, 3],
|
|
],
|
|
5,
|
|
2,
|
|
],
|
|
'Row 5 column 0 (flattened)' => [
|
|
8,
|
|
[
|
|
[4, 6],
|
|
[5, 3],
|
|
[6, 9],
|
|
[7, 5],
|
|
[8, 3],
|
|
],
|
|
5,
|
|
0,
|
|
],
|
|
'Row 0 column 2 (flattened)' => [
|
|
6,
|
|
[
|
|
[4, 6],
|
|
[5, 3],
|
|
[6, 9],
|
|
[7, 5],
|
|
[8, 3],
|
|
],
|
|
0,
|
|
2,
|
|
],
|
|
];
|