mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 21:28:17 +00:00
c79a9a8e21
* Improved Support for INDIRECT, ROW, and COLUMN Functions This should address issues #1913 and #1993. INDIRECT had heretofore not supported an optional parameter intended to support addresses in R1C1 format which was introduced with Excel 2010. It also had not supported the use of defined names as an argument. This PR is a replacement for #1995, which is currently in draft status and which I will close in a day or two. The ROW and COLUMN functions also should support defined names. I have added that, and test cases, with the latest push. ROWS and COLUMNS already supported it correctly, but there had been no test cases. Because ROW and COLUMN can return arrays, and PhpSpreadsheet does not support dynamic arrays, I left the existing direct-call tests unchanged to demonstrate those capabilities. The unit tests for INDIRECT had used mocking, and were sorely lacking (tested only error conditions). They have been replaced with normal, and hopefully adequate, tests. This includes testing globally defined names, as well as locally defined names, both in and out of scope. The test case in 1913 was too complicated for me to add as a unit test. The main impediments to it are now removed, and its complex situation will, I hope, be corrected with this fix. INDIRECT can also support a reference of the form Sheetname!localName when localName on its own would be out of scope. That functionality is added. It is also added, in theory, for ROW and COLUMN, however such a construction is rejected by the Calculation engine before passing control to ROW or COLUMN. It might be possible to change the engine to allow this, and I may want to look into that later, but it seems much too risky, and not nearly useful enough, to attempt to address that as part of this change. Several unusual test cases (leading equals sign, not-quite-as-expected name definition in file, complex indirection involving concatenation and a dropdown list) were suggested by @MarkBaker and are included in this request.
38 lines
2.0 KiB
PHP
38 lines
2.0 KiB
PHP
<?php
|
|
|
|
return [
|
|
'cell range absolute' => [600, '$A$1:$A$3'],
|
|
'cell range on different sheet' => [30, 'OtherSheet!A1:A2'],
|
|
'cell range on different sheet absolute' => [60, 'OtherSheet!$A$1:$A$3'],
|
|
'cell range relative' => [500, 'A2:A3'],
|
|
'global name qualified with correct sheet' => [90, 'OtherSheet!newnr'],
|
|
'global name qualified with incorrect sheet' => [90, 'ThisSheet!newnr'],
|
|
'global name qualified with non-existent sheet' => ['#REF!', 'UnknownSheet!newnr'],
|
|
'invalid address' => ['#REF!', 'InvalidCellAddress'],
|
|
'invalid address as first part of range' => ['#REF!', 'Invalid:A2'],
|
|
'invalid address as second part of range' => ['#REF!', 'A2:Invalid'],
|
|
'local name out of scope' => ['#REF!', 'localname'],
|
|
'named range' => [90, 'newnr'],
|
|
'named range a1 arg ignored' => [90, 'newnr', false],
|
|
'named range case-insensitive' => [90, 'newNr'],
|
|
'null address' => ['#REF!', null],
|
|
'omit a1 argument' => [900, 'A2:A4'],
|
|
'qualified name correct sheet even out of scope' => [9, 'OtherSheet!localname'],
|
|
'qualified name incorrect sheet' => ['#REF!', 'ThisSheet!localname'],
|
|
'qualified name non-existent sheet' => ['#REF!', 'OtherSheetx!localname'],
|
|
'r1c1 cell on different sheet' => [40, 'OtherSheet!R4C1', false],
|
|
'r1c1 format a1 as string not permitted' => ['#VALUE!', 'R2C1', '0'],
|
|
'r1c1 format a1 is bool' => [200, 'R2C1', false],
|
|
'r1c1 format a1 is int' => [200, 'R2C1', 0],
|
|
'r1c1 range' => [600, 'R1C1:R3C1', false],
|
|
'r1c1 range on different sheet' => [90, 'OtherSheet!R4C1:R5C1', false],
|
|
'single cell absolute' => [200, '$A$2'],
|
|
'single cell relative' => [100, 'A1'],
|
|
'single cell on different sheet absolute' => [30, 'OtherSheet!$A$3'],
|
|
'single cell on different sheet relative' => [10, 'OtherSheet!A1'],
|
|
'supply a1 argument as bool' => [900, 'A2:A4', true],
|
|
'supply a1 argument as int' => [900, 'A2:A4', 1],
|
|
'supply a1 argument as float' => [900, 'A2:A4', 7.3],
|
|
'supply a1 argument as string not permitted' => ['#VALUE!', 'A2:A4', '1'],
|
|
];
|