1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Calculation; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Address; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\HLookup; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Indirect; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Lookup; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Matrix; |
10
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Offset; |
11
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\RowColumnInformation; |
12
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\VLookup; |
13
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Cell; |
14
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @deprecated 1.18.0 |
18
|
|
|
*/ |
19
|
|
|
class LookupRef |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* CELL_ADDRESS. |
23
|
|
|
* |
24
|
|
|
* Creates a cell address as text, given specified row and column numbers. |
25
|
|
|
* |
26
|
|
|
* Excel Function: |
27
|
|
|
* =ADDRESS(row, column, [relativity], [referenceStyle], [sheetText]) |
28
|
|
|
* |
29
|
|
|
* @deprecated 1.18.0 |
30
|
|
|
* Use the cell() method in the LookupRef\Address class instead |
31
|
|
|
* @see LookupRef\Address::cell() |
32
|
|
|
* |
33
|
|
|
* @param mixed $row Row number to use in the cell reference |
34
|
|
|
* @param mixed $column Column number to use in the cell reference |
35
|
|
|
* @param int $relativity Flag indicating the type of reference to return |
36
|
|
|
* 1 or omitted Absolute |
37
|
|
|
* 2 Absolute row; relative column |
38
|
|
|
* 3 Relative row; absolute column |
39
|
|
|
* 4 Relative |
40
|
|
|
* @param bool $referenceStyle A logical value that specifies the A1 or R1C1 reference style. |
41
|
|
|
* TRUE or omitted CELL_ADDRESS returns an A1-style reference |
42
|
|
|
* FALSE CELL_ADDRESS returns an R1C1-style reference |
43
|
|
|
* @param array|string $sheetText Optional Name of worksheet to use |
44
|
|
|
* |
45
|
|
|
* @return array|string |
46
|
|
|
*/ |
47
|
|
|
public static function cellAddress($row, $column, $relativity = 1, $referenceStyle = true, $sheetText = '') |
48
|
|
|
{ |
49
|
|
|
return Address::cell($row, $column, $relativity, $referenceStyle, $sheetText); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* COLUMN. |
54
|
|
|
* |
55
|
|
|
* Returns the column number of the given cell reference |
56
|
|
|
* If the cell reference is a range of cells, COLUMN returns the column numbers of each column |
57
|
|
|
* in the reference as a horizontal array. |
58
|
|
|
* If cell reference is omitted, and the function is being called through the calculation engine, |
59
|
|
|
* then it is assumed to be the reference of the cell in which the COLUMN function appears; |
60
|
|
|
* otherwise this function returns 1. |
61
|
|
|
* |
62
|
|
|
* Excel Function: |
63
|
|
|
* =COLUMN([cellAddress]) |
64
|
|
|
* |
65
|
|
|
* @deprecated 1.18.0 |
66
|
|
|
* Use the COLUMN() method in the LookupRef\RowColumnInformation class instead |
67
|
|
|
* @see LookupRef\RowColumnInformation::COLUMN() |
68
|
|
|
* |
69
|
|
|
* @param null|array|string $cellAddress A reference to a range of cells for which you want the column numbers |
70
|
|
|
* |
71
|
|
|
* @return int|int[]|string |
72
|
|
|
*/ |
73
|
1 |
|
public static function COLUMN($cellAddress = null, ?Cell $cell = null) |
74
|
|
|
{ |
75
|
1 |
|
return RowColumnInformation::COLUMN($cellAddress, $cell); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* COLUMNS. |
80
|
|
|
* |
81
|
|
|
* Returns the number of columns in an array or reference. |
82
|
|
|
* |
83
|
|
|
* Excel Function: |
84
|
|
|
* =COLUMNS(cellAddress) |
85
|
|
|
* |
86
|
|
|
* @deprecated 1.18.0 |
87
|
|
|
* Use the COLUMNS() method in the LookupRef\RowColumnInformation class instead |
88
|
|
|
* @see LookupRef\RowColumnInformation::COLUMNS() |
89
|
|
|
* |
90
|
|
|
* @param null|array|string $cellAddress An array or array formula, or a reference to a range of cells |
91
|
|
|
* for which you want the number of columns |
92
|
|
|
* |
93
|
|
|
* @return int|string The number of columns in cellAddress, or a string if arguments are invalid |
94
|
|
|
*/ |
95
|
|
|
public static function COLUMNS($cellAddress = null) |
96
|
|
|
{ |
97
|
|
|
return RowColumnInformation::COLUMNS($cellAddress); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* ROW. |
102
|
|
|
* |
103
|
|
|
* Returns the row number of the given cell reference |
104
|
|
|
* If the cell reference is a range of cells, ROW returns the row numbers of each row in the reference |
105
|
|
|
* as a vertical array. |
106
|
|
|
* If cell reference is omitted, and the function is being called through the calculation engine, |
107
|
|
|
* then it is assumed to be the reference of the cell in which the ROW function appears; |
108
|
|
|
* otherwise this function returns 1. |
109
|
|
|
* |
110
|
|
|
* Excel Function: |
111
|
|
|
* =ROW([cellAddress]) |
112
|
|
|
* |
113
|
|
|
* @deprecated 1.18.0 |
114
|
|
|
* Use the ROW() method in the LookupRef\RowColumnInformation class instead |
115
|
|
|
* @see LookupRef\RowColumnInformation::ROW() |
116
|
|
|
* |
117
|
|
|
* @param null|array|string $cellAddress A reference to a range of cells for which you want the row numbers |
118
|
|
|
* |
119
|
|
|
* @return int|mixed[]|string |
120
|
|
|
*/ |
121
|
1 |
|
public static function ROW($cellAddress = null, ?Cell $cell = null) |
122
|
|
|
{ |
123
|
1 |
|
return RowColumnInformation::ROW($cellAddress, $cell); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* ROWS. |
128
|
|
|
* |
129
|
|
|
* Returns the number of rows in an array or reference. |
130
|
|
|
* |
131
|
|
|
* Excel Function: |
132
|
|
|
* =ROWS(cellAddress) |
133
|
|
|
* |
134
|
|
|
* @deprecated 1.18.0 |
135
|
|
|
* Use the ROWS() method in the LookupRef\RowColumnInformation class instead |
136
|
|
|
* @see LookupRef\RowColumnInformation::ROWS() |
137
|
|
|
* |
138
|
|
|
* @param null|array|string $cellAddress An array or array formula, or a reference to a range of cells |
139
|
|
|
* for which you want the number of rows |
140
|
|
|
* |
141
|
|
|
* @return int|string The number of rows in cellAddress, or a string if arguments are invalid |
142
|
|
|
*/ |
143
|
|
|
public static function ROWS($cellAddress = null) |
144
|
|
|
{ |
145
|
|
|
return RowColumnInformation::ROWS($cellAddress); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* HYPERLINK. |
150
|
|
|
* |
151
|
|
|
* Excel Function: |
152
|
|
|
* =HYPERLINK(linkURL,displayName) |
153
|
|
|
* |
154
|
|
|
* @deprecated 1.18.0 |
155
|
|
|
* Use the set() method in the LookupRef\Hyperlink class instead |
156
|
|
|
* @see LookupRef\Hyperlink::set() |
157
|
|
|
* |
158
|
|
|
* @param mixed $linkURL Expect string. Value to check, is also the value returned when no error |
159
|
|
|
* @param mixed $displayName Expect string. Value to return when testValue is an error condition |
160
|
|
|
* @param Cell $cell The cell to set the hyperlink in |
161
|
|
|
* |
162
|
|
|
* @return string The value of $displayName (or $linkURL if $displayName was blank) |
163
|
|
|
*/ |
164
|
1 |
|
public static function HYPERLINK($linkURL = '', $displayName = null, ?Cell $cell = null) |
165
|
|
|
{ |
166
|
1 |
|
return LookupRef\Hyperlink::set($linkURL, $displayName, $cell); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* INDIRECT. |
171
|
|
|
* |
172
|
|
|
* Returns the reference specified by a text string. |
173
|
|
|
* References are immediately evaluated to display their contents. |
174
|
|
|
* |
175
|
|
|
* Excel Function: |
176
|
|
|
* =INDIRECT(cellAddress) |
177
|
|
|
* |
178
|
|
|
* @deprecated 1.18.0 |
179
|
|
|
* Use the INDIRECT() method in the LookupRef\Indirect class instead |
180
|
|
|
* @see LookupRef\Indirect::INDIRECT() |
181
|
|
|
* |
182
|
|
|
* @param array|string $cellAddress $cellAddress The cell address of the current cell (containing this formula) |
183
|
|
|
* @param Cell $cell The current cell (containing this formula) |
184
|
|
|
* |
185
|
|
|
* @return array|string An array containing a cell or range of cells, or a string on error |
186
|
|
|
* |
187
|
|
|
* NOTE - INDIRECT() does not yet support the optional a1 parameter introduced in Excel 2010 |
188
|
|
|
*/ |
189
|
1 |
|
public static function INDIRECT($cellAddress, Cell $cell) |
190
|
|
|
{ |
191
|
1 |
|
return Indirect::INDIRECT($cellAddress, true, $cell); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* OFFSET. |
196
|
|
|
* |
197
|
|
|
* Returns a reference to a range that is a specified number of rows and columns from a cell or range of cells. |
198
|
|
|
* The reference that is returned can be a single cell or a range of cells. You can specify the number of rows and |
199
|
|
|
* the number of columns to be returned. |
200
|
|
|
* |
201
|
|
|
* Excel Function: |
202
|
|
|
* =OFFSET(cellAddress, rows, cols, [height], [width]) |
203
|
|
|
* |
204
|
|
|
* @deprecated 1.18.0 |
205
|
|
|
* Use the OFFSET() method in the LookupRef\Offset class instead |
206
|
|
|
* @see LookupRef\Offset::OFFSET() |
207
|
|
|
* |
208
|
|
|
* @param null|string $cellAddress The reference from which you want to base the offset. |
209
|
|
|
* Reference must refer to a cell or range of adjacent cells; |
210
|
|
|
* otherwise, OFFSET returns the #VALUE! error value. |
211
|
|
|
* @param mixed $rows The number of rows, up or down, that you want the upper-left cell to refer to. |
212
|
|
|
* Using 5 as the rows argument specifies that the upper-left cell in the |
213
|
|
|
* reference is five rows below reference. Rows can be positive (which means |
214
|
|
|
* below the starting reference) or negative (which means above the starting |
215
|
|
|
* reference). |
216
|
|
|
* @param mixed $columns The number of columns, to the left or right, that you want the upper-left cell |
217
|
|
|
* of the result to refer to. Using 5 as the cols argument specifies that the |
218
|
|
|
* upper-left cell in the reference is five columns to the right of reference. |
219
|
|
|
* Cols can be positive (which means to the right of the starting reference) |
220
|
|
|
* or negative (which means to the left of the starting reference). |
221
|
|
|
* @param mixed $height The height, in number of rows, that you want the returned reference to be. |
222
|
|
|
* Height must be a positive number. |
223
|
|
|
* @param mixed $width The width, in number of columns, that you want the returned reference to be. |
224
|
|
|
* Width must be a positive number. |
225
|
|
|
* |
226
|
|
|
* @return array|string An array containing a cell or range of cells, or a string on error |
227
|
|
|
*/ |
228
|
1 |
|
public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, ?Cell $cell = null) |
229
|
|
|
{ |
230
|
1 |
|
return Offset::OFFSET($cellAddress, $rows, $columns, $height, $width, $cell); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* CHOOSE. |
235
|
|
|
* |
236
|
|
|
* Uses lookup_value to return a value from the list of value arguments. |
237
|
|
|
* Use CHOOSE to select one of up to 254 values based on the lookup_value. |
238
|
|
|
* |
239
|
|
|
* Excel Function: |
240
|
|
|
* =CHOOSE(index_num, value1, [value2], ...) |
241
|
|
|
* |
242
|
|
|
* @deprecated 1.18.0 |
243
|
|
|
* Use the choose() method in the LookupRef\Selection class instead |
244
|
|
|
* @see LookupRef\Selection::choose() |
245
|
|
|
* |
246
|
|
|
* @return mixed The selected value |
247
|
|
|
*/ |
248
|
|
|
public static function CHOOSE(...$chooseArgs) |
249
|
|
|
{ |
250
|
|
|
return LookupRef\Selection::choose(...$chooseArgs); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* MATCH. |
255
|
|
|
* |
256
|
|
|
* The MATCH function searches for a specified item in a range of cells |
257
|
|
|
* |
258
|
|
|
* Excel Function: |
259
|
|
|
* =MATCH(lookup_value, lookup_array, [match_type]) |
260
|
|
|
* |
261
|
|
|
* @deprecated 1.18.0 |
262
|
|
|
* Use the MATCH() method in the LookupRef\ExcelMatch class instead |
263
|
|
|
* @see LookupRef\ExcelMatch::MATCH() |
264
|
|
|
* |
265
|
|
|
* @param mixed $lookupValue The value that you want to match in lookup_array |
266
|
|
|
* @param mixed $lookupArray The range of cells being searched |
267
|
|
|
* @param mixed $matchType The number -1, 0, or 1. -1 means above, 0 means exact match, 1 means below. |
268
|
|
|
* If match_type is 1 or -1, the list has to be ordered. |
269
|
|
|
* |
270
|
|
|
* @return array|int|string The relative position of the found item |
271
|
|
|
*/ |
272
|
|
|
public static function MATCH($lookupValue, $lookupArray, $matchType = 1) |
273
|
|
|
{ |
274
|
|
|
return LookupRef\ExcelMatch::MATCH($lookupValue, $lookupArray, $matchType); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* INDEX. |
279
|
|
|
* |
280
|
|
|
* Uses an index to choose a value from a reference or array |
281
|
|
|
* |
282
|
|
|
* Excel Function: |
283
|
|
|
* =INDEX(range_array, row_num, [column_num]) |
284
|
|
|
* |
285
|
|
|
* @deprecated 1.18.0 |
286
|
|
|
* Use the index() method in the LookupRef\Matrix class instead |
287
|
|
|
* @see LookupRef\Matrix::index() |
288
|
|
|
* |
289
|
|
|
* @param mixed $rowNum The row in the array or range from which to return a value. |
290
|
|
|
* If row_num is omitted, column_num is required. |
291
|
|
|
* @param mixed $columnNum The column in the array or range from which to return a value. |
292
|
|
|
* If column_num is omitted, row_num is required. |
293
|
|
|
* @param mixed $matrix |
294
|
|
|
* |
295
|
|
|
* @return mixed the value of a specified cell or array of cells |
296
|
|
|
*/ |
297
|
|
|
public static function INDEX($matrix, $rowNum = 0, $columnNum = 0) |
298
|
|
|
{ |
299
|
|
|
return Matrix::index($matrix, $rowNum, $columnNum); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* TRANSPOSE. |
304
|
|
|
* |
305
|
|
|
* @deprecated 1.18.0 |
306
|
|
|
* Use the transpose() method in the LookupRef\Matrix class instead |
307
|
|
|
* @see LookupRef\Matrix::transpose() |
308
|
|
|
* |
309
|
|
|
* @param array $matrixData A matrix of values |
310
|
|
|
* |
311
|
|
|
* @return array |
312
|
|
|
* |
313
|
|
|
* Unlike the Excel TRANSPOSE function, which will only work on a single row or column, |
314
|
|
|
* this function will transpose a full matrix |
315
|
|
|
*/ |
316
|
1 |
|
public static function TRANSPOSE($matrixData) |
317
|
|
|
{ |
318
|
1 |
|
return Matrix::transpose($matrixData); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* VLOOKUP |
323
|
|
|
* The VLOOKUP function searches for value in the left-most column of lookup_array and returns the value |
324
|
|
|
* in the same row based on the index_number. |
325
|
|
|
* |
326
|
|
|
* @deprecated 1.18.0 |
327
|
|
|
* Use the lookup() method in the LookupRef\VLookup class instead |
328
|
|
|
* @see LookupRef\VLookup::lookup() |
329
|
|
|
* |
330
|
|
|
* @param mixed $lookup_value The value that you want to match in lookup_array |
331
|
|
|
* @param mixed $lookup_array The range of cells being searched |
332
|
|
|
* @param mixed $index_number The column number in table_array from which the matching value must be returned. |
333
|
|
|
* The first column is 1. |
334
|
|
|
* @param mixed $not_exact_match determines if you are looking for an exact match based on lookup_value |
335
|
|
|
* |
336
|
|
|
* @return mixed The value of the found cell |
337
|
|
|
*/ |
338
|
|
|
public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true) |
339
|
|
|
{ |
340
|
|
|
return VLookup::lookup($lookup_value, $lookup_array, $index_number, $not_exact_match); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* HLOOKUP |
345
|
|
|
* The HLOOKUP function searches for value in the top-most row of lookup_array and returns the value |
346
|
|
|
* in the same column based on the index_number. |
347
|
|
|
* |
348
|
|
|
* @deprecated 1.18.0 |
349
|
|
|
* Use the lookup() method in the LookupRef\HLookup class instead |
350
|
|
|
* @see LookupRef\HLookup::lookup() |
351
|
|
|
* |
352
|
|
|
* @param mixed $lookup_value The value that you want to match in lookup_array |
353
|
|
|
* @param mixed $lookup_array The range of cells being searched |
354
|
|
|
* @param mixed $index_number The row number in table_array from which the matching value must be returned. |
355
|
|
|
* The first row is 1. |
356
|
|
|
* @param mixed $not_exact_match determines if you are looking for an exact match based on lookup_value |
357
|
|
|
* |
358
|
|
|
* @return mixed The value of the found cell |
359
|
|
|
*/ |
360
|
1 |
|
public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true) |
361
|
|
|
{ |
362
|
1 |
|
return HLookup::lookup($lookup_value, $lookup_array, $index_number, $not_exact_match); |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* LOOKUP |
367
|
|
|
* The LOOKUP function searches for value either from a one-row or one-column range or from an array. |
368
|
|
|
* |
369
|
|
|
* @deprecated 1.18.0 |
370
|
|
|
* Use the lookup() method in the LookupRef\Lookup class instead |
371
|
|
|
* @see LookupRef\Lookup::lookup() |
372
|
|
|
* |
373
|
|
|
* @param mixed $lookup_value The value that you want to match in lookup_array |
374
|
|
|
* @param mixed $lookup_vector The range of cells being searched |
375
|
|
|
* @param null|mixed $result_vector The column from which the matching value must be returned |
376
|
|
|
* |
377
|
|
|
* @return mixed The value of the found cell |
378
|
|
|
*/ |
379
|
|
|
public static function LOOKUP($lookup_value, $lookup_vector, $result_vector = null) |
380
|
|
|
{ |
381
|
|
|
return Lookup::lookup($lookup_value, $lookup_vector, $result_vector); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* FORMULATEXT. |
386
|
|
|
* |
387
|
|
|
* @deprecated 1.18.0 |
388
|
|
|
* Use the text() method in the LookupRef\Formula class instead |
389
|
|
|
* @see LookupRef\Formula::text() |
390
|
|
|
* |
391
|
|
|
* @param mixed $cellReference The cell to check |
392
|
|
|
* @param Cell $cell The current cell (containing this formula) |
393
|
|
|
* |
394
|
|
|
* @return string |
395
|
|
|
*/ |
396
|
1 |
|
public static function FORMULATEXT($cellReference = '', ?Cell $cell = null) |
397
|
|
|
{ |
398
|
1 |
|
return LookupRef\Formula::text($cellReference, $cell); |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
|