1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Calculation; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Engine\BranchPruner; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Engine\CyclicReferenceStack; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Engine\Logger; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Engine\Operands; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; |
10
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Token\Stack; |
11
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\AddressRange; |
12
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Cell; |
13
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
14
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataType; |
15
|
|
|
use PhpOffice\PhpSpreadsheet\DefinedName; |
16
|
|
|
use PhpOffice\PhpSpreadsheet\NamedRange; |
17
|
|
|
use PhpOffice\PhpSpreadsheet\ReferenceHelper; |
18
|
|
|
use PhpOffice\PhpSpreadsheet\Shared; |
19
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
20
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
21
|
|
|
use ReflectionClassConstant; |
22
|
|
|
use ReflectionMethod; |
23
|
|
|
use ReflectionParameter; |
24
|
|
|
use Throwable; |
25
|
|
|
|
26
|
|
|
class Calculation |
27
|
|
|
{ |
28
|
|
|
/** Constants */ |
29
|
|
|
/** Regular Expressions */ |
30
|
|
|
// Numeric operand |
31
|
|
|
public const CALCULATION_REGEXP_NUMBER = '[-+]?\d*\.?\d+(e[-+]?\d+)?'; |
32
|
|
|
// String operand |
33
|
|
|
public const CALCULATION_REGEXP_STRING = '"(?:[^"]|"")*"'; |
34
|
|
|
// Opening bracket |
35
|
|
|
public const CALCULATION_REGEXP_OPENBRACE = '\('; |
36
|
|
|
// Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it) |
37
|
|
|
public const CALCULATION_REGEXP_FUNCTION = '@?(?:_xlfn\.)?(?:_xlws\.)?([\p{L}][\p{L}\p{N}\.]*)[\s]*\('; |
38
|
|
|
// Strip xlfn and xlws prefixes from function name |
39
|
|
|
public const CALCULATION_REGEXP_STRIP_XLFN_XLWS = '/(_xlfn[.])?(_xlws[.])?(?=[\p{L}][\p{L}\p{N}\.]*[\s]*[(])/'; |
40
|
|
|
// Cell reference (cell or range of cells, with or without a sheet reference) |
41
|
|
|
public const CALCULATION_REGEXP_CELLREF = '((([^\s,!&%^\/\*\+<>=:`-]*)|(\'(?:[^\']|\'[^!])+?\')|(\"(?:[^\"]|\"[^!])+?\"))!)?\$?\b([a-z]{1,3})\$?(\d{1,7})(?![\w.])'; |
42
|
|
|
// Cell reference (with or without a sheet reference) ensuring absolute/relative |
43
|
|
|
public const CALCULATION_REGEXP_CELLREF_RELATIVE = '((([^\s\(,!&%^\/\*\+<>=:`-]*)|(\'(?:[^\']|\'[^!])+?\')|(\"(?:[^\"]|\"[^!])+?\"))!)?(\$?\b[a-z]{1,3})(\$?\d{1,7})(?![\w.])'; |
44
|
|
|
public const CALCULATION_REGEXP_COLUMN_RANGE = '(((([^\s\(,!&%^\/\*\+<>=:`-]*)|(\'(?:[^\']|\'[^!])+?\')|(\".(?:[^\"]|\"[^!])?\"))!)?(\$?[a-z]{1,3})):(?![.*])'; |
45
|
|
|
public const CALCULATION_REGEXP_ROW_RANGE = '(((([^\s\(,!&%^\/\*\+<>=:`-]*)|(\'(?:[^\']|\'[^!])+?\')|(\"(?:[^\"]|\"[^!])+?\"))!)?(\$?[1-9][0-9]{0,6})):(?![.*])'; |
46
|
|
|
// Cell reference (with or without a sheet reference) ensuring absolute/relative |
47
|
|
|
// Cell ranges ensuring absolute/relative |
48
|
|
|
public const CALCULATION_REGEXP_COLUMNRANGE_RELATIVE = '(\$?[a-z]{1,3}):(\$?[a-z]{1,3})'; |
49
|
|
|
public const CALCULATION_REGEXP_ROWRANGE_RELATIVE = '(\$?\d{1,7}):(\$?\d{1,7})'; |
50
|
|
|
// Defined Names: Named Range of cells, or Named Formulae |
51
|
|
|
public const CALCULATION_REGEXP_DEFINEDNAME = '((([^\s,!&%^\/\*\+<>=-]*)|(\'(?:[^\']|\'[^!])+?\')|(\"(?:[^\"]|\"[^!])+?\"))!)?([_\p{L}][_\p{L}\p{N}\.]*)'; |
52
|
|
|
// Structured Reference (Fully Qualified and Unqualified) |
53
|
|
|
public const CALCULATION_REGEXP_STRUCTURED_REFERENCE = '([\p{L}_\\\\][\p{L}\p{N}\._]+)?(\[(?:[^\d\]+-])?)'; |
54
|
|
|
// Error |
55
|
|
|
public const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?'; |
56
|
|
|
|
57
|
|
|
/** constants */ |
58
|
|
|
public const RETURN_ARRAY_AS_ERROR = 'error'; |
59
|
|
|
public const RETURN_ARRAY_AS_VALUE = 'value'; |
60
|
|
|
public const RETURN_ARRAY_AS_ARRAY = 'array'; |
61
|
|
|
|
62
|
|
|
public const FORMULA_OPEN_FUNCTION_BRACE = '('; |
63
|
|
|
public const FORMULA_CLOSE_FUNCTION_BRACE = ')'; |
64
|
|
|
public const FORMULA_OPEN_MATRIX_BRACE = '{'; |
65
|
|
|
public const FORMULA_CLOSE_MATRIX_BRACE = '}'; |
66
|
|
|
public const FORMULA_STRING_QUOTE = '"'; |
67
|
|
|
|
68
|
|
|
private static string $returnArrayAsType = self::RETURN_ARRAY_AS_VALUE; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Instance of this class. |
72
|
|
|
* |
73
|
|
|
* @var ?Calculation |
74
|
|
|
*/ |
75
|
|
|
private static ?Calculation $instance = null; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Calculation cache. |
79
|
|
|
*/ |
80
|
|
|
private array $calculationCache = []; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Calculation cache enabled. |
84
|
|
|
*/ |
85
|
|
|
private bool $calculationCacheEnabled = true; |
86
|
|
|
|
87
|
|
|
private BranchPruner $branchPruner; |
88
|
|
|
|
89
|
|
|
private bool $branchPruningEnabled = true; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* List of operators that can be used within formulae |
93
|
|
|
* The true/false value indicates whether it is a binary operator or a unary operator. |
94
|
|
|
*/ |
95
|
|
|
private const CALCULATION_OPERATORS = [ |
96
|
|
|
'+' => true, '-' => true, '*' => true, '/' => true, |
97
|
|
|
'^' => true, '&' => true, '%' => false, '~' => false, |
98
|
|
|
'>' => true, '<' => true, '=' => true, '>=' => true, |
99
|
|
|
'<=' => true, '<>' => true, '∩' => true, '∪' => true, |
100
|
|
|
':' => true, |
101
|
|
|
]; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* List of binary operators (those that expect two operands). |
105
|
|
|
*/ |
106
|
|
|
private const BINARY_OPERATORS = [ |
107
|
|
|
'+' => true, '-' => true, '*' => true, '/' => true, |
108
|
|
|
'^' => true, '&' => true, '>' => true, '<' => true, |
109
|
|
|
'=' => true, '>=' => true, '<=' => true, '<>' => true, |
110
|
|
|
'∩' => true, '∪' => true, ':' => true, |
111
|
|
|
]; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* The debug log generated by the calculation engine. |
115
|
|
|
*/ |
116
|
|
|
private Logger $debugLog; |
117
|
|
|
|
118
|
|
|
private bool $suppressFormulaErrorsNew = false; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Error message for any error that was raised/thrown by the calculation engine. |
122
|
|
|
*/ |
123
|
|
|
public ?string $formulaError = null; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Reference Helper. |
127
|
|
|
*/ |
128
|
|
|
private static ReferenceHelper $referenceHelper; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* An array of the nested cell references accessed by the calculation engine, used for the debug log. |
132
|
|
|
*/ |
133
|
|
|
private CyclicReferenceStack $cyclicReferenceStack; |
134
|
|
|
|
135
|
|
|
private array $cellStack = []; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Current iteration counter for cyclic formulae |
139
|
|
|
* If the value is 0 (or less) then cyclic formulae will throw an exception, |
140
|
|
|
* otherwise they will iterate to the limit defined here before returning a result. |
141
|
|
|
*/ |
142
|
|
|
private int $cyclicFormulaCounter = 1; |
143
|
|
|
|
144
|
|
|
private string $cyclicFormulaCell = ''; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Number of iterations for cyclic formulae. |
148
|
|
|
*/ |
149
|
|
|
public int $cyclicFormulaCount = 1; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* The current locale setting. |
153
|
|
|
*/ |
154
|
|
|
private static string $localeLanguage = 'en_us'; // US English (default locale) |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* List of available locale settings |
158
|
|
|
* Note that this is read for the locale subdirectory only when requested. |
159
|
|
|
* |
160
|
|
|
* @var string[] |
161
|
|
|
*/ |
162
|
|
|
private static array $validLocaleLanguages = [ |
163
|
|
|
'en', // English (default language) |
164
|
|
|
]; |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Locale-specific argument separator for function arguments. |
168
|
|
|
*/ |
169
|
|
|
private static string $localeArgumentSeparator = ','; |
170
|
|
|
|
171
|
|
|
private static array $localeFunctions = []; |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Locale-specific translations for Excel constants (True, False and Null). |
175
|
|
|
* |
176
|
|
|
* @var array<string, string> |
177
|
|
|
*/ |
178
|
|
|
private static array $localeBoolean = [ |
179
|
|
|
'TRUE' => 'TRUE', |
180
|
|
|
'FALSE' => 'FALSE', |
181
|
|
|
'NULL' => 'NULL', |
182
|
|
|
]; |
183
|
|
|
|
184
|
4 |
|
public static function getLocaleBoolean(string $index): string |
185
|
|
|
{ |
186
|
4 |
|
return self::$localeBoolean[$index]; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Excel constant string translations to their PHP equivalents |
191
|
|
|
* Constant conversion from text name/value to actual (datatyped) value. |
192
|
|
|
* |
193
|
|
|
* @var array<string, null|bool> |
194
|
|
|
*/ |
195
|
|
|
private static array $excelConstants = [ |
196
|
|
|
'TRUE' => true, |
197
|
|
|
'FALSE' => false, |
198
|
|
|
'NULL' => null, |
199
|
|
|
]; |
200
|
|
|
|
201
|
20 |
|
public static function keyInExcelConstants(string $key): bool |
202
|
|
|
{ |
203
|
20 |
|
return array_key_exists($key, self::$excelConstants); |
204
|
|
|
} |
205
|
|
|
|
206
|
3 |
|
public static function getExcelConstants(string $key): bool|null |
207
|
|
|
{ |
208
|
3 |
|
return self::$excelConstants[$key]; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Array of functions usable on Spreadsheet. |
213
|
|
|
* In theory, this could be const rather than static; |
214
|
|
|
* however, Phpstan breaks trying to analyze it when attempted. |
215
|
|
|
*/ |
216
|
|
|
private static array $phpSpreadsheetFunctions = [ |
217
|
|
|
'ABS' => [ |
218
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
219
|
|
|
'functionCall' => [MathTrig\Absolute::class, 'evaluate'], |
220
|
|
|
'argumentCount' => '1', |
221
|
|
|
], |
222
|
|
|
'ACCRINT' => [ |
223
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
224
|
|
|
'functionCall' => [Financial\Securities\AccruedInterest::class, 'periodic'], |
225
|
|
|
'argumentCount' => '4-8', |
226
|
|
|
], |
227
|
|
|
'ACCRINTM' => [ |
228
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
229
|
|
|
'functionCall' => [Financial\Securities\AccruedInterest::class, 'atMaturity'], |
230
|
|
|
'argumentCount' => '3-5', |
231
|
|
|
], |
232
|
|
|
'ACOS' => [ |
233
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
234
|
|
|
'functionCall' => [MathTrig\Trig\Cosine::class, 'acos'], |
235
|
|
|
'argumentCount' => '1', |
236
|
|
|
], |
237
|
|
|
'ACOSH' => [ |
238
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
239
|
|
|
'functionCall' => [MathTrig\Trig\Cosine::class, 'acosh'], |
240
|
|
|
'argumentCount' => '1', |
241
|
|
|
], |
242
|
|
|
'ACOT' => [ |
243
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
244
|
|
|
'functionCall' => [MathTrig\Trig\Cotangent::class, 'acot'], |
245
|
|
|
'argumentCount' => '1', |
246
|
|
|
], |
247
|
|
|
'ACOTH' => [ |
248
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
249
|
|
|
'functionCall' => [MathTrig\Trig\Cotangent::class, 'acoth'], |
250
|
|
|
'argumentCount' => '1', |
251
|
|
|
], |
252
|
|
|
'ADDRESS' => [ |
253
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
254
|
|
|
'functionCall' => [LookupRef\Address::class, 'cell'], |
255
|
|
|
'argumentCount' => '2-5', |
256
|
|
|
], |
257
|
|
|
'AGGREGATE' => [ |
258
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
259
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
260
|
|
|
'argumentCount' => '3+', |
261
|
|
|
], |
262
|
|
|
'AMORDEGRC' => [ |
263
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
264
|
|
|
'functionCall' => [Financial\Amortization::class, 'AMORDEGRC'], |
265
|
|
|
'argumentCount' => '6,7', |
266
|
|
|
], |
267
|
|
|
'AMORLINC' => [ |
268
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
269
|
|
|
'functionCall' => [Financial\Amortization::class, 'AMORLINC'], |
270
|
|
|
'argumentCount' => '6,7', |
271
|
|
|
], |
272
|
|
|
'ANCHORARRAY' => [ |
273
|
|
|
'category' => Category::CATEGORY_UNCATEGORISED, |
274
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
275
|
|
|
'argumentCount' => '*', |
276
|
|
|
], |
277
|
|
|
'AND' => [ |
278
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
279
|
|
|
'functionCall' => [Logical\Operations::class, 'logicalAnd'], |
280
|
|
|
'argumentCount' => '1+', |
281
|
|
|
], |
282
|
|
|
'ARABIC' => [ |
283
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
284
|
|
|
'functionCall' => [MathTrig\Arabic::class, 'evaluate'], |
285
|
|
|
'argumentCount' => '1', |
286
|
|
|
], |
287
|
|
|
'AREAS' => [ |
288
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
289
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
290
|
|
|
'argumentCount' => '1', |
291
|
|
|
], |
292
|
|
|
'ARRAYTOTEXT' => [ |
293
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
294
|
|
|
'functionCall' => [TextData\Text::class, 'fromArray'], |
295
|
|
|
'argumentCount' => '1,2', |
296
|
|
|
], |
297
|
|
|
'ASC' => [ |
298
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
299
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
300
|
|
|
'argumentCount' => '1', |
301
|
|
|
], |
302
|
|
|
'ASIN' => [ |
303
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
304
|
|
|
'functionCall' => [MathTrig\Trig\Sine::class, 'asin'], |
305
|
|
|
'argumentCount' => '1', |
306
|
|
|
], |
307
|
|
|
'ASINH' => [ |
308
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
309
|
|
|
'functionCall' => [MathTrig\Trig\Sine::class, 'asinh'], |
310
|
|
|
'argumentCount' => '1', |
311
|
|
|
], |
312
|
|
|
'ATAN' => [ |
313
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
314
|
|
|
'functionCall' => [MathTrig\Trig\Tangent::class, 'atan'], |
315
|
|
|
'argumentCount' => '1', |
316
|
|
|
], |
317
|
|
|
'ATAN2' => [ |
318
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
319
|
|
|
'functionCall' => [MathTrig\Trig\Tangent::class, 'atan2'], |
320
|
|
|
'argumentCount' => '2', |
321
|
|
|
], |
322
|
|
|
'ATANH' => [ |
323
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
324
|
|
|
'functionCall' => [MathTrig\Trig\Tangent::class, 'atanh'], |
325
|
|
|
'argumentCount' => '1', |
326
|
|
|
], |
327
|
|
|
'AVEDEV' => [ |
328
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
329
|
|
|
'functionCall' => [Statistical\Averages::class, 'averageDeviations'], |
330
|
|
|
'argumentCount' => '1+', |
331
|
|
|
], |
332
|
|
|
'AVERAGE' => [ |
333
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
334
|
|
|
'functionCall' => [Statistical\Averages::class, 'average'], |
335
|
|
|
'argumentCount' => '1+', |
336
|
|
|
], |
337
|
|
|
'AVERAGEA' => [ |
338
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
339
|
|
|
'functionCall' => [Statistical\Averages::class, 'averageA'], |
340
|
|
|
'argumentCount' => '1+', |
341
|
|
|
], |
342
|
|
|
'AVERAGEIF' => [ |
343
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
344
|
|
|
'functionCall' => [Statistical\Conditional::class, 'AVERAGEIF'], |
345
|
|
|
'argumentCount' => '2,3', |
346
|
|
|
], |
347
|
|
|
'AVERAGEIFS' => [ |
348
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
349
|
|
|
'functionCall' => [Statistical\Conditional::class, 'AVERAGEIFS'], |
350
|
|
|
'argumentCount' => '3+', |
351
|
|
|
], |
352
|
|
|
'BAHTTEXT' => [ |
353
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
354
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
355
|
|
|
'argumentCount' => '1', |
356
|
|
|
], |
357
|
|
|
'BASE' => [ |
358
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
359
|
|
|
'functionCall' => [MathTrig\Base::class, 'evaluate'], |
360
|
|
|
'argumentCount' => '2,3', |
361
|
|
|
], |
362
|
|
|
'BESSELI' => [ |
363
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
364
|
|
|
'functionCall' => [Engineering\BesselI::class, 'BESSELI'], |
365
|
|
|
'argumentCount' => '2', |
366
|
|
|
], |
367
|
|
|
'BESSELJ' => [ |
368
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
369
|
|
|
'functionCall' => [Engineering\BesselJ::class, 'BESSELJ'], |
370
|
|
|
'argumentCount' => '2', |
371
|
|
|
], |
372
|
|
|
'BESSELK' => [ |
373
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
374
|
|
|
'functionCall' => [Engineering\BesselK::class, 'BESSELK'], |
375
|
|
|
'argumentCount' => '2', |
376
|
|
|
], |
377
|
|
|
'BESSELY' => [ |
378
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
379
|
|
|
'functionCall' => [Engineering\BesselY::class, 'BESSELY'], |
380
|
|
|
'argumentCount' => '2', |
381
|
|
|
], |
382
|
|
|
'BETADIST' => [ |
383
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
384
|
|
|
'functionCall' => [Statistical\Distributions\Beta::class, 'distribution'], |
385
|
|
|
'argumentCount' => '3-5', |
386
|
|
|
], |
387
|
|
|
'BETA.DIST' => [ |
388
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
389
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
390
|
|
|
'argumentCount' => '4-6', |
391
|
|
|
], |
392
|
|
|
'BETAINV' => [ |
393
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
394
|
|
|
'functionCall' => [Statistical\Distributions\Beta::class, 'inverse'], |
395
|
|
|
'argumentCount' => '3-5', |
396
|
|
|
], |
397
|
|
|
'BETA.INV' => [ |
398
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
399
|
|
|
'functionCall' => [Statistical\Distributions\Beta::class, 'inverse'], |
400
|
|
|
'argumentCount' => '3-5', |
401
|
|
|
], |
402
|
|
|
'BIN2DEC' => [ |
403
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
404
|
|
|
'functionCall' => [Engineering\ConvertBinary::class, 'toDecimal'], |
405
|
|
|
'argumentCount' => '1', |
406
|
|
|
], |
407
|
|
|
'BIN2HEX' => [ |
408
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
409
|
|
|
'functionCall' => [Engineering\ConvertBinary::class, 'toHex'], |
410
|
|
|
'argumentCount' => '1,2', |
411
|
|
|
], |
412
|
|
|
'BIN2OCT' => [ |
413
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
414
|
|
|
'functionCall' => [Engineering\ConvertBinary::class, 'toOctal'], |
415
|
|
|
'argumentCount' => '1,2', |
416
|
|
|
], |
417
|
|
|
'BINOMDIST' => [ |
418
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
419
|
|
|
'functionCall' => [Statistical\Distributions\Binomial::class, 'distribution'], |
420
|
|
|
'argumentCount' => '4', |
421
|
|
|
], |
422
|
|
|
'BINOM.DIST' => [ |
423
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
424
|
|
|
'functionCall' => [Statistical\Distributions\Binomial::class, 'distribution'], |
425
|
|
|
'argumentCount' => '4', |
426
|
|
|
], |
427
|
|
|
'BINOM.DIST.RANGE' => [ |
428
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
429
|
|
|
'functionCall' => [Statistical\Distributions\Binomial::class, 'range'], |
430
|
|
|
'argumentCount' => '3,4', |
431
|
|
|
], |
432
|
|
|
'BINOM.INV' => [ |
433
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
434
|
|
|
'functionCall' => [Statistical\Distributions\Binomial::class, 'inverse'], |
435
|
|
|
'argumentCount' => '3', |
436
|
|
|
], |
437
|
|
|
'BITAND' => [ |
438
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
439
|
|
|
'functionCall' => [Engineering\BitWise::class, 'BITAND'], |
440
|
|
|
'argumentCount' => '2', |
441
|
|
|
], |
442
|
|
|
'BITOR' => [ |
443
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
444
|
|
|
'functionCall' => [Engineering\BitWise::class, 'BITOR'], |
445
|
|
|
'argumentCount' => '2', |
446
|
|
|
], |
447
|
|
|
'BITXOR' => [ |
448
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
449
|
|
|
'functionCall' => [Engineering\BitWise::class, 'BITXOR'], |
450
|
|
|
'argumentCount' => '2', |
451
|
|
|
], |
452
|
|
|
'BITLSHIFT' => [ |
453
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
454
|
|
|
'functionCall' => [Engineering\BitWise::class, 'BITLSHIFT'], |
455
|
|
|
'argumentCount' => '2', |
456
|
|
|
], |
457
|
|
|
'BITRSHIFT' => [ |
458
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
459
|
|
|
'functionCall' => [Engineering\BitWise::class, 'BITRSHIFT'], |
460
|
|
|
'argumentCount' => '2', |
461
|
|
|
], |
462
|
|
|
'BYCOL' => [ |
463
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
464
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
465
|
|
|
'argumentCount' => '*', |
466
|
|
|
], |
467
|
|
|
'BYROW' => [ |
468
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
469
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
470
|
|
|
'argumentCount' => '*', |
471
|
|
|
], |
472
|
|
|
'CEILING' => [ |
473
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
474
|
|
|
'functionCall' => [MathTrig\Ceiling::class, 'ceiling'], |
475
|
|
|
'argumentCount' => '1-2', // 2 for Excel, 1-2 for Ods/Gnumeric |
476
|
|
|
], |
477
|
|
|
'CEILING.MATH' => [ |
478
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
479
|
|
|
'functionCall' => [MathTrig\Ceiling::class, 'math'], |
480
|
|
|
'argumentCount' => '1-3', |
481
|
|
|
], |
482
|
|
|
'CEILING.PRECISE' => [ |
483
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
484
|
|
|
'functionCall' => [MathTrig\Ceiling::class, 'precise'], |
485
|
|
|
'argumentCount' => '1,2', |
486
|
|
|
], |
487
|
|
|
'CELL' => [ |
488
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
489
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
490
|
|
|
'argumentCount' => '1,2', |
491
|
|
|
], |
492
|
|
|
'CHAR' => [ |
493
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
494
|
|
|
'functionCall' => [TextData\CharacterConvert::class, 'character'], |
495
|
|
|
'argumentCount' => '1', |
496
|
|
|
], |
497
|
|
|
'CHIDIST' => [ |
498
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
499
|
|
|
'functionCall' => [Statistical\Distributions\ChiSquared::class, 'distributionRightTail'], |
500
|
|
|
'argumentCount' => '2', |
501
|
|
|
], |
502
|
|
|
'CHISQ.DIST' => [ |
503
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
504
|
|
|
'functionCall' => [Statistical\Distributions\ChiSquared::class, 'distributionLeftTail'], |
505
|
|
|
'argumentCount' => '3', |
506
|
|
|
], |
507
|
|
|
'CHISQ.DIST.RT' => [ |
508
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
509
|
|
|
'functionCall' => [Statistical\Distributions\ChiSquared::class, 'distributionRightTail'], |
510
|
|
|
'argumentCount' => '2', |
511
|
|
|
], |
512
|
|
|
'CHIINV' => [ |
513
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
514
|
|
|
'functionCall' => [Statistical\Distributions\ChiSquared::class, 'inverseRightTail'], |
515
|
|
|
'argumentCount' => '2', |
516
|
|
|
], |
517
|
|
|
'CHISQ.INV' => [ |
518
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
519
|
|
|
'functionCall' => [Statistical\Distributions\ChiSquared::class, 'inverseLeftTail'], |
520
|
|
|
'argumentCount' => '2', |
521
|
|
|
], |
522
|
|
|
'CHISQ.INV.RT' => [ |
523
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
524
|
|
|
'functionCall' => [Statistical\Distributions\ChiSquared::class, 'inverseRightTail'], |
525
|
|
|
'argumentCount' => '2', |
526
|
|
|
], |
527
|
|
|
'CHITEST' => [ |
528
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
529
|
|
|
'functionCall' => [Statistical\Distributions\ChiSquared::class, 'test'], |
530
|
|
|
'argumentCount' => '2', |
531
|
|
|
], |
532
|
|
|
'CHISQ.TEST' => [ |
533
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
534
|
|
|
'functionCall' => [Statistical\Distributions\ChiSquared::class, 'test'], |
535
|
|
|
'argumentCount' => '2', |
536
|
|
|
], |
537
|
|
|
'CHOOSE' => [ |
538
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
539
|
|
|
'functionCall' => [LookupRef\Selection::class, 'CHOOSE'], |
540
|
|
|
'argumentCount' => '2+', |
541
|
|
|
], |
542
|
|
|
'CHOOSECOLS' => [ |
543
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
544
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
545
|
|
|
'argumentCount' => '2+', |
546
|
|
|
], |
547
|
|
|
'CHOOSEROWS' => [ |
548
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
549
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
550
|
|
|
'argumentCount' => '2+', |
551
|
|
|
], |
552
|
|
|
'CLEAN' => [ |
553
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
554
|
|
|
'functionCall' => [TextData\Trim::class, 'nonPrintable'], |
555
|
|
|
'argumentCount' => '1', |
556
|
|
|
], |
557
|
|
|
'CODE' => [ |
558
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
559
|
|
|
'functionCall' => [TextData\CharacterConvert::class, 'code'], |
560
|
|
|
'argumentCount' => '1', |
561
|
|
|
], |
562
|
|
|
'COLUMN' => [ |
563
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
564
|
|
|
'functionCall' => [LookupRef\RowColumnInformation::class, 'COLUMN'], |
565
|
|
|
'argumentCount' => '-1', |
566
|
|
|
'passCellReference' => true, |
567
|
|
|
'passByReference' => [true], |
568
|
|
|
], |
569
|
|
|
'COLUMNS' => [ |
570
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
571
|
|
|
'functionCall' => [LookupRef\RowColumnInformation::class, 'COLUMNS'], |
572
|
|
|
'argumentCount' => '1', |
573
|
|
|
], |
574
|
|
|
'COMBIN' => [ |
575
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
576
|
|
|
'functionCall' => [MathTrig\Combinations::class, 'withoutRepetition'], |
577
|
|
|
'argumentCount' => '2', |
578
|
|
|
], |
579
|
|
|
'COMBINA' => [ |
580
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
581
|
|
|
'functionCall' => [MathTrig\Combinations::class, 'withRepetition'], |
582
|
|
|
'argumentCount' => '2', |
583
|
|
|
], |
584
|
|
|
'COMPLEX' => [ |
585
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
586
|
|
|
'functionCall' => [Engineering\Complex::class, 'COMPLEX'], |
587
|
|
|
'argumentCount' => '2,3', |
588
|
|
|
], |
589
|
|
|
'CONCAT' => [ |
590
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
591
|
|
|
'functionCall' => [TextData\Concatenate::class, 'CONCATENATE'], |
592
|
|
|
'argumentCount' => '1+', |
593
|
|
|
], |
594
|
|
|
'CONCATENATE' => [ |
595
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
596
|
|
|
'functionCall' => [TextData\Concatenate::class, 'CONCATENATE'], |
597
|
|
|
'argumentCount' => '1+', |
598
|
|
|
], |
599
|
|
|
'CONFIDENCE' => [ |
600
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
601
|
|
|
'functionCall' => [Statistical\Confidence::class, 'CONFIDENCE'], |
602
|
|
|
'argumentCount' => '3', |
603
|
|
|
], |
604
|
|
|
'CONFIDENCE.NORM' => [ |
605
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
606
|
|
|
'functionCall' => [Statistical\Confidence::class, 'CONFIDENCE'], |
607
|
|
|
'argumentCount' => '3', |
608
|
|
|
], |
609
|
|
|
'CONFIDENCE.T' => [ |
610
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
611
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
612
|
|
|
'argumentCount' => '3', |
613
|
|
|
], |
614
|
|
|
'CONVERT' => [ |
615
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
616
|
|
|
'functionCall' => [Engineering\ConvertUOM::class, 'CONVERT'], |
617
|
|
|
'argumentCount' => '3', |
618
|
|
|
], |
619
|
|
|
'CORREL' => [ |
620
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
621
|
|
|
'functionCall' => [Statistical\Trends::class, 'CORREL'], |
622
|
|
|
'argumentCount' => '2', |
623
|
|
|
], |
624
|
|
|
'COS' => [ |
625
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
626
|
|
|
'functionCall' => [MathTrig\Trig\Cosine::class, 'cos'], |
627
|
|
|
'argumentCount' => '1', |
628
|
|
|
], |
629
|
|
|
'COSH' => [ |
630
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
631
|
|
|
'functionCall' => [MathTrig\Trig\Cosine::class, 'cosh'], |
632
|
|
|
'argumentCount' => '1', |
633
|
|
|
], |
634
|
|
|
'COT' => [ |
635
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
636
|
|
|
'functionCall' => [MathTrig\Trig\Cotangent::class, 'cot'], |
637
|
|
|
'argumentCount' => '1', |
638
|
|
|
], |
639
|
|
|
'COTH' => [ |
640
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
641
|
|
|
'functionCall' => [MathTrig\Trig\Cotangent::class, 'coth'], |
642
|
|
|
'argumentCount' => '1', |
643
|
|
|
], |
644
|
|
|
'COUNT' => [ |
645
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
646
|
|
|
'functionCall' => [Statistical\Counts::class, 'COUNT'], |
647
|
|
|
'argumentCount' => '1+', |
648
|
|
|
], |
649
|
|
|
'COUNTA' => [ |
650
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
651
|
|
|
'functionCall' => [Statistical\Counts::class, 'COUNTA'], |
652
|
|
|
'argumentCount' => '1+', |
653
|
|
|
], |
654
|
|
|
'COUNTBLANK' => [ |
655
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
656
|
|
|
'functionCall' => [Statistical\Counts::class, 'COUNTBLANK'], |
657
|
|
|
'argumentCount' => '1', |
658
|
|
|
], |
659
|
|
|
'COUNTIF' => [ |
660
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
661
|
|
|
'functionCall' => [Statistical\Conditional::class, 'COUNTIF'], |
662
|
|
|
'argumentCount' => '2', |
663
|
|
|
], |
664
|
|
|
'COUNTIFS' => [ |
665
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
666
|
|
|
'functionCall' => [Statistical\Conditional::class, 'COUNTIFS'], |
667
|
|
|
'argumentCount' => '2+', |
668
|
|
|
], |
669
|
|
|
'COUPDAYBS' => [ |
670
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
671
|
|
|
'functionCall' => [Financial\Coupons::class, 'COUPDAYBS'], |
672
|
|
|
'argumentCount' => '3,4', |
673
|
|
|
], |
674
|
|
|
'COUPDAYS' => [ |
675
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
676
|
|
|
'functionCall' => [Financial\Coupons::class, 'COUPDAYS'], |
677
|
|
|
'argumentCount' => '3,4', |
678
|
|
|
], |
679
|
|
|
'COUPDAYSNC' => [ |
680
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
681
|
|
|
'functionCall' => [Financial\Coupons::class, 'COUPDAYSNC'], |
682
|
|
|
'argumentCount' => '3,4', |
683
|
|
|
], |
684
|
|
|
'COUPNCD' => [ |
685
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
686
|
|
|
'functionCall' => [Financial\Coupons::class, 'COUPNCD'], |
687
|
|
|
'argumentCount' => '3,4', |
688
|
|
|
], |
689
|
|
|
'COUPNUM' => [ |
690
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
691
|
|
|
'functionCall' => [Financial\Coupons::class, 'COUPNUM'], |
692
|
|
|
'argumentCount' => '3,4', |
693
|
|
|
], |
694
|
|
|
'COUPPCD' => [ |
695
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
696
|
|
|
'functionCall' => [Financial\Coupons::class, 'COUPPCD'], |
697
|
|
|
'argumentCount' => '3,4', |
698
|
|
|
], |
699
|
|
|
'COVAR' => [ |
700
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
701
|
|
|
'functionCall' => [Statistical\Trends::class, 'COVAR'], |
702
|
|
|
'argumentCount' => '2', |
703
|
|
|
], |
704
|
|
|
'COVARIANCE.P' => [ |
705
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
706
|
|
|
'functionCall' => [Statistical\Trends::class, 'COVAR'], |
707
|
|
|
'argumentCount' => '2', |
708
|
|
|
], |
709
|
|
|
'COVARIANCE.S' => [ |
710
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
711
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
712
|
|
|
'argumentCount' => '2', |
713
|
|
|
], |
714
|
|
|
'CRITBINOM' => [ |
715
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
716
|
|
|
'functionCall' => [Statistical\Distributions\Binomial::class, 'inverse'], |
717
|
|
|
'argumentCount' => '3', |
718
|
|
|
], |
719
|
|
|
'CSC' => [ |
720
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
721
|
|
|
'functionCall' => [MathTrig\Trig\Cosecant::class, 'csc'], |
722
|
|
|
'argumentCount' => '1', |
723
|
|
|
], |
724
|
|
|
'CSCH' => [ |
725
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
726
|
|
|
'functionCall' => [MathTrig\Trig\Cosecant::class, 'csch'], |
727
|
|
|
'argumentCount' => '1', |
728
|
|
|
], |
729
|
|
|
'CUBEKPIMEMBER' => [ |
730
|
|
|
'category' => Category::CATEGORY_CUBE, |
731
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
732
|
|
|
'argumentCount' => '?', |
733
|
|
|
], |
734
|
|
|
'CUBEMEMBER' => [ |
735
|
|
|
'category' => Category::CATEGORY_CUBE, |
736
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
737
|
|
|
'argumentCount' => '?', |
738
|
|
|
], |
739
|
|
|
'CUBEMEMBERPROPERTY' => [ |
740
|
|
|
'category' => Category::CATEGORY_CUBE, |
741
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
742
|
|
|
'argumentCount' => '?', |
743
|
|
|
], |
744
|
|
|
'CUBERANKEDMEMBER' => [ |
745
|
|
|
'category' => Category::CATEGORY_CUBE, |
746
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
747
|
|
|
'argumentCount' => '?', |
748
|
|
|
], |
749
|
|
|
'CUBESET' => [ |
750
|
|
|
'category' => Category::CATEGORY_CUBE, |
751
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
752
|
|
|
'argumentCount' => '?', |
753
|
|
|
], |
754
|
|
|
'CUBESETCOUNT' => [ |
755
|
|
|
'category' => Category::CATEGORY_CUBE, |
756
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
757
|
|
|
'argumentCount' => '?', |
758
|
|
|
], |
759
|
|
|
'CUBEVALUE' => [ |
760
|
|
|
'category' => Category::CATEGORY_CUBE, |
761
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
762
|
|
|
'argumentCount' => '?', |
763
|
|
|
], |
764
|
|
|
'CUMIPMT' => [ |
765
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
766
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic\Cumulative::class, 'interest'], |
767
|
|
|
'argumentCount' => '6', |
768
|
|
|
], |
769
|
|
|
'CUMPRINC' => [ |
770
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
771
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic\Cumulative::class, 'principal'], |
772
|
|
|
'argumentCount' => '6', |
773
|
|
|
], |
774
|
|
|
'DATE' => [ |
775
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
776
|
|
|
'functionCall' => [DateTimeExcel\Date::class, 'fromYMD'], |
777
|
|
|
'argumentCount' => '3', |
778
|
|
|
], |
779
|
|
|
'DATEDIF' => [ |
780
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
781
|
|
|
'functionCall' => [DateTimeExcel\Difference::class, 'interval'], |
782
|
|
|
'argumentCount' => '2,3', |
783
|
|
|
], |
784
|
|
|
'DATESTRING' => [ |
785
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
786
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
787
|
|
|
'argumentCount' => '?', |
788
|
|
|
], |
789
|
|
|
'DATEVALUE' => [ |
790
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
791
|
|
|
'functionCall' => [DateTimeExcel\DateValue::class, 'fromString'], |
792
|
|
|
'argumentCount' => '1', |
793
|
|
|
], |
794
|
|
|
'DAVERAGE' => [ |
795
|
|
|
'category' => Category::CATEGORY_DATABASE, |
796
|
|
|
'functionCall' => [Database\DAverage::class, 'evaluate'], |
797
|
|
|
'argumentCount' => '3', |
798
|
|
|
], |
799
|
|
|
'DAY' => [ |
800
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
801
|
|
|
'functionCall' => [DateTimeExcel\DateParts::class, 'day'], |
802
|
|
|
'argumentCount' => '1', |
803
|
|
|
], |
804
|
|
|
'DAYS' => [ |
805
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
806
|
|
|
'functionCall' => [DateTimeExcel\Days::class, 'between'], |
807
|
|
|
'argumentCount' => '2', |
808
|
|
|
], |
809
|
|
|
'DAYS360' => [ |
810
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
811
|
|
|
'functionCall' => [DateTimeExcel\Days360::class, 'between'], |
812
|
|
|
'argumentCount' => '2,3', |
813
|
|
|
], |
814
|
|
|
'DB' => [ |
815
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
816
|
|
|
'functionCall' => [Financial\Depreciation::class, 'DB'], |
817
|
|
|
'argumentCount' => '4,5', |
818
|
|
|
], |
819
|
|
|
'DBCS' => [ |
820
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
821
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
822
|
|
|
'argumentCount' => '1', |
823
|
|
|
], |
824
|
|
|
'DCOUNT' => [ |
825
|
|
|
'category' => Category::CATEGORY_DATABASE, |
826
|
|
|
'functionCall' => [Database\DCount::class, 'evaluate'], |
827
|
|
|
'argumentCount' => '3', |
828
|
|
|
], |
829
|
|
|
'DCOUNTA' => [ |
830
|
|
|
'category' => Category::CATEGORY_DATABASE, |
831
|
|
|
'functionCall' => [Database\DCountA::class, 'evaluate'], |
832
|
|
|
'argumentCount' => '3', |
833
|
|
|
], |
834
|
|
|
'DDB' => [ |
835
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
836
|
|
|
'functionCall' => [Financial\Depreciation::class, 'DDB'], |
837
|
|
|
'argumentCount' => '4,5', |
838
|
|
|
], |
839
|
|
|
'DEC2BIN' => [ |
840
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
841
|
|
|
'functionCall' => [Engineering\ConvertDecimal::class, 'toBinary'], |
842
|
|
|
'argumentCount' => '1,2', |
843
|
|
|
], |
844
|
|
|
'DEC2HEX' => [ |
845
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
846
|
|
|
'functionCall' => [Engineering\ConvertDecimal::class, 'toHex'], |
847
|
|
|
'argumentCount' => '1,2', |
848
|
|
|
], |
849
|
|
|
'DEC2OCT' => [ |
850
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
851
|
|
|
'functionCall' => [Engineering\ConvertDecimal::class, 'toOctal'], |
852
|
|
|
'argumentCount' => '1,2', |
853
|
|
|
], |
854
|
|
|
'DECIMAL' => [ |
855
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
856
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
857
|
|
|
'argumentCount' => '2', |
858
|
|
|
], |
859
|
|
|
'DEGREES' => [ |
860
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
861
|
|
|
'functionCall' => [MathTrig\Angle::class, 'toDegrees'], |
862
|
|
|
'argumentCount' => '1', |
863
|
|
|
], |
864
|
|
|
'DELTA' => [ |
865
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
866
|
|
|
'functionCall' => [Engineering\Compare::class, 'DELTA'], |
867
|
|
|
'argumentCount' => '1,2', |
868
|
|
|
], |
869
|
|
|
'DEVSQ' => [ |
870
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
871
|
|
|
'functionCall' => [Statistical\Deviations::class, 'sumSquares'], |
872
|
|
|
'argumentCount' => '1+', |
873
|
|
|
], |
874
|
|
|
'DGET' => [ |
875
|
|
|
'category' => Category::CATEGORY_DATABASE, |
876
|
|
|
'functionCall' => [Database\DGet::class, 'evaluate'], |
877
|
|
|
'argumentCount' => '3', |
878
|
|
|
], |
879
|
|
|
'DISC' => [ |
880
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
881
|
|
|
'functionCall' => [Financial\Securities\Rates::class, 'discount'], |
882
|
|
|
'argumentCount' => '4,5', |
883
|
|
|
], |
884
|
|
|
'DMAX' => [ |
885
|
|
|
'category' => Category::CATEGORY_DATABASE, |
886
|
|
|
'functionCall' => [Database\DMax::class, 'evaluate'], |
887
|
|
|
'argumentCount' => '3', |
888
|
|
|
], |
889
|
|
|
'DMIN' => [ |
890
|
|
|
'category' => Category::CATEGORY_DATABASE, |
891
|
|
|
'functionCall' => [Database\DMin::class, 'evaluate'], |
892
|
|
|
'argumentCount' => '3', |
893
|
|
|
], |
894
|
|
|
'DOLLAR' => [ |
895
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
896
|
|
|
'functionCall' => [TextData\Format::class, 'DOLLAR'], |
897
|
|
|
'argumentCount' => '1,2', |
898
|
|
|
], |
899
|
|
|
'DOLLARDE' => [ |
900
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
901
|
|
|
'functionCall' => [Financial\Dollar::class, 'decimal'], |
902
|
|
|
'argumentCount' => '2', |
903
|
|
|
], |
904
|
|
|
'DOLLARFR' => [ |
905
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
906
|
|
|
'functionCall' => [Financial\Dollar::class, 'fractional'], |
907
|
|
|
'argumentCount' => '2', |
908
|
|
|
], |
909
|
|
|
'DPRODUCT' => [ |
910
|
|
|
'category' => Category::CATEGORY_DATABASE, |
911
|
|
|
'functionCall' => [Database\DProduct::class, 'evaluate'], |
912
|
|
|
'argumentCount' => '3', |
913
|
|
|
], |
914
|
|
|
'DROP' => [ |
915
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
916
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
917
|
|
|
'argumentCount' => '2-3', |
918
|
|
|
], |
919
|
|
|
'DSTDEV' => [ |
920
|
|
|
'category' => Category::CATEGORY_DATABASE, |
921
|
|
|
'functionCall' => [Database\DStDev::class, 'evaluate'], |
922
|
|
|
'argumentCount' => '3', |
923
|
|
|
], |
924
|
|
|
'DSTDEVP' => [ |
925
|
|
|
'category' => Category::CATEGORY_DATABASE, |
926
|
|
|
'functionCall' => [Database\DStDevP::class, 'evaluate'], |
927
|
|
|
'argumentCount' => '3', |
928
|
|
|
], |
929
|
|
|
'DSUM' => [ |
930
|
|
|
'category' => Category::CATEGORY_DATABASE, |
931
|
|
|
'functionCall' => [Database\DSum::class, 'evaluate'], |
932
|
|
|
'argumentCount' => '3', |
933
|
|
|
], |
934
|
|
|
'DURATION' => [ |
935
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
936
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
937
|
|
|
'argumentCount' => '5,6', |
938
|
|
|
], |
939
|
|
|
'DVAR' => [ |
940
|
|
|
'category' => Category::CATEGORY_DATABASE, |
941
|
|
|
'functionCall' => [Database\DVar::class, 'evaluate'], |
942
|
|
|
'argumentCount' => '3', |
943
|
|
|
], |
944
|
|
|
'DVARP' => [ |
945
|
|
|
'category' => Category::CATEGORY_DATABASE, |
946
|
|
|
'functionCall' => [Database\DVarP::class, 'evaluate'], |
947
|
|
|
'argumentCount' => '3', |
948
|
|
|
], |
949
|
|
|
'ECMA.CEILING' => [ |
950
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
951
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
952
|
|
|
'argumentCount' => '1,2', |
953
|
|
|
], |
954
|
|
|
'EDATE' => [ |
955
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
956
|
|
|
'functionCall' => [DateTimeExcel\Month::class, 'adjust'], |
957
|
|
|
'argumentCount' => '2', |
958
|
|
|
], |
959
|
|
|
'EFFECT' => [ |
960
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
961
|
|
|
'functionCall' => [Financial\InterestRate::class, 'effective'], |
962
|
|
|
'argumentCount' => '2', |
963
|
|
|
], |
964
|
|
|
'ENCODEURL' => [ |
965
|
|
|
'category' => Category::CATEGORY_WEB, |
966
|
|
|
'functionCall' => [Web\Service::class, 'urlEncode'], |
967
|
|
|
'argumentCount' => '1', |
968
|
|
|
], |
969
|
|
|
'EOMONTH' => [ |
970
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
971
|
|
|
'functionCall' => [DateTimeExcel\Month::class, 'lastDay'], |
972
|
|
|
'argumentCount' => '2', |
973
|
|
|
], |
974
|
|
|
'ERF' => [ |
975
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
976
|
|
|
'functionCall' => [Engineering\Erf::class, 'ERF'], |
977
|
|
|
'argumentCount' => '1,2', |
978
|
|
|
], |
979
|
|
|
'ERF.PRECISE' => [ |
980
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
981
|
|
|
'functionCall' => [Engineering\Erf::class, 'ERFPRECISE'], |
982
|
|
|
'argumentCount' => '1', |
983
|
|
|
], |
984
|
|
|
'ERFC' => [ |
985
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
986
|
|
|
'functionCall' => [Engineering\ErfC::class, 'ERFC'], |
987
|
|
|
'argumentCount' => '1', |
988
|
|
|
], |
989
|
|
|
'ERFC.PRECISE' => [ |
990
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
991
|
|
|
'functionCall' => [Engineering\ErfC::class, 'ERFC'], |
992
|
|
|
'argumentCount' => '1', |
993
|
|
|
], |
994
|
|
|
'ERROR.TYPE' => [ |
995
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
996
|
|
|
'functionCall' => [Information\ExcelError::class, 'type'], |
997
|
|
|
'argumentCount' => '1', |
998
|
|
|
], |
999
|
|
|
'EVEN' => [ |
1000
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1001
|
|
|
'functionCall' => [MathTrig\Round::class, 'even'], |
1002
|
|
|
'argumentCount' => '1', |
1003
|
|
|
], |
1004
|
|
|
'EXACT' => [ |
1005
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1006
|
|
|
'functionCall' => [TextData\Text::class, 'exact'], |
1007
|
|
|
'argumentCount' => '2', |
1008
|
|
|
], |
1009
|
|
|
'EXP' => [ |
1010
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1011
|
|
|
'functionCall' => [MathTrig\Exp::class, 'evaluate'], |
1012
|
|
|
'argumentCount' => '1', |
1013
|
|
|
], |
1014
|
|
|
'EXPAND' => [ |
1015
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1016
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1017
|
|
|
'argumentCount' => '2-4', |
1018
|
|
|
], |
1019
|
|
|
'EXPONDIST' => [ |
1020
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1021
|
|
|
'functionCall' => [Statistical\Distributions\Exponential::class, 'distribution'], |
1022
|
|
|
'argumentCount' => '3', |
1023
|
|
|
], |
1024
|
|
|
'EXPON.DIST' => [ |
1025
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1026
|
|
|
'functionCall' => [Statistical\Distributions\Exponential::class, 'distribution'], |
1027
|
|
|
'argumentCount' => '3', |
1028
|
|
|
], |
1029
|
|
|
'FACT' => [ |
1030
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1031
|
|
|
'functionCall' => [MathTrig\Factorial::class, 'fact'], |
1032
|
|
|
'argumentCount' => '1', |
1033
|
|
|
], |
1034
|
|
|
'FACTDOUBLE' => [ |
1035
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1036
|
|
|
'functionCall' => [MathTrig\Factorial::class, 'factDouble'], |
1037
|
|
|
'argumentCount' => '1', |
1038
|
|
|
], |
1039
|
|
|
'FALSE' => [ |
1040
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1041
|
|
|
'functionCall' => [Logical\Boolean::class, 'FALSE'], |
1042
|
|
|
'argumentCount' => '0', |
1043
|
|
|
], |
1044
|
|
|
'FDIST' => [ |
1045
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1046
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1047
|
|
|
'argumentCount' => '3', |
1048
|
|
|
], |
1049
|
|
|
'F.DIST' => [ |
1050
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1051
|
|
|
'functionCall' => [Statistical\Distributions\F::class, 'distribution'], |
1052
|
|
|
'argumentCount' => '4', |
1053
|
|
|
], |
1054
|
|
|
'F.DIST.RT' => [ |
1055
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1056
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1057
|
|
|
'argumentCount' => '3', |
1058
|
|
|
], |
1059
|
|
|
'FILTER' => [ |
1060
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1061
|
|
|
'functionCall' => [LookupRef\Filter::class, 'filter'], |
1062
|
|
|
'argumentCount' => '2-3', |
1063
|
|
|
], |
1064
|
|
|
'FILTERXML' => [ |
1065
|
|
|
'category' => Category::CATEGORY_WEB, |
1066
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1067
|
|
|
'argumentCount' => '2', |
1068
|
|
|
], |
1069
|
|
|
'FIND' => [ |
1070
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1071
|
|
|
'functionCall' => [TextData\Search::class, 'sensitive'], |
1072
|
|
|
'argumentCount' => '2,3', |
1073
|
|
|
], |
1074
|
|
|
'FINDB' => [ |
1075
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1076
|
|
|
'functionCall' => [TextData\Search::class, 'sensitive'], |
1077
|
|
|
'argumentCount' => '2,3', |
1078
|
|
|
], |
1079
|
|
|
'FINV' => [ |
1080
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1081
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1082
|
|
|
'argumentCount' => '3', |
1083
|
|
|
], |
1084
|
|
|
'F.INV' => [ |
1085
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1086
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1087
|
|
|
'argumentCount' => '3', |
1088
|
|
|
], |
1089
|
|
|
'F.INV.RT' => [ |
1090
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1091
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1092
|
|
|
'argumentCount' => '3', |
1093
|
|
|
], |
1094
|
|
|
'FISHER' => [ |
1095
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1096
|
|
|
'functionCall' => [Statistical\Distributions\Fisher::class, 'distribution'], |
1097
|
|
|
'argumentCount' => '1', |
1098
|
|
|
], |
1099
|
|
|
'FISHERINV' => [ |
1100
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1101
|
|
|
'functionCall' => [Statistical\Distributions\Fisher::class, 'inverse'], |
1102
|
|
|
'argumentCount' => '1', |
1103
|
|
|
], |
1104
|
|
|
'FIXED' => [ |
1105
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1106
|
|
|
'functionCall' => [TextData\Format::class, 'FIXEDFORMAT'], |
1107
|
|
|
'argumentCount' => '1-3', |
1108
|
|
|
], |
1109
|
|
|
'FLOOR' => [ |
1110
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1111
|
|
|
'functionCall' => [MathTrig\Floor::class, 'floor'], |
1112
|
|
|
'argumentCount' => '1-2', // Excel requries 2, Ods/Gnumeric 1-2 |
1113
|
|
|
], |
1114
|
|
|
'FLOOR.MATH' => [ |
1115
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1116
|
|
|
'functionCall' => [MathTrig\Floor::class, 'math'], |
1117
|
|
|
'argumentCount' => '1-3', |
1118
|
|
|
], |
1119
|
|
|
'FLOOR.PRECISE' => [ |
1120
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1121
|
|
|
'functionCall' => [MathTrig\Floor::class, 'precise'], |
1122
|
|
|
'argumentCount' => '1-2', |
1123
|
|
|
], |
1124
|
|
|
'FORECAST' => [ |
1125
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1126
|
|
|
'functionCall' => [Statistical\Trends::class, 'FORECAST'], |
1127
|
|
|
'argumentCount' => '3', |
1128
|
|
|
], |
1129
|
|
|
'FORECAST.ETS' => [ |
1130
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1131
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1132
|
|
|
'argumentCount' => '3-6', |
1133
|
|
|
], |
1134
|
|
|
'FORECAST.ETS.CONFINT' => [ |
1135
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1136
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1137
|
|
|
'argumentCount' => '3-6', |
1138
|
|
|
], |
1139
|
|
|
'FORECAST.ETS.SEASONALITY' => [ |
1140
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1141
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1142
|
|
|
'argumentCount' => '2-4', |
1143
|
|
|
], |
1144
|
|
|
'FORECAST.ETS.STAT' => [ |
1145
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1146
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1147
|
|
|
'argumentCount' => '3-6', |
1148
|
|
|
], |
1149
|
|
|
'FORECAST.LINEAR' => [ |
1150
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1151
|
|
|
'functionCall' => [Statistical\Trends::class, 'FORECAST'], |
1152
|
|
|
'argumentCount' => '3', |
1153
|
|
|
], |
1154
|
|
|
'FORMULATEXT' => [ |
1155
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1156
|
|
|
'functionCall' => [LookupRef\Formula::class, 'text'], |
1157
|
|
|
'argumentCount' => '1', |
1158
|
|
|
'passCellReference' => true, |
1159
|
|
|
'passByReference' => [true], |
1160
|
|
|
], |
1161
|
|
|
'FREQUENCY' => [ |
1162
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1163
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1164
|
|
|
'argumentCount' => '2', |
1165
|
|
|
], |
1166
|
|
|
'FTEST' => [ |
1167
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1168
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1169
|
|
|
'argumentCount' => '2', |
1170
|
|
|
], |
1171
|
|
|
'F.TEST' => [ |
1172
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1173
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1174
|
|
|
'argumentCount' => '2', |
1175
|
|
|
], |
1176
|
|
|
'FV' => [ |
1177
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1178
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic::class, 'futureValue'], |
1179
|
|
|
'argumentCount' => '3-5', |
1180
|
|
|
], |
1181
|
|
|
'FVSCHEDULE' => [ |
1182
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1183
|
|
|
'functionCall' => [Financial\CashFlow\Single::class, 'futureValue'], |
1184
|
|
|
'argumentCount' => '2', |
1185
|
|
|
], |
1186
|
|
|
'GAMMA' => [ |
1187
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1188
|
|
|
'functionCall' => [Statistical\Distributions\Gamma::class, 'gamma'], |
1189
|
|
|
'argumentCount' => '1', |
1190
|
|
|
], |
1191
|
|
|
'GAMMADIST' => [ |
1192
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1193
|
|
|
'functionCall' => [Statistical\Distributions\Gamma::class, 'distribution'], |
1194
|
|
|
'argumentCount' => '4', |
1195
|
|
|
], |
1196
|
|
|
'GAMMA.DIST' => [ |
1197
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1198
|
|
|
'functionCall' => [Statistical\Distributions\Gamma::class, 'distribution'], |
1199
|
|
|
'argumentCount' => '4', |
1200
|
|
|
], |
1201
|
|
|
'GAMMAINV' => [ |
1202
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1203
|
|
|
'functionCall' => [Statistical\Distributions\Gamma::class, 'inverse'], |
1204
|
|
|
'argumentCount' => '3', |
1205
|
|
|
], |
1206
|
|
|
'GAMMA.INV' => [ |
1207
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1208
|
|
|
'functionCall' => [Statistical\Distributions\Gamma::class, 'inverse'], |
1209
|
|
|
'argumentCount' => '3', |
1210
|
|
|
], |
1211
|
|
|
'GAMMALN' => [ |
1212
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1213
|
|
|
'functionCall' => [Statistical\Distributions\Gamma::class, 'ln'], |
1214
|
|
|
'argumentCount' => '1', |
1215
|
|
|
], |
1216
|
|
|
'GAMMALN.PRECISE' => [ |
1217
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1218
|
|
|
'functionCall' => [Statistical\Distributions\Gamma::class, 'ln'], |
1219
|
|
|
'argumentCount' => '1', |
1220
|
|
|
], |
1221
|
|
|
'GAUSS' => [ |
1222
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1223
|
|
|
'functionCall' => [Statistical\Distributions\StandardNormal::class, 'gauss'], |
1224
|
|
|
'argumentCount' => '1', |
1225
|
|
|
], |
1226
|
|
|
'GCD' => [ |
1227
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1228
|
|
|
'functionCall' => [MathTrig\Gcd::class, 'evaluate'], |
1229
|
|
|
'argumentCount' => '1+', |
1230
|
|
|
], |
1231
|
|
|
'GEOMEAN' => [ |
1232
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1233
|
|
|
'functionCall' => [Statistical\Averages\Mean::class, 'geometric'], |
1234
|
|
|
'argumentCount' => '1+', |
1235
|
|
|
], |
1236
|
|
|
'GESTEP' => [ |
1237
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1238
|
|
|
'functionCall' => [Engineering\Compare::class, 'GESTEP'], |
1239
|
|
|
'argumentCount' => '1,2', |
1240
|
|
|
], |
1241
|
|
|
'GETPIVOTDATA' => [ |
1242
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1243
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1244
|
|
|
'argumentCount' => '2+', |
1245
|
|
|
], |
1246
|
|
|
'GROWTH' => [ |
1247
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1248
|
|
|
'functionCall' => [Statistical\Trends::class, 'GROWTH'], |
1249
|
|
|
'argumentCount' => '1-4', |
1250
|
|
|
], |
1251
|
|
|
'HARMEAN' => [ |
1252
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1253
|
|
|
'functionCall' => [Statistical\Averages\Mean::class, 'harmonic'], |
1254
|
|
|
'argumentCount' => '1+', |
1255
|
|
|
], |
1256
|
|
|
'HEX2BIN' => [ |
1257
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1258
|
|
|
'functionCall' => [Engineering\ConvertHex::class, 'toBinary'], |
1259
|
|
|
'argumentCount' => '1,2', |
1260
|
|
|
], |
1261
|
|
|
'HEX2DEC' => [ |
1262
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1263
|
|
|
'functionCall' => [Engineering\ConvertHex::class, 'toDecimal'], |
1264
|
|
|
'argumentCount' => '1', |
1265
|
|
|
], |
1266
|
|
|
'HEX2OCT' => [ |
1267
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1268
|
|
|
'functionCall' => [Engineering\ConvertHex::class, 'toOctal'], |
1269
|
|
|
'argumentCount' => '1,2', |
1270
|
|
|
], |
1271
|
|
|
'HLOOKUP' => [ |
1272
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1273
|
|
|
'functionCall' => [LookupRef\HLookup::class, 'lookup'], |
1274
|
|
|
'argumentCount' => '3,4', |
1275
|
|
|
], |
1276
|
|
|
'HOUR' => [ |
1277
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
1278
|
|
|
'functionCall' => [DateTimeExcel\TimeParts::class, 'hour'], |
1279
|
|
|
'argumentCount' => '1', |
1280
|
|
|
], |
1281
|
|
|
'HSTACK' => [ |
1282
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1283
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1284
|
|
|
'argumentCount' => '1+', |
1285
|
|
|
], |
1286
|
|
|
'HYPERLINK' => [ |
1287
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1288
|
|
|
'functionCall' => [LookupRef\Hyperlink::class, 'set'], |
1289
|
|
|
'argumentCount' => '1,2', |
1290
|
|
|
'passCellReference' => true, |
1291
|
|
|
], |
1292
|
|
|
'HYPGEOMDIST' => [ |
1293
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1294
|
|
|
'functionCall' => [Statistical\Distributions\HyperGeometric::class, 'distribution'], |
1295
|
|
|
'argumentCount' => '4', |
1296
|
|
|
], |
1297
|
|
|
'HYPGEOM.DIST' => [ |
1298
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1299
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1300
|
|
|
'argumentCount' => '5', |
1301
|
|
|
], |
1302
|
|
|
'IF' => [ |
1303
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1304
|
|
|
'functionCall' => [Logical\Conditional::class, 'statementIf'], |
1305
|
|
|
'argumentCount' => '1-3', |
1306
|
|
|
], |
1307
|
|
|
'IFERROR' => [ |
1308
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1309
|
|
|
'functionCall' => [Logical\Conditional::class, 'IFERROR'], |
1310
|
|
|
'argumentCount' => '2', |
1311
|
|
|
], |
1312
|
|
|
'IFNA' => [ |
1313
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1314
|
|
|
'functionCall' => [Logical\Conditional::class, 'IFNA'], |
1315
|
|
|
'argumentCount' => '2', |
1316
|
|
|
], |
1317
|
|
|
'IFS' => [ |
1318
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1319
|
|
|
'functionCall' => [Logical\Conditional::class, 'IFS'], |
1320
|
|
|
'argumentCount' => '2+', |
1321
|
|
|
], |
1322
|
|
|
'IMABS' => [ |
1323
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1324
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMABS'], |
1325
|
|
|
'argumentCount' => '1', |
1326
|
|
|
], |
1327
|
|
|
'IMAGINARY' => [ |
1328
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1329
|
|
|
'functionCall' => [Engineering\Complex::class, 'IMAGINARY'], |
1330
|
|
|
'argumentCount' => '1', |
1331
|
|
|
], |
1332
|
|
|
'IMARGUMENT' => [ |
1333
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1334
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMARGUMENT'], |
1335
|
|
|
'argumentCount' => '1', |
1336
|
|
|
], |
1337
|
|
|
'IMCONJUGATE' => [ |
1338
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1339
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMCONJUGATE'], |
1340
|
|
|
'argumentCount' => '1', |
1341
|
|
|
], |
1342
|
|
|
'IMCOS' => [ |
1343
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1344
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMCOS'], |
1345
|
|
|
'argumentCount' => '1', |
1346
|
|
|
], |
1347
|
|
|
'IMCOSH' => [ |
1348
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1349
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMCOSH'], |
1350
|
|
|
'argumentCount' => '1', |
1351
|
|
|
], |
1352
|
|
|
'IMCOT' => [ |
1353
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1354
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMCOT'], |
1355
|
|
|
'argumentCount' => '1', |
1356
|
|
|
], |
1357
|
|
|
'IMCSC' => [ |
1358
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1359
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMCSC'], |
1360
|
|
|
'argumentCount' => '1', |
1361
|
|
|
], |
1362
|
|
|
'IMCSCH' => [ |
1363
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1364
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMCSCH'], |
1365
|
|
|
'argumentCount' => '1', |
1366
|
|
|
], |
1367
|
|
|
'IMDIV' => [ |
1368
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1369
|
|
|
'functionCall' => [Engineering\ComplexOperations::class, 'IMDIV'], |
1370
|
|
|
'argumentCount' => '2', |
1371
|
|
|
], |
1372
|
|
|
'IMEXP' => [ |
1373
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1374
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMEXP'], |
1375
|
|
|
'argumentCount' => '1', |
1376
|
|
|
], |
1377
|
|
|
'IMLN' => [ |
1378
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1379
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMLN'], |
1380
|
|
|
'argumentCount' => '1', |
1381
|
|
|
], |
1382
|
|
|
'IMLOG10' => [ |
1383
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1384
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMLOG10'], |
1385
|
|
|
'argumentCount' => '1', |
1386
|
|
|
], |
1387
|
|
|
'IMLOG2' => [ |
1388
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1389
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMLOG2'], |
1390
|
|
|
'argumentCount' => '1', |
1391
|
|
|
], |
1392
|
|
|
'IMPOWER' => [ |
1393
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1394
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMPOWER'], |
1395
|
|
|
'argumentCount' => '2', |
1396
|
|
|
], |
1397
|
|
|
'IMPRODUCT' => [ |
1398
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1399
|
|
|
'functionCall' => [Engineering\ComplexOperations::class, 'IMPRODUCT'], |
1400
|
|
|
'argumentCount' => '1+', |
1401
|
|
|
], |
1402
|
|
|
'IMREAL' => [ |
1403
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1404
|
|
|
'functionCall' => [Engineering\Complex::class, 'IMREAL'], |
1405
|
|
|
'argumentCount' => '1', |
1406
|
|
|
], |
1407
|
|
|
'IMSEC' => [ |
1408
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1409
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMSEC'], |
1410
|
|
|
'argumentCount' => '1', |
1411
|
|
|
], |
1412
|
|
|
'IMSECH' => [ |
1413
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1414
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMSECH'], |
1415
|
|
|
'argumentCount' => '1', |
1416
|
|
|
], |
1417
|
|
|
'IMSIN' => [ |
1418
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1419
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMSIN'], |
1420
|
|
|
'argumentCount' => '1', |
1421
|
|
|
], |
1422
|
|
|
'IMSINH' => [ |
1423
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1424
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMSINH'], |
1425
|
|
|
'argumentCount' => '1', |
1426
|
|
|
], |
1427
|
|
|
'IMSQRT' => [ |
1428
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1429
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMSQRT'], |
1430
|
|
|
'argumentCount' => '1', |
1431
|
|
|
], |
1432
|
|
|
'IMSUB' => [ |
1433
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1434
|
|
|
'functionCall' => [Engineering\ComplexOperations::class, 'IMSUB'], |
1435
|
|
|
'argumentCount' => '2', |
1436
|
|
|
], |
1437
|
|
|
'IMSUM' => [ |
1438
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1439
|
|
|
'functionCall' => [Engineering\ComplexOperations::class, 'IMSUM'], |
1440
|
|
|
'argumentCount' => '1+', |
1441
|
|
|
], |
1442
|
|
|
'IMTAN' => [ |
1443
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1444
|
|
|
'functionCall' => [Engineering\ComplexFunctions::class, 'IMTAN'], |
1445
|
|
|
'argumentCount' => '1', |
1446
|
|
|
], |
1447
|
|
|
'INDEX' => [ |
1448
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1449
|
|
|
'functionCall' => [LookupRef\Matrix::class, 'index'], |
1450
|
|
|
'argumentCount' => '2-4', |
1451
|
|
|
], |
1452
|
|
|
'INDIRECT' => [ |
1453
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1454
|
|
|
'functionCall' => [LookupRef\Indirect::class, 'INDIRECT'], |
1455
|
|
|
'argumentCount' => '1,2', |
1456
|
|
|
'passCellReference' => true, |
1457
|
|
|
], |
1458
|
|
|
'INFO' => [ |
1459
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1460
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1461
|
|
|
'argumentCount' => '1', |
1462
|
|
|
], |
1463
|
|
|
'INT' => [ |
1464
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1465
|
|
|
'functionCall' => [MathTrig\IntClass::class, 'evaluate'], |
1466
|
|
|
'argumentCount' => '1', |
1467
|
|
|
], |
1468
|
|
|
'INTERCEPT' => [ |
1469
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1470
|
|
|
'functionCall' => [Statistical\Trends::class, 'INTERCEPT'], |
1471
|
|
|
'argumentCount' => '2', |
1472
|
|
|
], |
1473
|
|
|
'INTRATE' => [ |
1474
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1475
|
|
|
'functionCall' => [Financial\Securities\Rates::class, 'interest'], |
1476
|
|
|
'argumentCount' => '4,5', |
1477
|
|
|
], |
1478
|
|
|
'IPMT' => [ |
1479
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1480
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic\Interest::class, 'payment'], |
1481
|
|
|
'argumentCount' => '4-6', |
1482
|
|
|
], |
1483
|
|
|
'IRR' => [ |
1484
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1485
|
|
|
'functionCall' => [Financial\CashFlow\Variable\Periodic::class, 'rate'], |
1486
|
|
|
'argumentCount' => '1,2', |
1487
|
|
|
], |
1488
|
|
|
'ISBLANK' => [ |
1489
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1490
|
|
|
'functionCall' => [Information\Value::class, 'isBlank'], |
1491
|
|
|
'argumentCount' => '1', |
1492
|
|
|
], |
1493
|
|
|
'ISERR' => [ |
1494
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1495
|
|
|
'functionCall' => [Information\ErrorValue::class, 'isErr'], |
1496
|
|
|
'argumentCount' => '1', |
1497
|
|
|
], |
1498
|
|
|
'ISERROR' => [ |
1499
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1500
|
|
|
'functionCall' => [Information\ErrorValue::class, 'isError'], |
1501
|
|
|
'argumentCount' => '1', |
1502
|
|
|
], |
1503
|
|
|
'ISEVEN' => [ |
1504
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1505
|
|
|
'functionCall' => [Information\Value::class, 'isEven'], |
1506
|
|
|
'argumentCount' => '1', |
1507
|
|
|
], |
1508
|
|
|
'ISFORMULA' => [ |
1509
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1510
|
|
|
'functionCall' => [Information\Value::class, 'isFormula'], |
1511
|
|
|
'argumentCount' => '1', |
1512
|
|
|
'passCellReference' => true, |
1513
|
|
|
'passByReference' => [true], |
1514
|
|
|
], |
1515
|
|
|
'ISLOGICAL' => [ |
1516
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1517
|
|
|
'functionCall' => [Information\Value::class, 'isLogical'], |
1518
|
|
|
'argumentCount' => '1', |
1519
|
|
|
], |
1520
|
|
|
'ISNA' => [ |
1521
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1522
|
|
|
'functionCall' => [Information\ErrorValue::class, 'isNa'], |
1523
|
|
|
'argumentCount' => '1', |
1524
|
|
|
], |
1525
|
|
|
'ISNONTEXT' => [ |
1526
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1527
|
|
|
'functionCall' => [Information\Value::class, 'isNonText'], |
1528
|
|
|
'argumentCount' => '1', |
1529
|
|
|
], |
1530
|
|
|
'ISNUMBER' => [ |
1531
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1532
|
|
|
'functionCall' => [Information\Value::class, 'isNumber'], |
1533
|
|
|
'argumentCount' => '1', |
1534
|
|
|
], |
1535
|
|
|
'ISO.CEILING' => [ |
1536
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1537
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1538
|
|
|
'argumentCount' => '1,2', |
1539
|
|
|
], |
1540
|
|
|
'ISODD' => [ |
1541
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1542
|
|
|
'functionCall' => [Information\Value::class, 'isOdd'], |
1543
|
|
|
'argumentCount' => '1', |
1544
|
|
|
], |
1545
|
|
|
'ISOMITTED' => [ |
1546
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1547
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1548
|
|
|
'argumentCount' => '*', |
1549
|
|
|
], |
1550
|
|
|
'ISOWEEKNUM' => [ |
1551
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
1552
|
|
|
'functionCall' => [DateTimeExcel\Week::class, 'isoWeekNumber'], |
1553
|
|
|
'argumentCount' => '1', |
1554
|
|
|
], |
1555
|
|
|
'ISPMT' => [ |
1556
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1557
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic\Interest::class, 'schedulePayment'], |
1558
|
|
|
'argumentCount' => '4', |
1559
|
|
|
], |
1560
|
|
|
'ISREF' => [ |
1561
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1562
|
|
|
'functionCall' => [Information\Value::class, 'isRef'], |
1563
|
|
|
'argumentCount' => '1', |
1564
|
|
|
'passCellReference' => true, |
1565
|
|
|
'passByReference' => [true], |
1566
|
|
|
], |
1567
|
|
|
'ISTEXT' => [ |
1568
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1569
|
|
|
'functionCall' => [Information\Value::class, 'isText'], |
1570
|
|
|
'argumentCount' => '1', |
1571
|
|
|
], |
1572
|
|
|
'ISTHAIDIGIT' => [ |
1573
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1574
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1575
|
|
|
'argumentCount' => '?', |
1576
|
|
|
], |
1577
|
|
|
'JIS' => [ |
1578
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1579
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1580
|
|
|
'argumentCount' => '1', |
1581
|
|
|
], |
1582
|
|
|
'KURT' => [ |
1583
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1584
|
|
|
'functionCall' => [Statistical\Deviations::class, 'kurtosis'], |
1585
|
|
|
'argumentCount' => '1+', |
1586
|
|
|
], |
1587
|
|
|
'LAMBDA' => [ |
1588
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1589
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1590
|
|
|
'argumentCount' => '*', |
1591
|
|
|
], |
1592
|
|
|
'LARGE' => [ |
1593
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1594
|
|
|
'functionCall' => [Statistical\Size::class, 'large'], |
1595
|
|
|
'argumentCount' => '2', |
1596
|
|
|
], |
1597
|
|
|
'LCM' => [ |
1598
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1599
|
|
|
'functionCall' => [MathTrig\Lcm::class, 'evaluate'], |
1600
|
|
|
'argumentCount' => '1+', |
1601
|
|
|
], |
1602
|
|
|
'LEFT' => [ |
1603
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1604
|
|
|
'functionCall' => [TextData\Extract::class, 'left'], |
1605
|
|
|
'argumentCount' => '1,2', |
1606
|
|
|
], |
1607
|
|
|
'LEFTB' => [ |
1608
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1609
|
|
|
'functionCall' => [TextData\Extract::class, 'left'], |
1610
|
|
|
'argumentCount' => '1,2', |
1611
|
|
|
], |
1612
|
|
|
'LEN' => [ |
1613
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1614
|
|
|
'functionCall' => [TextData\Text::class, 'length'], |
1615
|
|
|
'argumentCount' => '1', |
1616
|
|
|
], |
1617
|
|
|
'LENB' => [ |
1618
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1619
|
|
|
'functionCall' => [TextData\Text::class, 'length'], |
1620
|
|
|
'argumentCount' => '1', |
1621
|
|
|
], |
1622
|
|
|
'LET' => [ |
1623
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1624
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1625
|
|
|
'argumentCount' => '*', |
1626
|
|
|
], |
1627
|
|
|
'LINEST' => [ |
1628
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1629
|
|
|
'functionCall' => [Statistical\Trends::class, 'LINEST'], |
1630
|
|
|
'argumentCount' => '1-4', |
1631
|
|
|
], |
1632
|
|
|
'LN' => [ |
1633
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1634
|
|
|
'functionCall' => [MathTrig\Logarithms::class, 'natural'], |
1635
|
|
|
'argumentCount' => '1', |
1636
|
|
|
], |
1637
|
|
|
'LOG' => [ |
1638
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1639
|
|
|
'functionCall' => [MathTrig\Logarithms::class, 'withBase'], |
1640
|
|
|
'argumentCount' => '1,2', |
1641
|
|
|
], |
1642
|
|
|
'LOG10' => [ |
1643
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1644
|
|
|
'functionCall' => [MathTrig\Logarithms::class, 'base10'], |
1645
|
|
|
'argumentCount' => '1', |
1646
|
|
|
], |
1647
|
|
|
'LOGEST' => [ |
1648
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1649
|
|
|
'functionCall' => [Statistical\Trends::class, 'LOGEST'], |
1650
|
|
|
'argumentCount' => '1-4', |
1651
|
|
|
], |
1652
|
|
|
'LOGINV' => [ |
1653
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1654
|
|
|
'functionCall' => [Statistical\Distributions\LogNormal::class, 'inverse'], |
1655
|
|
|
'argumentCount' => '3', |
1656
|
|
|
], |
1657
|
|
|
'LOGNORMDIST' => [ |
1658
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1659
|
|
|
'functionCall' => [Statistical\Distributions\LogNormal::class, 'cumulative'], |
1660
|
|
|
'argumentCount' => '3', |
1661
|
|
|
], |
1662
|
|
|
'LOGNORM.DIST' => [ |
1663
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1664
|
|
|
'functionCall' => [Statistical\Distributions\LogNormal::class, 'distribution'], |
1665
|
|
|
'argumentCount' => '4', |
1666
|
|
|
], |
1667
|
|
|
'LOGNORM.INV' => [ |
1668
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1669
|
|
|
'functionCall' => [Statistical\Distributions\LogNormal::class, 'inverse'], |
1670
|
|
|
'argumentCount' => '3', |
1671
|
|
|
], |
1672
|
|
|
'LOOKUP' => [ |
1673
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1674
|
|
|
'functionCall' => [LookupRef\Lookup::class, 'lookup'], |
1675
|
|
|
'argumentCount' => '2,3', |
1676
|
|
|
], |
1677
|
|
|
'LOWER' => [ |
1678
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1679
|
|
|
'functionCall' => [TextData\CaseConvert::class, 'lower'], |
1680
|
|
|
'argumentCount' => '1', |
1681
|
|
|
], |
1682
|
|
|
'MAKEARRAY' => [ |
1683
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1684
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1685
|
|
|
'argumentCount' => '*', |
1686
|
|
|
], |
1687
|
|
|
'MAP' => [ |
1688
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1689
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1690
|
|
|
'argumentCount' => '*', |
1691
|
|
|
], |
1692
|
|
|
'MATCH' => [ |
1693
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1694
|
|
|
'functionCall' => [LookupRef\ExcelMatch::class, 'MATCH'], |
1695
|
|
|
'argumentCount' => '2,3', |
1696
|
|
|
], |
1697
|
|
|
'MAX' => [ |
1698
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1699
|
|
|
'functionCall' => [Statistical\Maximum::class, 'max'], |
1700
|
|
|
'argumentCount' => '1+', |
1701
|
|
|
], |
1702
|
|
|
'MAXA' => [ |
1703
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1704
|
|
|
'functionCall' => [Statistical\Maximum::class, 'maxA'], |
1705
|
|
|
'argumentCount' => '1+', |
1706
|
|
|
], |
1707
|
|
|
'MAXIFS' => [ |
1708
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1709
|
|
|
'functionCall' => [Statistical\Conditional::class, 'MAXIFS'], |
1710
|
|
|
'argumentCount' => '3+', |
1711
|
|
|
], |
1712
|
|
|
'MDETERM' => [ |
1713
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1714
|
|
|
'functionCall' => [MathTrig\MatrixFunctions::class, 'determinant'], |
1715
|
|
|
'argumentCount' => '1', |
1716
|
|
|
], |
1717
|
|
|
'MDURATION' => [ |
1718
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1719
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1720
|
|
|
'argumentCount' => '5,6', |
1721
|
|
|
], |
1722
|
|
|
'MEDIAN' => [ |
1723
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1724
|
|
|
'functionCall' => [Statistical\Averages::class, 'median'], |
1725
|
|
|
'argumentCount' => '1+', |
1726
|
|
|
], |
1727
|
|
|
'MEDIANIF' => [ |
1728
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1729
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1730
|
|
|
'argumentCount' => '2+', |
1731
|
|
|
], |
1732
|
|
|
'MID' => [ |
1733
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1734
|
|
|
'functionCall' => [TextData\Extract::class, 'mid'], |
1735
|
|
|
'argumentCount' => '3', |
1736
|
|
|
], |
1737
|
|
|
'MIDB' => [ |
1738
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1739
|
|
|
'functionCall' => [TextData\Extract::class, 'mid'], |
1740
|
|
|
'argumentCount' => '3', |
1741
|
|
|
], |
1742
|
|
|
'MIN' => [ |
1743
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1744
|
|
|
'functionCall' => [Statistical\Minimum::class, 'min'], |
1745
|
|
|
'argumentCount' => '1+', |
1746
|
|
|
], |
1747
|
|
|
'MINA' => [ |
1748
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1749
|
|
|
'functionCall' => [Statistical\Minimum::class, 'minA'], |
1750
|
|
|
'argumentCount' => '1+', |
1751
|
|
|
], |
1752
|
|
|
'MINIFS' => [ |
1753
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1754
|
|
|
'functionCall' => [Statistical\Conditional::class, 'MINIFS'], |
1755
|
|
|
'argumentCount' => '3+', |
1756
|
|
|
], |
1757
|
|
|
'MINUTE' => [ |
1758
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
1759
|
|
|
'functionCall' => [DateTimeExcel\TimeParts::class, 'minute'], |
1760
|
|
|
'argumentCount' => '1', |
1761
|
|
|
], |
1762
|
|
|
'MINVERSE' => [ |
1763
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1764
|
|
|
'functionCall' => [MathTrig\MatrixFunctions::class, 'inverse'], |
1765
|
|
|
'argumentCount' => '1', |
1766
|
|
|
], |
1767
|
|
|
'MIRR' => [ |
1768
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1769
|
|
|
'functionCall' => [Financial\CashFlow\Variable\Periodic::class, 'modifiedRate'], |
1770
|
|
|
'argumentCount' => '3', |
1771
|
|
|
], |
1772
|
|
|
'MMULT' => [ |
1773
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1774
|
|
|
'functionCall' => [MathTrig\MatrixFunctions::class, 'multiply'], |
1775
|
|
|
'argumentCount' => '2', |
1776
|
|
|
], |
1777
|
|
|
'MOD' => [ |
1778
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1779
|
|
|
'functionCall' => [MathTrig\Operations::class, 'mod'], |
1780
|
|
|
'argumentCount' => '2', |
1781
|
|
|
], |
1782
|
|
|
'MODE' => [ |
1783
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1784
|
|
|
'functionCall' => [Statistical\Averages::class, 'mode'], |
1785
|
|
|
'argumentCount' => '1+', |
1786
|
|
|
], |
1787
|
|
|
'MODE.MULT' => [ |
1788
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1789
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1790
|
|
|
'argumentCount' => '1+', |
1791
|
|
|
], |
1792
|
|
|
'MODE.SNGL' => [ |
1793
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1794
|
|
|
'functionCall' => [Statistical\Averages::class, 'mode'], |
1795
|
|
|
'argumentCount' => '1+', |
1796
|
|
|
], |
1797
|
|
|
'MONTH' => [ |
1798
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
1799
|
|
|
'functionCall' => [DateTimeExcel\DateParts::class, 'month'], |
1800
|
|
|
'argumentCount' => '1', |
1801
|
|
|
], |
1802
|
|
|
'MROUND' => [ |
1803
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1804
|
|
|
'functionCall' => [MathTrig\Round::class, 'multiple'], |
1805
|
|
|
'argumentCount' => '2', |
1806
|
|
|
], |
1807
|
|
|
'MULTINOMIAL' => [ |
1808
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1809
|
|
|
'functionCall' => [MathTrig\Factorial::class, 'multinomial'], |
1810
|
|
|
'argumentCount' => '1+', |
1811
|
|
|
], |
1812
|
|
|
'MUNIT' => [ |
1813
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1814
|
|
|
'functionCall' => [MathTrig\MatrixFunctions::class, 'identity'], |
1815
|
|
|
'argumentCount' => '1', |
1816
|
|
|
], |
1817
|
|
|
'N' => [ |
1818
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1819
|
|
|
'functionCall' => [Information\Value::class, 'asNumber'], |
1820
|
|
|
'argumentCount' => '1', |
1821
|
|
|
], |
1822
|
|
|
'NA' => [ |
1823
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
1824
|
|
|
'functionCall' => [Information\ExcelError::class, 'NA'], |
1825
|
|
|
'argumentCount' => '0', |
1826
|
|
|
], |
1827
|
|
|
'NEGBINOMDIST' => [ |
1828
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1829
|
|
|
'functionCall' => [Statistical\Distributions\Binomial::class, 'negative'], |
1830
|
|
|
'argumentCount' => '3', |
1831
|
|
|
], |
1832
|
|
|
'NEGBINOM.DIST' => [ |
1833
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1834
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1835
|
|
|
'argumentCount' => '4', |
1836
|
|
|
], |
1837
|
|
|
'NETWORKDAYS' => [ |
1838
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
1839
|
|
|
'functionCall' => [DateTimeExcel\NetworkDays::class, 'count'], |
1840
|
|
|
'argumentCount' => '2-3', |
1841
|
|
|
], |
1842
|
|
|
'NETWORKDAYS.INTL' => [ |
1843
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
1844
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1845
|
|
|
'argumentCount' => '2-4', |
1846
|
|
|
], |
1847
|
|
|
'NOMINAL' => [ |
1848
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1849
|
|
|
'functionCall' => [Financial\InterestRate::class, 'nominal'], |
1850
|
|
|
'argumentCount' => '2', |
1851
|
|
|
], |
1852
|
|
|
'NORMDIST' => [ |
1853
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1854
|
|
|
'functionCall' => [Statistical\Distributions\Normal::class, 'distribution'], |
1855
|
|
|
'argumentCount' => '4', |
1856
|
|
|
], |
1857
|
|
|
'NORM.DIST' => [ |
1858
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1859
|
|
|
'functionCall' => [Statistical\Distributions\Normal::class, 'distribution'], |
1860
|
|
|
'argumentCount' => '4', |
1861
|
|
|
], |
1862
|
|
|
'NORMINV' => [ |
1863
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1864
|
|
|
'functionCall' => [Statistical\Distributions\Normal::class, 'inverse'], |
1865
|
|
|
'argumentCount' => '3', |
1866
|
|
|
], |
1867
|
|
|
'NORM.INV' => [ |
1868
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1869
|
|
|
'functionCall' => [Statistical\Distributions\Normal::class, 'inverse'], |
1870
|
|
|
'argumentCount' => '3', |
1871
|
|
|
], |
1872
|
|
|
'NORMSDIST' => [ |
1873
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1874
|
|
|
'functionCall' => [Statistical\Distributions\StandardNormal::class, 'cumulative'], |
1875
|
|
|
'argumentCount' => '1', |
1876
|
|
|
], |
1877
|
|
|
'NORM.S.DIST' => [ |
1878
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1879
|
|
|
'functionCall' => [Statistical\Distributions\StandardNormal::class, 'distribution'], |
1880
|
|
|
'argumentCount' => '1,2', |
1881
|
|
|
], |
1882
|
|
|
'NORMSINV' => [ |
1883
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1884
|
|
|
'functionCall' => [Statistical\Distributions\StandardNormal::class, 'inverse'], |
1885
|
|
|
'argumentCount' => '1', |
1886
|
|
|
], |
1887
|
|
|
'NORM.S.INV' => [ |
1888
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1889
|
|
|
'functionCall' => [Statistical\Distributions\StandardNormal::class, 'inverse'], |
1890
|
|
|
'argumentCount' => '1', |
1891
|
|
|
], |
1892
|
|
|
'NOT' => [ |
1893
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1894
|
|
|
'functionCall' => [Logical\Operations::class, 'NOT'], |
1895
|
|
|
'argumentCount' => '1', |
1896
|
|
|
], |
1897
|
|
|
'NOW' => [ |
1898
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
1899
|
|
|
'functionCall' => [DateTimeExcel\Current::class, 'now'], |
1900
|
|
|
'argumentCount' => '0', |
1901
|
|
|
], |
1902
|
|
|
'NPER' => [ |
1903
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1904
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic::class, 'periods'], |
1905
|
|
|
'argumentCount' => '3-5', |
1906
|
|
|
], |
1907
|
|
|
'NPV' => [ |
1908
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1909
|
|
|
'functionCall' => [Financial\CashFlow\Variable\Periodic::class, 'presentValue'], |
1910
|
|
|
'argumentCount' => '2+', |
1911
|
|
|
], |
1912
|
|
|
'NUMBERSTRING' => [ |
1913
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1914
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1915
|
|
|
'argumentCount' => '?', |
1916
|
|
|
], |
1917
|
|
|
'NUMBERVALUE' => [ |
1918
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
1919
|
|
|
'functionCall' => [TextData\Format::class, 'NUMBERVALUE'], |
1920
|
|
|
'argumentCount' => '1+', |
1921
|
|
|
], |
1922
|
|
|
'OCT2BIN' => [ |
1923
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1924
|
|
|
'functionCall' => [Engineering\ConvertOctal::class, 'toBinary'], |
1925
|
|
|
'argumentCount' => '1,2', |
1926
|
|
|
], |
1927
|
|
|
'OCT2DEC' => [ |
1928
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1929
|
|
|
'functionCall' => [Engineering\ConvertOctal::class, 'toDecimal'], |
1930
|
|
|
'argumentCount' => '1', |
1931
|
|
|
], |
1932
|
|
|
'OCT2HEX' => [ |
1933
|
|
|
'category' => Category::CATEGORY_ENGINEERING, |
1934
|
|
|
'functionCall' => [Engineering\ConvertOctal::class, 'toHex'], |
1935
|
|
|
'argumentCount' => '1,2', |
1936
|
|
|
], |
1937
|
|
|
'ODD' => [ |
1938
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
1939
|
|
|
'functionCall' => [MathTrig\Round::class, 'odd'], |
1940
|
|
|
'argumentCount' => '1', |
1941
|
|
|
], |
1942
|
|
|
'ODDFPRICE' => [ |
1943
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1944
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1945
|
|
|
'argumentCount' => '8,9', |
1946
|
|
|
], |
1947
|
|
|
'ODDFYIELD' => [ |
1948
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1949
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1950
|
|
|
'argumentCount' => '8,9', |
1951
|
|
|
], |
1952
|
|
|
'ODDLPRICE' => [ |
1953
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1954
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1955
|
|
|
'argumentCount' => '7,8', |
1956
|
|
|
], |
1957
|
|
|
'ODDLYIELD' => [ |
1958
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1959
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1960
|
|
|
'argumentCount' => '7,8', |
1961
|
|
|
], |
1962
|
|
|
'OFFSET' => [ |
1963
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
1964
|
|
|
'functionCall' => [LookupRef\Offset::class, 'OFFSET'], |
1965
|
|
|
'argumentCount' => '3-5', |
1966
|
|
|
'passCellReference' => true, |
1967
|
|
|
'passByReference' => [true], |
1968
|
|
|
], |
1969
|
|
|
'OR' => [ |
1970
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
1971
|
|
|
'functionCall' => [Logical\Operations::class, 'logicalOr'], |
1972
|
|
|
'argumentCount' => '1+', |
1973
|
|
|
], |
1974
|
|
|
'PDURATION' => [ |
1975
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
1976
|
|
|
'functionCall' => [Financial\CashFlow\Single::class, 'periods'], |
1977
|
|
|
'argumentCount' => '3', |
1978
|
|
|
], |
1979
|
|
|
'PEARSON' => [ |
1980
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1981
|
|
|
'functionCall' => [Statistical\Trends::class, 'CORREL'], |
1982
|
|
|
'argumentCount' => '2', |
1983
|
|
|
], |
1984
|
|
|
'PERCENTILE' => [ |
1985
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1986
|
|
|
'functionCall' => [Statistical\Percentiles::class, 'PERCENTILE'], |
1987
|
|
|
'argumentCount' => '2', |
1988
|
|
|
], |
1989
|
|
|
'PERCENTILE.EXC' => [ |
1990
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1991
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
1992
|
|
|
'argumentCount' => '2', |
1993
|
|
|
], |
1994
|
|
|
'PERCENTILE.INC' => [ |
1995
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
1996
|
|
|
'functionCall' => [Statistical\Percentiles::class, 'PERCENTILE'], |
1997
|
|
|
'argumentCount' => '2', |
1998
|
|
|
], |
1999
|
|
|
'PERCENTRANK' => [ |
2000
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2001
|
|
|
'functionCall' => [Statistical\Percentiles::class, 'PERCENTRANK'], |
2002
|
|
|
'argumentCount' => '2,3', |
2003
|
|
|
], |
2004
|
|
|
'PERCENTRANK.EXC' => [ |
2005
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2006
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2007
|
|
|
'argumentCount' => '2,3', |
2008
|
|
|
], |
2009
|
|
|
'PERCENTRANK.INC' => [ |
2010
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2011
|
|
|
'functionCall' => [Statistical\Percentiles::class, 'PERCENTRANK'], |
2012
|
|
|
'argumentCount' => '2,3', |
2013
|
|
|
], |
2014
|
|
|
'PERMUT' => [ |
2015
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2016
|
|
|
'functionCall' => [Statistical\Permutations::class, 'PERMUT'], |
2017
|
|
|
'argumentCount' => '2', |
2018
|
|
|
], |
2019
|
|
|
'PERMUTATIONA' => [ |
2020
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2021
|
|
|
'functionCall' => [Statistical\Permutations::class, 'PERMUTATIONA'], |
2022
|
|
|
'argumentCount' => '2', |
2023
|
|
|
], |
2024
|
|
|
'PHONETIC' => [ |
2025
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2026
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2027
|
|
|
'argumentCount' => '1', |
2028
|
|
|
], |
2029
|
|
|
'PHI' => [ |
2030
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2031
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2032
|
|
|
'argumentCount' => '1', |
2033
|
|
|
], |
2034
|
|
|
'PI' => [ |
2035
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2036
|
|
|
'functionCall' => 'pi', |
2037
|
|
|
'argumentCount' => '0', |
2038
|
|
|
], |
2039
|
|
|
'PMT' => [ |
2040
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2041
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic\Payments::class, 'annuity'], |
2042
|
|
|
'argumentCount' => '3-5', |
2043
|
|
|
], |
2044
|
|
|
'POISSON' => [ |
2045
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2046
|
|
|
'functionCall' => [Statistical\Distributions\Poisson::class, 'distribution'], |
2047
|
|
|
'argumentCount' => '3', |
2048
|
|
|
], |
2049
|
|
|
'POISSON.DIST' => [ |
2050
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2051
|
|
|
'functionCall' => [Statistical\Distributions\Poisson::class, 'distribution'], |
2052
|
|
|
'argumentCount' => '3', |
2053
|
|
|
], |
2054
|
|
|
'POWER' => [ |
2055
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2056
|
|
|
'functionCall' => [MathTrig\Operations::class, 'power'], |
2057
|
|
|
'argumentCount' => '2', |
2058
|
|
|
], |
2059
|
|
|
'PPMT' => [ |
2060
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2061
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic\Payments::class, 'interestPayment'], |
2062
|
|
|
'argumentCount' => '4-6', |
2063
|
|
|
], |
2064
|
|
|
'PRICE' => [ |
2065
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2066
|
|
|
'functionCall' => [Financial\Securities\Price::class, 'price'], |
2067
|
|
|
'argumentCount' => '6,7', |
2068
|
|
|
], |
2069
|
|
|
'PRICEDISC' => [ |
2070
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2071
|
|
|
'functionCall' => [Financial\Securities\Price::class, 'priceDiscounted'], |
2072
|
|
|
'argumentCount' => '4,5', |
2073
|
|
|
], |
2074
|
|
|
'PRICEMAT' => [ |
2075
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2076
|
|
|
'functionCall' => [Financial\Securities\Price::class, 'priceAtMaturity'], |
2077
|
|
|
'argumentCount' => '5,6', |
2078
|
|
|
], |
2079
|
|
|
'PROB' => [ |
2080
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2081
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2082
|
|
|
'argumentCount' => '3,4', |
2083
|
|
|
], |
2084
|
|
|
'PRODUCT' => [ |
2085
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2086
|
|
|
'functionCall' => [MathTrig\Operations::class, 'product'], |
2087
|
|
|
'argumentCount' => '1+', |
2088
|
|
|
], |
2089
|
|
|
'PROPER' => [ |
2090
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2091
|
|
|
'functionCall' => [TextData\CaseConvert::class, 'proper'], |
2092
|
|
|
'argumentCount' => '1', |
2093
|
|
|
], |
2094
|
|
|
'PV' => [ |
2095
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2096
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic::class, 'presentValue'], |
2097
|
|
|
'argumentCount' => '3-5', |
2098
|
|
|
], |
2099
|
|
|
'QUARTILE' => [ |
2100
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2101
|
|
|
'functionCall' => [Statistical\Percentiles::class, 'QUARTILE'], |
2102
|
|
|
'argumentCount' => '2', |
2103
|
|
|
], |
2104
|
|
|
'QUARTILE.EXC' => [ |
2105
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2106
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2107
|
|
|
'argumentCount' => '2', |
2108
|
|
|
], |
2109
|
|
|
'QUARTILE.INC' => [ |
2110
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2111
|
|
|
'functionCall' => [Statistical\Percentiles::class, 'QUARTILE'], |
2112
|
|
|
'argumentCount' => '2', |
2113
|
|
|
], |
2114
|
|
|
'QUOTIENT' => [ |
2115
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2116
|
|
|
'functionCall' => [MathTrig\Operations::class, 'quotient'], |
2117
|
|
|
'argumentCount' => '2', |
2118
|
|
|
], |
2119
|
|
|
'RADIANS' => [ |
2120
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2121
|
|
|
'functionCall' => [MathTrig\Angle::class, 'toRadians'], |
2122
|
|
|
'argumentCount' => '1', |
2123
|
|
|
], |
2124
|
|
|
'RAND' => [ |
2125
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2126
|
|
|
'functionCall' => [MathTrig\Random::class, 'rand'], |
2127
|
|
|
'argumentCount' => '0', |
2128
|
|
|
], |
2129
|
|
|
'RANDARRAY' => [ |
2130
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2131
|
|
|
'functionCall' => [MathTrig\Random::class, 'randArray'], |
2132
|
|
|
'argumentCount' => '0-5', |
2133
|
|
|
], |
2134
|
|
|
'RANDBETWEEN' => [ |
2135
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2136
|
|
|
'functionCall' => [MathTrig\Random::class, 'randBetween'], |
2137
|
|
|
'argumentCount' => '2', |
2138
|
|
|
], |
2139
|
|
|
'RANK' => [ |
2140
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2141
|
|
|
'functionCall' => [Statistical\Percentiles::class, 'RANK'], |
2142
|
|
|
'argumentCount' => '2,3', |
2143
|
|
|
], |
2144
|
|
|
'RANK.AVG' => [ |
2145
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2146
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2147
|
|
|
'argumentCount' => '2,3', |
2148
|
|
|
], |
2149
|
|
|
'RANK.EQ' => [ |
2150
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2151
|
|
|
'functionCall' => [Statistical\Percentiles::class, 'RANK'], |
2152
|
|
|
'argumentCount' => '2,3', |
2153
|
|
|
], |
2154
|
|
|
'RATE' => [ |
2155
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2156
|
|
|
'functionCall' => [Financial\CashFlow\Constant\Periodic\Interest::class, 'rate'], |
2157
|
|
|
'argumentCount' => '3-6', |
2158
|
|
|
], |
2159
|
|
|
'RECEIVED' => [ |
2160
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2161
|
|
|
'functionCall' => [Financial\Securities\Price::class, 'received'], |
2162
|
|
|
'argumentCount' => '4-5', |
2163
|
|
|
], |
2164
|
|
|
'REDUCE' => [ |
2165
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
2166
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2167
|
|
|
'argumentCount' => '*', |
2168
|
|
|
], |
2169
|
|
|
'REPLACE' => [ |
2170
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2171
|
|
|
'functionCall' => [TextData\Replace::class, 'replace'], |
2172
|
|
|
'argumentCount' => '4', |
2173
|
|
|
], |
2174
|
|
|
'REPLACEB' => [ |
2175
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2176
|
|
|
'functionCall' => [TextData\Replace::class, 'replace'], |
2177
|
|
|
'argumentCount' => '4', |
2178
|
|
|
], |
2179
|
|
|
'REPT' => [ |
2180
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2181
|
|
|
'functionCall' => [TextData\Concatenate::class, 'builtinREPT'], |
2182
|
|
|
'argumentCount' => '2', |
2183
|
|
|
], |
2184
|
|
|
'RIGHT' => [ |
2185
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2186
|
|
|
'functionCall' => [TextData\Extract::class, 'right'], |
2187
|
|
|
'argumentCount' => '1,2', |
2188
|
|
|
], |
2189
|
|
|
'RIGHTB' => [ |
2190
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2191
|
|
|
'functionCall' => [TextData\Extract::class, 'right'], |
2192
|
|
|
'argumentCount' => '1,2', |
2193
|
|
|
], |
2194
|
|
|
'ROMAN' => [ |
2195
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2196
|
|
|
'functionCall' => [MathTrig\Roman::class, 'evaluate'], |
2197
|
|
|
'argumentCount' => '1,2', |
2198
|
|
|
], |
2199
|
|
|
'ROUND' => [ |
2200
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2201
|
|
|
'functionCall' => [MathTrig\Round::class, 'round'], |
2202
|
|
|
'argumentCount' => '2', |
2203
|
|
|
], |
2204
|
|
|
'ROUNDBAHTDOWN' => [ |
2205
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2206
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2207
|
|
|
'argumentCount' => '?', |
2208
|
|
|
], |
2209
|
|
|
'ROUNDBAHTUP' => [ |
2210
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2211
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2212
|
|
|
'argumentCount' => '?', |
2213
|
|
|
], |
2214
|
|
|
'ROUNDDOWN' => [ |
2215
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2216
|
|
|
'functionCall' => [MathTrig\Round::class, 'down'], |
2217
|
|
|
'argumentCount' => '2', |
2218
|
|
|
], |
2219
|
|
|
'ROUNDUP' => [ |
2220
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2221
|
|
|
'functionCall' => [MathTrig\Round::class, 'up'], |
2222
|
|
|
'argumentCount' => '2', |
2223
|
|
|
], |
2224
|
|
|
'ROW' => [ |
2225
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2226
|
|
|
'functionCall' => [LookupRef\RowColumnInformation::class, 'ROW'], |
2227
|
|
|
'argumentCount' => '-1', |
2228
|
|
|
'passCellReference' => true, |
2229
|
|
|
'passByReference' => [true], |
2230
|
|
|
], |
2231
|
|
|
'ROWS' => [ |
2232
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2233
|
|
|
'functionCall' => [LookupRef\RowColumnInformation::class, 'ROWS'], |
2234
|
|
|
'argumentCount' => '1', |
2235
|
|
|
], |
2236
|
|
|
'RRI' => [ |
2237
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2238
|
|
|
'functionCall' => [Financial\CashFlow\Single::class, 'interestRate'], |
2239
|
|
|
'argumentCount' => '3', |
2240
|
|
|
], |
2241
|
|
|
'RSQ' => [ |
2242
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2243
|
|
|
'functionCall' => [Statistical\Trends::class, 'RSQ'], |
2244
|
|
|
'argumentCount' => '2', |
2245
|
|
|
], |
2246
|
|
|
'RTD' => [ |
2247
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2248
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2249
|
|
|
'argumentCount' => '1+', |
2250
|
|
|
], |
2251
|
|
|
'SEARCH' => [ |
2252
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2253
|
|
|
'functionCall' => [TextData\Search::class, 'insensitive'], |
2254
|
|
|
'argumentCount' => '2,3', |
2255
|
|
|
], |
2256
|
|
|
'SCAN' => [ |
2257
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
2258
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2259
|
|
|
'argumentCount' => '*', |
2260
|
|
|
], |
2261
|
|
|
'SEARCHB' => [ |
2262
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2263
|
|
|
'functionCall' => [TextData\Search::class, 'insensitive'], |
2264
|
|
|
'argumentCount' => '2,3', |
2265
|
|
|
], |
2266
|
|
|
'SEC' => [ |
2267
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2268
|
|
|
'functionCall' => [MathTrig\Trig\Secant::class, 'sec'], |
2269
|
|
|
'argumentCount' => '1', |
2270
|
|
|
], |
2271
|
|
|
'SECH' => [ |
2272
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2273
|
|
|
'functionCall' => [MathTrig\Trig\Secant::class, 'sech'], |
2274
|
|
|
'argumentCount' => '1', |
2275
|
|
|
], |
2276
|
|
|
'SECOND' => [ |
2277
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2278
|
|
|
'functionCall' => [DateTimeExcel\TimeParts::class, 'second'], |
2279
|
|
|
'argumentCount' => '1', |
2280
|
|
|
], |
2281
|
|
|
'SEQUENCE' => [ |
2282
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2283
|
|
|
'functionCall' => [MathTrig\MatrixFunctions::class, 'sequence'], |
2284
|
|
|
'argumentCount' => '1-4', |
2285
|
|
|
], |
2286
|
|
|
'SERIESSUM' => [ |
2287
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2288
|
|
|
'functionCall' => [MathTrig\SeriesSum::class, 'evaluate'], |
2289
|
|
|
'argumentCount' => '4', |
2290
|
|
|
], |
2291
|
|
|
'SHEET' => [ |
2292
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
2293
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2294
|
|
|
'argumentCount' => '0,1', |
2295
|
|
|
], |
2296
|
|
|
'SHEETS' => [ |
2297
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
2298
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2299
|
|
|
'argumentCount' => '0,1', |
2300
|
|
|
], |
2301
|
|
|
'SIGN' => [ |
2302
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2303
|
|
|
'functionCall' => [MathTrig\Sign::class, 'evaluate'], |
2304
|
|
|
'argumentCount' => '1', |
2305
|
|
|
], |
2306
|
|
|
'SIN' => [ |
2307
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2308
|
|
|
'functionCall' => [MathTrig\Trig\Sine::class, 'sin'], |
2309
|
|
|
'argumentCount' => '1', |
2310
|
|
|
], |
2311
|
|
|
'SINGLE' => [ |
2312
|
|
|
'category' => Category::CATEGORY_UNCATEGORISED, |
2313
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2314
|
|
|
'argumentCount' => '*', |
2315
|
|
|
], |
2316
|
|
|
'SINH' => [ |
2317
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2318
|
|
|
'functionCall' => [MathTrig\Trig\Sine::class, 'sinh'], |
2319
|
|
|
'argumentCount' => '1', |
2320
|
|
|
], |
2321
|
|
|
'SKEW' => [ |
2322
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2323
|
|
|
'functionCall' => [Statistical\Deviations::class, 'skew'], |
2324
|
|
|
'argumentCount' => '1+', |
2325
|
|
|
], |
2326
|
|
|
'SKEW.P' => [ |
2327
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2328
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2329
|
|
|
'argumentCount' => '1+', |
2330
|
|
|
], |
2331
|
|
|
'SLN' => [ |
2332
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2333
|
|
|
'functionCall' => [Financial\Depreciation::class, 'SLN'], |
2334
|
|
|
'argumentCount' => '3', |
2335
|
|
|
], |
2336
|
|
|
'SLOPE' => [ |
2337
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2338
|
|
|
'functionCall' => [Statistical\Trends::class, 'SLOPE'], |
2339
|
|
|
'argumentCount' => '2', |
2340
|
|
|
], |
2341
|
|
|
'SMALL' => [ |
2342
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2343
|
|
|
'functionCall' => [Statistical\Size::class, 'small'], |
2344
|
|
|
'argumentCount' => '2', |
2345
|
|
|
], |
2346
|
|
|
'SORT' => [ |
2347
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2348
|
|
|
'functionCall' => [LookupRef\Sort::class, 'sort'], |
2349
|
|
|
'argumentCount' => '1-4', |
2350
|
|
|
], |
2351
|
|
|
'SORTBY' => [ |
2352
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2353
|
|
|
'functionCall' => [LookupRef\Sort::class, 'sortBy'], |
2354
|
|
|
'argumentCount' => '2+', |
2355
|
|
|
], |
2356
|
|
|
'SQRT' => [ |
2357
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2358
|
|
|
'functionCall' => [MathTrig\Sqrt::class, 'sqrt'], |
2359
|
|
|
'argumentCount' => '1', |
2360
|
|
|
], |
2361
|
|
|
'SQRTPI' => [ |
2362
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2363
|
|
|
'functionCall' => [MathTrig\Sqrt::class, 'pi'], |
2364
|
|
|
'argumentCount' => '1', |
2365
|
|
|
], |
2366
|
|
|
'STANDARDIZE' => [ |
2367
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2368
|
|
|
'functionCall' => [Statistical\Standardize::class, 'execute'], |
2369
|
|
|
'argumentCount' => '3', |
2370
|
|
|
], |
2371
|
|
|
'STDEV' => [ |
2372
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2373
|
|
|
'functionCall' => [Statistical\StandardDeviations::class, 'STDEV'], |
2374
|
|
|
'argumentCount' => '1+', |
2375
|
|
|
], |
2376
|
|
|
'STDEV.S' => [ |
2377
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2378
|
|
|
'functionCall' => [Statistical\StandardDeviations::class, 'STDEV'], |
2379
|
|
|
'argumentCount' => '1+', |
2380
|
|
|
], |
2381
|
|
|
'STDEV.P' => [ |
2382
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2383
|
|
|
'functionCall' => [Statistical\StandardDeviations::class, 'STDEVP'], |
2384
|
|
|
'argumentCount' => '1+', |
2385
|
|
|
], |
2386
|
|
|
'STDEVA' => [ |
2387
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2388
|
|
|
'functionCall' => [Statistical\StandardDeviations::class, 'STDEVA'], |
2389
|
|
|
'argumentCount' => '1+', |
2390
|
|
|
], |
2391
|
|
|
'STDEVP' => [ |
2392
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2393
|
|
|
'functionCall' => [Statistical\StandardDeviations::class, 'STDEVP'], |
2394
|
|
|
'argumentCount' => '1+', |
2395
|
|
|
], |
2396
|
|
|
'STDEVPA' => [ |
2397
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2398
|
|
|
'functionCall' => [Statistical\StandardDeviations::class, 'STDEVPA'], |
2399
|
|
|
'argumentCount' => '1+', |
2400
|
|
|
], |
2401
|
|
|
'STEYX' => [ |
2402
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2403
|
|
|
'functionCall' => [Statistical\Trends::class, 'STEYX'], |
2404
|
|
|
'argumentCount' => '2', |
2405
|
|
|
], |
2406
|
|
|
'SUBSTITUTE' => [ |
2407
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2408
|
|
|
'functionCall' => [TextData\Replace::class, 'substitute'], |
2409
|
|
|
'argumentCount' => '3,4', |
2410
|
|
|
], |
2411
|
|
|
'SUBTOTAL' => [ |
2412
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2413
|
|
|
'functionCall' => [MathTrig\Subtotal::class, 'evaluate'], |
2414
|
|
|
'argumentCount' => '2+', |
2415
|
|
|
'passCellReference' => true, |
2416
|
|
|
], |
2417
|
|
|
'SUM' => [ |
2418
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2419
|
|
|
'functionCall' => [MathTrig\Sum::class, 'sumErroringStrings'], |
2420
|
|
|
'argumentCount' => '1+', |
2421
|
|
|
], |
2422
|
|
|
'SUMIF' => [ |
2423
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2424
|
|
|
'functionCall' => [Statistical\Conditional::class, 'SUMIF'], |
2425
|
|
|
'argumentCount' => '2,3', |
2426
|
|
|
], |
2427
|
|
|
'SUMIFS' => [ |
2428
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2429
|
|
|
'functionCall' => [Statistical\Conditional::class, 'SUMIFS'], |
2430
|
|
|
'argumentCount' => '3+', |
2431
|
|
|
], |
2432
|
|
|
'SUMPRODUCT' => [ |
2433
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2434
|
|
|
'functionCall' => [MathTrig\Sum::class, 'product'], |
2435
|
|
|
'argumentCount' => '1+', |
2436
|
|
|
], |
2437
|
|
|
'SUMSQ' => [ |
2438
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2439
|
|
|
'functionCall' => [MathTrig\SumSquares::class, 'sumSquare'], |
2440
|
|
|
'argumentCount' => '1+', |
2441
|
|
|
], |
2442
|
|
|
'SUMX2MY2' => [ |
2443
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2444
|
|
|
'functionCall' => [MathTrig\SumSquares::class, 'sumXSquaredMinusYSquared'], |
2445
|
|
|
'argumentCount' => '2', |
2446
|
|
|
], |
2447
|
|
|
'SUMX2PY2' => [ |
2448
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2449
|
|
|
'functionCall' => [MathTrig\SumSquares::class, 'sumXSquaredPlusYSquared'], |
2450
|
|
|
'argumentCount' => '2', |
2451
|
|
|
], |
2452
|
|
|
'SUMXMY2' => [ |
2453
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2454
|
|
|
'functionCall' => [MathTrig\SumSquares::class, 'sumXMinusYSquared'], |
2455
|
|
|
'argumentCount' => '2', |
2456
|
|
|
], |
2457
|
|
|
'SWITCH' => [ |
2458
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
2459
|
|
|
'functionCall' => [Logical\Conditional::class, 'statementSwitch'], |
2460
|
|
|
'argumentCount' => '3+', |
2461
|
|
|
], |
2462
|
|
|
'SYD' => [ |
2463
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2464
|
|
|
'functionCall' => [Financial\Depreciation::class, 'SYD'], |
2465
|
|
|
'argumentCount' => '4', |
2466
|
|
|
], |
2467
|
|
|
'T' => [ |
2468
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2469
|
|
|
'functionCall' => [TextData\Text::class, 'test'], |
2470
|
|
|
'argumentCount' => '1', |
2471
|
|
|
], |
2472
|
|
|
'TAKE' => [ |
2473
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2474
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2475
|
|
|
'argumentCount' => '2-3', |
2476
|
|
|
], |
2477
|
|
|
'TAN' => [ |
2478
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2479
|
|
|
'functionCall' => [MathTrig\Trig\Tangent::class, 'tan'], |
2480
|
|
|
'argumentCount' => '1', |
2481
|
|
|
], |
2482
|
|
|
'TANH' => [ |
2483
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2484
|
|
|
'functionCall' => [MathTrig\Trig\Tangent::class, 'tanh'], |
2485
|
|
|
'argumentCount' => '1', |
2486
|
|
|
], |
2487
|
|
|
'TBILLEQ' => [ |
2488
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2489
|
|
|
'functionCall' => [Financial\TreasuryBill::class, 'bondEquivalentYield'], |
2490
|
|
|
'argumentCount' => '3', |
2491
|
|
|
], |
2492
|
|
|
'TBILLPRICE' => [ |
2493
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2494
|
|
|
'functionCall' => [Financial\TreasuryBill::class, 'price'], |
2495
|
|
|
'argumentCount' => '3', |
2496
|
|
|
], |
2497
|
|
|
'TBILLYIELD' => [ |
2498
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2499
|
|
|
'functionCall' => [Financial\TreasuryBill::class, 'yield'], |
2500
|
|
|
'argumentCount' => '3', |
2501
|
|
|
], |
2502
|
|
|
'TDIST' => [ |
2503
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2504
|
|
|
'functionCall' => [Statistical\Distributions\StudentT::class, 'distribution'], |
2505
|
|
|
'argumentCount' => '3', |
2506
|
|
|
], |
2507
|
|
|
'T.DIST' => [ |
2508
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2509
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2510
|
|
|
'argumentCount' => '3', |
2511
|
|
|
], |
2512
|
|
|
'T.DIST.2T' => [ |
2513
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2514
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2515
|
|
|
'argumentCount' => '2', |
2516
|
|
|
], |
2517
|
|
|
'T.DIST.RT' => [ |
2518
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2519
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2520
|
|
|
'argumentCount' => '2', |
2521
|
|
|
], |
2522
|
|
|
'TEXT' => [ |
2523
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2524
|
|
|
'functionCall' => [TextData\Format::class, 'TEXTFORMAT'], |
2525
|
|
|
'argumentCount' => '2', |
2526
|
|
|
], |
2527
|
|
|
'TEXTAFTER' => [ |
2528
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2529
|
|
|
'functionCall' => [TextData\Extract::class, 'after'], |
2530
|
|
|
'argumentCount' => '2-6', |
2531
|
|
|
], |
2532
|
|
|
'TEXTBEFORE' => [ |
2533
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2534
|
|
|
'functionCall' => [TextData\Extract::class, 'before'], |
2535
|
|
|
'argumentCount' => '2-6', |
2536
|
|
|
], |
2537
|
|
|
'TEXTJOIN' => [ |
2538
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2539
|
|
|
'functionCall' => [TextData\Concatenate::class, 'TEXTJOIN'], |
2540
|
|
|
'argumentCount' => '3+', |
2541
|
|
|
], |
2542
|
|
|
'TEXTSPLIT' => [ |
2543
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2544
|
|
|
'functionCall' => [TextData\Text::class, 'split'], |
2545
|
|
|
'argumentCount' => '2-6', |
2546
|
|
|
], |
2547
|
|
|
'THAIDAYOFWEEK' => [ |
2548
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2549
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2550
|
|
|
'argumentCount' => '?', |
2551
|
|
|
], |
2552
|
|
|
'THAIDIGIT' => [ |
2553
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2554
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2555
|
|
|
'argumentCount' => '?', |
2556
|
|
|
], |
2557
|
|
|
'THAIMONTHOFYEAR' => [ |
2558
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2559
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2560
|
|
|
'argumentCount' => '?', |
2561
|
|
|
], |
2562
|
|
|
'THAINUMSOUND' => [ |
2563
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2564
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2565
|
|
|
'argumentCount' => '?', |
2566
|
|
|
], |
2567
|
|
|
'THAINUMSTRING' => [ |
2568
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2569
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2570
|
|
|
'argumentCount' => '?', |
2571
|
|
|
], |
2572
|
|
|
'THAISTRINGLENGTH' => [ |
2573
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2574
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2575
|
|
|
'argumentCount' => '?', |
2576
|
|
|
], |
2577
|
|
|
'THAIYEAR' => [ |
2578
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2579
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2580
|
|
|
'argumentCount' => '?', |
2581
|
|
|
], |
2582
|
|
|
'TIME' => [ |
2583
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2584
|
|
|
'functionCall' => [DateTimeExcel\Time::class, 'fromHMS'], |
2585
|
|
|
'argumentCount' => '3', |
2586
|
|
|
], |
2587
|
|
|
'TIMEVALUE' => [ |
2588
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2589
|
|
|
'functionCall' => [DateTimeExcel\TimeValue::class, 'fromString'], |
2590
|
|
|
'argumentCount' => '1', |
2591
|
|
|
], |
2592
|
|
|
'TINV' => [ |
2593
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2594
|
|
|
'functionCall' => [Statistical\Distributions\StudentT::class, 'inverse'], |
2595
|
|
|
'argumentCount' => '2', |
2596
|
|
|
], |
2597
|
|
|
'T.INV' => [ |
2598
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2599
|
|
|
'functionCall' => [Statistical\Distributions\StudentT::class, 'inverse'], |
2600
|
|
|
'argumentCount' => '2', |
2601
|
|
|
], |
2602
|
|
|
'T.INV.2T' => [ |
2603
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2604
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2605
|
|
|
'argumentCount' => '2', |
2606
|
|
|
], |
2607
|
|
|
'TODAY' => [ |
2608
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2609
|
|
|
'functionCall' => [DateTimeExcel\Current::class, 'today'], |
2610
|
|
|
'argumentCount' => '0', |
2611
|
|
|
], |
2612
|
|
|
'TOCOL' => [ |
2613
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2614
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2615
|
|
|
'argumentCount' => '1-3', |
2616
|
|
|
], |
2617
|
|
|
'TOROW' => [ |
2618
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2619
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2620
|
|
|
'argumentCount' => '1-3', |
2621
|
|
|
], |
2622
|
|
|
'TRANSPOSE' => [ |
2623
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2624
|
|
|
'functionCall' => [LookupRef\Matrix::class, 'transpose'], |
2625
|
|
|
'argumentCount' => '1', |
2626
|
|
|
], |
2627
|
|
|
'TREND' => [ |
2628
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2629
|
|
|
'functionCall' => [Statistical\Trends::class, 'TREND'], |
2630
|
|
|
'argumentCount' => '1-4', |
2631
|
|
|
], |
2632
|
|
|
'TRIM' => [ |
2633
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2634
|
|
|
'functionCall' => [TextData\Trim::class, 'spaces'], |
2635
|
|
|
'argumentCount' => '1', |
2636
|
|
|
], |
2637
|
|
|
'TRIMMEAN' => [ |
2638
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2639
|
|
|
'functionCall' => [Statistical\Averages\Mean::class, 'trim'], |
2640
|
|
|
'argumentCount' => '2', |
2641
|
|
|
], |
2642
|
|
|
'TRUE' => [ |
2643
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
2644
|
|
|
'functionCall' => [Logical\Boolean::class, 'TRUE'], |
2645
|
|
|
'argumentCount' => '0', |
2646
|
|
|
], |
2647
|
|
|
'TRUNC' => [ |
2648
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2649
|
|
|
'functionCall' => [MathTrig\Trunc::class, 'evaluate'], |
2650
|
|
|
'argumentCount' => '1,2', |
2651
|
|
|
], |
2652
|
|
|
'TTEST' => [ |
2653
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2654
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2655
|
|
|
'argumentCount' => '4', |
2656
|
|
|
], |
2657
|
|
|
'T.TEST' => [ |
2658
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2659
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2660
|
|
|
'argumentCount' => '4', |
2661
|
|
|
], |
2662
|
|
|
'TYPE' => [ |
2663
|
|
|
'category' => Category::CATEGORY_INFORMATION, |
2664
|
|
|
'functionCall' => [Information\Value::class, 'type'], |
2665
|
|
|
'argumentCount' => '1', |
2666
|
|
|
], |
2667
|
|
|
'UNICHAR' => [ |
2668
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2669
|
|
|
'functionCall' => [TextData\CharacterConvert::class, 'character'], |
2670
|
|
|
'argumentCount' => '1', |
2671
|
|
|
], |
2672
|
|
|
'UNICODE' => [ |
2673
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2674
|
|
|
'functionCall' => [TextData\CharacterConvert::class, 'code'], |
2675
|
|
|
'argumentCount' => '1', |
2676
|
|
|
], |
2677
|
|
|
'UNIQUE' => [ |
2678
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2679
|
|
|
'functionCall' => [LookupRef\Unique::class, 'unique'], |
2680
|
|
|
'argumentCount' => '1+', |
2681
|
|
|
], |
2682
|
|
|
'UPPER' => [ |
2683
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2684
|
|
|
'functionCall' => [TextData\CaseConvert::class, 'upper'], |
2685
|
|
|
'argumentCount' => '1', |
2686
|
|
|
], |
2687
|
|
|
'USDOLLAR' => [ |
2688
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2689
|
|
|
'functionCall' => [Financial\Dollar::class, 'format'], |
2690
|
|
|
'argumentCount' => '2', |
2691
|
|
|
], |
2692
|
|
|
'VALUE' => [ |
2693
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2694
|
|
|
'functionCall' => [TextData\Format::class, 'VALUE'], |
2695
|
|
|
'argumentCount' => '1', |
2696
|
|
|
], |
2697
|
|
|
'VALUETOTEXT' => [ |
2698
|
|
|
'category' => Category::CATEGORY_TEXT_AND_DATA, |
2699
|
|
|
'functionCall' => [TextData\Format::class, 'valueToText'], |
2700
|
|
|
'argumentCount' => '1,2', |
2701
|
|
|
], |
2702
|
|
|
'VAR' => [ |
2703
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2704
|
|
|
'functionCall' => [Statistical\Variances::class, 'VAR'], |
2705
|
|
|
'argumentCount' => '1+', |
2706
|
|
|
], |
2707
|
|
|
'VAR.P' => [ |
2708
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2709
|
|
|
'functionCall' => [Statistical\Variances::class, 'VARP'], |
2710
|
|
|
'argumentCount' => '1+', |
2711
|
|
|
], |
2712
|
|
|
'VAR.S' => [ |
2713
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2714
|
|
|
'functionCall' => [Statistical\Variances::class, 'VAR'], |
2715
|
|
|
'argumentCount' => '1+', |
2716
|
|
|
], |
2717
|
|
|
'VARA' => [ |
2718
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2719
|
|
|
'functionCall' => [Statistical\Variances::class, 'VARA'], |
2720
|
|
|
'argumentCount' => '1+', |
2721
|
|
|
], |
2722
|
|
|
'VARP' => [ |
2723
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2724
|
|
|
'functionCall' => [Statistical\Variances::class, 'VARP'], |
2725
|
|
|
'argumentCount' => '1+', |
2726
|
|
|
], |
2727
|
|
|
'VARPA' => [ |
2728
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2729
|
|
|
'functionCall' => [Statistical\Variances::class, 'VARPA'], |
2730
|
|
|
'argumentCount' => '1+', |
2731
|
|
|
], |
2732
|
|
|
'VDB' => [ |
2733
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2734
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2735
|
|
|
'argumentCount' => '5-7', |
2736
|
|
|
], |
2737
|
|
|
'VLOOKUP' => [ |
2738
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2739
|
|
|
'functionCall' => [LookupRef\VLookup::class, 'lookup'], |
2740
|
|
|
'argumentCount' => '3,4', |
2741
|
|
|
], |
2742
|
|
|
'VSTACK' => [ |
2743
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2744
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2745
|
|
|
'argumentCount' => '1+', |
2746
|
|
|
], |
2747
|
|
|
'WEBSERVICE' => [ |
2748
|
|
|
'category' => Category::CATEGORY_WEB, |
2749
|
|
|
'functionCall' => [Web\Service::class, 'webService'], |
2750
|
|
|
'argumentCount' => '1', |
2751
|
|
|
], |
2752
|
|
|
'WEEKDAY' => [ |
2753
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2754
|
|
|
'functionCall' => [DateTimeExcel\Week::class, 'day'], |
2755
|
|
|
'argumentCount' => '1,2', |
2756
|
|
|
], |
2757
|
|
|
'WEEKNUM' => [ |
2758
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2759
|
|
|
'functionCall' => [DateTimeExcel\Week::class, 'number'], |
2760
|
|
|
'argumentCount' => '1,2', |
2761
|
|
|
], |
2762
|
|
|
'WEIBULL' => [ |
2763
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2764
|
|
|
'functionCall' => [Statistical\Distributions\Weibull::class, 'distribution'], |
2765
|
|
|
'argumentCount' => '4', |
2766
|
|
|
], |
2767
|
|
|
'WEIBULL.DIST' => [ |
2768
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2769
|
|
|
'functionCall' => [Statistical\Distributions\Weibull::class, 'distribution'], |
2770
|
|
|
'argumentCount' => '4', |
2771
|
|
|
], |
2772
|
|
|
'WORKDAY' => [ |
2773
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2774
|
|
|
'functionCall' => [DateTimeExcel\WorkDay::class, 'date'], |
2775
|
|
|
'argumentCount' => '2-3', |
2776
|
|
|
], |
2777
|
|
|
'WORKDAY.INTL' => [ |
2778
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2779
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2780
|
|
|
'argumentCount' => '2-4', |
2781
|
|
|
], |
2782
|
|
|
'WRAPCOLS' => [ |
2783
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2784
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2785
|
|
|
'argumentCount' => '2-3', |
2786
|
|
|
], |
2787
|
|
|
'WRAPROWS' => [ |
2788
|
|
|
'category' => Category::CATEGORY_MATH_AND_TRIG, |
2789
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2790
|
|
|
'argumentCount' => '2-3', |
2791
|
|
|
], |
2792
|
|
|
'XIRR' => [ |
2793
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2794
|
|
|
'functionCall' => [Financial\CashFlow\Variable\NonPeriodic::class, 'rate'], |
2795
|
|
|
'argumentCount' => '2,3', |
2796
|
|
|
], |
2797
|
|
|
'XLOOKUP' => [ |
2798
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2799
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2800
|
|
|
'argumentCount' => '3-6', |
2801
|
|
|
], |
2802
|
|
|
'XNPV' => [ |
2803
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2804
|
|
|
'functionCall' => [Financial\CashFlow\Variable\NonPeriodic::class, 'presentValue'], |
2805
|
|
|
'argumentCount' => '3', |
2806
|
|
|
], |
2807
|
|
|
'XMATCH' => [ |
2808
|
|
|
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE, |
2809
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2810
|
|
|
'argumentCount' => '2,3', |
2811
|
|
|
], |
2812
|
|
|
'XOR' => [ |
2813
|
|
|
'category' => Category::CATEGORY_LOGICAL, |
2814
|
|
|
'functionCall' => [Logical\Operations::class, 'logicalXor'], |
2815
|
|
|
'argumentCount' => '1+', |
2816
|
|
|
], |
2817
|
|
|
'YEAR' => [ |
2818
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2819
|
|
|
'functionCall' => [DateTimeExcel\DateParts::class, 'year'], |
2820
|
|
|
'argumentCount' => '1', |
2821
|
|
|
], |
2822
|
|
|
'YEARFRAC' => [ |
2823
|
|
|
'category' => Category::CATEGORY_DATE_AND_TIME, |
2824
|
|
|
'functionCall' => [DateTimeExcel\YearFrac::class, 'fraction'], |
2825
|
|
|
'argumentCount' => '2,3', |
2826
|
|
|
], |
2827
|
|
|
'YIELD' => [ |
2828
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2829
|
|
|
'functionCall' => [Functions::class, 'DUMMY'], |
2830
|
|
|
'argumentCount' => '6,7', |
2831
|
|
|
], |
2832
|
|
|
'YIELDDISC' => [ |
2833
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2834
|
|
|
'functionCall' => [Financial\Securities\Yields::class, 'yieldDiscounted'], |
2835
|
|
|
'argumentCount' => '4,5', |
2836
|
|
|
], |
2837
|
|
|
'YIELDMAT' => [ |
2838
|
|
|
'category' => Category::CATEGORY_FINANCIAL, |
2839
|
|
|
'functionCall' => [Financial\Securities\Yields::class, 'yieldAtMaturity'], |
2840
|
|
|
'argumentCount' => '5,6', |
2841
|
|
|
], |
2842
|
|
|
'ZTEST' => [ |
2843
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2844
|
|
|
'functionCall' => [Statistical\Distributions\StandardNormal::class, 'zTest'], |
2845
|
|
|
'argumentCount' => '2-3', |
2846
|
|
|
], |
2847
|
|
|
'Z.TEST' => [ |
2848
|
|
|
'category' => Category::CATEGORY_STATISTICAL, |
2849
|
|
|
'functionCall' => [Statistical\Distributions\StandardNormal::class, 'zTest'], |
2850
|
|
|
'argumentCount' => '2-3', |
2851
|
|
|
], |
2852
|
|
|
]; |
2853
|
|
|
|
2854
|
|
|
/** |
2855
|
|
|
* Internal functions used for special control purposes. |
2856
|
|
|
*/ |
2857
|
|
|
private static array $controlFunctions = [ |
2858
|
|
|
'MKMATRIX' => [ |
2859
|
|
|
'argumentCount' => '*', |
2860
|
|
|
'functionCall' => [Internal\MakeMatrix::class, 'make'], |
2861
|
|
|
], |
2862
|
|
|
'NAME.ERROR' => [ |
2863
|
|
|
'argumentCount' => '*', |
2864
|
|
|
'functionCall' => [ExcelError::class, 'NAME'], |
2865
|
|
|
], |
2866
|
|
|
'WILDCARDMATCH' => [ |
2867
|
|
|
'argumentCount' => '2', |
2868
|
|
|
'functionCall' => [Internal\WildcardMatch::class, 'compare'], |
2869
|
|
|
], |
2870
|
|
|
]; |
2871
|
|
|
|
2872
|
9925 |
|
public function __construct(/** |
2873
|
|
|
* Instance of the spreadsheet this Calculation Engine is using. |
2874
|
|
|
*/ |
2875
|
|
|
private ?Spreadsheet $spreadsheet = null |
2876
|
|
|
) { |
2877
|
9925 |
|
$this->cyclicReferenceStack = new CyclicReferenceStack(); |
2878
|
9925 |
|
$this->debugLog = new Logger($this->cyclicReferenceStack); |
2879
|
9925 |
|
$this->branchPruner = new BranchPruner($this->branchPruningEnabled); |
2880
|
9925 |
|
self::$referenceHelper = ReferenceHelper::getInstance(); |
2881
|
|
|
} |
2882
|
|
|
|
2883
|
1 |
|
private static function loadLocales(): void |
2884
|
|
|
{ |
2885
|
1 |
|
$localeFileDirectory = __DIR__ . '/locale/'; |
2886
|
1 |
|
$localeFileNames = glob($localeFileDirectory . '*', GLOB_ONLYDIR) ?: []; |
2887
|
1 |
|
foreach ($localeFileNames as $filename) { |
2888
|
1 |
|
$filename = substr($filename, strlen($localeFileDirectory)); |
2889
|
1 |
|
if ($filename != 'en') { |
2890
|
1 |
|
self::$validLocaleLanguages[] = $filename; |
2891
|
|
|
} |
2892
|
|
|
} |
2893
|
|
|
} |
2894
|
|
|
|
2895
|
|
|
/** |
2896
|
|
|
* Get an instance of this class. |
2897
|
|
|
* |
2898
|
|
|
* @param ?Spreadsheet $spreadsheet Injected spreadsheet for working with a PhpSpreadsheet Spreadsheet object, |
2899
|
|
|
* or NULL to create a standalone calculation engine |
2900
|
|
|
*/ |
2901
|
12999 |
|
public static function getInstance(?Spreadsheet $spreadsheet = null): self |
2902
|
|
|
{ |
2903
|
12999 |
|
if ($spreadsheet !== null) { |
2904
|
8726 |
|
$instance = $spreadsheet->getCalculationEngine(); |
2905
|
8726 |
|
if (isset($instance)) { |
2906
|
8726 |
|
return $instance; |
2907
|
|
|
} |
2908
|
|
|
} |
2909
|
|
|
|
2910
|
5125 |
|
if (!self::$instance) { |
2911
|
17 |
|
self::$instance = new self(); |
2912
|
|
|
} |
2913
|
|
|
|
2914
|
5125 |
|
return self::$instance; |
2915
|
|
|
} |
2916
|
|
|
|
2917
|
|
|
/** |
2918
|
|
|
* Flush the calculation cache for any existing instance of this class |
2919
|
|
|
* but only if a Calculation instance exists. |
2920
|
|
|
*/ |
2921
|
200 |
|
public function flushInstance(): void |
2922
|
|
|
{ |
2923
|
200 |
|
$this->clearCalculationCache(); |
2924
|
200 |
|
$this->branchPruner->clearBranchStore(); |
2925
|
|
|
} |
2926
|
|
|
|
2927
|
|
|
/** |
2928
|
|
|
* Get the Logger for this calculation engine instance. |
2929
|
|
|
*/ |
2930
|
949 |
|
public function getDebugLog(): Logger |
2931
|
|
|
{ |
2932
|
949 |
|
return $this->debugLog; |
2933
|
|
|
} |
2934
|
|
|
|
2935
|
|
|
/** |
2936
|
|
|
* __clone implementation. Cloning should not be allowed in a Singleton! |
2937
|
|
|
*/ |
2938
|
|
|
final public function __clone() |
2939
|
|
|
{ |
2940
|
|
|
throw new Exception('Cloning the calculation engine is not allowed!'); |
2941
|
|
|
} |
2942
|
|
|
|
2943
|
|
|
/** |
2944
|
|
|
* Return the locale-specific translation of TRUE. |
2945
|
|
|
* |
2946
|
|
|
* @return string locale-specific translation of TRUE |
2947
|
|
|
*/ |
2948
|
409 |
|
public static function getTRUE(): string |
2949
|
|
|
{ |
2950
|
409 |
|
return self::$localeBoolean['TRUE']; |
2951
|
|
|
} |
2952
|
|
|
|
2953
|
|
|
/** |
2954
|
|
|
* Return the locale-specific translation of FALSE. |
2955
|
|
|
* |
2956
|
|
|
* @return string locale-specific translation of FALSE |
2957
|
|
|
*/ |
2958
|
394 |
|
public static function getFALSE(): string |
2959
|
|
|
{ |
2960
|
394 |
|
return self::$localeBoolean['FALSE']; |
2961
|
|
|
} |
2962
|
|
|
|
2963
|
|
|
/** |
2964
|
|
|
* Set the Array Return Type (Array or Value of first element in the array). |
2965
|
|
|
* |
2966
|
|
|
* @param string $returnType Array return type |
2967
|
|
|
* |
2968
|
|
|
* @return bool Success or failure |
2969
|
|
|
*/ |
2970
|
497 |
|
public static function setArrayReturnType(string $returnType): bool |
2971
|
|
|
{ |
2972
|
|
|
if ( |
2973
|
497 |
|
($returnType == self::RETURN_ARRAY_AS_VALUE) |
2974
|
497 |
|
|| ($returnType == self::RETURN_ARRAY_AS_ERROR) |
2975
|
497 |
|
|| ($returnType == self::RETURN_ARRAY_AS_ARRAY) |
2976
|
|
|
) { |
2977
|
497 |
|
self::$returnArrayAsType = $returnType; |
2978
|
|
|
|
2979
|
497 |
|
return true; |
2980
|
|
|
} |
2981
|
|
|
|
2982
|
|
|
return false; |
2983
|
|
|
} |
2984
|
|
|
|
2985
|
|
|
/** |
2986
|
|
|
* Return the Array Return Type (Array or Value of first element in the array). |
2987
|
|
|
* |
2988
|
|
|
* @return string $returnType Array return type |
2989
|
|
|
*/ |
2990
|
497 |
|
public static function getArrayReturnType(): string |
2991
|
|
|
{ |
2992
|
497 |
|
return self::$returnArrayAsType; |
2993
|
|
|
} |
2994
|
|
|
|
2995
|
|
|
/** |
2996
|
|
|
* Is calculation caching enabled? |
2997
|
|
|
*/ |
2998
|
174 |
|
public function getCalculationCacheEnabled(): bool |
2999
|
|
|
{ |
3000
|
174 |
|
return $this->calculationCacheEnabled; |
3001
|
|
|
} |
3002
|
|
|
|
3003
|
|
|
/** |
3004
|
|
|
* Enable/disable calculation cache. |
3005
|
|
|
*/ |
3006
|
|
|
public function setCalculationCacheEnabled(bool $calculationCacheEnabled): void |
3007
|
|
|
{ |
3008
|
|
|
$this->calculationCacheEnabled = $calculationCacheEnabled; |
3009
|
|
|
$this->clearCalculationCache(); |
3010
|
|
|
} |
3011
|
|
|
|
3012
|
|
|
/** |
3013
|
|
|
* Enable calculation cache. |
3014
|
|
|
*/ |
3015
|
|
|
public function enableCalculationCache(): void |
3016
|
|
|
{ |
3017
|
|
|
$this->setCalculationCacheEnabled(true); |
3018
|
|
|
} |
3019
|
|
|
|
3020
|
|
|
/** |
3021
|
|
|
* Disable calculation cache. |
3022
|
|
|
*/ |
3023
|
|
|
public function disableCalculationCache(): void |
3024
|
|
|
{ |
3025
|
|
|
$this->setCalculationCacheEnabled(false); |
3026
|
|
|
} |
3027
|
|
|
|
3028
|
|
|
/** |
3029
|
|
|
* Clear calculation cache. |
3030
|
|
|
*/ |
3031
|
200 |
|
public function clearCalculationCache(): void |
3032
|
|
|
{ |
3033
|
200 |
|
$this->calculationCache = []; |
3034
|
|
|
} |
3035
|
|
|
|
3036
|
|
|
/** |
3037
|
|
|
* Clear calculation cache for a specified worksheet. |
3038
|
|
|
*/ |
3039
|
115 |
|
public function clearCalculationCacheForWorksheet(string $worksheetName): void |
3040
|
|
|
{ |
3041
|
115 |
|
if (isset($this->calculationCache[$worksheetName])) { |
3042
|
|
|
unset($this->calculationCache[$worksheetName]); |
3043
|
|
|
} |
3044
|
|
|
} |
3045
|
|
|
|
3046
|
|
|
/** |
3047
|
|
|
* Rename calculation cache for a specified worksheet. |
3048
|
|
|
*/ |
3049
|
9925 |
|
public function renameCalculationCacheForWorksheet(string $fromWorksheetName, string $toWorksheetName): void |
3050
|
|
|
{ |
3051
|
9925 |
|
if (isset($this->calculationCache[$fromWorksheetName])) { |
3052
|
|
|
$this->calculationCache[$toWorksheetName] = &$this->calculationCache[$fromWorksheetName]; |
3053
|
|
|
unset($this->calculationCache[$fromWorksheetName]); |
3054
|
|
|
} |
3055
|
|
|
} |
3056
|
|
|
|
3057
|
|
|
/** |
3058
|
|
|
* Enable/disable calculation cache. |
3059
|
|
|
*/ |
3060
|
10 |
|
public function setBranchPruningEnabled(mixed $enabled): void |
3061
|
|
|
{ |
3062
|
10 |
|
$this->branchPruningEnabled = $enabled; |
3063
|
10 |
|
$this->branchPruner = new BranchPruner($this->branchPruningEnabled); |
3064
|
|
|
} |
3065
|
|
|
|
3066
|
|
|
public function enableBranchPruning(): void |
3067
|
|
|
{ |
3068
|
|
|
$this->setBranchPruningEnabled(true); |
3069
|
|
|
} |
3070
|
|
|
|
3071
|
10 |
|
public function disableBranchPruning(): void |
3072
|
|
|
{ |
3073
|
10 |
|
$this->setBranchPruningEnabled(false); |
3074
|
|
|
} |
3075
|
|
|
|
3076
|
|
|
/** |
3077
|
|
|
* Get the currently defined locale code. |
3078
|
|
|
*/ |
3079
|
1359 |
|
public function getLocale(): string |
3080
|
|
|
{ |
3081
|
1359 |
|
return self::$localeLanguage; |
3082
|
|
|
} |
3083
|
|
|
|
3084
|
116 |
|
private function getLocaleFile(string $localeDir, string $locale, string $language, string $file): string |
3085
|
|
|
{ |
3086
|
116 |
|
$localeFileName = $localeDir . str_replace('_', DIRECTORY_SEPARATOR, $locale) |
3087
|
116 |
|
. DIRECTORY_SEPARATOR . $file; |
3088
|
116 |
|
if (!file_exists($localeFileName)) { |
3089
|
|
|
// If there isn't a locale specific file, look for a language specific file |
3090
|
29 |
|
$localeFileName = $localeDir . $language . DIRECTORY_SEPARATOR . $file; |
3091
|
29 |
|
if (!file_exists($localeFileName)) { |
3092
|
3 |
|
throw new Exception('Locale file not found'); |
3093
|
|
|
} |
3094
|
|
|
} |
3095
|
|
|
|
3096
|
113 |
|
return $localeFileName; |
3097
|
|
|
} |
3098
|
|
|
|
3099
|
|
|
/** |
3100
|
|
|
* Set the locale code. |
3101
|
|
|
* |
3102
|
|
|
* @param string $locale The locale to use for formula translation, eg: 'en_us' |
3103
|
|
|
*/ |
3104
|
1359 |
|
public function setLocale(string $locale): bool |
3105
|
|
|
{ |
3106
|
|
|
// Identify our locale and language |
3107
|
1359 |
|
$language = $locale = strtolower($locale); |
3108
|
1359 |
|
if (str_contains($locale, '_')) { |
3109
|
1359 |
|
[$language] = explode('_', $locale); |
3110
|
|
|
} |
3111
|
1359 |
|
if (count(self::$validLocaleLanguages) == 1) { |
3112
|
1 |
|
self::loadLocales(); |
3113
|
|
|
} |
3114
|
|
|
|
3115
|
|
|
// Test whether we have any language data for this language (any locale) |
3116
|
1359 |
|
if (in_array($language, self::$validLocaleLanguages, true)) { |
3117
|
|
|
// initialise language/locale settings |
3118
|
1359 |
|
self::$localeFunctions = []; |
3119
|
1359 |
|
self::$localeArgumentSeparator = ','; |
3120
|
1359 |
|
self::$localeBoolean = ['TRUE' => 'TRUE', 'FALSE' => 'FALSE', 'NULL' => 'NULL']; |
3121
|
|
|
|
3122
|
|
|
// Default is US English, if user isn't requesting US english, then read the necessary data from the locale files |
3123
|
1359 |
|
if ($locale !== 'en_us') { |
3124
|
116 |
|
$localeDir = implode(DIRECTORY_SEPARATOR, [__DIR__, 'locale', null]); |
3125
|
|
|
|
3126
|
|
|
// Search for a file with a list of function names for locale |
3127
|
|
|
try { |
3128
|
116 |
|
$functionNamesFile = $this->getLocaleFile($localeDir, $locale, $language, 'functions'); |
3129
|
3 |
|
} catch (Exception) { |
3130
|
3 |
|
return false; |
3131
|
|
|
} |
3132
|
|
|
|
3133
|
|
|
// Retrieve the list of locale or language specific function names |
3134
|
113 |
|
$localeFunctions = file($functionNamesFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: []; |
3135
|
113 |
|
foreach ($localeFunctions as $localeFunction) { |
3136
|
113 |
|
[$localeFunction] = explode('##', $localeFunction); // Strip out comments |
3137
|
113 |
|
if (str_contains($localeFunction, '=')) { |
3138
|
113 |
|
[$fName, $lfName] = array_map('trim', explode('=', $localeFunction)); |
3139
|
113 |
|
if ((str_starts_with($fName, '*') || isset(self::$phpSpreadsheetFunctions[$fName])) && ($lfName != '') && ($fName != $lfName)) { |
3140
|
113 |
|
self::$localeFunctions[$fName] = $lfName; |
3141
|
|
|
} |
3142
|
|
|
} |
3143
|
|
|
} |
3144
|
|
|
// Default the TRUE and FALSE constants to the locale names of the TRUE() and FALSE() functions |
3145
|
113 |
|
if (isset(self::$localeFunctions['TRUE'])) { |
3146
|
113 |
|
self::$localeBoolean['TRUE'] = self::$localeFunctions['TRUE']; |
3147
|
|
|
} |
3148
|
113 |
|
if (isset(self::$localeFunctions['FALSE'])) { |
3149
|
113 |
|
self::$localeBoolean['FALSE'] = self::$localeFunctions['FALSE']; |
3150
|
|
|
} |
3151
|
|
|
|
3152
|
|
|
try { |
3153
|
113 |
|
$configFile = $this->getLocaleFile($localeDir, $locale, $language, 'config'); |
3154
|
|
|
} catch (Exception) { |
3155
|
|
|
return false; |
3156
|
|
|
} |
3157
|
|
|
|
3158
|
113 |
|
$localeSettings = file($configFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: []; |
3159
|
113 |
|
foreach ($localeSettings as $localeSetting) { |
3160
|
113 |
|
[$localeSetting] = explode('##', $localeSetting); // Strip out comments |
3161
|
113 |
|
if (str_contains($localeSetting, '=')) { |
3162
|
113 |
|
[$settingName, $settingValue] = array_map('trim', explode('=', $localeSetting)); |
3163
|
113 |
|
$settingName = strtoupper($settingName); |
3164
|
113 |
|
if ($settingValue !== '') { |
3165
|
|
|
switch ($settingName) { |
3166
|
113 |
|
case 'ARGUMENTSEPARATOR': |
3167
|
113 |
|
self::$localeArgumentSeparator = $settingValue; |
3168
|
|
|
|
3169
|
113 |
|
break; |
3170
|
|
|
} |
3171
|
|
|
} |
3172
|
|
|
} |
3173
|
|
|
} |
3174
|
|
|
} |
3175
|
|
|
|
3176
|
1359 |
|
self::$functionReplaceFromExcel = self::$functionReplaceToExcel |
3177
|
1359 |
|
= self::$functionReplaceFromLocale = self::$functionReplaceToLocale = null; |
3178
|
1359 |
|
self::$localeLanguage = $locale; |
3179
|
|
|
|
3180
|
1359 |
|
return true; |
3181
|
|
|
} |
3182
|
|
|
|
3183
|
3 |
|
return false; |
3184
|
|
|
} |
3185
|
|
|
|
3186
|
33 |
|
public static function translateSeparator( |
3187
|
|
|
string $fromSeparator, |
3188
|
|
|
string $toSeparator, |
3189
|
|
|
string $formula, |
3190
|
|
|
int &$inBracesLevel, |
3191
|
|
|
string $openBrace = self::FORMULA_OPEN_FUNCTION_BRACE, |
3192
|
|
|
string $closeBrace = self::FORMULA_CLOSE_FUNCTION_BRACE |
3193
|
|
|
): string { |
3194
|
33 |
|
$strlen = mb_strlen($formula); |
3195
|
33 |
|
for ($i = 0; $i < $strlen; ++$i) { |
3196
|
33 |
|
$chr = mb_substr($formula, $i, 1); |
3197
|
|
|
switch ($chr) { |
3198
|
33 |
|
case $openBrace: |
3199
|
29 |
|
++$inBracesLevel; |
3200
|
|
|
|
3201
|
29 |
|
break; |
3202
|
33 |
|
case $closeBrace: |
3203
|
29 |
|
--$inBracesLevel; |
3204
|
|
|
|
3205
|
29 |
|
break; |
3206
|
33 |
|
case $fromSeparator: |
3207
|
15 |
|
if ($inBracesLevel > 0) { |
3208
|
15 |
|
$formula = mb_substr($formula, 0, $i) . $toSeparator . mb_substr($formula, $i + 1); |
3209
|
|
|
} |
3210
|
|
|
} |
3211
|
|
|
} |
3212
|
|
|
|
3213
|
33 |
|
return $formula; |
3214
|
|
|
} |
3215
|
|
|
|
3216
|
19 |
|
private static function translateFormulaBlock( |
3217
|
|
|
array $from, |
3218
|
|
|
array $to, |
3219
|
|
|
string $formula, |
3220
|
|
|
int &$inFunctionBracesLevel, |
3221
|
|
|
int &$inMatrixBracesLevel, |
3222
|
|
|
string $fromSeparator, |
3223
|
|
|
string $toSeparator |
3224
|
|
|
): string { |
3225
|
|
|
// Function Names |
3226
|
19 |
|
$formula = (string) preg_replace($from, $to, $formula); |
3227
|
|
|
|
3228
|
|
|
// Temporarily adjust matrix separators so that they won't be confused with function arguments |
3229
|
19 |
|
$formula = self::translateSeparator(';', '|', $formula, $inMatrixBracesLevel, self::FORMULA_OPEN_MATRIX_BRACE, self::FORMULA_CLOSE_MATRIX_BRACE); |
3230
|
19 |
|
$formula = self::translateSeparator(',', '!', $formula, $inMatrixBracesLevel, self::FORMULA_OPEN_MATRIX_BRACE, self::FORMULA_CLOSE_MATRIX_BRACE); |
3231
|
|
|
// Function Argument Separators |
3232
|
19 |
|
$formula = self::translateSeparator($fromSeparator, $toSeparator, $formula, $inFunctionBracesLevel); |
3233
|
|
|
// Restore matrix separators |
3234
|
19 |
|
$formula = self::translateSeparator('|', ';', $formula, $inMatrixBracesLevel, self::FORMULA_OPEN_MATRIX_BRACE, self::FORMULA_CLOSE_MATRIX_BRACE); |
3235
|
19 |
|
$formula = self::translateSeparator('!', ',', $formula, $inMatrixBracesLevel, self::FORMULA_OPEN_MATRIX_BRACE, self::FORMULA_CLOSE_MATRIX_BRACE); |
3236
|
|
|
|
3237
|
19 |
|
return $formula; |
3238
|
|
|
} |
3239
|
|
|
|
3240
|
19 |
|
private static function translateFormula(array $from, array $to, string $formula, string $fromSeparator, string $toSeparator): string |
3241
|
|
|
{ |
3242
|
|
|
// Convert any Excel function names and constant names to the required language; |
3243
|
|
|
// and adjust function argument separators |
3244
|
19 |
|
if (self::$localeLanguage !== 'en_us') { |
3245
|
19 |
|
$inFunctionBracesLevel = 0; |
3246
|
19 |
|
$inMatrixBracesLevel = 0; |
3247
|
|
|
// If there is the possibility of separators within a quoted string, then we treat them as literals |
3248
|
19 |
|
if (str_contains($formula, self::FORMULA_STRING_QUOTE)) { |
3249
|
|
|
// So instead we skip replacing in any quoted strings by only replacing in every other array element |
3250
|
|
|
// after we've exploded the formula |
3251
|
6 |
|
$temp = explode(self::FORMULA_STRING_QUOTE, $formula); |
3252
|
6 |
|
$notWithinQuotes = false; |
3253
|
6 |
|
foreach ($temp as &$value) { |
3254
|
|
|
// Only adjust in alternating array entries |
3255
|
6 |
|
$notWithinQuotes = $notWithinQuotes === false; |
3256
|
6 |
|
if ($notWithinQuotes === true) { |
3257
|
6 |
|
$value = self::translateFormulaBlock($from, $to, $value, $inFunctionBracesLevel, $inMatrixBracesLevel, $fromSeparator, $toSeparator); |
3258
|
|
|
} |
3259
|
|
|
} |
3260
|
6 |
|
unset($value); |
3261
|
|
|
// Then rebuild the formula string |
3262
|
6 |
|
$formula = implode(self::FORMULA_STRING_QUOTE, $temp); |
3263
|
|
|
} else { |
3264
|
|
|
// If there's no quoted strings, then we do a simple count/replace |
3265
|
13 |
|
$formula = self::translateFormulaBlock($from, $to, $formula, $inFunctionBracesLevel, $inMatrixBracesLevel, $fromSeparator, $toSeparator); |
3266
|
|
|
} |
3267
|
|
|
} |
3268
|
|
|
|
3269
|
19 |
|
return $formula; |
3270
|
|
|
} |
3271
|
|
|
|
3272
|
|
|
/** @var ?array */ |
3273
|
|
|
private static ?array $functionReplaceFromExcel = null; |
3274
|
|
|
|
3275
|
|
|
/** @var ?array */ |
3276
|
|
|
private static ?array $functionReplaceToLocale = null; |
3277
|
|
|
|
3278
|
|
|
/** |
3279
|
|
|
* @deprecated 1.30.0 use translateFormulaToLocale() instead |
3280
|
|
|
* |
3281
|
|
|
* @codeCoverageIgnore |
3282
|
|
|
*/ |
3283
|
|
|
public function _translateFormulaToLocale(string $formula): string |
3284
|
|
|
{ |
3285
|
|
|
return $this->translateFormulaToLocale($formula); |
3286
|
|
|
} |
3287
|
|
|
|
3288
|
19 |
|
public function translateFormulaToLocale(string $formula): string |
3289
|
|
|
{ |
3290
|
19 |
|
$formula = preg_replace(self::CALCULATION_REGEXP_STRIP_XLFN_XLWS, '', $formula) ?? ''; |
3291
|
|
|
// Build list of function names and constants for translation |
3292
|
19 |
|
if (self::$functionReplaceFromExcel === null) { |
3293
|
19 |
|
self::$functionReplaceFromExcel = []; |
3294
|
19 |
|
foreach (array_keys(self::$localeFunctions) as $excelFunctionName) { |
3295
|
19 |
|
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelFunctionName, '/') . '([\s]*\()/ui'; |
3296
|
|
|
} |
3297
|
19 |
|
foreach (array_keys(self::$localeBoolean) as $excelBoolean) { |
3298
|
19 |
|
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/ui'; |
3299
|
|
|
} |
3300
|
|
|
} |
3301
|
|
|
|
3302
|
19 |
|
if (self::$functionReplaceToLocale === null) { |
3303
|
19 |
|
self::$functionReplaceToLocale = []; |
3304
|
19 |
|
foreach (self::$localeFunctions as $localeFunctionName) { |
3305
|
19 |
|
self::$functionReplaceToLocale[] = '$1' . trim($localeFunctionName) . '$2'; |
3306
|
|
|
} |
3307
|
19 |
|
foreach (self::$localeBoolean as $localeBoolean) { |
3308
|
19 |
|
self::$functionReplaceToLocale[] = '$1' . trim($localeBoolean) . '$2'; |
3309
|
|
|
} |
3310
|
|
|
} |
3311
|
|
|
|
3312
|
19 |
|
return self::translateFormula( |
3313
|
19 |
|
self::$functionReplaceFromExcel, |
3314
|
19 |
|
self::$functionReplaceToLocale, |
3315
|
19 |
|
$formula, |
3316
|
19 |
|
',', |
3317
|
19 |
|
self::$localeArgumentSeparator |
3318
|
19 |
|
); |
3319
|
|
|
} |
3320
|
|
|
|
3321
|
|
|
/** @var ?array */ |
3322
|
|
|
private static ?array $functionReplaceFromLocale = null; |
3323
|
|
|
|
3324
|
|
|
/** @var ?array */ |
3325
|
|
|
private static ?array $functionReplaceToExcel = null; |
3326
|
|
|
|
3327
|
|
|
/** |
3328
|
|
|
* @deprecated 1.30.0 use translateFormulaToEnglish() instead |
3329
|
|
|
* |
3330
|
|
|
* @codeCoverageIgnore |
3331
|
|
|
*/ |
3332
|
|
|
public function _translateFormulaToEnglish(string $formula): string |
3333
|
|
|
{ |
3334
|
|
|
return $this->translateFormulaToEnglish($formula); |
3335
|
|
|
} |
3336
|
|
|
|
3337
|
19 |
|
public function translateFormulaToEnglish(string $formula): string |
3338
|
|
|
{ |
3339
|
19 |
|
if (self::$functionReplaceFromLocale === null) { |
3340
|
19 |
|
self::$functionReplaceFromLocale = []; |
3341
|
19 |
|
foreach (self::$localeFunctions as $localeFunctionName) { |
3342
|
19 |
|
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($localeFunctionName, '/') . '([\s]*\()/ui'; |
3343
|
|
|
} |
3344
|
19 |
|
foreach (self::$localeBoolean as $excelBoolean) { |
3345
|
19 |
|
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/ui'; |
3346
|
|
|
} |
3347
|
|
|
} |
3348
|
|
|
|
3349
|
19 |
|
if (self::$functionReplaceToExcel === null) { |
3350
|
19 |
|
self::$functionReplaceToExcel = []; |
3351
|
19 |
|
foreach (array_keys(self::$localeFunctions) as $excelFunctionName) { |
3352
|
19 |
|
self::$functionReplaceToExcel[] = '$1' . trim($excelFunctionName) . '$2'; |
3353
|
|
|
} |
3354
|
19 |
|
foreach (array_keys(self::$localeBoolean) as $excelBoolean) { |
3355
|
19 |
|
self::$functionReplaceToExcel[] = '$1' . trim($excelBoolean) . '$2'; |
3356
|
|
|
} |
3357
|
|
|
} |
3358
|
|
|
|
3359
|
19 |
|
return self::translateFormula(self::$functionReplaceFromLocale, self::$functionReplaceToExcel, $formula, self::$localeArgumentSeparator, ','); |
3360
|
|
|
} |
3361
|
|
|
|
3362
|
11408 |
|
public static function localeFunc(string $function): string |
3363
|
|
|
{ |
3364
|
11408 |
|
if (self::$localeLanguage !== 'en_us') { |
3365
|
71 |
|
$functionName = trim($function, '('); |
3366
|
71 |
|
if (isset(self::$localeFunctions[$functionName])) { |
3367
|
69 |
|
$brace = ($functionName != $function); |
3368
|
69 |
|
$function = self::$localeFunctions[$functionName]; |
3369
|
69 |
|
if ($brace) { |
3370
|
66 |
|
$function .= '('; |
3371
|
|
|
} |
3372
|
|
|
} |
3373
|
|
|
} |
3374
|
|
|
|
3375
|
11408 |
|
return $function; |
3376
|
|
|
} |
3377
|
|
|
|
3378
|
|
|
/** |
3379
|
|
|
* Wrap string values in quotes. |
3380
|
|
|
*/ |
3381
|
11194 |
|
public static function wrapResult(mixed $value): mixed |
3382
|
|
|
{ |
3383
|
11194 |
|
if (is_string($value)) { |
3384
|
|
|
// Error values cannot be "wrapped" |
3385
|
3880 |
|
if (preg_match('/^' . self::CALCULATION_REGEXP_ERROR . '$/i', $value, $match)) { |
3386
|
|
|
// Return Excel errors "as is" |
3387
|
1207 |
|
return $value; |
3388
|
|
|
} |
3389
|
|
|
|
3390
|
|
|
// Return strings wrapped in quotes |
3391
|
3119 |
|
return self::FORMULA_STRING_QUOTE . $value . self::FORMULA_STRING_QUOTE; |
3392
|
8842 |
|
} elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) { |
3393
|
|
|
// Convert numeric errors to NaN error |
3394
|
4 |
|
return Information\ExcelError::NAN(); |
3395
|
|
|
} |
3396
|
|
|
|
3397
|
8839 |
|
return $value; |
3398
|
|
|
} |
3399
|
|
|
|
3400
|
|
|
/** |
3401
|
|
|
* Remove quotes used as a wrapper to identify string values. |
3402
|
|
|
*/ |
3403
|
11353 |
|
public static function unwrapResult(mixed $value): mixed |
3404
|
|
|
{ |
3405
|
11353 |
|
if (is_string($value)) { |
3406
|
3546 |
|
if ((isset($value[0])) && ($value[0] == self::FORMULA_STRING_QUOTE) && (substr($value, -1) == self::FORMULA_STRING_QUOTE)) { |
3407
|
3546 |
|
return substr($value, 1, -1); |
3408
|
|
|
} |
3409
|
|
|
// Convert numeric errors to NAN error |
3410
|
10116 |
|
} elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) { |
3411
|
|
|
return Information\ExcelError::NAN(); |
3412
|
|
|
} |
3413
|
|
|
|
3414
|
10180 |
|
return $value; |
3415
|
|
|
} |
3416
|
|
|
|
3417
|
|
|
/** |
3418
|
|
|
* Calculate cell value (using formula from a cell ID) |
3419
|
|
|
* Retained for backward compatibility. |
3420
|
|
|
* |
3421
|
|
|
* @param ?Cell $cell Cell to calculate |
3422
|
|
|
*/ |
3423
|
|
|
public function calculate(?Cell $cell = null): mixed |
3424
|
|
|
{ |
3425
|
|
|
try { |
3426
|
|
|
return $this->calculateCellValue($cell); |
3427
|
|
|
} catch (\Exception $e) { |
3428
|
|
|
throw new Exception($e->getMessage()); |
3429
|
|
|
} |
3430
|
|
|
} |
3431
|
|
|
|
3432
|
|
|
/** |
3433
|
|
|
* Calculate the value of a cell formula. |
3434
|
|
|
* |
3435
|
|
|
* @param ?Cell $cell Cell to calculate |
3436
|
|
|
* @param bool $resetLog Flag indicating whether the debug log should be reset or not |
3437
|
|
|
*/ |
3438
|
7773 |
|
public function calculateCellValue(?Cell $cell = null, bool $resetLog = true): mixed |
3439
|
|
|
{ |
3440
|
7773 |
|
if ($cell === null) { |
3441
|
|
|
return null; |
3442
|
|
|
} |
3443
|
|
|
|
3444
|
7773 |
|
$returnArrayAsType = self::$returnArrayAsType; |
3445
|
7773 |
|
if ($resetLog) { |
3446
|
|
|
// Initialise the logging settings if requested |
3447
|
7761 |
|
$this->formulaError = null; |
3448
|
7761 |
|
$this->debugLog->clearLog(); |
3449
|
7761 |
|
$this->cyclicReferenceStack->clear(); |
3450
|
7761 |
|
$this->cyclicFormulaCounter = 1; |
3451
|
|
|
|
3452
|
7761 |
|
self::$returnArrayAsType = self::RETURN_ARRAY_AS_ARRAY; |
3453
|
|
|
} |
3454
|
|
|
|
3455
|
|
|
// Execute the calculation for the cell formula |
3456
|
7773 |
|
$this->cellStack[] = [ |
3457
|
7773 |
|
'sheet' => $cell->getWorksheet()->getTitle(), |
3458
|
7773 |
|
'cell' => $cell->getCoordinate(), |
3459
|
7773 |
|
]; |
3460
|
|
|
|
3461
|
7773 |
|
$cellAddressAttempted = false; |
3462
|
7773 |
|
$cellAddress = null; |
3463
|
|
|
|
3464
|
|
|
try { |
3465
|
7773 |
|
$result = self::unwrapResult($this->_calculateFormulaValue($cell->getValue(), $cell->getCoordinate(), $cell)); |
3466
|
7533 |
|
if ($this->spreadsheet === null) { |
3467
|
|
|
throw new Exception('null spreadsheet in calculateCellValue'); |
3468
|
|
|
} |
3469
|
7533 |
|
$cellAddressAttempted = true; |
3470
|
7533 |
|
$cellAddress = array_pop($this->cellStack); |
3471
|
7533 |
|
if ($cellAddress === null) { |
3472
|
|
|
throw new Exception('null cellAddress in calculateCellValue'); |
3473
|
|
|
} |
3474
|
7533 |
|
$testSheet = $this->spreadsheet->getSheetByName($cellAddress['sheet']); |
3475
|
7533 |
|
if ($testSheet === null) { |
3476
|
|
|
throw new Exception('worksheet not found in calculateCellValue'); |
3477
|
|
|
} |
3478
|
7533 |
|
$testSheet->getCell($cellAddress['cell']); |
3479
|
257 |
|
} catch (\Exception $e) { |
3480
|
257 |
|
if (!$cellAddressAttempted) { |
3481
|
257 |
|
$cellAddress = array_pop($this->cellStack); |
3482
|
|
|
} |
3483
|
257 |
|
if ($this->spreadsheet !== null && is_array($cellAddress) && array_key_exists('sheet', $cellAddress)) { |
3484
|
257 |
|
$testSheet = $this->spreadsheet->getSheetByName($cellAddress['sheet']); |
3485
|
257 |
|
if ($testSheet !== null && array_key_exists('cell', $cellAddress)) { |
3486
|
257 |
|
$testSheet->getCell($cellAddress['cell']); |
3487
|
|
|
} |
3488
|
|
|
} |
3489
|
|
|
|
3490
|
257 |
|
throw new Exception($e->getMessage(), $e->getCode(), $e); |
3491
|
|
|
} |
3492
|
|
|
|
3493
|
7533 |
|
if ((is_array($result)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) { |
3494
|
4 |
|
self::$returnArrayAsType = $returnArrayAsType; |
3495
|
4 |
|
$testResult = Functions::flattenArray($result); |
3496
|
4 |
|
if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) { |
3497
|
|
|
return Information\ExcelError::VALUE(); |
3498
|
|
|
} |
3499
|
|
|
// If there's only a single cell in the array, then we allow it |
3500
|
4 |
|
if (count($testResult) != 1) { |
3501
|
|
|
// If keys are numeric, then it's a matrix result rather than a cell range result, so we permit it |
3502
|
|
|
$r = array_keys($result); |
3503
|
|
|
$r = array_shift($r); |
3504
|
|
|
if (!is_numeric($r)) { |
3505
|
|
|
return Information\ExcelError::VALUE(); |
3506
|
|
|
} |
3507
|
|
|
if (is_array($result[$r])) { |
3508
|
|
|
$c = array_keys($result[$r]); |
3509
|
|
|
$c = array_shift($c); |
3510
|
|
|
if (!is_numeric($c)) { |
3511
|
|
|
return Information\ExcelError::VALUE(); |
3512
|
|
|
} |
3513
|
|
|
} |
3514
|
|
|
} |
3515
|
4 |
|
$result = array_shift($testResult); |
3516
|
|
|
} |
3517
|
7533 |
|
self::$returnArrayAsType = $returnArrayAsType; |
3518
|
|
|
|
3519
|
7533 |
|
if ($result === null && $cell->getWorksheet()->getSheetView()->getShowZeros()) { |
3520
|
13 |
|
return 0; |
3521
|
7533 |
|
} elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) { |
3522
|
|
|
return Information\ExcelError::NAN(); |
3523
|
|
|
} |
3524
|
|
|
|
3525
|
7533 |
|
return $result; |
3526
|
|
|
} |
3527
|
|
|
|
3528
|
|
|
/** |
3529
|
|
|
* Validate and parse a formula string. |
3530
|
|
|
* |
3531
|
|
|
* @param string $formula Formula to parse |
3532
|
|
|
*/ |
3533
|
43 |
|
public function parseFormula(string $formula): array|bool |
3534
|
|
|
{ |
3535
|
|
|
// Basic validation that this is indeed a formula |
3536
|
|
|
// We return an empty array if not |
3537
|
43 |
|
$formula = trim($formula); |
3538
|
43 |
|
if ((!isset($formula[0])) || ($formula[0] != '=')) { |
3539
|
|
|
return []; |
3540
|
|
|
} |
3541
|
43 |
|
$formula = ltrim(substr($formula, 1)); |
3542
|
43 |
|
if (!isset($formula[0])) { |
3543
|
|
|
return []; |
3544
|
|
|
} |
3545
|
|
|
|
3546
|
|
|
// Parse the formula and return the token stack |
3547
|
43 |
|
return $this->internalParseFormula($formula); |
3548
|
|
|
} |
3549
|
|
|
|
3550
|
|
|
/** |
3551
|
|
|
* Calculate the value of a formula. |
3552
|
|
|
* |
3553
|
|
|
* @param string $formula Formula to parse |
3554
|
|
|
* @param ?string $cellID Address of the cell to calculate |
3555
|
|
|
* @param ?Cell $cell Cell to calculate |
3556
|
|
|
*/ |
3557
|
174 |
|
public function calculateFormula(string $formula, ?string $cellID = null, ?Cell $cell = null): mixed |
3558
|
|
|
{ |
3559
|
|
|
// Initialise the logging settings |
3560
|
174 |
|
$this->formulaError = null; |
3561
|
174 |
|
$this->debugLog->clearLog(); |
3562
|
174 |
|
$this->cyclicReferenceStack->clear(); |
3563
|
|
|
|
3564
|
174 |
|
$resetCache = $this->getCalculationCacheEnabled(); |
3565
|
174 |
|
if ($this->spreadsheet !== null && $cellID === null && $cell === null) { |
3566
|
167 |
|
$cellID = 'A1'; |
3567
|
167 |
|
$cell = $this->spreadsheet->getActiveSheet()->getCell($cellID); |
3568
|
|
|
} else { |
3569
|
|
|
// Disable calculation cacheing because it only applies to cell calculations, not straight formulae |
3570
|
|
|
// But don't actually flush any cache |
3571
|
7 |
|
$this->calculationCacheEnabled = false; |
3572
|
|
|
} |
3573
|
|
|
|
3574
|
|
|
// Execute the calculation |
3575
|
|
|
try { |
3576
|
174 |
|
$result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $cell)); |
3577
|
1 |
|
} catch (\Exception $e) { |
3578
|
1 |
|
throw new Exception($e->getMessage()); |
3579
|
|
|
} |
3580
|
|
|
|
3581
|
174 |
|
if ($this->spreadsheet === null) { |
3582
|
|
|
// Reset calculation cacheing to its previous state |
3583
|
|
|
$this->calculationCacheEnabled = $resetCache; |
3584
|
|
|
} |
3585
|
|
|
|
3586
|
174 |
|
return $result; |
3587
|
|
|
} |
3588
|
|
|
|
3589
|
7917 |
|
public function getValueFromCache(string $cellReference, mixed &$cellValue): bool |
3590
|
|
|
{ |
3591
|
7917 |
|
$this->debugLog->writeDebugLog('Testing cache value for cell %s', $cellReference); |
3592
|
|
|
// Is calculation cacheing enabled? |
3593
|
|
|
// If so, is the required value present in calculation cache? |
3594
|
7917 |
|
if (($this->calculationCacheEnabled) && (isset($this->calculationCache[$cellReference]))) { |
3595
|
236 |
|
$this->debugLog->writeDebugLog('Retrieving value for cell %s from cache', $cellReference); |
3596
|
|
|
// Return the cached result |
3597
|
|
|
|
3598
|
236 |
|
$cellValue = $this->calculationCache[$cellReference]; |
3599
|
|
|
|
3600
|
236 |
|
return true; |
3601
|
|
|
} |
3602
|
|
|
|
3603
|
7917 |
|
return false; |
3604
|
|
|
} |
3605
|
|
|
|
3606
|
7676 |
|
public function saveValueToCache(string $cellReference, mixed $cellValue): void |
3607
|
|
|
{ |
3608
|
7676 |
|
if ($this->calculationCacheEnabled) { |
3609
|
7671 |
|
$this->calculationCache[$cellReference] = $cellValue; |
3610
|
|
|
} |
3611
|
|
|
} |
3612
|
|
|
|
3613
|
|
|
/** |
3614
|
|
|
* Parse a cell formula and calculate its value. |
3615
|
|
|
* |
3616
|
|
|
* @param string $formula The formula to parse and calculate |
3617
|
|
|
* @param ?string $cellID The ID (e.g. A3) of the cell that we are calculating |
3618
|
|
|
* @param ?Cell $cell Cell to calculate |
3619
|
|
|
* @param bool $ignoreQuotePrefix If set to true, evaluate the formyla even if the referenced cell is quote prefixed |
3620
|
|
|
*/ |
3621
|
11617 |
|
public function _calculateFormulaValue(string $formula, ?string $cellID = null, ?Cell $cell = null, bool $ignoreQuotePrefix = false): mixed |
3622
|
|
|
{ |
3623
|
11617 |
|
$cellValue = null; |
3624
|
|
|
|
3625
|
|
|
// Quote-Prefixed cell values cannot be formulae, but are treated as strings |
3626
|
11617 |
|
if ($cell !== null && $ignoreQuotePrefix === false && $cell->getStyle()->getQuotePrefix() === true) { |
3627
|
2 |
|
return self::wrapResult((string) $formula); |
3628
|
|
|
} |
3629
|
|
|
|
3630
|
11617 |
|
if (preg_match('/^=\s*cmd\s*\|/miu', $formula) !== 0) { |
3631
|
1 |
|
return self::wrapResult($formula); |
3632
|
|
|
} |
3633
|
|
|
|
3634
|
|
|
// Basic validation that this is indeed a formula |
3635
|
|
|
// We simply return the cell value if not |
3636
|
11616 |
|
$formula = trim($formula); |
3637
|
11616 |
|
if ($formula[0] != '=') { |
3638
|
1 |
|
return self::wrapResult($formula); |
3639
|
|
|
} |
3640
|
11616 |
|
$formula = ltrim(substr($formula, 1)); |
3641
|
11616 |
|
if (!isset($formula[0])) { |
3642
|
6 |
|
return self::wrapResult($formula); |
3643
|
|
|
} |
3644
|
|
|
|
3645
|
11615 |
|
$pCellParent = ($cell !== null) ? $cell->getWorksheet() : null; |
3646
|
11615 |
|
$wsTitle = ($pCellParent !== null) ? $pCellParent->getTitle() : "\x00Wrk"; |
3647
|
11615 |
|
$wsCellReference = $wsTitle . '!' . $cellID; |
3648
|
|
|
|
3649
|
11615 |
|
if (($cellID !== null) && ($this->getValueFromCache($wsCellReference, $cellValue))) { |
3650
|
232 |
|
return $cellValue; |
3651
|
|
|
} |
3652
|
11615 |
|
$this->debugLog->writeDebugLog('Evaluating formula for cell %s', $wsCellReference); |
3653
|
|
|
|
3654
|
11615 |
|
if (($wsTitle[0] !== "\x00") && ($this->cyclicReferenceStack->onStack($wsCellReference))) { |
3655
|
11 |
|
if ($this->cyclicFormulaCount <= 0) { |
3656
|
1 |
|
$this->cyclicFormulaCell = ''; |
3657
|
|
|
|
3658
|
1 |
|
return $this->raiseFormulaError('Cyclic Reference in Formula'); |
3659
|
10 |
|
} elseif ($this->cyclicFormulaCell === $wsCellReference) { |
3660
|
|
|
++$this->cyclicFormulaCounter; |
3661
|
|
|
if ($this->cyclicFormulaCounter >= $this->cyclicFormulaCount) { |
3662
|
|
|
$this->cyclicFormulaCell = ''; |
3663
|
|
|
|
3664
|
|
|
return $cellValue; |
3665
|
|
|
} |
3666
|
10 |
|
} elseif ($this->cyclicFormulaCell == '') { |
3667
|
10 |
|
if ($this->cyclicFormulaCounter >= $this->cyclicFormulaCount) { |
3668
|
10 |
|
return $cellValue; |
3669
|
|
|
} |
3670
|
|
|
$this->cyclicFormulaCell = $wsCellReference; |
3671
|
|
|
} |
3672
|
|
|
} |
3673
|
|
|
|
3674
|
11615 |
|
$this->debugLog->writeDebugLog('Formula for cell %s is %s', $wsCellReference, $formula); |
3675
|
|
|
// Parse the formula onto the token stack and calculate the value |
3676
|
11615 |
|
$this->cyclicReferenceStack->push($wsCellReference); |
3677
|
|
|
|
3678
|
11615 |
|
$cellValue = $this->processTokenStack($this->internalParseFormula($formula, $cell), $cellID, $cell); |
3679
|
11372 |
|
$this->cyclicReferenceStack->pop(); |
3680
|
|
|
|
3681
|
|
|
// Save to calculation cache |
3682
|
11372 |
|
if ($cellID !== null) { |
3683
|
7676 |
|
$this->saveValueToCache($wsCellReference, $cellValue); |
3684
|
|
|
} |
3685
|
|
|
|
3686
|
|
|
// Return the calculated value |
3687
|
11372 |
|
return $cellValue; |
3688
|
|
|
} |
3689
|
|
|
|
3690
|
|
|
/** |
3691
|
|
|
* Ensure that paired matrix operands are both matrices and of the same size. |
3692
|
|
|
* |
3693
|
|
|
* @param mixed $operand1 First matrix operand |
3694
|
|
|
* @param mixed $operand2 Second matrix operand |
3695
|
|
|
* @param int $resize Flag indicating whether the matrices should be resized to match |
3696
|
|
|
* and (if so), whether the smaller dimension should grow or the |
3697
|
|
|
* larger should shrink. |
3698
|
|
|
* 0 = no resize |
3699
|
|
|
* 1 = shrink to fit |
3700
|
|
|
* 2 = extend to fit |
3701
|
|
|
*/ |
3702
|
35 |
|
private static function checkMatrixOperands(mixed &$operand1, mixed &$operand2, int $resize = 1): array |
3703
|
|
|
{ |
3704
|
|
|
// Examine each of the two operands, and turn them into an array if they aren't one already |
3705
|
|
|
// Note that this function should only be called if one or both of the operand is already an array |
3706
|
35 |
|
if (!is_array($operand1)) { |
3707
|
12 |
|
[$matrixRows, $matrixColumns] = self::getMatrixDimensions($operand2); |
3708
|
12 |
|
$operand1 = array_fill(0, $matrixRows, array_fill(0, $matrixColumns, $operand1)); |
3709
|
12 |
|
$resize = 0; |
3710
|
26 |
|
} elseif (!is_array($operand2)) { |
3711
|
13 |
|
[$matrixRows, $matrixColumns] = self::getMatrixDimensions($operand1); |
3712
|
13 |
|
$operand2 = array_fill(0, $matrixRows, array_fill(0, $matrixColumns, $operand2)); |
3713
|
13 |
|
$resize = 0; |
3714
|
|
|
} |
3715
|
|
|
|
3716
|
35 |
|
[$matrix1Rows, $matrix1Columns] = self::getMatrixDimensions($operand1); |
3717
|
35 |
|
[$matrix2Rows, $matrix2Columns] = self::getMatrixDimensions($operand2); |
3718
|
35 |
|
if (($matrix1Rows == $matrix2Columns) && ($matrix2Rows == $matrix1Columns)) { |
3719
|
29 |
|
$resize = 1; |
3720
|
|
|
} |
3721
|
|
|
|
3722
|
35 |
|
if ($resize == 2) { |
3723
|
|
|
// Given two matrices of (potentially) unequal size, convert the smaller in each dimension to match the larger |
3724
|
3 |
|
self::resizeMatricesExtend($operand1, $operand2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns); |
3725
|
34 |
|
} elseif ($resize == 1) { |
3726
|
|
|
// Given two matrices of (potentially) unequal size, convert the larger in each dimension to match the smaller |
3727
|
29 |
|
self::resizeMatricesShrink($operand1, $operand2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns); |
3728
|
|
|
} |
3729
|
|
|
|
3730
|
35 |
|
return [$matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns]; |
3731
|
|
|
} |
3732
|
|
|
|
3733
|
|
|
/** |
3734
|
|
|
* Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0. |
3735
|
|
|
* |
3736
|
|
|
* @param array $matrix matrix operand |
3737
|
|
|
* |
3738
|
|
|
* @return int[] An array comprising the number of rows, and number of columns |
3739
|
|
|
*/ |
3740
|
69 |
|
public static function getMatrixDimensions(array &$matrix): array |
3741
|
|
|
{ |
3742
|
69 |
|
$matrixRows = count($matrix); |
3743
|
69 |
|
$matrixColumns = 0; |
3744
|
69 |
|
foreach ($matrix as $rowKey => $rowValue) { |
3745
|
67 |
|
if (!is_array($rowValue)) { |
3746
|
4 |
|
$matrix[$rowKey] = [$rowValue]; |
3747
|
4 |
|
$matrixColumns = max(1, $matrixColumns); |
3748
|
|
|
} else { |
3749
|
63 |
|
$matrix[$rowKey] = array_values($rowValue); |
3750
|
63 |
|
$matrixColumns = max(count($rowValue), $matrixColumns); |
3751
|
|
|
} |
3752
|
|
|
} |
3753
|
69 |
|
$matrix = array_values($matrix); |
3754
|
|
|
|
3755
|
69 |
|
return [$matrixRows, $matrixColumns]; |
3756
|
|
|
} |
3757
|
|
|
|
3758
|
|
|
/** |
3759
|
|
|
* Ensure that paired matrix operands are both matrices of the same size. |
3760
|
|
|
* |
3761
|
|
|
* @param array $matrix1 First matrix operand |
3762
|
|
|
* @param array $matrix2 Second matrix operand |
3763
|
|
|
* @param int $matrix1Rows Row size of first matrix operand |
3764
|
|
|
* @param int $matrix1Columns Column size of first matrix operand |
3765
|
|
|
* @param int $matrix2Rows Row size of second matrix operand |
3766
|
|
|
* @param int $matrix2Columns Column size of second matrix operand |
3767
|
|
|
*/ |
3768
|
29 |
|
private static function resizeMatricesShrink(array &$matrix1, array &$matrix2, int $matrix1Rows, int $matrix1Columns, int $matrix2Rows, int $matrix2Columns): void |
3769
|
|
|
{ |
3770
|
29 |
|
if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) { |
3771
|
|
|
if ($matrix2Rows < $matrix1Rows) { |
3772
|
|
|
for ($i = $matrix2Rows; $i < $matrix1Rows; ++$i) { |
3773
|
|
|
unset($matrix1[$i]); |
3774
|
|
|
} |
3775
|
|
|
} |
3776
|
|
|
if ($matrix2Columns < $matrix1Columns) { |
3777
|
|
|
for ($i = 0; $i < $matrix1Rows; ++$i) { |
3778
|
|
|
for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) { |
3779
|
|
|
unset($matrix1[$i][$j]); |
3780
|
|
|
} |
3781
|
|
|
} |
3782
|
|
|
} |
3783
|
|
|
} |
3784
|
|
|
|
3785
|
29 |
|
if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) { |
3786
|
|
|
if ($matrix1Rows < $matrix2Rows) { |
3787
|
|
|
for ($i = $matrix1Rows; $i < $matrix2Rows; ++$i) { |
3788
|
|
|
unset($matrix2[$i]); |
3789
|
|
|
} |
3790
|
|
|
} |
3791
|
|
|
if ($matrix1Columns < $matrix2Columns) { |
3792
|
|
|
for ($i = 0; $i < $matrix2Rows; ++$i) { |
3793
|
|
|
for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) { |
3794
|
|
|
unset($matrix2[$i][$j]); |
3795
|
|
|
} |
3796
|
|
|
} |
3797
|
|
|
} |
3798
|
|
|
} |
3799
|
|
|
} |
3800
|
|
|
|
3801
|
|
|
/** |
3802
|
|
|
* Ensure that paired matrix operands are both matrices of the same size. |
3803
|
|
|
* |
3804
|
|
|
* @param array $matrix1 First matrix operand |
3805
|
|
|
* @param array $matrix2 Second matrix operand |
3806
|
|
|
* @param int $matrix1Rows Row size of first matrix operand |
3807
|
|
|
* @param int $matrix1Columns Column size of first matrix operand |
3808
|
|
|
* @param int $matrix2Rows Row size of second matrix operand |
3809
|
|
|
* @param int $matrix2Columns Column size of second matrix operand |
3810
|
|
|
*/ |
3811
|
3 |
|
private static function resizeMatricesExtend(array &$matrix1, array &$matrix2, int $matrix1Rows, int $matrix1Columns, int $matrix2Rows, int $matrix2Columns): void |
3812
|
|
|
{ |
3813
|
3 |
|
if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) { |
3814
|
1 |
|
if ($matrix2Columns < $matrix1Columns) { |
3815
|
|
|
for ($i = 0; $i < $matrix2Rows; ++$i) { |
3816
|
|
|
$x = $matrix2[$i][$matrix2Columns - 1]; |
3817
|
|
|
for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) { |
3818
|
|
|
$matrix2[$i][$j] = $x; |
3819
|
|
|
} |
3820
|
|
|
} |
3821
|
|
|
} |
3822
|
1 |
|
if ($matrix2Rows < $matrix1Rows) { |
3823
|
1 |
|
$x = $matrix2[$matrix2Rows - 1]; |
3824
|
1 |
|
for ($i = 0; $i < $matrix1Rows; ++$i) { |
3825
|
1 |
|
$matrix2[$i] = $x; |
3826
|
|
|
} |
3827
|
|
|
} |
3828
|
|
|
} |
3829
|
|
|
|
3830
|
3 |
|
if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) { |
3831
|
|
|
if ($matrix1Columns < $matrix2Columns) { |
3832
|
|
|
for ($i = 0; $i < $matrix1Rows; ++$i) { |
3833
|
|
|
$x = $matrix1[$i][$matrix1Columns - 1]; |
3834
|
|
|
for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) { |
3835
|
|
|
$matrix1[$i][$j] = $x; |
3836
|
|
|
} |
3837
|
|
|
} |
3838
|
|
|
} |
3839
|
|
|
if ($matrix1Rows < $matrix2Rows) { |
3840
|
|
|
$x = $matrix1[$matrix1Rows - 1]; |
3841
|
|
|
for ($i = 0; $i < $matrix2Rows; ++$i) { |
3842
|
|
|
$matrix1[$i] = $x; |
3843
|
|
|
} |
3844
|
|
|
} |
3845
|
|
|
} |
3846
|
|
|
} |
3847
|
|
|
|
3848
|
|
|
/** |
3849
|
|
|
* Format details of an operand for display in the log (based on operand type). |
3850
|
|
|
* |
3851
|
|
|
* @param mixed $value First matrix operand |
3852
|
|
|
*/ |
3853
|
11360 |
|
private function showValue(mixed $value): mixed |
3854
|
|
|
{ |
3855
|
11360 |
|
if ($this->debugLog->getWriteDebugLog()) { |
3856
|
3 |
|
$testArray = Functions::flattenArray($value); |
3857
|
3 |
|
if (count($testArray) == 1) { |
3858
|
3 |
|
$value = array_pop($testArray); |
3859
|
|
|
} |
3860
|
|
|
|
3861
|
3 |
|
if (is_array($value)) { |
3862
|
2 |
|
$returnMatrix = []; |
3863
|
2 |
|
$pad = $rpad = ', '; |
3864
|
2 |
|
foreach ($value as $row) { |
3865
|
2 |
|
if (is_array($row)) { |
3866
|
2 |
|
$returnMatrix[] = implode($pad, array_map([$this, 'showValue'], $row)); |
3867
|
2 |
|
$rpad = '; '; |
3868
|
|
|
} else { |
3869
|
|
|
$returnMatrix[] = $this->showValue($row); |
3870
|
|
|
} |
3871
|
|
|
} |
3872
|
|
|
|
3873
|
2 |
|
return '{ ' . implode($rpad, $returnMatrix) . ' }'; |
3874
|
3 |
|
} elseif (is_string($value) && (trim($value, self::FORMULA_STRING_QUOTE) == $value)) { |
3875
|
2 |
|
return self::FORMULA_STRING_QUOTE . $value . self::FORMULA_STRING_QUOTE; |
3876
|
3 |
|
} elseif (is_bool($value)) { |
3877
|
|
|
return ($value) ? self::$localeBoolean['TRUE'] : self::$localeBoolean['FALSE']; |
3878
|
3 |
|
} elseif ($value === null) { |
3879
|
|
|
return self::$localeBoolean['NULL']; |
3880
|
|
|
} |
3881
|
|
|
} |
3882
|
|
|
|
3883
|
11360 |
|
return Functions::flattenSingleValue($value); |
3884
|
|
|
} |
3885
|
|
|
|
3886
|
|
|
/** |
3887
|
|
|
* Format type and details of an operand for display in the log (based on operand type). |
3888
|
|
|
* |
3889
|
|
|
* @param mixed $value First matrix operand |
3890
|
|
|
*/ |
3891
|
11374 |
|
private function showTypeDetails(mixed $value): ?string |
3892
|
|
|
{ |
3893
|
11374 |
|
if ($this->debugLog->getWriteDebugLog()) { |
3894
|
3 |
|
$testArray = Functions::flattenArray($value); |
3895
|
3 |
|
if (count($testArray) == 1) { |
3896
|
3 |
|
$value = array_pop($testArray); |
3897
|
|
|
} |
3898
|
|
|
|
3899
|
3 |
|
if ($value === null) { |
3900
|
|
|
return 'a NULL value'; |
3901
|
3 |
|
} elseif (is_float($value)) { |
3902
|
3 |
|
$typeString = 'a floating point number'; |
3903
|
3 |
|
} elseif (is_int($value)) { |
3904
|
3 |
|
$typeString = 'an integer number'; |
3905
|
2 |
|
} elseif (is_bool($value)) { |
3906
|
|
|
$typeString = 'a boolean'; |
3907
|
2 |
|
} elseif (is_array($value)) { |
3908
|
2 |
|
$typeString = 'a matrix'; |
3909
|
|
|
} else { |
3910
|
|
|
if ($value == '') { |
3911
|
|
|
return 'an empty string'; |
3912
|
|
|
} elseif ($value[0] == '#') { |
3913
|
|
|
return 'a ' . $value . ' error'; |
3914
|
|
|
} |
3915
|
|
|
$typeString = 'a string'; |
3916
|
|
|
} |
3917
|
|
|
|
3918
|
3 |
|
return $typeString . ' with a value of ' . $this->showValue($value); |
3919
|
|
|
} |
3920
|
|
|
|
3921
|
11371 |
|
return null; |
3922
|
|
|
} |
3923
|
|
|
|
3924
|
|
|
/** |
3925
|
|
|
* @return false|string False indicates an error |
3926
|
|
|
*/ |
3927
|
11658 |
|
private function convertMatrixReferences(string $formula): false|string |
3928
|
|
|
{ |
3929
|
11658 |
|
static $matrixReplaceFrom = [self::FORMULA_OPEN_MATRIX_BRACE, ';', self::FORMULA_CLOSE_MATRIX_BRACE]; |
3930
|
11658 |
|
static $matrixReplaceTo = ['MKMATRIX(MKMATRIX(', '),MKMATRIX(', '))']; |
3931
|
|
|
|
3932
|
|
|
// Convert any Excel matrix references to the MKMATRIX() function |
3933
|
11658 |
|
if (str_contains($formula, self::FORMULA_OPEN_MATRIX_BRACE)) { |
3934
|
|
|
// If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators |
3935
|
751 |
|
if (str_contains($formula, self::FORMULA_STRING_QUOTE)) { |
3936
|
|
|
// So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded |
3937
|
|
|
// the formula |
3938
|
238 |
|
$temp = explode(self::FORMULA_STRING_QUOTE, $formula); |
3939
|
|
|
// Open and Closed counts used for trapping mismatched braces in the formula |
3940
|
238 |
|
$openCount = $closeCount = 0; |
3941
|
238 |
|
$notWithinQuotes = false; |
3942
|
238 |
|
foreach ($temp as &$value) { |
3943
|
|
|
// Only count/replace in alternating array entries |
3944
|
238 |
|
$notWithinQuotes = $notWithinQuotes === false; |
3945
|
238 |
|
if ($notWithinQuotes === true) { |
3946
|
238 |
|
$openCount += substr_count($value, self::FORMULA_OPEN_MATRIX_BRACE); |
3947
|
238 |
|
$closeCount += substr_count($value, self::FORMULA_CLOSE_MATRIX_BRACE); |
3948
|
238 |
|
$value = str_replace($matrixReplaceFrom, $matrixReplaceTo, $value); |
3949
|
|
|
} |
3950
|
|
|
} |
3951
|
238 |
|
unset($value); |
3952
|
|
|
// Then rebuild the formula string |
3953
|
238 |
|
$formula = implode(self::FORMULA_STRING_QUOTE, $temp); |
3954
|
|
|
} else { |
3955
|
|
|
// If there's no quoted strings, then we do a simple count/replace |
3956
|
514 |
|
$openCount = substr_count($formula, self::FORMULA_OPEN_MATRIX_BRACE); |
3957
|
514 |
|
$closeCount = substr_count($formula, self::FORMULA_CLOSE_MATRIX_BRACE); |
3958
|
514 |
|
$formula = str_replace($matrixReplaceFrom, $matrixReplaceTo, $formula); |
3959
|
|
|
} |
3960
|
|
|
// Trap for mismatched braces and trigger an appropriate error |
3961
|
751 |
|
if ($openCount < $closeCount) { |
3962
|
|
|
if ($openCount > 0) { |
3963
|
|
|
return $this->raiseFormulaError("Formula Error: Mismatched matrix braces '}'"); |
3964
|
|
|
} |
3965
|
|
|
|
3966
|
|
|
return $this->raiseFormulaError("Formula Error: Unexpected '}' encountered"); |
3967
|
751 |
|
} elseif ($openCount > $closeCount) { |
3968
|
|
|
if ($closeCount > 0) { |
3969
|
|
|
return $this->raiseFormulaError("Formula Error: Mismatched matrix braces '{'"); |
3970
|
|
|
} |
3971
|
|
|
|
3972
|
|
|
return $this->raiseFormulaError("Formula Error: Unexpected '{' encountered"); |
3973
|
|
|
} |
3974
|
|
|
} |
3975
|
|
|
|
3976
|
11658 |
|
return $formula; |
3977
|
|
|
} |
3978
|
|
|
|
3979
|
|
|
/** |
3980
|
|
|
* Binary Operators. |
3981
|
|
|
* These operators always work on two values. |
3982
|
|
|
* Array key is the operator, the value indicates whether this is a left or right associative operator. |
3983
|
|
|
*/ |
3984
|
|
|
private static array $operatorAssociativity = [ |
3985
|
|
|
'^' => 0, // Exponentiation |
3986
|
|
|
'*' => 0, '/' => 0, // Multiplication and Division |
3987
|
|
|
'+' => 0, '-' => 0, // Addition and Subtraction |
3988
|
|
|
'&' => 0, // Concatenation |
3989
|
|
|
'∪' => 0, '∩' => 0, ':' => 0, // Union, Intersect and Range |
3990
|
|
|
'>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0, // Comparison |
3991
|
|
|
]; |
3992
|
|
|
|
3993
|
|
|
/** |
3994
|
|
|
* Comparison (Boolean) Operators. |
3995
|
|
|
* These operators work on two values, but always return a boolean result. |
3996
|
|
|
*/ |
3997
|
|
|
private static array $comparisonOperators = ['>' => true, '<' => true, '=' => true, '>=' => true, '<=' => true, '<>' => true]; |
3998
|
|
|
|
3999
|
|
|
/** |
4000
|
|
|
* Operator Precedence. |
4001
|
|
|
* This list includes all valid operators, whether binary (including boolean) or unary (such as %). |
4002
|
|
|
* Array key is the operator, the value is its precedence. |
4003
|
|
|
*/ |
4004
|
|
|
private static array $operatorPrecedence = [ |
4005
|
|
|
':' => 9, // Range |
4006
|
|
|
'∩' => 8, // Intersect |
4007
|
|
|
'∪' => 7, // Union |
4008
|
|
|
'~' => 6, // Negation |
4009
|
|
|
'%' => 5, // Percentage |
4010
|
|
|
'^' => 4, // Exponentiation |
4011
|
|
|
'*' => 3, '/' => 3, // Multiplication and Division |
4012
|
|
|
'+' => 2, '-' => 2, // Addition and Subtraction |
4013
|
|
|
'&' => 1, // Concatenation |
4014
|
|
|
'>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0, // Comparison |
4015
|
|
|
]; |
4016
|
|
|
|
4017
|
|
|
// Convert infix to postfix notation |
4018
|
|
|
|
4019
|
|
|
/** |
4020
|
|
|
* @return array<int, mixed>|false |
4021
|
|
|
*/ |
4022
|
11658 |
|
private function internalParseFormula(string $formula, ?Cell $cell = null): bool|array |
4023
|
|
|
{ |
4024
|
11658 |
|
if (($formula = $this->convertMatrixReferences(trim($formula))) === false) { |
4025
|
|
|
return false; |
4026
|
|
|
} |
4027
|
|
|
|
4028
|
|
|
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet), |
4029
|
|
|
// so we store the parent worksheet so that we can re-attach it when necessary |
4030
|
11658 |
|
$pCellParent = ($cell !== null) ? $cell->getWorksheet() : null; |
4031
|
|
|
|
4032
|
11658 |
|
$regexpMatchString = '/^((?<string>' . self::CALCULATION_REGEXP_STRING |
4033
|
11658 |
|
. ')|(?<function>' . self::CALCULATION_REGEXP_FUNCTION |
4034
|
11658 |
|
. ')|(?<cellRef>' . self::CALCULATION_REGEXP_CELLREF |
4035
|
11658 |
|
. ')|(?<colRange>' . self::CALCULATION_REGEXP_COLUMN_RANGE |
4036
|
11658 |
|
. ')|(?<rowRange>' . self::CALCULATION_REGEXP_ROW_RANGE |
4037
|
11658 |
|
. ')|(?<number>' . self::CALCULATION_REGEXP_NUMBER |
4038
|
11658 |
|
. ')|(?<openBrace>' . self::CALCULATION_REGEXP_OPENBRACE |
4039
|
11658 |
|
. ')|(?<structuredReference>' . self::CALCULATION_REGEXP_STRUCTURED_REFERENCE |
4040
|
11658 |
|
. ')|(?<definedName>' . self::CALCULATION_REGEXP_DEFINEDNAME |
4041
|
11658 |
|
. ')|(?<error>' . self::CALCULATION_REGEXP_ERROR |
4042
|
11658 |
|
. '))/sui'; |
4043
|
|
|
|
4044
|
|
|
// Start with initialisation |
4045
|
11658 |
|
$index = 0; |
4046
|
11658 |
|
$stack = new Stack($this->branchPruner); |
4047
|
11658 |
|
$output = []; |
4048
|
11658 |
|
$expectingOperator = false; // We use this test in syntax-checking the expression to determine when a |
4049
|
|
|
// - is a negation or + is a positive operator rather than an operation |
4050
|
11658 |
|
$expectingOperand = false; // We use this test in syntax-checking the expression to determine whether an operand |
4051
|
|
|
// should be null in a function call |
4052
|
|
|
|
4053
|
|
|
// The guts of the lexical parser |
4054
|
|
|
// Loop through the formula extracting each operator and operand in turn |
4055
|
11658 |
|
while (true) { |
4056
|
|
|
// Branch pruning: we adapt the output item to the context (it will |
4057
|
|
|
// be used to limit its computation) |
4058
|
11658 |
|
$this->branchPruner->initialiseForLoop(); |
4059
|
|
|
|
4060
|
11658 |
|
$opCharacter = $formula[$index]; // Get the first character of the value at the current index position |
4061
|
|
|
|
4062
|
|
|
// Check for two-character operators (e.g. >=, <=, <>) |
4063
|
11658 |
|
if ((isset(self::$comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset(self::$comparisonOperators[$formula[$index + 1]]))) { |
4064
|
75 |
|
$opCharacter .= $formula[++$index]; |
4065
|
|
|
} |
4066
|
|
|
// Find out if we're currently at the beginning of a number, variable, cell/row/column reference, |
4067
|
|
|
// function, defined name, structured reference, parenthesis, error or operand |
4068
|
11658 |
|
$isOperandOrFunction = (bool) preg_match($regexpMatchString, substr($formula, $index), $match); |
4069
|
|
|
|
4070
|
11658 |
|
$expectingOperatorCopy = $expectingOperator; |
4071
|
11658 |
|
if ($opCharacter === '-' && !$expectingOperator) { // Is it a negation instead of a minus? |
4072
|
|
|
// Put a negation on the stack |
4073
|
1069 |
|
$stack->push('Unary Operator', '~'); |
4074
|
1069 |
|
++$index; // and drop the negation symbol |
4075
|
11658 |
|
} elseif ($opCharacter === '%' && $expectingOperator) { |
4076
|
|
|
// Put a percentage on the stack |
4077
|
8 |
|
$stack->push('Unary Operator', '%'); |
4078
|
8 |
|
++$index; |
4079
|
11658 |
|
} elseif ($opCharacter === '+' && !$expectingOperator) { // Positive (unary plus rather than binary operator plus) can be discarded? |
4080
|
6 |
|
++$index; // Drop the redundant plus symbol |
4081
|
11658 |
|
} elseif ((($opCharacter === '~') || ($opCharacter === '∩') || ($opCharacter === '∪')) && (!$isOperandOrFunction)) { |
4082
|
|
|
// We have to explicitly deny a tilde, union or intersect because they are legal |
4083
|
|
|
return $this->raiseFormulaError("Formula Error: Illegal character '~'"); // on the stack but not in the input expression |
4084
|
11658 |
|
} elseif ((isset(self::CALCULATION_OPERATORS[$opCharacter]) || $isOperandOrFunction) && $expectingOperator) { // Are we putting an operator on the stack? |
4085
|
|
|
while ( |
4086
|
1517 |
|
$stack->count() > 0 |
4087
|
1517 |
|
&& ($o2 = $stack->last()) |
4088
|
1517 |
|
&& isset(self::CALCULATION_OPERATORS[$o2['value']]) |
4089
|
1517 |
|
&& @(self::$operatorAssociativity[$opCharacter] ? self::$operatorPrecedence[$opCharacter] < self::$operatorPrecedence[$o2['value']] : self::$operatorPrecedence[$opCharacter] <= self::$operatorPrecedence[$o2['value']]) |
4090
|
|
|
) { |
4091
|
63 |
|
$output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output |
4092
|
|
|
} |
4093
|
|
|
|
4094
|
|
|
// Finally put our current operator onto the stack |
4095
|
1517 |
|
$stack->push('Binary Operator', $opCharacter); |
4096
|
|
|
|
4097
|
1517 |
|
++$index; |
4098
|
1517 |
|
$expectingOperator = false; |
4099
|
11658 |
|
} elseif ($opCharacter === ')' && $expectingOperator) { // Are we expecting to close a parenthesis? |
4100
|
11377 |
|
$expectingOperand = false; |
4101
|
11377 |
|
while (($o2 = $stack->pop()) && $o2['value'] !== '(') { // Pop off the stack back to the last ( |
4102
|
1269 |
|
$output[] = $o2; |
4103
|
|
|
} |
4104
|
11377 |
|
$d = $stack->last(2); |
4105
|
|
|
|
4106
|
|
|
// Branch pruning we decrease the depth whether is it a function |
4107
|
|
|
// call or a parenthesis |
4108
|
11377 |
|
$this->branchPruner->decrementDepth(); |
4109
|
|
|
|
4110
|
11377 |
|
if (is_array($d) && preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $d['value'], $matches)) { |
4111
|
|
|
// Did this parenthesis just close a function? |
4112
|
|
|
try { |
4113
|
11373 |
|
$this->branchPruner->closingBrace($d['value']); |
4114
|
3 |
|
} catch (Exception $e) { |
4115
|
3 |
|
return $this->raiseFormulaError($e->getMessage(), $e->getCode(), $e); |
4116
|
|
|
} |
4117
|
|
|
|
4118
|
11370 |
|
$functionName = $matches[1]; // Get the function name |
4119
|
11370 |
|
$d = $stack->pop(); |
4120
|
11370 |
|
$argumentCount = $d['value'] ?? 0; // See how many arguments there were (argument count is the next value stored on the stack) |
4121
|
11370 |
|
$output[] = $d; // Dump the argument count on the output |
4122
|
11370 |
|
$output[] = $stack->pop(); // Pop the function and push onto the output |
4123
|
11370 |
|
if (isset(self::$controlFunctions[$functionName])) { |
4124
|
769 |
|
$expectedArgumentCount = self::$controlFunctions[$functionName]['argumentCount']; |
4125
|
11367 |
|
} elseif (isset(self::$phpSpreadsheetFunctions[$functionName])) { |
4126
|
11367 |
|
$expectedArgumentCount = self::$phpSpreadsheetFunctions[$functionName]['argumentCount']; |
4127
|
|
|
} else { // did we somehow push a non-function on the stack? this should never happen |
4128
|
|
|
return $this->raiseFormulaError('Formula Error: Internal error, non-function on stack'); |
4129
|
|
|
} |
4130
|
|
|
// Check the argument count |
4131
|
11370 |
|
$argumentCountError = false; |
4132
|
11370 |
|
$expectedArgumentCountString = null; |
4133
|
11370 |
|
if (is_numeric($expectedArgumentCount)) { |
4134
|
5786 |
|
if ($expectedArgumentCount < 0) { |
4135
|
36 |
|
if ($argumentCount > abs($expectedArgumentCount)) { |
4136
|
|
|
$argumentCountError = true; |
4137
|
36 |
|
$expectedArgumentCountString = 'no more than ' . abs($expectedArgumentCount); |
4138
|
|
|
} |
4139
|
|
|
} else { |
4140
|
5752 |
|
if ($argumentCount != $expectedArgumentCount) { |
4141
|
142 |
|
$argumentCountError = true; |
4142
|
5786 |
|
$expectedArgumentCountString = $expectedArgumentCount; |
4143
|
|
|
} |
4144
|
|
|
} |
4145
|
6288 |
|
} elseif ($expectedArgumentCount != '*') { |
4146
|
5814 |
|
preg_match('/(\d*)([-+,])(\d*)/', $expectedArgumentCount, $argMatch); |
4147
|
5814 |
|
switch ($argMatch[2] ?? '') { |
4148
|
5814 |
|
case '+': |
4149
|
1008 |
|
if ($argumentCount < $argMatch[1]) { |
4150
|
24 |
|
$argumentCountError = true; |
4151
|
24 |
|
$expectedArgumentCountString = $argMatch[1] . ' or more '; |
4152
|
|
|
} |
4153
|
|
|
|
4154
|
1008 |
|
break; |
4155
|
4947 |
|
case '-': |
4156
|
764 |
|
if (($argumentCount < $argMatch[1]) || ($argumentCount > $argMatch[3])) { |
4157
|
8 |
|
$argumentCountError = true; |
4158
|
8 |
|
$expectedArgumentCountString = 'between ' . $argMatch[1] . ' and ' . $argMatch[3]; |
4159
|
|
|
} |
4160
|
|
|
|
4161
|
764 |
|
break; |
4162
|
4215 |
|
case ',': |
4163
|
4215 |
|
if (($argumentCount != $argMatch[1]) && ($argumentCount != $argMatch[3])) { |
4164
|
39 |
|
$argumentCountError = true; |
4165
|
39 |
|
$expectedArgumentCountString = 'either ' . $argMatch[1] . ' or ' . $argMatch[3]; |
4166
|
|
|
} |
4167
|
|
|
|
4168
|
4215 |
|
break; |
4169
|
|
|
} |
4170
|
|
|
} |
4171
|
11370 |
|
if ($argumentCountError) { |
4172
|
213 |
|
return $this->raiseFormulaError("Formula Error: Wrong number of arguments for $functionName() function: $argumentCount given, " . $expectedArgumentCountString . ' expected'); |
4173
|
|
|
} |
4174
|
|
|
} |
4175
|
11164 |
|
++$index; |
4176
|
11658 |
|
} elseif ($opCharacter === ',') { // Is this the separator for function arguments? |
4177
|
|
|
try { |
4178
|
7722 |
|
$this->branchPruner->argumentSeparator(); |
4179
|
|
|
} catch (Exception $e) { |
4180
|
|
|
return $this->raiseFormulaError($e->getMessage(), $e->getCode(), $e); |
4181
|
|
|
} |
4182
|
|
|
|
4183
|
7722 |
|
while (($o2 = $stack->pop()) && $o2['value'] !== '(') { // Pop off the stack back to the last ( |
4184
|
1308 |
|
$output[] = $o2; // pop the argument expression stuff and push onto the output |
4185
|
|
|
} |
4186
|
|
|
// If we've a comma when we're expecting an operand, then what we actually have is a null operand; |
4187
|
|
|
// so push a null onto the stack |
4188
|
7722 |
|
if (($expectingOperand) || (!$expectingOperator)) { |
4189
|
100 |
|
$output[] = ['type' => 'Empty Argument', 'value' => self::$excelConstants['NULL'], 'reference' => 'NULL']; |
4190
|
|
|
} |
4191
|
|
|
// make sure there was a function |
4192
|
7722 |
|
$d = $stack->last(2); |
4193
|
7722 |
|
if (!preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $d['value'] ?? '', $matches)) { |
4194
|
|
|
// Can we inject a dummy function at this point so that the braces at least have some context |
4195
|
|
|
// because at least the braces are paired up (at this stage in the formula) |
4196
|
|
|
// MS Excel allows this if the content is cell references; but doesn't allow actual values, |
4197
|
|
|
// but at this point, we can't differentiate (so allow both) |
4198
|
|
|
return $this->raiseFormulaError('Formula Error: Unexpected ,'); |
4199
|
|
|
} |
4200
|
|
|
|
4201
|
|
|
/** @var array $d */ |
4202
|
7722 |
|
$d = $stack->pop(); |
4203
|
7722 |
|
++$d['value']; // increment the argument count |
4204
|
|
|
|
4205
|
7722 |
|
$stack->pushStackItem($d); |
4206
|
7722 |
|
$stack->push('Brace', '('); // put the ( back on, we'll need to pop back to it again |
4207
|
|
|
|
4208
|
7722 |
|
$expectingOperator = false; |
4209
|
7722 |
|
$expectingOperand = true; |
4210
|
7722 |
|
++$index; |
4211
|
11658 |
|
} elseif ($opCharacter === '(' && !$expectingOperator) { |
4212
|
|
|
// Branch pruning: we go deeper |
4213
|
25 |
|
$this->branchPruner->incrementDepth(); |
4214
|
25 |
|
$stack->push('Brace', '(', null); |
4215
|
25 |
|
++$index; |
4216
|
11658 |
|
} elseif ($isOperandOrFunction && !$expectingOperatorCopy) { |
4217
|
|
|
// do we now have a function/variable/number? |
4218
|
11658 |
|
$expectingOperator = true; |
4219
|
11658 |
|
$expectingOperand = false; |
4220
|
11658 |
|
$val = $match[1]; |
4221
|
11658 |
|
$length = strlen($val); |
4222
|
|
|
|
4223
|
11658 |
|
if (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $val, $matches)) { |
4224
|
11378 |
|
$val = (string) preg_replace('/\s/u', '', $val); |
4225
|
11378 |
|
if (isset(self::$phpSpreadsheetFunctions[strtoupper($matches[1])]) || isset(self::$controlFunctions[strtoupper($matches[1])])) { // it's a function |
4226
|
11376 |
|
$valToUpper = strtoupper($val); |
4227
|
|
|
} else { |
4228
|
3 |
|
$valToUpper = 'NAME.ERROR('; |
4229
|
|
|
} |
4230
|
|
|
// here $matches[1] will contain values like "IF" |
4231
|
|
|
// and $val "IF(" |
4232
|
|
|
|
4233
|
11378 |
|
$this->branchPruner->functionCall($valToUpper); |
4234
|
|
|
|
4235
|
11378 |
|
$stack->push('Function', $valToUpper); |
4236
|
|
|
// tests if the function is closed right after opening |
4237
|
11378 |
|
$ax = preg_match('/^\s*\)/u', substr($formula, $index + $length)); |
4238
|
11378 |
|
if ($ax) { |
4239
|
301 |
|
$stack->push('Operand Count for Function ' . $valToUpper . ')', 0); |
4240
|
301 |
|
$expectingOperator = true; |
4241
|
|
|
} else { |
4242
|
11202 |
|
$stack->push('Operand Count for Function ' . $valToUpper . ')', 1); |
4243
|
11202 |
|
$expectingOperator = false; |
4244
|
|
|
} |
4245
|
11378 |
|
$stack->push('Brace', '('); |
4246
|
11457 |
|
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/miu', $val, $matches)) { |
4247
|
|
|
// Watch for this case-change when modifying to allow cell references in different worksheets... |
4248
|
|
|
// Should only be applied to the actual cell column, not the worksheet name |
4249
|
|
|
// If the last entry on the stack was a : operator, then we have a cell range reference |
4250
|
6731 |
|
$testPrevOp = $stack->last(1); |
4251
|
6731 |
|
if ($testPrevOp !== null && $testPrevOp['value'] === ':') { |
4252
|
|
|
// If we have a worksheet reference, then we're playing with a 3D reference |
4253
|
1046 |
|
if ($matches[2] === '') { |
4254
|
|
|
// Otherwise, we 'inherit' the worksheet reference from the start cell reference |
4255
|
|
|
// The start of the cell range reference should be the last entry in $output |
4256
|
1043 |
|
$rangeStartCellRef = $output[count($output) - 1]['value'] ?? ''; |
4257
|
1043 |
|
if ($rangeStartCellRef === ':') { |
4258
|
|
|
// Do we have chained range operators? |
4259
|
5 |
|
$rangeStartCellRef = $output[count($output) - 2]['value'] ?? ''; |
4260
|
|
|
} |
4261
|
1043 |
|
preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/miu', $rangeStartCellRef, $rangeStartMatches); |
4262
|
1043 |
|
if (array_key_exists(2, $rangeStartMatches)) { |
4263
|
1038 |
|
if ($rangeStartMatches[2] > '') { |
4264
|
1038 |
|
$val = $rangeStartMatches[2] . '!' . $val; |
4265
|
|
|
} |
4266
|
|
|
} else { |
4267
|
1043 |
|
$val = Information\ExcelError::REF(); |
4268
|
|
|
} |
4269
|
|
|
} else { |
4270
|
3 |
|
$rangeStartCellRef = $output[count($output) - 1]['value'] ?? ''; |
4271
|
3 |
|
if ($rangeStartCellRef === ':') { |
4272
|
|
|
// Do we have chained range operators? |
4273
|
|
|
$rangeStartCellRef = $output[count($output) - 2]['value'] ?? ''; |
4274
|
|
|
} |
4275
|
3 |
|
preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/miu', $rangeStartCellRef, $rangeStartMatches); |
4276
|
3 |
|
if ($rangeStartMatches[2] !== $matches[2]) { |
4277
|
1046 |
|
return $this->raiseFormulaError('3D Range references are not yet supported'); |
4278
|
|
|
} |
4279
|
|
|
} |
4280
|
6726 |
|
} elseif (!str_contains($val, '!') && $pCellParent !== null) { |
4281
|
6567 |
|
$worksheet = $pCellParent->getTitle(); |
4282
|
6567 |
|
$val = "'{$worksheet}'!{$val}"; |
4283
|
|
|
} |
4284
|
|
|
// unescape any apostrophes or double quotes in worksheet name |
4285
|
6731 |
|
$val = str_replace(["''", '""'], ["'", '"'], $val); |
4286
|
6731 |
|
$outputItem = $stack->getStackItem('Cell Reference', $val, $val); |
4287
|
|
|
|
4288
|
6731 |
|
$output[] = $outputItem; |
4289
|
5983 |
|
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_STRUCTURED_REFERENCE . '$/miu', $val, $matches)) { |
4290
|
|
|
try { |
4291
|
26 |
|
$structuredReference = Operands\StructuredReference::fromParser($formula, $index, $matches); |
4292
|
|
|
} catch (Exception $e) { |
4293
|
|
|
return $this->raiseFormulaError($e->getMessage(), $e->getCode(), $e); |
4294
|
|
|
} |
4295
|
|
|
|
4296
|
26 |
|
$val = $structuredReference->value(); |
4297
|
26 |
|
$length = strlen($val); |
4298
|
26 |
|
$outputItem = $stack->getStackItem(Operands\StructuredReference::NAME, $structuredReference, null); |
4299
|
|
|
|
4300
|
26 |
|
$output[] = $outputItem; |
4301
|
26 |
|
$expectingOperator = true; |
4302
|
|
|
} else { |
4303
|
|
|
// it's a variable, constant, string, number or boolean |
4304
|
5963 |
|
$localeConstant = false; |
4305
|
5963 |
|
$stackItemType = 'Value'; |
4306
|
5963 |
|
$stackItemReference = null; |
4307
|
|
|
|
4308
|
|
|
// If the last entry on the stack was a : operator, then we may have a row or column range reference |
4309
|
5963 |
|
$testPrevOp = $stack->last(1); |
4310
|
5963 |
|
if ($testPrevOp !== null && $testPrevOp['value'] === ':') { |
4311
|
34 |
|
$stackItemType = 'Cell Reference'; |
4312
|
|
|
|
4313
|
|
|
if ( |
4314
|
34 |
|
!is_numeric($val) |
4315
|
34 |
|
&& ((ctype_alpha($val) === false || strlen($val) > 3)) |
4316
|
34 |
|
&& (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '$/mui', $val) !== false) |
4317
|
34 |
|
&& ($this->spreadsheet === null || $this->spreadsheet->getNamedRange($val) !== null) |
4318
|
|
|
) { |
4319
|
4 |
|
$namedRange = ($this->spreadsheet === null) ? null : $this->spreadsheet->getNamedRange($val); |
4320
|
4 |
|
if ($namedRange !== null) { |
4321
|
4 |
|
$stackItemType = 'Defined Name'; |
4322
|
4 |
|
$address = str_replace('$', '', $namedRange->getValue()); |
4323
|
4 |
|
$stackItemReference = $val; |
4324
|
4 |
|
if (str_contains($address, ':')) { |
4325
|
|
|
// We'll need to manipulate the stack for an actual named range rather than a named cell |
4326
|
3 |
|
$fromTo = explode(':', $address); |
4327
|
3 |
|
$to = array_pop($fromTo); |
4328
|
3 |
|
foreach ($fromTo as $from) { |
4329
|
3 |
|
$output[] = $stack->getStackItem($stackItemType, $from, $stackItemReference); |
4330
|
3 |
|
$output[] = $stack->getStackItem('Binary Operator', ':'); |
4331
|
|
|
} |
4332
|
3 |
|
$address = $to; |
4333
|
|
|
} |
4334
|
4 |
|
$val = $address; |
4335
|
|
|
} |
4336
|
30 |
|
} elseif ($val === Information\ExcelError::REF()) { |
4337
|
3 |
|
$stackItemReference = $val; |
4338
|
|
|
} else { |
4339
|
|
|
/** @var non-empty-string $startRowColRef */ |
4340
|
27 |
|
$startRowColRef = $output[count($output) - 1]['value'] ?? ''; |
4341
|
27 |
|
[$rangeWS1, $startRowColRef] = Worksheet::extractSheetTitle($startRowColRef, true); |
4342
|
27 |
|
$rangeSheetRef = $rangeWS1; |
4343
|
27 |
|
if ($rangeWS1 !== '') { |
4344
|
18 |
|
$rangeWS1 .= '!'; |
4345
|
|
|
} |
4346
|
27 |
|
$rangeSheetRef = trim($rangeSheetRef, "'"); |
4347
|
27 |
|
[$rangeWS2, $val] = Worksheet::extractSheetTitle($val, true); |
4348
|
27 |
|
if ($rangeWS2 !== '') { |
4349
|
|
|
$rangeWS2 .= '!'; |
4350
|
|
|
} else { |
4351
|
27 |
|
$rangeWS2 = $rangeWS1; |
4352
|
|
|
} |
4353
|
|
|
|
4354
|
27 |
|
$refSheet = $pCellParent; |
4355
|
27 |
|
if ($pCellParent !== null && $rangeSheetRef !== '' && $rangeSheetRef !== $pCellParent->getTitle()) { |
4356
|
4 |
|
$refSheet = $pCellParent->getParentOrThrow()->getSheetByName($rangeSheetRef); |
4357
|
|
|
} |
4358
|
|
|
|
4359
|
27 |
|
if (ctype_digit($val) && $val <= 1_048_576) { |
|
|
|
|
4360
|
|
|
// Row range |
4361
|
8 |
|
$stackItemType = 'Row Reference'; |
4362
|
|
|
/** @var int $valx */ |
4363
|
8 |
|
$valx = $val; |
4364
|
8 |
|
$endRowColRef = ($refSheet !== null) ? $refSheet->getHighestDataColumn($valx) : AddressRange::MAX_COLUMN; // Max 16,384 columns for Excel2007 |
4365
|
8 |
|
$val = "{$rangeWS2}{$endRowColRef}{$val}"; |
4366
|
19 |
|
} elseif (ctype_alpha($val) && strlen($val ?? '') <= 3) { |
4367
|
|
|
// Column range |
4368
|
14 |
|
$stackItemType = 'Column Reference'; |
4369
|
14 |
|
$endRowColRef = ($refSheet !== null) ? $refSheet->getHighestDataRow($val) : AddressRange::MAX_ROW; // Max 1,048,576 rows for Excel2007 |
4370
|
14 |
|
$val = "{$rangeWS2}{$val}{$endRowColRef}"; |
4371
|
|
|
} |
4372
|
34 |
|
$stackItemReference = $val; |
4373
|
|
|
} |
4374
|
5958 |
|
} elseif ($opCharacter === self::FORMULA_STRING_QUOTE) { |
4375
|
|
|
// UnEscape any quotes within the string |
4376
|
2746 |
|
$val = self::wrapResult(str_replace('""', self::FORMULA_STRING_QUOTE, self::unwrapResult($val))); |
4377
|
4373 |
|
} elseif (isset(self::$excelConstants[trim(strtoupper($val))])) { |
4378
|
530 |
|
$stackItemType = 'Constant'; |
4379
|
530 |
|
$excelConstant = trim(strtoupper($val)); |
4380
|
530 |
|
$val = self::$excelConstants[$excelConstant]; |
4381
|
530 |
|
$stackItemReference = $excelConstant; |
4382
|
4096 |
|
} elseif (($localeConstant = array_search(trim(strtoupper($val)), self::$localeBoolean)) !== false) { |
4383
|
36 |
|
$stackItemType = 'Constant'; |
4384
|
36 |
|
$val = self::$excelConstants[$localeConstant]; |
4385
|
36 |
|
$stackItemReference = $localeConstant; |
4386
|
|
|
} elseif ( |
4387
|
4077 |
|
preg_match('/^' . self::CALCULATION_REGEXP_ROW_RANGE . '/miu', substr($formula, $index), $rowRangeReference) |
4388
|
|
|
) { |
4389
|
8 |
|
$val = $rowRangeReference[1]; |
4390
|
8 |
|
$length = strlen($rowRangeReference[1]); |
4391
|
8 |
|
$stackItemType = 'Row Reference'; |
4392
|
|
|
// unescape any apostrophes or double quotes in worksheet name |
4393
|
8 |
|
$val = str_replace(["''", '""'], ["'", '"'], $val); |
4394
|
8 |
|
$column = 'A'; |
4395
|
8 |
|
if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) { |
4396
|
|
|
$column = $pCellParent->getHighestDataColumn($val); |
4397
|
|
|
} |
4398
|
8 |
|
$val = "{$rowRangeReference[2]}{$column}{$rowRangeReference[7]}"; |
4399
|
8 |
|
$stackItemReference = $val; |
4400
|
|
|
} elseif ( |
4401
|
4070 |
|
preg_match('/^' . self::CALCULATION_REGEXP_COLUMN_RANGE . '/miu', substr($formula, $index), $columnRangeReference) |
4402
|
|
|
) { |
4403
|
14 |
|
$val = $columnRangeReference[1]; |
4404
|
14 |
|
$length = strlen($val); |
4405
|
14 |
|
$stackItemType = 'Column Reference'; |
4406
|
|
|
// unescape any apostrophes or double quotes in worksheet name |
4407
|
14 |
|
$val = str_replace(["''", '""'], ["'", '"'], $val); |
4408
|
14 |
|
$row = '1'; |
4409
|
14 |
|
if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) { |
4410
|
|
|
$row = $pCellParent->getHighestDataRow($val); |
4411
|
|
|
} |
4412
|
14 |
|
$val = "{$val}{$row}"; |
4413
|
14 |
|
$stackItemReference = $val; |
4414
|
4056 |
|
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '.*/miu', $val, $match)) { |
4415
|
129 |
|
$stackItemType = 'Defined Name'; |
4416
|
129 |
|
$stackItemReference = $val; |
4417
|
3950 |
|
} elseif (is_numeric($val)) { |
4418
|
3944 |
|
if ((str_contains((string) $val, '.')) || (stripos((string) $val, 'e') !== false) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) { |
4419
|
1634 |
|
$val = (float) $val; |
4420
|
|
|
} else { |
4421
|
3194 |
|
$val = (int) $val; |
4422
|
|
|
} |
4423
|
|
|
} |
4424
|
|
|
|
4425
|
5963 |
|
$details = $stack->getStackItem($stackItemType, $val, $stackItemReference); |
4426
|
5963 |
|
if ($localeConstant) { |
4427
|
36 |
|
$details['localeValue'] = $localeConstant; |
4428
|
|
|
} |
4429
|
5963 |
|
$output[] = $details; |
4430
|
|
|
} |
4431
|
11658 |
|
$index += $length; |
4432
|
85 |
|
} elseif ($opCharacter === '$') { // absolute row or column range |
4433
|
6 |
|
++$index; |
4434
|
79 |
|
} elseif ($opCharacter === ')') { // miscellaneous error checking |
4435
|
79 |
|
if ($expectingOperand) { |
4436
|
79 |
|
$output[] = ['type' => 'Empty Argument', 'value' => self::$excelConstants['NULL'], 'reference' => 'NULL']; |
4437
|
79 |
|
$expectingOperand = false; |
4438
|
79 |
|
$expectingOperator = true; |
4439
|
|
|
} else { |
4440
|
79 |
|
return $this->raiseFormulaError("Formula Error: Unexpected ')'"); |
4441
|
|
|
} |
4442
|
|
|
} elseif (isset(self::CALCULATION_OPERATORS[$opCharacter]) && !$expectingOperator) { |
4443
|
|
|
return $this->raiseFormulaError("Formula Error: Unexpected operator '$opCharacter'"); |
4444
|
|
|
} else { // I don't even want to know what you did to get here |
4445
|
|
|
return $this->raiseFormulaError('Formula Error: An unexpected error occurred'); |
4446
|
|
|
} |
4447
|
|
|
// Test for end of formula string |
4448
|
11658 |
|
if ($index == strlen($formula)) { |
4449
|
|
|
// Did we end with an operator?. |
4450
|
|
|
// Only valid for the % unary operator |
4451
|
11444 |
|
if ((isset(self::CALCULATION_OPERATORS[$opCharacter])) && ($opCharacter != '%')) { |
4452
|
|
|
return $this->raiseFormulaError("Formula Error: Operator '$opCharacter' has no operands"); |
4453
|
|
|
} |
4454
|
|
|
|
4455
|
11444 |
|
break; |
4456
|
|
|
} |
4457
|
|
|
// Ignore white space |
4458
|
11635 |
|
while (($formula[$index] === "\n") || ($formula[$index] === "\r")) { |
4459
|
|
|
++$index; |
4460
|
|
|
} |
4461
|
|
|
|
4462
|
11635 |
|
if ($formula[$index] === ' ') { |
4463
|
1884 |
|
while ($formula[$index] === ' ') { |
4464
|
1884 |
|
++$index; |
4465
|
|
|
} |
4466
|
|
|
|
4467
|
|
|
// If we're expecting an operator, but only have a space between the previous and next operands (and both are |
4468
|
|
|
// Cell References, Defined Names or Structured References) then we have an INTERSECTION operator |
4469
|
1884 |
|
$countOutputMinus1 = count($output) - 1; |
4470
|
|
|
if ( |
4471
|
1884 |
|
($expectingOperator) |
4472
|
1884 |
|
&& array_key_exists($countOutputMinus1, $output) |
4473
|
1884 |
|
&& is_array($output[$countOutputMinus1]) |
4474
|
1884 |
|
&& array_key_exists('type', $output[$countOutputMinus1]) |
4475
|
|
|
&& ( |
4476
|
1884 |
|
(preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '.*/miu', substr($formula, $index), $match)) |
4477
|
1884 |
|
&& ($output[$countOutputMinus1]['type'] === 'Cell Reference') |
4478
|
1884 |
|
|| (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '.*/miu', substr($formula, $index), $match)) |
4479
|
1884 |
|
&& ($output[$countOutputMinus1]['type'] === 'Defined Name' || $output[$countOutputMinus1]['type'] === 'Value') |
4480
|
1884 |
|
|| (preg_match('/^' . self::CALCULATION_REGEXP_STRUCTURED_REFERENCE . '.*/miu', substr($formula, $index), $match)) |
4481
|
1884 |
|
&& ($output[$countOutputMinus1]['type'] === Operands\StructuredReference::NAME || $output[$countOutputMinus1]['type'] === 'Value') |
4482
|
|
|
) |
4483
|
|
|
) { |
4484
|
|
|
while ( |
4485
|
18 |
|
$stack->count() > 0 |
4486
|
18 |
|
&& ($o2 = $stack->last()) |
4487
|
18 |
|
&& isset(self::CALCULATION_OPERATORS[$o2['value']]) |
4488
|
18 |
|
&& @(self::$operatorAssociativity[$opCharacter] ? self::$operatorPrecedence[$opCharacter] < self::$operatorPrecedence[$o2['value']] : self::$operatorPrecedence[$opCharacter] <= self::$operatorPrecedence[$o2['value']]) |
4489
|
|
|
) { |
4490
|
12 |
|
$output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output |
4491
|
|
|
} |
4492
|
18 |
|
$stack->push('Binary Operator', '∩'); // Put an Intersect Operator on the stack |
4493
|
18 |
|
$expectingOperator = false; |
4494
|
|
|
} |
4495
|
|
|
} |
4496
|
|
|
} |
4497
|
|
|
|
4498
|
11444 |
|
while (($op = $stack->pop()) !== null) { |
4499
|
|
|
// pop everything off the stack and push onto output |
4500
|
571 |
|
if ((is_array($op) && $op['value'] == '(')) { |
4501
|
4 |
|
return $this->raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced |
4502
|
|
|
} |
4503
|
568 |
|
$output[] = $op; |
4504
|
|
|
} |
4505
|
|
|
|
4506
|
11441 |
|
return $output; |
4507
|
|
|
} |
4508
|
|
|
|
4509
|
1480 |
|
private static function dataTestReference(array &$operandData): mixed |
4510
|
|
|
{ |
4511
|
1480 |
|
$operand = $operandData['value']; |
4512
|
1480 |
|
if (($operandData['reference'] === null) && (is_array($operand))) { |
4513
|
30 |
|
$rKeys = array_keys($operand); |
4514
|
30 |
|
$rowKey = array_shift($rKeys); |
4515
|
30 |
|
if (is_array($operand[$rowKey]) === false) { |
4516
|
5 |
|
$operandData['value'] = $operand[$rowKey]; |
4517
|
|
|
|
4518
|
5 |
|
return $operand[$rowKey]; |
4519
|
|
|
} |
4520
|
|
|
|
4521
|
29 |
|
$cKeys = array_keys(array_keys($operand[$rowKey])); |
4522
|
29 |
|
$colKey = array_shift($cKeys); |
4523
|
29 |
|
if (ctype_upper("$colKey")) { |
4524
|
|
|
$operandData['reference'] = $colKey . $rowKey; |
4525
|
|
|
} |
4526
|
|
|
} |
4527
|
|
|
|
4528
|
1480 |
|
return $operand; |
4529
|
|
|
} |
4530
|
|
|
|
4531
|
|
|
/** |
4532
|
|
|
* @return array<int, mixed>|false |
4533
|
|
|
*/ |
4534
|
11399 |
|
private function processTokenStack(mixed $tokens, ?string $cellID = null, ?Cell $cell = null) |
4535
|
|
|
{ |
4536
|
11399 |
|
if ($tokens === false) { |
4537
|
2 |
|
return false; |
4538
|
|
|
} |
4539
|
|
|
|
4540
|
|
|
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent cell collection), |
4541
|
|
|
// so we store the parent cell collection so that we can re-attach it when necessary |
4542
|
11398 |
|
$pCellWorksheet = ($cell !== null) ? $cell->getWorksheet() : null; |
4543
|
11398 |
|
$pCellParent = ($cell !== null) ? $cell->getParent() : null; |
4544
|
11398 |
|
$stack = new Stack($this->branchPruner); |
4545
|
|
|
|
4546
|
|
|
// Stores branches that have been pruned |
4547
|
11398 |
|
$fakedForBranchPruning = []; |
4548
|
|
|
// help us to know when pruning ['branchTestId' => true/false] |
4549
|
11398 |
|
$branchStore = []; |
4550
|
|
|
// Loop through each token in turn |
4551
|
11398 |
|
foreach ($tokens as $tokenData) { |
4552
|
11398 |
|
$token = $tokenData['value']; |
4553
|
|
|
// Branch pruning: skip useless resolutions |
4554
|
11398 |
|
$storeKey = $tokenData['storeKey'] ?? null; |
4555
|
11398 |
|
if ($this->branchPruningEnabled && isset($tokenData['onlyIf'])) { |
4556
|
62 |
|
$onlyIfStoreKey = $tokenData['onlyIf']; |
4557
|
62 |
|
$storeValue = $branchStore[$onlyIfStoreKey] ?? null; |
4558
|
62 |
|
$storeValueAsBool = ($storeValue === null) |
4559
|
62 |
|
? true : (bool) Functions::flattenSingleValue($storeValue); |
4560
|
62 |
|
if (is_array($storeValue)) { |
4561
|
41 |
|
$wrappedItem = end($storeValue); |
4562
|
41 |
|
$storeValue = is_array($wrappedItem) ? end($wrappedItem) : $wrappedItem; |
4563
|
|
|
} |
4564
|
|
|
|
4565
|
|
|
if ( |
4566
|
62 |
|
(isset($storeValue) || $tokenData['reference'] === 'NULL') |
4567
|
62 |
|
&& (!$storeValueAsBool || Information\ErrorValue::isError($storeValue) || ($storeValue === 'Pruned branch')) |
4568
|
|
|
) { |
4569
|
|
|
// If branching value is not true, we don't need to compute |
4570
|
45 |
|
if (!isset($fakedForBranchPruning['onlyIf-' . $onlyIfStoreKey])) { |
4571
|
44 |
|
$stack->push('Value', 'Pruned branch (only if ' . $onlyIfStoreKey . ') ' . $token); |
4572
|
44 |
|
$fakedForBranchPruning['onlyIf-' . $onlyIfStoreKey] = true; |
4573
|
|
|
} |
4574
|
|
|
|
4575
|
45 |
|
if (isset($storeKey)) { |
4576
|
|
|
// We are processing an if condition |
4577
|
|
|
// We cascade the pruning to the depending branches |
4578
|
1 |
|
$branchStore[$storeKey] = 'Pruned branch'; |
4579
|
1 |
|
$fakedForBranchPruning['onlyIfNot-' . $storeKey] = true; |
4580
|
1 |
|
$fakedForBranchPruning['onlyIf-' . $storeKey] = true; |
4581
|
|
|
} |
4582
|
|
|
|
4583
|
45 |
|
continue; |
4584
|
|
|
} |
4585
|
|
|
} |
4586
|
|
|
|
4587
|
11398 |
|
if ($this->branchPruningEnabled && isset($tokenData['onlyIfNot'])) { |
4588
|
59 |
|
$onlyIfNotStoreKey = $tokenData['onlyIfNot']; |
4589
|
59 |
|
$storeValue = $branchStore[$onlyIfNotStoreKey] ?? null; |
4590
|
59 |
|
$storeValueAsBool = ($storeValue === null) |
4591
|
59 |
|
? true : (bool) Functions::flattenSingleValue($storeValue); |
4592
|
59 |
|
if (is_array($storeValue)) { |
4593
|
38 |
|
$wrappedItem = end($storeValue); |
4594
|
38 |
|
$storeValue = is_array($wrappedItem) ? end($wrappedItem) : $wrappedItem; |
4595
|
|
|
} |
4596
|
|
|
|
4597
|
|
|
if ( |
4598
|
59 |
|
(isset($storeValue) || $tokenData['reference'] === 'NULL') |
4599
|
59 |
|
&& ($storeValueAsBool || Information\ErrorValue::isError($storeValue) || ($storeValue === 'Pruned branch')) |
4600
|
|
|
) { |
4601
|
|
|
// If branching value is true, we don't need to compute |
4602
|
46 |
|
if (!isset($fakedForBranchPruning['onlyIfNot-' . $onlyIfNotStoreKey])) { |
4603
|
46 |
|
$stack->push('Value', 'Pruned branch (only if not ' . $onlyIfNotStoreKey . ') ' . $token); |
4604
|
46 |
|
$fakedForBranchPruning['onlyIfNot-' . $onlyIfNotStoreKey] = true; |
4605
|
|
|
} |
4606
|
|
|
|
4607
|
46 |
|
if (isset($storeKey)) { |
4608
|
|
|
// We are processing an if condition |
4609
|
|
|
// We cascade the pruning to the depending branches |
4610
|
6 |
|
$branchStore[$storeKey] = 'Pruned branch'; |
4611
|
6 |
|
$fakedForBranchPruning['onlyIfNot-' . $storeKey] = true; |
4612
|
6 |
|
$fakedForBranchPruning['onlyIf-' . $storeKey] = true; |
4613
|
|
|
} |
4614
|
|
|
|
4615
|
46 |
|
continue; |
4616
|
|
|
} |
4617
|
|
|
} |
4618
|
|
|
|
4619
|
11398 |
|
if ($token instanceof Operands\StructuredReference) { |
4620
|
15 |
|
if ($cell === null) { |
4621
|
|
|
return $this->raiseFormulaError('Structured References must exist in a Cell context'); |
4622
|
|
|
} |
4623
|
|
|
|
4624
|
|
|
try { |
4625
|
15 |
|
$cellRange = $token->parse($cell); |
4626
|
15 |
|
if (str_contains($cellRange, ':')) { |
4627
|
6 |
|
$this->debugLog->writeDebugLog('Evaluating Structured Reference %s as Cell Range %s', $token->value(), $cellRange); |
4628
|
6 |
|
$rangeValue = self::getInstance($cell->getWorksheet()->getParent())->_calculateFormulaValue("={$cellRange}", $cellRange, $cell); |
4629
|
6 |
|
$stack->push('Value', $rangeValue); |
4630
|
6 |
|
$this->debugLog->writeDebugLog('Evaluated Structured Reference %s as value %s', $token->value(), $this->showValue($rangeValue)); |
4631
|
|
|
} else { |
4632
|
10 |
|
$this->debugLog->writeDebugLog('Evaluating Structured Reference %s as Cell %s', $token->value(), $cellRange); |
4633
|
10 |
|
$cellValue = $cell->getWorksheet()->getCell($cellRange)->getCalculatedValue(false); |
4634
|
10 |
|
$stack->push('Cell Reference', $cellValue, $cellRange); |
4635
|
15 |
|
$this->debugLog->writeDebugLog('Evaluated Structured Reference %s as value %s', $token->value(), $this->showValue($cellValue)); |
4636
|
|
|
} |
4637
|
2 |
|
} catch (Exception $e) { |
4638
|
2 |
|
if ($e->getCode() === Exception::CALCULATION_ENGINE_PUSH_TO_STACK) { |
4639
|
2 |
|
$stack->push('Error', Information\ExcelError::REF(), null); |
4640
|
2 |
|
$this->debugLog->writeDebugLog('Evaluated Structured Reference %s as error value %s', $token->value(), Information\ExcelError::REF()); |
4641
|
|
|
} else { |
4642
|
15 |
|
return $this->raiseFormulaError($e->getMessage(), $e->getCode(), $e); |
4643
|
|
|
} |
4644
|
|
|
} |
4645
|
11397 |
|
} elseif (!is_numeric($token) && !is_object($token) && isset(self::BINARY_OPERATORS[$token])) { |
4646
|
|
|
// if the token is a binary operator, pop the top two values off the stack, do the operation, and push the result back on the stack |
4647
|
|
|
// We must have two operands, error if we don't |
4648
|
1480 |
|
if (($operand2Data = $stack->pop()) === null) { |
4649
|
|
|
return $this->raiseFormulaError('Internal error - Operand value missing from stack'); |
4650
|
|
|
} |
4651
|
1480 |
|
if (($operand1Data = $stack->pop()) === null) { |
4652
|
|
|
return $this->raiseFormulaError('Internal error - Operand value missing from stack'); |
4653
|
|
|
} |
4654
|
|
|
|
4655
|
1480 |
|
$operand1 = self::dataTestReference($operand1Data); |
4656
|
1480 |
|
$operand2 = self::dataTestReference($operand2Data); |
4657
|
|
|
|
4658
|
|
|
// Log what we're doing |
4659
|
1480 |
|
if ($token == ':') { |
4660
|
1048 |
|
$this->debugLog->writeDebugLog('Evaluating Range %s %s %s', $this->showValue($operand1Data['reference']), $token, $this->showValue($operand2Data['reference'])); |
4661
|
|
|
} else { |
4662
|
658 |
|
$this->debugLog->writeDebugLog('Evaluating %s %s %s', $this->showValue($operand1), $token, $this->showValue($operand2)); |
4663
|
|
|
} |
4664
|
|
|
|
4665
|
|
|
// Process the operation in the appropriate manner |
4666
|
|
|
switch ($token) { |
4667
|
|
|
// Comparison (Boolean) Operators |
4668
|
1480 |
|
case '>': // Greater than |
4669
|
1467 |
|
case '<': // Less than |
4670
|
1450 |
|
case '>=': // Greater than or Equal to |
4671
|
1442 |
|
case '<=': // Less than or Equal to |
4672
|
1424 |
|
case '=': // Equality |
4673
|
1286 |
|
case '<>': // Inequality |
4674
|
381 |
|
$result = $this->executeBinaryComparisonOperation($operand1, $operand2, (string) $token, $stack); |
4675
|
381 |
|
if (isset($storeKey)) { |
4676
|
49 |
|
$branchStore[$storeKey] = $result; |
4677
|
|
|
} |
4678
|
|
|
|
4679
|
381 |
|
break; |
4680
|
|
|
// Binary Operators |
4681
|
1276 |
|
case ':': // Range |
4682
|
1048 |
|
if ($operand1Data['type'] === 'Defined Name') { |
4683
|
3 |
|
if (preg_match('/$' . self::CALCULATION_REGEXP_DEFINEDNAME . '^/mui', $operand1Data['reference']) !== false && $this->spreadsheet !== null) { |
4684
|
3 |
|
$definedName = $this->spreadsheet->getNamedRange($operand1Data['reference']); |
4685
|
3 |
|
if ($definedName !== null) { |
4686
|
3 |
|
$operand1Data['reference'] = $operand1Data['value'] = str_replace('$', '', $definedName->getValue()); |
4687
|
|
|
} |
4688
|
|
|
} |
4689
|
|
|
} |
4690
|
1048 |
|
if (str_contains($operand1Data['reference'] ?? '', '!')) { |
4691
|
1042 |
|
[$sheet1, $operand1Data['reference']] = Worksheet::extractSheetTitle($operand1Data['reference'], true); |
4692
|
|
|
} else { |
4693
|
10 |
|
$sheet1 = ($pCellWorksheet !== null) ? $pCellWorksheet->getTitle() : ''; |
4694
|
|
|
} |
4695
|
1048 |
|
$sheet1 ??= ''; |
4696
|
|
|
|
4697
|
1048 |
|
[$sheet2, $operand2Data['reference']] = Worksheet::extractSheetTitle($operand2Data['reference'], true); |
4698
|
1048 |
|
if (empty($sheet2)) { |
4699
|
4 |
|
$sheet2 = $sheet1; |
4700
|
|
|
} |
4701
|
|
|
|
4702
|
1048 |
|
if (trim($sheet1, "'") === trim($sheet2, "'")) { |
4703
|
1045 |
|
if ($operand1Data['reference'] === null && $cell !== null) { |
4704
|
|
|
if (is_array($operand1Data['value'])) { |
4705
|
|
|
$operand1Data['reference'] = $cell->getCoordinate(); |
4706
|
|
|
} elseif ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) { |
4707
|
|
|
$operand1Data['reference'] = $cell->getColumn() . $operand1Data['value']; |
4708
|
|
|
} elseif (trim($operand1Data['value']) == '') { |
4709
|
|
|
$operand1Data['reference'] = $cell->getCoordinate(); |
4710
|
|
|
} else { |
4711
|
|
|
$operand1Data['reference'] = $operand1Data['value'] . $cell->getRow(); |
4712
|
|
|
} |
4713
|
|
|
} |
4714
|
1045 |
|
if ($operand2Data['reference'] === null && $cell !== null) { |
4715
|
2 |
|
if (is_array($operand2Data['value'])) { |
4716
|
1 |
|
$operand2Data['reference'] = $cell->getCoordinate(); |
4717
|
1 |
|
} elseif ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) { |
4718
|
|
|
$operand2Data['reference'] = $cell->getColumn() . $operand2Data['value']; |
4719
|
1 |
|
} elseif (trim($operand2Data['value']) == '') { |
4720
|
|
|
$operand2Data['reference'] = $cell->getCoordinate(); |
4721
|
|
|
} else { |
4722
|
1 |
|
$operand2Data['reference'] = $operand2Data['value'] . $cell->getRow(); |
4723
|
|
|
} |
4724
|
|
|
} |
4725
|
|
|
|
4726
|
1045 |
|
$oData = array_merge(explode(':', $operand1Data['reference'] ?? ''), explode(':', $operand2Data['reference'] ?? '')); |
4727
|
1045 |
|
$oCol = $oRow = []; |
4728
|
1045 |
|
$breakNeeded = false; |
4729
|
1045 |
|
foreach ($oData as $oDatum) { |
4730
|
|
|
try { |
4731
|
1045 |
|
$oCR = Coordinate::coordinateFromString($oDatum); |
4732
|
1045 |
|
$oCol[] = Coordinate::columnIndexFromString($oCR[0]) - 1; |
4733
|
1045 |
|
$oRow[] = $oCR[1]; |
4734
|
1 |
|
} catch (\Exception) { |
4735
|
1 |
|
$stack->push('Error', Information\ExcelError::REF(), null); |
4736
|
1 |
|
$breakNeeded = true; |
4737
|
|
|
|
4738
|
1 |
|
break; |
4739
|
|
|
} |
4740
|
|
|
} |
4741
|
1045 |
|
if ($breakNeeded) { |
4742
|
1 |
|
break; |
4743
|
|
|
} |
4744
|
1044 |
|
$cellRef = Coordinate::stringFromColumnIndex(min($oCol) + 1) . min($oRow) . ':' . Coordinate::stringFromColumnIndex(max($oCol) + 1) . max($oRow); |
4745
|
1044 |
|
if ($pCellParent !== null && $this->spreadsheet !== null) { |
4746
|
1044 |
|
$cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($sheet1), false); |
4747
|
|
|
} else { |
4748
|
|
|
return $this->raiseFormulaError('Unable to access Cell Reference'); |
4749
|
|
|
} |
4750
|
|
|
|
4751
|
1044 |
|
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($cellValue)); |
4752
|
1044 |
|
$stack->push('Cell Reference', $cellValue, $cellRef); |
4753
|
|
|
} else { |
4754
|
4 |
|
$this->debugLog->writeDebugLog('Evaluation Result is a #REF! Error'); |
4755
|
4 |
|
$stack->push('Error', Information\ExcelError::REF(), null); |
4756
|
|
|
} |
4757
|
|
|
|
4758
|
1047 |
|
break; |
4759
|
331 |
|
case '+': // Addition |
4760
|
260 |
|
case '-': // Subtraction |
4761
|
225 |
|
case '*': // Multiplication |
4762
|
123 |
|
case '/': // Division |
4763
|
35 |
|
case '^': // Exponential |
4764
|
307 |
|
$result = $this->executeNumericBinaryOperation($operand1, $operand2, $token, $stack); |
4765
|
307 |
|
if (isset($storeKey)) { |
4766
|
5 |
|
$branchStore[$storeKey] = $result; |
4767
|
|
|
} |
4768
|
|
|
|
4769
|
307 |
|
break; |
4770
|
32 |
|
case '&': // Concatenation |
4771
|
|
|
// If either of the operands is a matrix, we need to treat them both as matrices |
4772
|
|
|
// (converting the other operand to a matrix if need be); then perform the required |
4773
|
|
|
// matrix operation |
4774
|
18 |
|
$operand1 = self::boolToString($operand1); |
4775
|
18 |
|
$operand2 = self::boolToString($operand2); |
4776
|
18 |
|
if (is_array($operand1) || is_array($operand2)) { |
4777
|
13 |
|
if (is_string($operand1)) { |
4778
|
5 |
|
$operand1 = self::unwrapResult($operand1); |
4779
|
|
|
} |
4780
|
13 |
|
if (is_string($operand2)) { |
4781
|
3 |
|
$operand2 = self::unwrapResult($operand2); |
4782
|
|
|
} |
4783
|
|
|
// Ensure that both operands are arrays/matrices |
4784
|
13 |
|
[$rows, $columns] = self::checkMatrixOperands($operand1, $operand2, 2); |
4785
|
|
|
|
4786
|
13 |
|
for ($row = 0; $row < $rows; ++$row) { |
4787
|
13 |
|
for ($column = 0; $column < $columns; ++$column) { |
4788
|
13 |
|
$operand1[$row][$column] |
4789
|
13 |
|
= Shared\StringHelper::substring( |
4790
|
13 |
|
self::boolToString($operand1[$row][$column]) |
4791
|
13 |
|
. self::boolToString($operand2[$row][$column]), |
4792
|
13 |
|
0, |
4793
|
13 |
|
DataType::MAX_STRING_LENGTH |
4794
|
13 |
|
); |
4795
|
|
|
} |
4796
|
|
|
} |
4797
|
13 |
|
$result = $operand1; |
4798
|
|
|
} else { |
4799
|
|
|
// In theory, we should truncate here. |
4800
|
|
|
// But I can't figure out a formula |
4801
|
|
|
// using the concatenation operator |
4802
|
|
|
// with literals that fits in 32K, |
4803
|
|
|
// so I don't think we can overflow here. |
4804
|
7 |
|
$result = self::FORMULA_STRING_QUOTE . str_replace('""', self::FORMULA_STRING_QUOTE, self::unwrapResult($operand1) . self::unwrapResult($operand2)) . self::FORMULA_STRING_QUOTE; |
4805
|
|
|
} |
4806
|
18 |
|
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($result)); |
4807
|
18 |
|
$stack->push('Value', $result); |
4808
|
|
|
|
4809
|
18 |
|
if (isset($storeKey)) { |
4810
|
|
|
$branchStore[$storeKey] = $result; |
4811
|
|
|
} |
4812
|
|
|
|
4813
|
18 |
|
break; |
4814
|
15 |
|
case '∩': // Intersect |
4815
|
15 |
|
$rowIntersect = array_intersect_key($operand1, $operand2); |
4816
|
15 |
|
$cellIntersect = $oCol = $oRow = []; |
4817
|
15 |
|
foreach (array_keys($rowIntersect) as $row) { |
4818
|
15 |
|
$oRow[] = $row; |
4819
|
15 |
|
foreach ($rowIntersect[$row] as $col => $data) { |
4820
|
15 |
|
$oCol[] = Coordinate::columnIndexFromString($col) - 1; |
4821
|
15 |
|
$cellIntersect[$row] = array_intersect_key($operand1[$row], $operand2[$row]); |
4822
|
|
|
} |
4823
|
|
|
} |
4824
|
15 |
|
if (count(Functions::flattenArray($cellIntersect)) === 0) { |
4825
|
2 |
|
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($cellIntersect)); |
4826
|
2 |
|
$stack->push('Error', Information\ExcelError::null(), null); |
4827
|
|
|
} else { |
4828
|
13 |
|
$cellRef = Coordinate::stringFromColumnIndex(min($oCol) + 1) . min($oRow) . ':' |
4829
|
13 |
|
. Coordinate::stringFromColumnIndex(max($oCol) + 1) . max($oRow); |
4830
|
13 |
|
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($cellIntersect)); |
4831
|
13 |
|
$stack->push('Value', $cellIntersect, $cellRef); |
4832
|
|
|
} |
4833
|
|
|
|
4834
|
1480 |
|
break; |
4835
|
|
|
} |
4836
|
11390 |
|
} elseif (($token === '~') || ($token === '%')) { |
4837
|
|
|
// if the token is a unary operator, pop one value off the stack, do the operation, and push it back on |
4838
|
1065 |
|
if (($arg = $stack->pop()) === null) { |
4839
|
|
|
return $this->raiseFormulaError('Internal error - Operand value missing from stack'); |
4840
|
|
|
} |
4841
|
1065 |
|
$arg = $arg['value']; |
4842
|
1065 |
|
if ($token === '~') { |
4843
|
1062 |
|
$this->debugLog->writeDebugLog('Evaluating Negation of %s', $this->showValue($arg)); |
4844
|
1062 |
|
$multiplier = -1; |
4845
|
|
|
} else { |
4846
|
5 |
|
$this->debugLog->writeDebugLog('Evaluating Percentile of %s', $this->showValue($arg)); |
4847
|
5 |
|
$multiplier = 0.01; |
4848
|
|
|
} |
4849
|
1065 |
|
if (is_array($arg)) { |
4850
|
4 |
|
$operand2 = $multiplier; |
4851
|
4 |
|
$result = $arg; |
4852
|
4 |
|
[$rows, $columns] = self::checkMatrixOperands($result, $operand2, 0); |
4853
|
4 |
|
for ($row = 0; $row < $rows; ++$row) { |
4854
|
4 |
|
for ($column = 0; $column < $columns; ++$column) { |
4855
|
4 |
|
if (self::isNumericOrBool($result[$row][$column])) { |
4856
|
4 |
|
$result[$row][$column] *= $multiplier; |
4857
|
|
|
} else { |
4858
|
2 |
|
$result[$row][$column] = self::makeError($result[$row][$column]); |
4859
|
|
|
} |
4860
|
|
|
} |
4861
|
|
|
} |
4862
|
|
|
|
4863
|
4 |
|
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($result)); |
4864
|
4 |
|
$stack->push('Value', $result); |
4865
|
4 |
|
if (isset($storeKey)) { |
4866
|
4 |
|
$branchStore[$storeKey] = $result; |
4867
|
|
|
} |
4868
|
|
|
} else { |
4869
|
1065 |
|
$this->executeNumericBinaryOperation($multiplier, $arg, '*', $stack); |
4870
|
|
|
} |
4871
|
11390 |
|
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $token ?? '', $matches)) { |
4872
|
6670 |
|
$cellRef = null; |
4873
|
|
|
|
4874
|
6670 |
|
if (isset($matches[8])) { |
4875
|
|
|
if ($cell === null) { |
4876
|
|
|
// We can't access the range, so return a REF error |
4877
|
|
|
$cellValue = Information\ExcelError::REF(); |
4878
|
|
|
} else { |
4879
|
|
|
$cellRef = $matches[6] . $matches[7] . ':' . $matches[9] . $matches[10]; |
4880
|
|
|
if ($matches[2] > '') { |
4881
|
|
|
$matches[2] = trim($matches[2], "\"'"); |
4882
|
|
|
if ((str_contains($matches[2], '[')) || (str_contains($matches[2], ']'))) { |
4883
|
|
|
// It's a Reference to an external spreadsheet (not currently supported) |
4884
|
|
|
return $this->raiseFormulaError('Unable to access External Workbook'); |
4885
|
|
|
} |
4886
|
|
|
$matches[2] = trim($matches[2], "\"'"); |
4887
|
|
|
$this->debugLog->writeDebugLog('Evaluating Cell Range %s in worksheet %s', $cellRef, $matches[2]); |
4888
|
|
|
if ($pCellParent !== null && $this->spreadsheet !== null) { |
4889
|
|
|
$cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($matches[2]), false); |
4890
|
|
|
} else { |
4891
|
|
|
return $this->raiseFormulaError('Unable to access Cell Reference'); |
4892
|
|
|
} |
4893
|
|
|
$this->debugLog->writeDebugLog('Evaluation Result for cells %s in worksheet %s is %s', $cellRef, $matches[2], $this->showTypeDetails($cellValue)); |
4894
|
|
|
} else { |
4895
|
|
|
$this->debugLog->writeDebugLog('Evaluating Cell Range %s in current worksheet', $cellRef); |
4896
|
|
|
if ($pCellParent !== null) { |
4897
|
|
|
$cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false); |
4898
|
|
|
} else { |
4899
|
|
|
return $this->raiseFormulaError('Unable to access Cell Reference'); |
4900
|
|
|
} |
4901
|
|
|
$this->debugLog->writeDebugLog('Evaluation Result for cells %s is %s', $cellRef, $this->showTypeDetails($cellValue)); |
4902
|
|
|
} |
4903
|
|
|
} |
4904
|
|
|
} else { |
4905
|
6670 |
|
if ($cell === null) { |
4906
|
|
|
// We can't access the cell, so return a REF error |
4907
|
|
|
$cellValue = Information\ExcelError::REF(); |
4908
|
|
|
} else { |
4909
|
6670 |
|
$cellRef = $matches[6] . $matches[7]; |
4910
|
6670 |
|
if ($matches[2] > '') { |
4911
|
6665 |
|
$matches[2] = trim($matches[2], "\"'"); |
4912
|
6665 |
|
if ((str_contains($matches[2], '[')) || (str_contains($matches[2], ']'))) { |
4913
|
|
|
// It's a Reference to an external spreadsheet (not currently supported) |
4914
|
1 |
|
return $this->raiseFormulaError('Unable to access External Workbook'); |
4915
|
|
|
} |
4916
|
6665 |
|
$this->debugLog->writeDebugLog('Evaluating Cell %s in worksheet %s', $cellRef, $matches[2]); |
4917
|
6665 |
|
if ($pCellParent !== null && $this->spreadsheet !== null) { |
4918
|
6665 |
|
$cellSheet = $this->spreadsheet->getSheetByName($matches[2]); |
4919
|
6665 |
|
if ($cellSheet && $cellSheet->cellExists($cellRef)) { |
4920
|
6553 |
|
$cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($matches[2]), false); |
4921
|
6553 |
|
$cell->attach($pCellParent); |
4922
|
|
|
} else { |
4923
|
318 |
|
$cellRef = ($cellSheet !== null) ? "'{$matches[2]}'!{$cellRef}" : $cellRef; |
4924
|
6665 |
|
$cellValue = ($cellSheet !== null) ? null : Information\ExcelError::REF(); |
4925
|
|
|
} |
4926
|
|
|
} else { |
4927
|
|
|
return $this->raiseFormulaError('Unable to access Cell Reference'); |
4928
|
|
|
} |
4929
|
6665 |
|
$this->debugLog->writeDebugLog('Evaluation Result for cell %s in worksheet %s is %s', $cellRef, $matches[2], $this->showTypeDetails($cellValue)); |
4930
|
|
|
} else { |
4931
|
9 |
|
$this->debugLog->writeDebugLog('Evaluating Cell %s in current worksheet', $cellRef); |
4932
|
9 |
|
if ($pCellParent !== null && $pCellParent->has($cellRef)) { |
4933
|
9 |
|
$cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false); |
4934
|
9 |
|
$cell->attach($pCellParent); |
4935
|
|
|
} else { |
4936
|
2 |
|
$cellValue = null; |
4937
|
|
|
} |
4938
|
9 |
|
$this->debugLog->writeDebugLog('Evaluation Result for cell %s is %s', $cellRef, $this->showTypeDetails($cellValue)); |
4939
|
|
|
} |
4940
|
|
|
} |
4941
|
|
|
} |
4942
|
|
|
|
4943
|
6670 |
|
$stack->push('Cell Value', $cellValue, $cellRef); |
4944
|
6670 |
|
if (isset($storeKey)) { |
4945
|
6670 |
|
$branchStore[$storeKey] = $cellValue; |
4946
|
|
|
} |
4947
|
11320 |
|
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $token ?? '', $matches)) { |
4948
|
|
|
// if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on |
4949
|
11129 |
|
if ($cell !== null && $pCellParent !== null) { |
4950
|
7559 |
|
$cell->attach($pCellParent); |
4951
|
|
|
} |
4952
|
|
|
|
4953
|
11129 |
|
$functionName = $matches[1]; |
4954
|
11129 |
|
$argCount = $stack->pop(); |
4955
|
11129 |
|
$argCount = $argCount['value']; |
4956
|
11129 |
|
if ($functionName !== 'MKMATRIX') { |
4957
|
11128 |
|
$this->debugLog->writeDebugLog('Evaluating Function %s() with %s argument%s', self::localeFunc($functionName), (($argCount == 0) ? 'no' : $argCount), (($argCount == 1) ? '' : 's')); |
4958
|
|
|
} |
4959
|
11129 |
|
if ((isset(self::$phpSpreadsheetFunctions[$functionName])) || (isset(self::$controlFunctions[$functionName]))) { // function |
4960
|
11129 |
|
$passByReference = false; |
4961
|
11129 |
|
$passCellReference = false; |
4962
|
11129 |
|
$functionCall = null; |
4963
|
11129 |
|
if (isset(self::$phpSpreadsheetFunctions[$functionName])) { |
4964
|
11126 |
|
$functionCall = self::$phpSpreadsheetFunctions[$functionName]['functionCall']; |
4965
|
11126 |
|
$passByReference = isset(self::$phpSpreadsheetFunctions[$functionName]['passByReference']); |
4966
|
11126 |
|
$passCellReference = isset(self::$phpSpreadsheetFunctions[$functionName]['passCellReference']); |
4967
|
769 |
|
} elseif (isset(self::$controlFunctions[$functionName])) { |
4968
|
769 |
|
$functionCall = self::$controlFunctions[$functionName]['functionCall']; |
4969
|
769 |
|
$passByReference = isset(self::$controlFunctions[$functionName]['passByReference']); |
4970
|
769 |
|
$passCellReference = isset(self::$controlFunctions[$functionName]['passCellReference']); |
4971
|
|
|
} |
4972
|
|
|
|
4973
|
|
|
// get the arguments for this function |
4974
|
11129 |
|
$args = $argArrayVals = []; |
4975
|
11129 |
|
$emptyArguments = []; |
4976
|
11129 |
|
for ($i = 0; $i < $argCount; ++$i) { |
4977
|
11111 |
|
$arg = $stack->pop(); |
4978
|
11111 |
|
$a = $argCount - $i - 1; |
4979
|
|
|
if ( |
4980
|
11111 |
|
($passByReference) |
4981
|
11111 |
|
&& (isset(self::$phpSpreadsheetFunctions[$functionName]['passByReference'][$a])) |
4982
|
11111 |
|
&& (self::$phpSpreadsheetFunctions[$functionName]['passByReference'][$a]) |
4983
|
|
|
) { |
4984
|
44 |
|
if ($arg['reference'] === null) { |
4985
|
2 |
|
$args[] = $cellID; |
4986
|
2 |
|
if ($functionName !== 'MKMATRIX') { |
4987
|
2 |
|
$argArrayVals[] = $this->showValue($cellID); |
4988
|
|
|
} |
4989
|
|
|
} else { |
4990
|
43 |
|
$args[] = $arg['reference']; |
4991
|
43 |
|
if ($functionName !== 'MKMATRIX') { |
4992
|
44 |
|
$argArrayVals[] = $this->showValue($arg['reference']); |
4993
|
|
|
} |
4994
|
|
|
} |
4995
|
|
|
} else { |
4996
|
11078 |
|
$emptyArguments[] = ($arg['type'] === 'Empty Argument'); |
4997
|
11078 |
|
if ($arg['type'] === 'Empty Argument' && in_array($functionName, ['MIN', 'MINA', 'MAX', 'MAXA'], true)) { |
4998
|
8 |
|
$args[] = $arg['value'] = 0; |
4999
|
8 |
|
$this->debugLog->writeDebugLog('Empty Argument reevaluated as 0'); |
5000
|
|
|
} else { |
5001
|
11078 |
|
$args[] = self::unwrapResult($arg['value']); |
5002
|
|
|
} |
5003
|
11078 |
|
if ($functionName !== 'MKMATRIX') { |
5004
|
11077 |
|
$argArrayVals[] = $this->showValue($arg['value']); |
5005
|
|
|
} |
5006
|
|
|
} |
5007
|
|
|
} |
5008
|
|
|
|
5009
|
|
|
// Reverse the order of the arguments |
5010
|
11129 |
|
krsort($args); |
5011
|
11129 |
|
krsort($emptyArguments); |
5012
|
|
|
|
5013
|
11129 |
|
if ($argCount > 0 && is_array($functionCall)) { |
5014
|
11111 |
|
$args = $this->addDefaultArgumentValues($functionCall, $args, $emptyArguments); |
5015
|
|
|
} |
5016
|
|
|
|
5017
|
11129 |
|
if (($passByReference) && ($argCount == 0)) { |
5018
|
9 |
|
$args[] = $cellID; |
5019
|
9 |
|
$argArrayVals[] = $this->showValue($cellID); |
5020
|
|
|
} |
5021
|
|
|
|
5022
|
11129 |
|
if ($functionName !== 'MKMATRIX') { |
5023
|
11128 |
|
if ($this->debugLog->getWriteDebugLog()) { |
5024
|
2 |
|
krsort($argArrayVals); |
5025
|
2 |
|
$this->debugLog->writeDebugLog('Evaluating %s ( %s )', self::localeFunc($functionName), implode(self::$localeArgumentSeparator . ' ', Functions::flattenArray($argArrayVals))); |
5026
|
|
|
} |
5027
|
|
|
} |
5028
|
|
|
|
5029
|
|
|
// Process the argument with the appropriate function call |
5030
|
11129 |
|
$args = $this->addCellReference($args, $passCellReference, $functionCall, $cell); |
5031
|
|
|
|
5032
|
11129 |
|
if (!is_array($functionCall)) { |
5033
|
53 |
|
foreach ($args as &$arg) { |
5034
|
|
|
$arg = Functions::flattenSingleValue($arg); |
5035
|
|
|
} |
5036
|
53 |
|
unset($arg); |
5037
|
|
|
} |
5038
|
|
|
|
5039
|
11129 |
|
$result = call_user_func_array($functionCall, $args); |
5040
|
|
|
|
5041
|
11123 |
|
if ($functionName !== 'MKMATRIX') { |
5042
|
11120 |
|
$this->debugLog->writeDebugLog('Evaluation Result for %s() function call is %s', self::localeFunc($functionName), $this->showTypeDetails($result)); |
5043
|
|
|
} |
5044
|
11123 |
|
$stack->push('Value', self::wrapResult($result)); |
5045
|
11123 |
|
if (isset($storeKey)) { |
5046
|
11123 |
|
$branchStore[$storeKey] = $result; |
5047
|
|
|
} |
5048
|
|
|
} |
5049
|
|
|
} else { |
5050
|
|
|
// if the token is a number, boolean, string or an Excel error, push it onto the stack |
5051
|
11320 |
|
if (isset(self::$excelConstants[strtoupper($token ?? '')])) { |
5052
|
|
|
$excelConstant = strtoupper($token); |
5053
|
|
|
$stack->push('Constant Value', self::$excelConstants[$excelConstant]); |
5054
|
|
|
if (isset($storeKey)) { |
5055
|
|
|
$branchStore[$storeKey] = self::$excelConstants[$excelConstant]; |
5056
|
|
|
} |
5057
|
|
|
$this->debugLog->writeDebugLog('Evaluating Constant %s as %s', $excelConstant, $this->showTypeDetails(self::$excelConstants[$excelConstant])); |
5058
|
11320 |
|
} elseif ((is_numeric($token)) || ($token === null) || (is_bool($token)) || ($token == '') || ($token[0] == self::FORMULA_STRING_QUOTE) || ($token[0] == '#')) { |
5059
|
11275 |
|
$stack->push($tokenData['type'], $token, $tokenData['reference']); |
5060
|
11275 |
|
if (isset($storeKey)) { |
5061
|
11275 |
|
$branchStore[$storeKey] = $token; |
5062
|
|
|
} |
5063
|
128 |
|
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '$/miu', $token, $matches)) { |
5064
|
|
|
// if the token is a named range or formula, evaluate it and push the result onto the stack |
5065
|
128 |
|
$definedName = $matches[6]; |
5066
|
128 |
|
if ($cell === null || $pCellWorksheet === null) { |
5067
|
|
|
return $this->raiseFormulaError("undefined name '$token'"); |
5068
|
|
|
} |
5069
|
|
|
|
5070
|
128 |
|
$this->debugLog->writeDebugLog('Evaluating Defined Name %s', $definedName); |
5071
|
128 |
|
$namedRange = DefinedName::resolveName($definedName, $pCellWorksheet); |
5072
|
|
|
// If not Defined Name, try as Table. |
5073
|
128 |
|
if ($namedRange === null && $this->spreadsheet !== null) { |
5074
|
31 |
|
$table = $this->spreadsheet->getTableByName($definedName); |
5075
|
31 |
|
if ($table !== null) { |
5076
|
2 |
|
$tableRange = Coordinate::getRangeBoundaries($table->getRange()); |
5077
|
2 |
|
if ($table->getShowHeaderRow()) { |
5078
|
2 |
|
++$tableRange[0][1]; |
5079
|
|
|
} |
5080
|
2 |
|
if ($table->getShowTotalsRow()) { |
5081
|
|
|
--$tableRange[1][1]; |
5082
|
|
|
} |
5083
|
2 |
|
$tableRangeString |
5084
|
2 |
|
= '$' . $tableRange[0][0] |
5085
|
2 |
|
. '$' . $tableRange[0][1] |
5086
|
2 |
|
. ':' |
5087
|
2 |
|
. '$' . $tableRange[1][0] |
5088
|
2 |
|
. '$' . $tableRange[1][1]; |
5089
|
2 |
|
$namedRange = new NamedRange($definedName, $table->getWorksheet(), $tableRangeString); |
5090
|
|
|
} |
5091
|
|
|
} |
5092
|
128 |
|
if ($namedRange === null) { |
5093
|
29 |
|
return $this->raiseFormulaError("undefined name '$definedName'"); |
5094
|
|
|
} |
5095
|
|
|
|
5096
|
108 |
|
$result = $this->evaluateDefinedName($cell, $namedRange, $pCellWorksheet, $stack); |
5097
|
108 |
|
if (isset($storeKey)) { |
5098
|
108 |
|
$branchStore[$storeKey] = $result; |
5099
|
|
|
} |
5100
|
|
|
} else { |
5101
|
|
|
return $this->raiseFormulaError("undefined name '$token'"); |
5102
|
|
|
} |
5103
|
|
|
} |
5104
|
|
|
} |
5105
|
|
|
// when we're out of tokens, the stack should have a single element, the final result |
5106
|
11371 |
|
if ($stack->count() != 1) { |
5107
|
1 |
|
return $this->raiseFormulaError('internal error'); |
5108
|
|
|
} |
5109
|
11371 |
|
$output = $stack->pop(); |
5110
|
11371 |
|
$output = $output['value']; |
5111
|
|
|
|
5112
|
11371 |
|
return $output; |
5113
|
|
|
} |
5114
|
|
|
|
5115
|
1323 |
|
private function validateBinaryOperand(mixed &$operand, mixed &$stack): bool |
5116
|
|
|
{ |
5117
|
1323 |
|
if (is_array($operand)) { |
5118
|
189 |
|
if ((count($operand, COUNT_RECURSIVE) - count($operand)) == 1) { |
5119
|
|
|
do { |
5120
|
176 |
|
$operand = array_pop($operand); |
5121
|
176 |
|
} while (is_array($operand)); |
5122
|
|
|
} |
5123
|
|
|
} |
5124
|
|
|
// Numbers, matrices and booleans can pass straight through, as they're already valid |
5125
|
1323 |
|
if (is_string($operand)) { |
5126
|
|
|
// We only need special validations for the operand if it is a string |
5127
|
|
|
// Start by stripping off the quotation marks we use to identify true excel string values internally |
5128
|
11 |
|
if ($operand > '' && $operand[0] == self::FORMULA_STRING_QUOTE) { |
5129
|
3 |
|
$operand = self::unwrapResult($operand); |
5130
|
|
|
} |
5131
|
|
|
// If the string is a numeric value, we treat it as a numeric, so no further testing |
5132
|
11 |
|
if (!is_numeric($operand)) { |
5133
|
|
|
// If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations |
5134
|
10 |
|
if ($operand > '' && $operand[0] == '#') { |
5135
|
2 |
|
$stack->push('Value', $operand); |
5136
|
2 |
|
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($operand)); |
5137
|
|
|
|
5138
|
2 |
|
return false; |
5139
|
8 |
|
} elseif (Engine\FormattedNumber::convertToNumberIfFormatted($operand) === false) { |
5140
|
|
|
// If not a numeric, a fraction or a percentage, then it's a text string, and so can't be used in mathematical binary operations |
5141
|
4 |
|
$stack->push('Error', '#VALUE!'); |
5142
|
4 |
|
$this->debugLog->writeDebugLog('Evaluation Result is a %s', $this->showTypeDetails('#VALUE!')); |
5143
|
|
|
|
5144
|
4 |
|
return false; |
5145
|
|
|
} |
5146
|
|
|
} |
5147
|
|
|
} |
5148
|
|
|
|
5149
|
|
|
// return a true if the value of the operand is one that we can use in normal binary mathematical operations |
5150
|
1322 |
|
return true; |
5151
|
|
|
} |
5152
|
|
|
|
5153
|
36 |
|
private function executeArrayComparison(mixed $operand1, mixed $operand2, string $operation, Stack &$stack, bool $recursingArrays): array |
5154
|
|
|
{ |
5155
|
36 |
|
$result = []; |
5156
|
36 |
|
if (!is_array($operand2)) { |
5157
|
|
|
// Operand 1 is an array, Operand 2 is a scalar |
5158
|
34 |
|
foreach ($operand1 as $x => $operandData) { |
5159
|
34 |
|
$this->debugLog->writeDebugLog('Evaluating Comparison %s %s %s', $this->showValue($operandData), $operation, $this->showValue($operand2)); |
5160
|
34 |
|
$this->executeBinaryComparisonOperation($operandData, $operand2, $operation, $stack); |
5161
|
34 |
|
$r = $stack->pop(); |
5162
|
34 |
|
$result[$x] = $r['value']; |
5163
|
|
|
} |
5164
|
6 |
|
} elseif (!is_array($operand1)) { |
5165
|
|
|
// Operand 1 is a scalar, Operand 2 is an array |
5166
|
3 |
|
foreach ($operand2 as $x => $operandData) { |
5167
|
3 |
|
$this->debugLog->writeDebugLog('Evaluating Comparison %s %s %s', $this->showValue($operand1), $operation, $this->showValue($operandData)); |
5168
|
3 |
|
$this->executeBinaryComparisonOperation($operand1, $operandData, $operation, $stack); |
5169
|
3 |
|
$r = $stack->pop(); |
5170
|
3 |
|
$result[$x] = $r['value']; |
5171
|
|
|
} |
5172
|
|
|
} else { |
5173
|
|
|
// Operand 1 and Operand 2 are both arrays |
5174
|
5 |
|
if (!$recursingArrays) { |
5175
|
5 |
|
self::checkMatrixOperands($operand1, $operand2, 2); |
5176
|
|
|
} |
5177
|
5 |
|
foreach ($operand1 as $x => $operandData) { |
5178
|
5 |
|
$this->debugLog->writeDebugLog('Evaluating Comparison %s %s %s', $this->showValue($operandData), $operation, $this->showValue($operand2[$x])); |
5179
|
5 |
|
$this->executeBinaryComparisonOperation($operandData, $operand2[$x], $operation, $stack, true); |
5180
|
5 |
|
$r = $stack->pop(); |
5181
|
5 |
|
$result[$x] = $r['value']; |
5182
|
|
|
} |
5183
|
|
|
} |
5184
|
|
|
// Log the result details |
5185
|
36 |
|
$this->debugLog->writeDebugLog('Comparison Evaluation Result is %s', $this->showTypeDetails($result)); |
5186
|
|
|
// And push the result onto the stack |
5187
|
36 |
|
$stack->push('Array', $result); |
5188
|
|
|
|
5189
|
36 |
|
return $result; |
5190
|
|
|
} |
5191
|
|
|
|
5192
|
381 |
|
private function executeBinaryComparisonOperation(mixed $operand1, mixed $operand2, string $operation, Stack &$stack, bool $recursingArrays = false): array|bool |
5193
|
|
|
{ |
5194
|
|
|
// If we're dealing with matrix operations, we want a matrix result |
5195
|
381 |
|
if ((is_array($operand1)) || (is_array($operand2))) { |
5196
|
36 |
|
return $this->executeArrayComparison($operand1, $operand2, $operation, $stack, $recursingArrays); |
5197
|
|
|
} |
5198
|
|
|
|
5199
|
381 |
|
$result = BinaryComparison::compare($operand1, $operand2, $operation); |
5200
|
|
|
|
5201
|
|
|
// Log the result details |
5202
|
381 |
|
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($result)); |
5203
|
|
|
// And push the result onto the stack |
5204
|
381 |
|
$stack->push('Value', $result); |
5205
|
|
|
|
5206
|
381 |
|
return $result; |
5207
|
|
|
} |
5208
|
|
|
|
5209
|
1323 |
|
private function executeNumericBinaryOperation(mixed $operand1, mixed $operand2, string $operation, Stack &$stack): mixed |
5210
|
|
|
{ |
5211
|
|
|
// Validate the two operands |
5212
|
|
|
if ( |
5213
|
1323 |
|
($this->validateBinaryOperand($operand1, $stack) === false) |
5214
|
1323 |
|
|| ($this->validateBinaryOperand($operand2, $stack) === false) |
5215
|
|
|
) { |
5216
|
6 |
|
return false; |
5217
|
|
|
} |
5218
|
|
|
|
5219
|
|
|
if ( |
5220
|
1318 |
|
(Functions::getCompatibilityMode() != Functions::COMPATIBILITY_OPENOFFICE) |
5221
|
1318 |
|
&& ((is_string($operand1) && !is_numeric($operand1) && $operand1 !== '') |
5222
|
1318 |
|
|| (is_string($operand2) && !is_numeric($operand2) && $operand2 !== '')) |
5223
|
|
|
) { |
5224
|
|
|
$result = Information\ExcelError::VALUE(); |
5225
|
1318 |
|
} elseif (is_array($operand1) || is_array($operand2)) { |
5226
|
|
|
// Ensure that both operands are arrays/matrices |
5227
|
15 |
|
if (is_array($operand1)) { |
5228
|
9 |
|
foreach ($operand1 as $key => $value) { |
5229
|
9 |
|
$operand1[$key] = Functions::flattenArray($value); |
5230
|
|
|
} |
5231
|
|
|
} |
5232
|
15 |
|
if (is_array($operand2)) { |
5233
|
9 |
|
foreach ($operand2 as $key => $value) { |
5234
|
9 |
|
$operand2[$key] = Functions::flattenArray($value); |
5235
|
|
|
} |
5236
|
|
|
} |
5237
|
15 |
|
[$rows, $columns] = self::checkMatrixOperands($operand1, $operand2, 2); |
5238
|
|
|
|
5239
|
15 |
|
for ($row = 0; $row < $rows; ++$row) { |
5240
|
15 |
|
for ($column = 0; $column < $columns; ++$column) { |
5241
|
15 |
|
if ($operand1[$row][$column] === null) { |
5242
|
|
|
$operand1[$row][$column] = 0; |
5243
|
15 |
|
} elseif (!self::isNumericOrBool($operand1[$row][$column])) { |
5244
|
1 |
|
$operand1[$row][$column] = self::makeError($operand1[$row][$column]); |
5245
|
|
|
|
5246
|
1 |
|
continue; |
5247
|
|
|
} |
5248
|
15 |
|
if ($operand2[$row][$column] === null) { |
5249
|
|
|
$operand2[$row][$column] = 0; |
5250
|
15 |
|
} elseif (!self::isNumericOrBool($operand2[$row][$column])) { |
5251
|
|
|
$operand1[$row][$column] = self::makeError($operand2[$row][$column]); |
5252
|
|
|
|
5253
|
|
|
continue; |
5254
|
|
|
} |
5255
|
|
|
switch ($operation) { |
5256
|
15 |
|
case '+': |
5257
|
2 |
|
$operand1[$row][$column] += $operand2[$row][$column]; |
5258
|
|
|
|
5259
|
2 |
|
break; |
5260
|
13 |
|
case '-': |
5261
|
3 |
|
$operand1[$row][$column] -= $operand2[$row][$column]; |
5262
|
|
|
|
5263
|
3 |
|
break; |
5264
|
11 |
|
case '*': |
5265
|
4 |
|
$operand1[$row][$column] *= $operand2[$row][$column]; |
5266
|
|
|
|
5267
|
4 |
|
break; |
5268
|
7 |
|
case '/': |
5269
|
5 |
|
if ($operand2[$row][$column] == 0) { |
5270
|
3 |
|
$operand1[$row][$column] = Information\ExcelError::DIV0(); |
5271
|
|
|
} else { |
5272
|
4 |
|
$operand1[$row][$column] /= $operand2[$row][$column]; |
5273
|
|
|
} |
5274
|
|
|
|
5275
|
5 |
|
break; |
5276
|
2 |
|
case '^': |
5277
|
2 |
|
$operand1[$row][$column] = $operand1[$row][$column] ** $operand2[$row][$column]; |
5278
|
|
|
|
5279
|
2 |
|
break; |
5280
|
|
|
|
5281
|
|
|
default: |
5282
|
|
|
throw new Exception('Unsupported numeric binary operation'); |
5283
|
|
|
} |
5284
|
|
|
} |
5285
|
|
|
} |
5286
|
15 |
|
$result = $operand1; |
5287
|
|
|
} else { |
5288
|
|
|
// If we're dealing with non-matrix operations, execute the necessary operation |
5289
|
|
|
switch ($operation) { |
5290
|
|
|
// Addition |
5291
|
1306 |
|
case '+': |
5292
|
142 |
|
$result = $operand1 + $operand2; |
5293
|
|
|
|
5294
|
142 |
|
break; |
5295
|
|
|
// Subtraction |
5296
|
1240 |
|
case '-': |
5297
|
45 |
|
$result = $operand1 - $operand2; |
5298
|
|
|
|
5299
|
45 |
|
break; |
5300
|
|
|
// Multiplication |
5301
|
1210 |
|
case '*': |
5302
|
1154 |
|
$result = $operand1 * $operand2; |
5303
|
|
|
|
5304
|
1154 |
|
break; |
5305
|
|
|
// Division |
5306
|
87 |
|
case '/': |
5307
|
86 |
|
if ($operand2 == 0) { |
5308
|
|
|
// Trap for Divide by Zero error |
5309
|
38 |
|
$stack->push('Error', Information\ExcelError::DIV0()); |
5310
|
38 |
|
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails(Information\ExcelError::DIV0())); |
5311
|
|
|
|
5312
|
38 |
|
return false; |
5313
|
|
|
} |
5314
|
58 |
|
$result = $operand1 / $operand2; |
5315
|
|
|
|
5316
|
58 |
|
break; |
5317
|
|
|
// Power |
5318
|
2 |
|
case '^': |
5319
|
2 |
|
$result = $operand1 ** $operand2; |
5320
|
|
|
|
5321
|
2 |
|
break; |
5322
|
|
|
|
5323
|
|
|
default: |
5324
|
|
|
throw new Exception('Unsupported numeric binary operation'); |
5325
|
|
|
} |
5326
|
|
|
} |
5327
|
|
|
|
5328
|
|
|
// Log the result details |
5329
|
1294 |
|
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($result)); |
5330
|
|
|
// And push the result onto the stack |
5331
|
1294 |
|
$stack->push('Value', $result); |
5332
|
|
|
|
5333
|
1294 |
|
return $result; |
5334
|
|
|
} |
5335
|
|
|
|
5336
|
|
|
/** |
5337
|
|
|
* Trigger an error, but nicely, if need be. |
5338
|
|
|
* |
5339
|
|
|
* @return false |
5340
|
|
|
*/ |
5341
|
252 |
|
protected function raiseFormulaError(string $errorMessage, int $code = 0, ?Throwable $exception = null): bool |
5342
|
|
|
{ |
5343
|
252 |
|
$this->formulaError = $errorMessage; |
5344
|
252 |
|
$this->cyclicReferenceStack->clear(); |
5345
|
252 |
|
$suppress = $this->suppressFormulaErrors ?? $this->suppressFormulaErrorsNew; |
5346
|
252 |
|
if (!$suppress) { |
5347
|
250 |
|
throw new Exception($errorMessage, $code, $exception); |
5348
|
|
|
} |
5349
|
|
|
|
5350
|
2 |
|
return false; |
5351
|
|
|
} |
5352
|
|
|
|
5353
|
|
|
/** |
5354
|
|
|
* Extract range values. |
5355
|
|
|
* |
5356
|
|
|
* @param string $range String based range representation |
5357
|
|
|
* @param ?Worksheet $worksheet Worksheet |
5358
|
|
|
* @param bool $resetLog Flag indicating whether calculation log should be reset or not |
5359
|
|
|
* |
5360
|
|
|
* @return array Array of values in range if range contains more than one element. Otherwise, a single value is returned. |
5361
|
|
|
*/ |
5362
|
6633 |
|
public function extractCellRange(string &$range = 'A1', ?Worksheet $worksheet = null, bool $resetLog = true): array |
5363
|
|
|
{ |
5364
|
|
|
// Return value |
5365
|
6633 |
|
$returnValue = []; |
5366
|
|
|
|
5367
|
6633 |
|
if ($worksheet !== null) { |
5368
|
6633 |
|
$worksheetName = $worksheet->getTitle(); |
5369
|
|
|
|
5370
|
6633 |
|
if (str_contains($range, '!')) { |
5371
|
10 |
|
[$worksheetName, $range] = Worksheet::extractSheetTitle($range, true); |
5372
|
10 |
|
$worksheet = ($this->spreadsheet === null) ? null : $this->spreadsheet->getSheetByName($worksheetName); |
5373
|
|
|
} |
5374
|
|
|
|
5375
|
|
|
// Extract range |
5376
|
6633 |
|
$aReferences = Coordinate::extractAllCellReferencesInRange($range); |
5377
|
6633 |
|
$range = "'" . $worksheetName . "'" . '!' . $range; |
5378
|
6633 |
|
$currentCol = ''; |
5379
|
6633 |
|
$currentRow = 0; |
5380
|
6633 |
|
if (!isset($aReferences[1])) { |
5381
|
|
|
// Single cell in range |
5382
|
6601 |
|
sscanf($aReferences[0], '%[A-Z]%d', $currentCol, $currentRow); |
5383
|
6601 |
|
if ($worksheet !== null && $worksheet->cellExists($aReferences[0])) { |
5384
|
6599 |
|
$returnValue[$currentRow][$currentCol] = $worksheet->getCell($aReferences[0])->getCalculatedValue($resetLog); |
5385
|
|
|
} else { |
5386
|
6601 |
|
$returnValue[$currentRow][$currentCol] = null; |
5387
|
|
|
} |
5388
|
|
|
} else { |
5389
|
|
|
// Extract cell data for all cells in the range |
5390
|
1047 |
|
foreach ($aReferences as $reference) { |
5391
|
|
|
// Extract range |
5392
|
1047 |
|
sscanf($reference, '%[A-Z]%d', $currentCol, $currentRow); |
5393
|
1047 |
|
if ($worksheet !== null && $worksheet->cellExists($reference)) { |
5394
|
1014 |
|
$returnValue[$currentRow][$currentCol] = $worksheet->getCell($reference)->getCalculatedValue($resetLog); |
5395
|
|
|
} else { |
5396
|
157 |
|
$returnValue[$currentRow][$currentCol] = null; |
5397
|
|
|
} |
5398
|
|
|
} |
5399
|
|
|
} |
5400
|
|
|
} |
5401
|
|
|
|
5402
|
6633 |
|
return $returnValue; |
5403
|
|
|
} |
5404
|
|
|
|
5405
|
|
|
/** |
5406
|
|
|
* Extract range values. |
5407
|
|
|
* |
5408
|
|
|
* @param string $range String based range representation |
5409
|
|
|
* @param null|Worksheet $worksheet Worksheet |
5410
|
|
|
* @param bool $resetLog Flag indicating whether calculation log should be reset or not |
5411
|
|
|
* |
5412
|
|
|
* @return array|string Array of values in range if range contains more than one element. Otherwise, a single value is returned. |
5413
|
|
|
*/ |
5414
|
|
|
public function extractNamedRange(string &$range = 'A1', ?Worksheet $worksheet = null, bool $resetLog = true): string|array |
5415
|
|
|
{ |
5416
|
|
|
// Return value |
5417
|
|
|
$returnValue = []; |
5418
|
|
|
|
5419
|
|
|
if ($worksheet !== null) { |
5420
|
|
|
if (str_contains($range, '!')) { |
5421
|
|
|
[$worksheetName, $range] = Worksheet::extractSheetTitle($range, true); |
5422
|
|
|
$worksheet = ($this->spreadsheet === null) ? null : $this->spreadsheet->getSheetByName($worksheetName); |
5423
|
|
|
} |
5424
|
|
|
|
5425
|
|
|
// Named range? |
5426
|
|
|
$namedRange = ($worksheet === null) ? null : DefinedName::resolveName($range, $worksheet); |
5427
|
|
|
if ($namedRange === null) { |
5428
|
|
|
return Information\ExcelError::REF(); |
5429
|
|
|
} |
5430
|
|
|
|
5431
|
|
|
$worksheet = $namedRange->getWorksheet(); |
5432
|
|
|
$range = $namedRange->getValue(); |
5433
|
|
|
$splitRange = Coordinate::splitRange($range); |
5434
|
|
|
// Convert row and column references |
5435
|
|
|
if ($worksheet !== null && ctype_alpha($splitRange[0][0])) { |
5436
|
|
|
$range = $splitRange[0][0] . '1:' . $splitRange[0][1] . $worksheet->getHighestRow(); |
5437
|
|
|
} elseif ($worksheet !== null && ctype_digit($splitRange[0][0])) { |
5438
|
|
|
$range = 'A' . $splitRange[0][0] . ':' . $worksheet->getHighestColumn() . $splitRange[0][1]; |
5439
|
|
|
} |
5440
|
|
|
|
5441
|
|
|
// Extract range |
5442
|
|
|
$aReferences = Coordinate::extractAllCellReferencesInRange($range); |
5443
|
|
|
if (!isset($aReferences[1])) { |
5444
|
|
|
// Single cell (or single column or row) in range |
5445
|
|
|
[$currentCol, $currentRow] = Coordinate::coordinateFromString($aReferences[0]); |
5446
|
|
|
if ($worksheet !== null && $worksheet->cellExists($aReferences[0])) { |
5447
|
|
|
$returnValue[$currentRow][$currentCol] = $worksheet->getCell($aReferences[0])->getCalculatedValue($resetLog); |
5448
|
|
|
} else { |
5449
|
|
|
$returnValue[$currentRow][$currentCol] = null; |
5450
|
|
|
} |
5451
|
|
|
} else { |
5452
|
|
|
// Extract cell data for all cells in the range |
5453
|
|
|
foreach ($aReferences as $reference) { |
5454
|
|
|
// Extract range |
5455
|
|
|
[$currentCol, $currentRow] = Coordinate::coordinateFromString($reference); |
5456
|
|
|
if ($worksheet !== null && $worksheet->cellExists($reference)) { |
5457
|
|
|
$returnValue[$currentRow][$currentCol] = $worksheet->getCell($reference)->getCalculatedValue($resetLog); |
5458
|
|
|
} else { |
5459
|
|
|
$returnValue[$currentRow][$currentCol] = null; |
5460
|
|
|
} |
5461
|
|
|
} |
5462
|
|
|
} |
5463
|
|
|
} |
5464
|
|
|
|
5465
|
|
|
return $returnValue; |
5466
|
|
|
} |
5467
|
|
|
|
5468
|
|
|
/** |
5469
|
|
|
* Is a specific function implemented? |
5470
|
|
|
* |
5471
|
|
|
* @param string $function Function Name |
5472
|
|
|
*/ |
5473
|
3 |
|
public function isImplemented(string $function): bool |
5474
|
|
|
{ |
5475
|
3 |
|
$function = strtoupper($function); |
5476
|
3 |
|
$notImplemented = !isset(self::$phpSpreadsheetFunctions[$function]) || (is_array(self::$phpSpreadsheetFunctions[$function]['functionCall']) && self::$phpSpreadsheetFunctions[$function]['functionCall'][1] === 'DUMMY'); |
5477
|
|
|
|
5478
|
3 |
|
return !$notImplemented; |
5479
|
|
|
} |
5480
|
|
|
|
5481
|
|
|
/** |
5482
|
|
|
* Get a list of all implemented functions as an array of function objects. |
5483
|
|
|
*/ |
5484
|
2 |
|
public static function getFunctions(): array |
5485
|
|
|
{ |
5486
|
2 |
|
return self::$phpSpreadsheetFunctions; |
5487
|
|
|
} |
5488
|
|
|
|
5489
|
|
|
/** |
5490
|
|
|
* Get a list of implemented Excel function names. |
5491
|
|
|
*/ |
5492
|
2 |
|
public function getImplementedFunctionNames(): array |
5493
|
|
|
{ |
5494
|
2 |
|
$returnValue = []; |
5495
|
2 |
|
foreach (self::$phpSpreadsheetFunctions as $functionName => $function) { |
5496
|
2 |
|
if ($this->isImplemented($functionName)) { |
5497
|
2 |
|
$returnValue[] = $functionName; |
5498
|
|
|
} |
5499
|
|
|
} |
5500
|
|
|
|
5501
|
2 |
|
return $returnValue; |
5502
|
|
|
} |
5503
|
|
|
|
5504
|
11111 |
|
private function addDefaultArgumentValues(array $functionCall, array $args, array $emptyArguments): array |
5505
|
|
|
{ |
5506
|
11111 |
|
$reflector = new ReflectionMethod($functionCall[0], $functionCall[1]); |
5507
|
11111 |
|
$methodArguments = $reflector->getParameters(); |
5508
|
|
|
|
5509
|
11111 |
|
if (count($methodArguments) > 0) { |
5510
|
|
|
// Apply any defaults for empty argument values |
5511
|
11104 |
|
foreach ($emptyArguments as $argumentId => $isArgumentEmpty) { |
5512
|
11071 |
|
if ($isArgumentEmpty === true) { |
5513
|
139 |
|
$reflectedArgumentId = count($args) - (int) $argumentId - 1; |
5514
|
|
|
if ( |
5515
|
139 |
|
!array_key_exists($reflectedArgumentId, $methodArguments) |
5516
|
139 |
|
|| $methodArguments[$reflectedArgumentId]->isVariadic() |
5517
|
|
|
) { |
5518
|
17 |
|
break; |
5519
|
|
|
} |
5520
|
|
|
|
5521
|
122 |
|
$args[$argumentId] = $this->getArgumentDefaultValue($methodArguments[$reflectedArgumentId]); |
5522
|
|
|
} |
5523
|
|
|
} |
5524
|
|
|
} |
5525
|
|
|
|
5526
|
11111 |
|
return $args; |
5527
|
|
|
} |
5528
|
|
|
|
5529
|
122 |
|
private function getArgumentDefaultValue(ReflectionParameter $methodArgument): mixed |
5530
|
|
|
{ |
5531
|
122 |
|
$defaultValue = null; |
5532
|
|
|
|
5533
|
122 |
|
if ($methodArgument->isDefaultValueAvailable()) { |
5534
|
57 |
|
$defaultValue = $methodArgument->getDefaultValue(); |
5535
|
57 |
|
if ($methodArgument->isDefaultValueConstant()) { |
5536
|
2 |
|
$constantName = $methodArgument->getDefaultValueConstantName() ?? ''; |
5537
|
|
|
// read constant value |
5538
|
2 |
|
if (str_contains($constantName, '::')) { |
5539
|
2 |
|
[$className, $constantName] = explode('::', $constantName); |
5540
|
2 |
|
$constantReflector = new ReflectionClassConstant($className, $constantName); |
5541
|
|
|
|
5542
|
2 |
|
return $constantReflector->getValue(); |
5543
|
|
|
} |
5544
|
|
|
|
5545
|
|
|
return constant($constantName); |
5546
|
|
|
} |
5547
|
|
|
} |
5548
|
|
|
|
5549
|
121 |
|
return $defaultValue; |
5550
|
|
|
} |
5551
|
|
|
|
5552
|
|
|
/** |
5553
|
|
|
* Add cell reference if needed while making sure that it is the last argument. |
5554
|
|
|
*/ |
5555
|
11129 |
|
private function addCellReference(array $args, bool $passCellReference, array|string $functionCall, ?Cell $cell = null): array |
5556
|
|
|
{ |
5557
|
11129 |
|
if ($passCellReference) { |
5558
|
197 |
|
if (is_array($functionCall)) { |
5559
|
197 |
|
$className = $functionCall[0]; |
5560
|
197 |
|
$methodName = $functionCall[1]; |
5561
|
|
|
|
5562
|
197 |
|
$reflectionMethod = new ReflectionMethod($className, $methodName); |
5563
|
197 |
|
$argumentCount = count($reflectionMethod->getParameters()); |
5564
|
197 |
|
while (count($args) < $argumentCount - 1) { |
5565
|
50 |
|
$args[] = null; |
5566
|
|
|
} |
5567
|
|
|
} |
5568
|
|
|
|
5569
|
197 |
|
$args[] = $cell; |
5570
|
|
|
} |
5571
|
|
|
|
5572
|
11129 |
|
return $args; |
5573
|
|
|
} |
5574
|
|
|
|
5575
|
108 |
|
private function evaluateDefinedName(Cell $cell, DefinedName $namedRange, Worksheet $cellWorksheet, Stack $stack): mixed |
5576
|
|
|
{ |
5577
|
108 |
|
$definedNameScope = $namedRange->getScope(); |
5578
|
108 |
|
if ($definedNameScope !== null && $definedNameScope !== $cellWorksheet) { |
5579
|
|
|
// The defined name isn't in our current scope, so #REF |
5580
|
|
|
$result = Information\ExcelError::REF(); |
5581
|
|
|
$stack->push('Error', $result, $namedRange->getName()); |
5582
|
|
|
|
5583
|
|
|
return $result; |
5584
|
|
|
} |
5585
|
|
|
|
5586
|
108 |
|
$definedNameValue = $namedRange->getValue(); |
5587
|
108 |
|
$definedNameType = $namedRange->isFormula() ? 'Formula' : 'Range'; |
5588
|
108 |
|
$definedNameWorksheet = $namedRange->getWorksheet(); |
5589
|
|
|
|
5590
|
108 |
|
if ($definedNameValue[0] !== '=') { |
5591
|
87 |
|
$definedNameValue = '=' . $definedNameValue; |
5592
|
|
|
} |
5593
|
|
|
|
5594
|
108 |
|
$this->debugLog->writeDebugLog('Defined Name is a %s with a value of %s', $definedNameType, $definedNameValue); |
5595
|
|
|
|
5596
|
108 |
|
$originalCoordinate = $cell->getCoordinate(); |
5597
|
108 |
|
$recursiveCalculationCell = ($definedNameType !== 'Formula' && $definedNameWorksheet !== null && $definedNameWorksheet !== $cellWorksheet) |
5598
|
13 |
|
? $definedNameWorksheet->getCell('A1') |
5599
|
103 |
|
: $cell; |
5600
|
108 |
|
$recursiveCalculationCellAddress = $recursiveCalculationCell->getCoordinate(); |
5601
|
|
|
|
5602
|
|
|
// Adjust relative references in ranges and formulae so that we execute the calculation for the correct rows and columns |
5603
|
108 |
|
$definedNameValue = self::$referenceHelper->updateFormulaReferencesAnyWorksheet( |
5604
|
108 |
|
$definedNameValue, |
5605
|
108 |
|
Coordinate::columnIndexFromString($cell->getColumn()) - 1, |
5606
|
108 |
|
$cell->getRow() - 1 |
5607
|
108 |
|
); |
5608
|
|
|
|
5609
|
108 |
|
$this->debugLog->writeDebugLog('Value adjusted for relative references is %s', $definedNameValue); |
5610
|
|
|
|
5611
|
108 |
|
$recursiveCalculator = new self($this->spreadsheet); |
5612
|
108 |
|
$recursiveCalculator->getDebugLog()->setWriteDebugLog($this->getDebugLog()->getWriteDebugLog()); |
5613
|
108 |
|
$recursiveCalculator->getDebugLog()->setEchoDebugLog($this->getDebugLog()->getEchoDebugLog()); |
5614
|
108 |
|
$result = $recursiveCalculator->_calculateFormulaValue($definedNameValue, $recursiveCalculationCellAddress, $recursiveCalculationCell, true); |
5615
|
108 |
|
$cellWorksheet->getCell($originalCoordinate); |
5616
|
|
|
|
5617
|
108 |
|
if ($this->getDebugLog()->getWriteDebugLog()) { |
5618
|
|
|
$this->debugLog->mergeDebugLog(array_slice($recursiveCalculator->getDebugLog()->getLog(), 3)); |
5619
|
|
|
$this->debugLog->writeDebugLog('Evaluation Result for Named %s %s is %s', $definedNameType, $namedRange->getName(), $this->showTypeDetails($result)); |
5620
|
|
|
} |
5621
|
|
|
|
5622
|
108 |
|
$stack->push('Defined Name', $result, $namedRange->getName()); |
5623
|
|
|
|
5624
|
108 |
|
return $result; |
5625
|
|
|
} |
5626
|
|
|
|
5627
|
2 |
|
public function setSuppressFormulaErrors(bool $suppressFormulaErrors): void |
5628
|
|
|
{ |
5629
|
2 |
|
$this->suppressFormulaErrorsNew = $suppressFormulaErrors; |
5630
|
|
|
} |
5631
|
|
|
|
5632
|
4 |
|
public function getSuppressFormulaErrors(): bool |
5633
|
|
|
{ |
5634
|
4 |
|
return $this->suppressFormulaErrorsNew; |
5635
|
|
|
} |
5636
|
|
|
|
5637
|
18 |
|
private static function boolToString(mixed $operand1): mixed |
5638
|
|
|
{ |
5639
|
18 |
|
if (is_bool($operand1)) { |
5640
|
1 |
|
$operand1 = ($operand1) ? self::$localeBoolean['TRUE'] : self::$localeBoolean['FALSE']; |
5641
|
18 |
|
} elseif ($operand1 === null) { |
5642
|
|
|
$operand1 = ''; |
5643
|
|
|
} |
5644
|
|
|
|
5645
|
18 |
|
return $operand1; |
5646
|
|
|
} |
5647
|
|
|
|
5648
|
19 |
|
private static function isNumericOrBool(mixed $operand): bool |
5649
|
|
|
{ |
5650
|
19 |
|
return is_numeric($operand) || is_bool($operand); |
5651
|
|
|
} |
5652
|
|
|
|
5653
|
3 |
|
private static function makeError(mixed $operand = ''): string |
5654
|
|
|
{ |
5655
|
3 |
|
return Information\ErrorValue::isError($operand) ? $operand : Information\ExcelError::VALUE(); |
5656
|
|
|
} |
5657
|
|
|
} |
5658
|
|
|
|