@syncfusion/ej2-calculate 35.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +263 -0
- package/README.md +132 -0
- package/base.d.ts +4 -0
- package/base.js +4 -0
- package/common.d.ts +4 -0
- package/common.js +4 -0
- package/dist/ej2-calculate.umd.min.js +11 -0
- package/dist/ej2-calculate.umd.min.js.map +1 -0
- package/dist/es6/ej2-calculate.es2015.js +24801 -0
- package/dist/es6/ej2-calculate.es2015.js.map +1 -0
- package/dist/es6/ej2-calculate.es5.js +27229 -0
- package/dist/es6/ej2-calculate.es5.js.map +1 -0
- package/dist/global/ej2-calculate.min.js +11 -0
- package/dist/global/ej2-calculate.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/formulas.d.ts +4 -0
- package/formulas.js +4 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -0
- package/src/base/calculate-model.d.ts +4 -0
- package/src/base/calculate-model.js +0 -0
- package/src/base/calculate.d.ts +1105 -0
- package/src/base/calculate.js +4720 -0
- package/src/base/index.d.ts +8 -0
- package/src/base/index.js +7 -0
- package/src/base/parser.d.ts +208 -0
- package/src/base/parser.js +1512 -0
- package/src/common/address.d.ts +59 -0
- package/src/common/address.js +96 -0
- package/src/common/cell-ref.d.ts +32 -0
- package/src/common/cell-ref.js +112 -0
- package/src/common/common.d.ts +44 -0
- package/src/common/common.js +134 -0
- package/src/common/enum.d.ts +94 -0
- package/src/common/enum.js +97 -0
- package/src/common/index.d.ts +9 -0
- package/src/common/index.js +8 -0
- package/src/common/interface.d.ts +122 -0
- package/src/common/interface.js +0 -0
- package/src/common/l10n.d.ts +24 -0
- package/src/common/l10n.js +54 -0
- package/src/common/number-date.d.ts +26 -0
- package/src/common/number-date.js +38 -0
- package/src/common/sheet-info.d.ts +10 -0
- package/src/common/sheet-info.js +17 -0
- package/src/common/sort.d.ts +17 -0
- package/src/common/sort.js +44 -0
- package/src/formulas/array.d.ts +47 -0
- package/src/formulas/array.js +718 -0
- package/src/formulas/basic.d.ts +47 -0
- package/src/formulas/basic.js +181 -0
- package/src/formulas/complex-numbers.d.ts +207 -0
- package/src/formulas/complex-numbers.js +549 -0
- package/src/formulas/database.d.ts +152 -0
- package/src/formulas/database.js +579 -0
- package/src/formulas/date-time-extra.d.ts +97 -0
- package/src/formulas/date-time-extra.js +415 -0
- package/src/formulas/date-time-intl.d.ts +57 -0
- package/src/formulas/date-time-intl.js +309 -0
- package/src/formulas/date-time.d.ts +164 -0
- package/src/formulas/date-time.js +1021 -0
- package/src/formulas/engineering-base.d.ts +150 -0
- package/src/formulas/engineering-base.js +404 -0
- package/src/formulas/engineering-bessel.d.ts +65 -0
- package/src/formulas/engineering-bessel.js +167 -0
- package/src/formulas/engineering-convert.d.ts +35 -0
- package/src/formulas/engineering-convert.js +120 -0
- package/src/formulas/engineering-misc.d.ts +64 -0
- package/src/formulas/engineering-misc.js +168 -0
- package/src/formulas/financial-amortization-ecma.d.ts +87 -0
- package/src/formulas/financial-amortization-ecma.js +288 -0
- package/src/formulas/financial-annuity.d.ts +104 -0
- package/src/formulas/financial-annuity.js +419 -0
- package/src/formulas/financial-bond-helpers.d.ts +106 -0
- package/src/formulas/financial-bond-helpers.js +190 -0
- package/src/formulas/financial-cashflow.d.ts +47 -0
- package/src/formulas/financial-cashflow.js +203 -0
- package/src/formulas/financial-coupons.d.ts +227 -0
- package/src/formulas/financial-coupons.js +810 -0
- package/src/formulas/financial-depreciation.d.ts +64 -0
- package/src/formulas/financial-depreciation.js +247 -0
- package/src/formulas/financial-rates.d.ts +54 -0
- package/src/formulas/financial-rates.js +140 -0
- package/src/formulas/financial-securities.d.ts +126 -0
- package/src/formulas/financial-securities.js +488 -0
- package/src/formulas/formula-math-helpers.d.ts +212 -0
- package/src/formulas/formula-math-helpers.js +599 -0
- package/src/formulas/formula-module-base.d.ts +54 -0
- package/src/formulas/formula-module-base.js +125 -0
- package/src/formulas/formula-owner.d.ts +17 -0
- package/src/formulas/formula-owner.js +0 -0
- package/src/formulas/index.d.ts +68 -0
- package/src/formulas/index.js +67 -0
- package/src/formulas/information-advanced.d.ts +44 -0
- package/src/formulas/information-advanced.js +157 -0
- package/src/formulas/information-ecma.d.ts +33 -0
- package/src/formulas/information-ecma.js +88 -0
- package/src/formulas/information-extra.d.ts +146 -0
- package/src/formulas/information-extra.js +351 -0
- package/src/formulas/information.d.ts +34 -0
- package/src/formulas/information.js +78 -0
- package/src/formulas/logical-extra.d.ts +75 -0
- package/src/formulas/logical-extra.js +217 -0
- package/src/formulas/logical.d.ts +83 -0
- package/src/formulas/logical.js +296 -0
- package/src/formulas/lookup-array.d.ts +98 -0
- package/src/formulas/lookup-array.js +364 -0
- package/src/formulas/lookup-ref-extra.d.ts +64 -0
- package/src/formulas/lookup-ref-extra.js +180 -0
- package/src/formulas/lookup-ref.d.ts +84 -0
- package/src/formulas/lookup-ref.js +263 -0
- package/src/formulas/lookup.d.ts +114 -0
- package/src/formulas/lookup.js +881 -0
- package/src/formulas/math-aggregate.d.ts +74 -0
- package/src/formulas/math-aggregate.js +376 -0
- package/src/formulas/math-ceiling-ecma.d.ts +42 -0
- package/src/formulas/math-ceiling-ecma.js +123 -0
- package/src/formulas/math-combinatorics.d.ts +75 -0
- package/src/formulas/math-combinatorics.js +290 -0
- package/src/formulas/math-misc.d.ts +164 -0
- package/src/formulas/math-misc.js +889 -0
- package/src/formulas/math-number.d.ts +76 -0
- package/src/formulas/math-number.js +261 -0
- package/src/formulas/math-rounding.d.ts +115 -0
- package/src/formulas/math-rounding.js +728 -0
- package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
- package/src/formulas/math-trig-hyperbolic.js +113 -0
- package/src/formulas/math-trig.d.ts +165 -0
- package/src/formulas/math-trig.js +334 -0
- package/src/formulas/matrix-base.d.ts +13 -0
- package/src/formulas/matrix-base.js +169 -0
- package/src/formulas/matrix.d.ts +64 -0
- package/src/formulas/matrix.js +161 -0
- package/src/formulas/regression-ecma.d.ts +66 -0
- package/src/formulas/regression-ecma.js +234 -0
- package/src/formulas/statistical-advanced.d.ts +125 -0
- package/src/formulas/statistical-advanced.js +756 -0
- package/src/formulas/statistical-correlation.d.ts +75 -0
- package/src/formulas/statistical-correlation.js +198 -0
- package/src/formulas/statistical-dispersion.d.ts +108 -0
- package/src/formulas/statistical-dispersion.js +337 -0
- package/src/formulas/statistical-distribution-extended.d.ts +176 -0
- package/src/formulas/statistical-distribution-extended.js +668 -0
- package/src/formulas/statistical-distribution.d.ts +104 -0
- package/src/formulas/statistical-distribution.js +368 -0
- package/src/formulas/statistical-ecma.d.ts +95 -0
- package/src/formulas/statistical-ecma.js +392 -0
- package/src/formulas/statistical-extended.d.ts +136 -0
- package/src/formulas/statistical-extended.js +340 -0
- package/src/formulas/statistical-ifs.d.ts +46 -0
- package/src/formulas/statistical-ifs.js +180 -0
- package/src/formulas/statistical-moments.d.ts +84 -0
- package/src/formulas/statistical-moments.js +269 -0
- package/src/formulas/statistical-percentile.d.ts +56 -0
- package/src/formulas/statistical-percentile.js +195 -0
- package/src/formulas/statistical-sample-base.d.ts +14 -0
- package/src/formulas/statistical-sample-base.js +124 -0
- package/src/formulas/statistical.d.ts +135 -0
- package/src/formulas/statistical.js +542 -0
- package/src/formulas/text-advanced.d.ts +64 -0
- package/src/formulas/text-advanced.js +222 -0
- package/src/formulas/text-ecma.d.ts +54 -0
- package/src/formulas/text-ecma.js +106 -0
- package/src/formulas/text-extra.d.ts +216 -0
- package/src/formulas/text-extra.js +657 -0
- package/src/formulas/text.d.ts +125 -0
- package/src/formulas/text.js +628 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +14 -0
- package/tslint.json +111 -0
|
@@ -0,0 +1,718 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { FormulasErrorsStrings, CommonErrors } from '../common/index';
|
|
15
|
+
import { getAlphalabel } from '../base/index';
|
|
16
|
+
import { isNullOrUndefined } from '@syncfusion/ej2-base';
|
|
17
|
+
import { isNumber } from '../common/number-date';
|
|
18
|
+
import { sortCollection } from '../common/sort';
|
|
19
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
20
|
+
/**
|
|
21
|
+
* Array formula helpers for dynamic spill-style range operations.
|
|
22
|
+
*
|
|
23
|
+
* Registered functions: UNIQUE, SORT.
|
|
24
|
+
*
|
|
25
|
+
* @hidden
|
|
26
|
+
*/
|
|
27
|
+
var ArrayFormulas = /** @class */ (function (_super) {
|
|
28
|
+
__extends(ArrayFormulas, _super);
|
|
29
|
+
/**
|
|
30
|
+
* @hidden
|
|
31
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
32
|
+
*/
|
|
33
|
+
function ArrayFormulas(owner) {
|
|
34
|
+
var _this = _super.call(this, owner) || this;
|
|
35
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
36
|
+
_this.formulas = [
|
|
37
|
+
{ formulaName: 'UNIQUE', category: 'Lookup & Reference', description: 'Returns a unique values from a range or array.' },
|
|
38
|
+
{ formulaName: 'SORT', category: 'Lookup & Reference', description: 'Sorts a range of an array.' }
|
|
39
|
+
];
|
|
40
|
+
return _this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns a unique values from a range or array.
|
|
44
|
+
*
|
|
45
|
+
* Excel: `UNIQUE(...)`.
|
|
46
|
+
*
|
|
47
|
+
* @hidden
|
|
48
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
49
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* engine.computeFormula('=UNIQUE(1)');
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
ArrayFormulas.prototype.ComputeUNIQUE = function () {
|
|
57
|
+
var _this = this;
|
|
58
|
+
var args = [];
|
|
59
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
60
|
+
args[_i] = arguments[_i];
|
|
61
|
+
}
|
|
62
|
+
var result;
|
|
63
|
+
var isComputeExp;
|
|
64
|
+
var errCollection = this.parent.getErrorStrings();
|
|
65
|
+
if (args[args.length - 1] === 'isComputeExp') {
|
|
66
|
+
isComputeExp = true;
|
|
67
|
+
args.pop();
|
|
68
|
+
}
|
|
69
|
+
if (isNullOrUndefined(args) || (args[0] === '' && args.length === 1)) {
|
|
70
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
|
|
71
|
+
}
|
|
72
|
+
else if (args.length > 3) {
|
|
73
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
74
|
+
}
|
|
75
|
+
var processArgs = function (actualValue) {
|
|
76
|
+
if (isNullOrUndefined(actualValue)) {
|
|
77
|
+
return _this.parent.falseValue;
|
|
78
|
+
}
|
|
79
|
+
var value = _this.parent.getValueFromArg(actualValue);
|
|
80
|
+
if (errCollection.indexOf(value) > -1) {
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
if (Number(value) === 0) {
|
|
84
|
+
return _this.parent.falseValue;
|
|
85
|
+
}
|
|
86
|
+
else if (Number(value) < 0 || Number(value) > 0) {
|
|
87
|
+
return _this.parent.trueValue;
|
|
88
|
+
}
|
|
89
|
+
if (!_this.parent.isCellReference(actualValue)) {
|
|
90
|
+
value = _this.parent.removeTics(value);
|
|
91
|
+
}
|
|
92
|
+
if (value.toUpperCase() === _this.parent.trueValue || value.toUpperCase() === _this.parent.falseValue) {
|
|
93
|
+
return value.toUpperCase();
|
|
94
|
+
}
|
|
95
|
+
else if (value.indexOf(_this.parent.tic) > -1 || actualValue.indexOf(_this.parent.tic) > -1) {
|
|
96
|
+
return errCollection[CommonErrors.Value];
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return errCollection[CommonErrors.Name];
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var byColumn = processArgs(args[1]);
|
|
103
|
+
if (errCollection.indexOf(byColumn) > -1) {
|
|
104
|
+
return byColumn;
|
|
105
|
+
}
|
|
106
|
+
var exactlyOne = processArgs(args[2]);
|
|
107
|
+
if (errCollection.indexOf(exactlyOne) > -1) {
|
|
108
|
+
return exactlyOne;
|
|
109
|
+
}
|
|
110
|
+
var valueCollection = [];
|
|
111
|
+
if (args[0].indexOf(':') > -1) {
|
|
112
|
+
if (isNullOrUndefined(args[0].match(/[0-9]/))) {
|
|
113
|
+
var splitArray = args[0].split(':');
|
|
114
|
+
args[0] = splitArray[0] + '1' + ':' + splitArray[1] + (this.parent.spreadSheetUsedRange[0] + 1);
|
|
115
|
+
}
|
|
116
|
+
else if (isNullOrUndefined(args[0].toUpperCase().match(/[A-Z]/))) {
|
|
117
|
+
var splitArray = args[0].split(':');
|
|
118
|
+
args[0] = 'A' + splitArray[0] + ':' + getAlphalabel(this.parent.spreadSheetUsedRange[1] + 1) + splitArray[1];
|
|
119
|
+
}
|
|
120
|
+
var rangeSplit = args[0].split(':');
|
|
121
|
+
if (this.parent.isCellReference(rangeSplit[0]) && this.parent.isCellReference(rangeSplit[1])) {
|
|
122
|
+
var collection = this.parent.dependencyCollection;
|
|
123
|
+
for (var i = 0; i < collection.length && !isComputeExp; i++) {
|
|
124
|
+
if (collection[i].split(':')[0] === args[0].split(':')[0]) {
|
|
125
|
+
this.clearDependency(collection[i]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (this.parent.dependencyCollection.indexOf(args[0]) === -1) {
|
|
129
|
+
if (!isComputeExp) {
|
|
130
|
+
this.parent.dependencyCollection.push(args[0]);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.clearDependency(args[0]);
|
|
135
|
+
}
|
|
136
|
+
var j = args[0].indexOf(':');
|
|
137
|
+
var swap = void 0;
|
|
138
|
+
var rowIdx = this.parent.rowIndex(this.parent.substring(args[0], 0, j));
|
|
139
|
+
var colIdx = this.parent.colIndex(this.parent.substring(args[0], 0, j));
|
|
140
|
+
var endRowIdx = this.parent.rowIndex(this.parent.substring(args[0], j + 1, j + args[0].length - j - 1));
|
|
141
|
+
var endColIdx = this.parent.colIndex(this.parent.substring(args[0], j + 1, j + args[0].length - j - 1));
|
|
142
|
+
if (rowIdx > endRowIdx) {
|
|
143
|
+
swap = endRowIdx;
|
|
144
|
+
endRowIdx = rowIdx;
|
|
145
|
+
rowIdx = swap;
|
|
146
|
+
}
|
|
147
|
+
if (colIdx > endColIdx) {
|
|
148
|
+
swap = endColIdx;
|
|
149
|
+
endColIdx = colIdx;
|
|
150
|
+
colIdx = swap;
|
|
151
|
+
}
|
|
152
|
+
var sheetIndex = '';
|
|
153
|
+
if (args[0].indexOf('!') === 0) {
|
|
154
|
+
sheetIndex = args[0].substring(0, args[0].replace('!', '').indexOf('!') + 2);
|
|
155
|
+
}
|
|
156
|
+
args[0] = sheetIndex + getAlphalabel(colIdx) + rowIdx + ':' + getAlphalabel(endColIdx) + endRowIdx;
|
|
157
|
+
var colDiff = endColIdx - colIdx;
|
|
158
|
+
var cellValues = this.parent.getCellCollection(args[0]);
|
|
159
|
+
var actCell = void 0;
|
|
160
|
+
var uniqueActCell = void 0;
|
|
161
|
+
actCell = uniqueActCell = this.parent.actCell;
|
|
162
|
+
if (byColumn === this.parent.falseValue) {
|
|
163
|
+
if (colDiff === 0) {
|
|
164
|
+
for (var i = 0; i < cellValues.length; i++) {
|
|
165
|
+
var val = this.parent.getValueFromArg(cellValues[i]);
|
|
166
|
+
val = val === '' ? '0' : val;
|
|
167
|
+
valueCollection.push(val);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
var temp = '';
|
|
172
|
+
var diff = colDiff;
|
|
173
|
+
for (var i = 0; i < cellValues.length; i++) {
|
|
174
|
+
if (i === cellValues.length - 1) {
|
|
175
|
+
var val = this.parent.getValueFromArg(cellValues[i]);
|
|
176
|
+
val = val === '' ? '0' : val;
|
|
177
|
+
temp = temp + val + '++';
|
|
178
|
+
valueCollection.push(temp.substring(0, temp.length - 2));
|
|
179
|
+
}
|
|
180
|
+
if (i <= diff) {
|
|
181
|
+
var val = this.parent.getValueFromArg(cellValues[i]);
|
|
182
|
+
val = val === '' ? '0' : val;
|
|
183
|
+
temp = temp + val + '++';
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
valueCollection.push(temp.substring(0, temp.length - 2));
|
|
187
|
+
diff = colDiff + i;
|
|
188
|
+
var val = this.parent.getValueFromArg(cellValues[i]);
|
|
189
|
+
val = val === '' ? '0' : val;
|
|
190
|
+
temp = val + '++';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
var temp = '';
|
|
197
|
+
var diff = colDiff + 1;
|
|
198
|
+
var rowDiff = endRowIdx - rowIdx;
|
|
199
|
+
for (var i = 0; i < diff; i++) {
|
|
200
|
+
for (var j_1 = 0; j_1 <= rowDiff; j_1++) {
|
|
201
|
+
var val = this.parent.getValueFromArg(cellValues[j_1 * diff + i]);
|
|
202
|
+
val = val === '' ? '0' : val;
|
|
203
|
+
temp = temp + val + '++';
|
|
204
|
+
}
|
|
205
|
+
valueCollection.push(temp.substring(0, temp.length - 2));
|
|
206
|
+
temp = '';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
var uniqueCollection = [];
|
|
210
|
+
var duplicateCollection = [];
|
|
211
|
+
var tmp = [];
|
|
212
|
+
var tmp2 = [];
|
|
213
|
+
for (var i = 0; i < valueCollection.length; i++) {
|
|
214
|
+
if (uniqueCollection.indexOf(valueCollection[i].toLowerCase()) === -1) {
|
|
215
|
+
uniqueCollection.push(valueCollection[i].toLowerCase());
|
|
216
|
+
tmp.push(valueCollection[i]);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
if (duplicateCollection.indexOf(valueCollection[i].toLowerCase()) === -1) {
|
|
220
|
+
duplicateCollection.push(valueCollection[i].toLowerCase());
|
|
221
|
+
}
|
|
222
|
+
tmp2.push(valueCollection[i]);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (exactlyOne === this.parent.trueValue) {
|
|
226
|
+
var exactOne = [];
|
|
227
|
+
for (var i = 0; i < tmp.length; i++) {
|
|
228
|
+
if (duplicateCollection.indexOf(tmp[i].toLowerCase()) === -1) {
|
|
229
|
+
exactOne.push(tmp[i]);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
tmp = exactOne;
|
|
233
|
+
if (tmp.length === 0) {
|
|
234
|
+
return errCollection[CommonErrors.Calc];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (isComputeExp) {
|
|
238
|
+
var computeExpResult_1;
|
|
239
|
+
if (colDiff !== 0) {
|
|
240
|
+
computeExpResult_1 = [];
|
|
241
|
+
(tmp).forEach(function (item) {
|
|
242
|
+
computeExpResult_1 = computeExpResult_1.concat(item.split('++'));
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
computeExpResult_1 = byColumn === this.parent.falseValue ? tmp : tmp[0].split('++');
|
|
247
|
+
}
|
|
248
|
+
return computeExpResult_1;
|
|
249
|
+
}
|
|
250
|
+
if (actCell.indexOf('!') > -1) {
|
|
251
|
+
actCell = actCell.substring(actCell.lastIndexOf('!') + 1);
|
|
252
|
+
}
|
|
253
|
+
var actRowIdx = this.parent.rowIndex(actCell);
|
|
254
|
+
var actColIdx = this.parent.colIndex(actCell);
|
|
255
|
+
if (this.parent.dependencyLevel === 0) {
|
|
256
|
+
var isSpill = false;
|
|
257
|
+
if (byColumn === this.parent.falseValue) {
|
|
258
|
+
for (var i = actRowIdx, diff = tmp.length + actRowIdx; i < diff; i++) {
|
|
259
|
+
var splitValue = tmp[0].split('++');
|
|
260
|
+
for (var j_2 = actColIdx, diff2 = splitValue.length + actColIdx; j_2 < diff2; j_2++) {
|
|
261
|
+
if (i === diff - 1 && j_2 === diff2 - 1 &&
|
|
262
|
+
this.parent.uniqueRange.indexOf(uniqueActCell + ':' + getAlphalabel(j_2) + i) === -1) {
|
|
263
|
+
this.parent.uniqueRange.push(uniqueActCell + ':' + getAlphalabel(j_2) + i);
|
|
264
|
+
}
|
|
265
|
+
if (this.checkSpill(j_2, i)) {
|
|
266
|
+
isSpill = true;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
for (var i = actColIdx, diff = tmp.length + actColIdx; i < diff; i++) {
|
|
273
|
+
var splitValue = tmp[0].split('++');
|
|
274
|
+
for (var j_3 = actRowIdx, diff2 = splitValue.length + actRowIdx; j_3 < diff2; j_3++) {
|
|
275
|
+
if (i === diff - 1 && j_3 === diff2 - 1 &&
|
|
276
|
+
this.parent.uniqueRange.indexOf(this.parent.actCell + ':' + getAlphalabel(i) + j_3) === -1) {
|
|
277
|
+
this.parent.uniqueRange.push(this.parent.actCell + ':' + getAlphalabel(i) + j_3);
|
|
278
|
+
}
|
|
279
|
+
if (this.checkSpill(i, j_3)) {
|
|
280
|
+
isSpill = true;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (isSpill) {
|
|
286
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.Spill];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else if (this.parent.dependencyLevel > 0 &&
|
|
290
|
+
this.parent.getValueFromArg(getAlphalabel(actColIdx) + actRowIdx, true).indexOf('#SPILL!') > -1) {
|
|
291
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.Spill];
|
|
292
|
+
}
|
|
293
|
+
if (byColumn === this.parent.falseValue) {
|
|
294
|
+
var calcFamily = this.parent.getSheetFamilyItem(this.parent.grid);
|
|
295
|
+
var token = '';
|
|
296
|
+
var cellTxt = void 0;
|
|
297
|
+
if (calcFamily.sheetNameToParentObject !== null && calcFamily.sheetNameToParentObject.size > 0) {
|
|
298
|
+
token = calcFamily.parentObjectToToken.get(this.parent.grid);
|
|
299
|
+
cellTxt = token + actCell;
|
|
300
|
+
}
|
|
301
|
+
for (var i = 0; i < tmp.length; i++) {
|
|
302
|
+
var splitValue = tmp[i].split('++');
|
|
303
|
+
if (i > 0) {
|
|
304
|
+
actRowIdx++;
|
|
305
|
+
actColIdx = this.parent.colIndex(actCell);
|
|
306
|
+
}
|
|
307
|
+
for (var j_4 = 0; j_4 < splitValue.length; j_4++) {
|
|
308
|
+
this.setValueRefresh(splitValue[j_4], actRowIdx, actColIdx);
|
|
309
|
+
if (i > 0 || j_4 > 0) {
|
|
310
|
+
this.parent.refreshDependentCells(token + getAlphalabel(actColIdx) + actRowIdx.toString(), cellTxt);
|
|
311
|
+
}
|
|
312
|
+
if (splitValue[j_4 + 1]) {
|
|
313
|
+
actColIdx++;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
result = tmp[0].split('++')[0];
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
for (var i = 0; i < tmp.length; i++) {
|
|
321
|
+
var splitValue = tmp[i].split('++');
|
|
322
|
+
for (var i_1 = 0; i_1 < splitValue.length; i_1++) {
|
|
323
|
+
this.setValueRefresh(splitValue[i_1], actRowIdx, actColIdx);
|
|
324
|
+
if (splitValue[i_1 + 1]) {
|
|
325
|
+
actRowIdx++;
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
actColIdx++;
|
|
329
|
+
actRowIdx = this.parent.rowIndex(actCell);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
result = tmp[0].split('++')[0];
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else if (this.parent.isCellReference(args[0])) {
|
|
338
|
+
if (this.parent.dependencyCollection.indexOf(args[0]) === -1) {
|
|
339
|
+
if (!isComputeExp) {
|
|
340
|
+
this.parent.dependencyCollection.push(args[0]);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
this.clearDependency(args[0]);
|
|
345
|
+
}
|
|
346
|
+
result = this.parent.getValueFromArg(args[0]);
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
result = this.parent.getValueFromArg(args[0].trim());
|
|
350
|
+
if (errCollection.indexOf(result) > -1) {
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
353
|
+
result = this.parent.removeTics(result);
|
|
354
|
+
}
|
|
355
|
+
return result;
|
|
356
|
+
};
|
|
357
|
+
ArrayFormulas.prototype.setValueRefresh = function (splitValue, rowIdx, colIdx) {
|
|
358
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
359
|
+
this.parent.parentObject.setValueRowCol(this.parent.getSheetId(this.parent.grid), splitValue, rowIdx, colIdx);
|
|
360
|
+
};
|
|
361
|
+
ArrayFormulas.prototype.checkSpill = function (i, j) {
|
|
362
|
+
var spill = false;
|
|
363
|
+
var value = this.parent.getValueFromArg(getAlphalabel(i) + j, true);
|
|
364
|
+
var formulaAddress = '!' + this.parent.getSheetID(this.parent.grid) + '!' + getAlphalabel(i) + j;
|
|
365
|
+
var formulaString;
|
|
366
|
+
if (this.parent.getFormulaInfoTable().get(formulaAddress)) {
|
|
367
|
+
formulaString = this.parent.getFormulaInfoTable().get(formulaAddress).formulaText;
|
|
368
|
+
}
|
|
369
|
+
if (value && (value.toUpperCase().indexOf('UNIQUE') < 0 ||
|
|
370
|
+
(formulaString && !formulaString.toUpperCase().includes('UNIQUE'))) &&
|
|
371
|
+
(value.toUpperCase().indexOf('SORT') < 0 ||
|
|
372
|
+
(formulaString && !formulaString.toUpperCase().includes('SORT'))) &&
|
|
373
|
+
value !== this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments]) {
|
|
374
|
+
spill = true;
|
|
375
|
+
}
|
|
376
|
+
return spill;
|
|
377
|
+
};
|
|
378
|
+
ArrayFormulas.prototype.clearDependency = function (value) {
|
|
379
|
+
var actCell = this.parent.actCell;
|
|
380
|
+
var actCellSheetName = '';
|
|
381
|
+
if (actCell.lastIndexOf('!') > -1) {
|
|
382
|
+
var actCellAddr = actCell;
|
|
383
|
+
actCell = actCellAddr.substring(actCellAddr.lastIndexOf('!') + 1);
|
|
384
|
+
actCellSheetName = actCellAddr.substring(0, actCellAddr.lastIndexOf('!')) + '!';
|
|
385
|
+
}
|
|
386
|
+
var actRowIdx = this.parent.rowIndex(actCell);
|
|
387
|
+
var actColIdx = this.parent.colIndex(actCell);
|
|
388
|
+
var j = value.indexOf(':');
|
|
389
|
+
var rowIndex = this.parent.rowIndex(this.parent.substring(value, 0, j));
|
|
390
|
+
var colIndex = this.parent.colIndex(this.parent.substring(value, 0, j));
|
|
391
|
+
var eRowIdx = this.parent.rowIndex(this.parent.substring(value, j + 1, j + value.length - j - 1));
|
|
392
|
+
var eColIdx = this.parent.colIndex(this.parent.substring(value, j + 1, j + value.length - j - 1));
|
|
393
|
+
var rowDiff = eRowIdx - rowIndex + actRowIdx;
|
|
394
|
+
var colDiff = eColIdx - colIndex + actColIdx;
|
|
395
|
+
var formulaText = this.parent.getFormulaInfoTable().get('!' + this.parent.getSheetID(this.parent.grid) + '!' + actCell) ?
|
|
396
|
+
this.parent.getFormulaInfoTable().get('!' + this.parent.getSheetID(this.parent.grid) + '!' + actCell).getFormulaText() : '';
|
|
397
|
+
for (var i = actRowIdx; i <= rowDiff; i++) {
|
|
398
|
+
for (var j_5 = actColIdx; j_5 <= colDiff; j_5++) {
|
|
399
|
+
if (this.parent.dependencyLevel > 0 || formulaText.indexOf('UNIQUE') > -1
|
|
400
|
+
|| formulaText.indexOf('SORT') > -1) {
|
|
401
|
+
if (this.parent.getValueFromArg('!' + this.parent.getSheetID(this.parent.grid) + '!' +
|
|
402
|
+
getAlphalabel(actColIdx) + actRowIdx, true).indexOf('#SPILL!') > -1) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
406
|
+
this.parent.parentObject.setValueRowCol(this.parent.getSheetID(this.parent.grid) + 1, '', i, j_5);
|
|
407
|
+
this.parent.refreshDependentCells('!' + this.parent.getSheetID(this.parent.grid) + '!' + getAlphalabel(j_5) + i, actCell);
|
|
408
|
+
this.parent.actCell = actCellSheetName + actCell;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* Sorts a range of an array.
|
|
415
|
+
*
|
|
416
|
+
* Excel: `SORT(...)`.
|
|
417
|
+
*
|
|
418
|
+
* @hidden
|
|
419
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
420
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
421
|
+
*/
|
|
422
|
+
ArrayFormulas.prototype.ComputeSORT = function () {
|
|
423
|
+
var _this = this;
|
|
424
|
+
var args = [];
|
|
425
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
426
|
+
args[_i] = arguments[_i];
|
|
427
|
+
}
|
|
428
|
+
var nestedFormula;
|
|
429
|
+
var isStringVal;
|
|
430
|
+
if (args.length && args[args.length - 1] === 'nestedFormulaTrue') {
|
|
431
|
+
nestedFormula = true;
|
|
432
|
+
args.pop();
|
|
433
|
+
}
|
|
434
|
+
var argArr = args;
|
|
435
|
+
var result;
|
|
436
|
+
var values = [];
|
|
437
|
+
if (isNullOrUndefined(args) || args[0] === '' || argArr.length > 4) {
|
|
438
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
439
|
+
}
|
|
440
|
+
argArr[1] = argArr[1] ? argArr[1] : '1';
|
|
441
|
+
argArr[2] = argArr[2] ? argArr[2] : '1'; // 1 = Ascending, -1 = Descending. Default is ascending order.
|
|
442
|
+
argArr[3] = argArr[3] ? argArr[3] : 'FALSE'; // Default is FALSE = sort by column or row
|
|
443
|
+
argArr[0] = argArr[0].split('$').join('');
|
|
444
|
+
var cellCollection;
|
|
445
|
+
var valueCollection = [];
|
|
446
|
+
if (argArr[0].indexOf(':') > -1) {
|
|
447
|
+
if (isNullOrUndefined(argArr[0].match(/[0-9]/))) {
|
|
448
|
+
var splitArray = argArr[0].split(':');
|
|
449
|
+
argArr[0] = splitArray[0] + '1' + ':' + splitArray[1] + (this.parent.spreadSheetUsedRange[0] + 1);
|
|
450
|
+
}
|
|
451
|
+
else if (isNullOrUndefined(argArr[0].toUpperCase().match(/[A-Z]/))) {
|
|
452
|
+
var splitArray = argArr[0].split(':');
|
|
453
|
+
argArr[0] = 'A' + splitArray[0] + ':' + getAlphalabel(this.parent.spreadSheetUsedRange[1] + 1) + splitArray[1];
|
|
454
|
+
}
|
|
455
|
+
var rangeSplit = argArr[0].split(':');
|
|
456
|
+
if (this.parent.isCellReference(rangeSplit[0]) && this.parent.isCellReference(rangeSplit[1])) {
|
|
457
|
+
var collection = this.parent.dependencyCollection;
|
|
458
|
+
for (var i = 0; i < collection.length && !nestedFormula; i++) {
|
|
459
|
+
if (collection[i].split(':')[0] === argArr[0].split(':')[0]) {
|
|
460
|
+
this.clearDependency(collection[i]);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (this.parent.dependencyCollection.indexOf(argArr[0]) === -1) {
|
|
464
|
+
if (!nestedFormula) {
|
|
465
|
+
this.parent.dependencyCollection.push(argArr[0]);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
this.clearDependency(argArr[0]);
|
|
470
|
+
}
|
|
471
|
+
var j = argArr[0].indexOf(':');
|
|
472
|
+
var swap = void 0;
|
|
473
|
+
var rowIdx = this.parent.rowIndex(this.parent.substring(argArr[0], 0, j));
|
|
474
|
+
var colIdx = this.parent.colIndex(this.parent.substring(argArr[0], 0, j));
|
|
475
|
+
var eRowIdx = this.parent.rowIndex(this.parent.substring(argArr[0], j + 1, j + argArr[0].length - j - 1));
|
|
476
|
+
var eColIdx = this.parent.colIndex(this.parent.substring(argArr[0], j + 1, j + argArr[0].length - j - 1));
|
|
477
|
+
if (rowIdx > eRowIdx) {
|
|
478
|
+
swap = eRowIdx;
|
|
479
|
+
eRowIdx = rowIdx;
|
|
480
|
+
rowIdx = swap;
|
|
481
|
+
}
|
|
482
|
+
if (colIdx > eColIdx) {
|
|
483
|
+
swap = eColIdx;
|
|
484
|
+
eColIdx = colIdx;
|
|
485
|
+
colIdx = swap;
|
|
486
|
+
}
|
|
487
|
+
if (this.parent.isCellReference(argArr[3])) {
|
|
488
|
+
argArr[3] = this.parent.getValueFromArg(argArr[3]).toUpperCase();
|
|
489
|
+
if (argArr[3] !== this.parent.trueValue && argArr[3] !== this.parent.falseValue) {
|
|
490
|
+
if (isNumber(argArr[3])) {
|
|
491
|
+
argArr[3] = Number(argArr[3]) === 0 ? this.parent.falseValue : this.parent.trueValue;
|
|
492
|
+
}
|
|
493
|
+
else if (argArr[3] === '') {
|
|
494
|
+
argArr[3] = this.parent.falseValue;
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
return this.parent.getErrorStrings()[CommonErrors.Value];
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
isStringVal = argArr[3].startsWith(this.parent.tic) && argArr[3].endsWith(this.parent.tic);
|
|
503
|
+
argArr[3] = this.parent.getValueFromArg(argArr[3]);
|
|
504
|
+
argArr[3] = isNumber(argArr[3]) ? (Number(argArr[3]) === 0 ? this.parent.falseValue : this.parent.trueValue) :
|
|
505
|
+
argArr[3].split(this.parent.tic).join('').toUpperCase();
|
|
506
|
+
if (argArr[3] !== this.parent.trueValue && argArr[3] !== this.parent.falseValue) {
|
|
507
|
+
return this.parent.getErrorStrings()[isStringVal ? CommonErrors.Value : CommonErrors.Name];
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (this.parent.isCellReference(argArr[2])) {
|
|
511
|
+
argArr[2] = this.parent.getValueFromArg(argArr[2]);
|
|
512
|
+
argArr[2] = argArr[2] === this.parent.trueValue ? '1' : argArr[2];
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
argArr[2] = this.parent.getValueFromArg(argArr[2]);
|
|
516
|
+
argArr[2] = argArr[2] === this.parent.trueValue ? '1' : argArr[2].split(this.parent.tic).join('');
|
|
517
|
+
}
|
|
518
|
+
argArr[2] = isNumber(argArr[2]) ? Math.floor(Number(argArr[2])).toString() : argArr[2];
|
|
519
|
+
if (argArr[2] !== '1' && argArr[2] !== '-1') {
|
|
520
|
+
return this.parent.getErrorStrings().indexOf(argArr[2]) > -1 ? this.parent.getErrorStrings()[CommonErrors.Name] :
|
|
521
|
+
this.parent.getErrorStrings()[CommonErrors.Value];
|
|
522
|
+
}
|
|
523
|
+
var order = argArr[2] === '1' ? 'Ascending' : 'Descending';
|
|
524
|
+
if (this.parent.isCellReference(argArr[1])) {
|
|
525
|
+
argArr[1] = this.parent.getValueFromArg(argArr[1]);
|
|
526
|
+
argArr[1] = isNumber(argArr[1]) ? Math.floor(Number(argArr[1])).toString() : (argArr[1] === this.parent.trueValue ? '1'
|
|
527
|
+
: (argArr[1] === this.parent.falseValue ? '0' : argArr[1]));
|
|
528
|
+
if (!isNaN(this.parseDouble(argArr[1])) ? (this.parseDouble(argArr[1]) < 1 || (argArr[3] === this.parent.trueValue ?
|
|
529
|
+
(eRowIdx - rowIdx) + 1 < this.parseDouble(argArr[1]) : (eColIdx - colIdx) + 1 < this.parseDouble(argArr[1])))
|
|
530
|
+
: true) {
|
|
531
|
+
return this.parent.getErrorStrings()[CommonErrors.Value];
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
isStringVal = argArr[1].startsWith(this.parent.tic) && argArr[1].endsWith(this.parent.tic);
|
|
536
|
+
argArr[1] = this.parent.getValueFromArg(argArr[1]);
|
|
537
|
+
argArr[1] = isNumber(argArr[1]) ? Math.floor(Number(argArr[1])).toString() : (argArr[1] === this.parent.trueValue ?
|
|
538
|
+
'1' : (argArr[1] === this.parent.falseValue ? '0' : argArr[1].split(this.parent.tic).join('')));
|
|
539
|
+
if (!isNaN(this.parseDouble(argArr[1])) ? (this.parseDouble(argArr[1]) < 1 || (argArr[3] === this.parent.trueValue ?
|
|
540
|
+
(eRowIdx - rowIdx) + 1 < this.parseDouble(argArr[1]) : (eColIdx - colIdx) + 1 < this.parseDouble(argArr[1])))
|
|
541
|
+
: isStringVal) {
|
|
542
|
+
return this.parent.getErrorStrings()[CommonErrors.Value];
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
var sheetIdx = '';
|
|
546
|
+
if (argArr[0].indexOf('!') === 0) {
|
|
547
|
+
sheetIdx = argArr[0];
|
|
548
|
+
sheetIdx = sheetIdx.replace('!', '');
|
|
549
|
+
sheetIdx = sheetIdx.indexOf('!');
|
|
550
|
+
sheetIdx = argArr[0].substring(0, sheetIdx + 2);
|
|
551
|
+
}
|
|
552
|
+
argArr[0] = sheetIdx + getAlphalabel(colIdx) + rowIdx + ':' + getAlphalabel(eColIdx) + eRowIdx;
|
|
553
|
+
cellCollection = this.parent.getCellCollection(argArr[0]);
|
|
554
|
+
for (var i = 0; i < cellCollection.length; i++) {
|
|
555
|
+
valueCollection.push(this.parent.getValueFromArg(cellCollection[i]));
|
|
556
|
+
}
|
|
557
|
+
var colSort_1 = [];
|
|
558
|
+
var numColl_1 = [];
|
|
559
|
+
var strColl_1 = [];
|
|
560
|
+
var booleanColl_1 = [];
|
|
561
|
+
var emptyCellColl_1 = [];
|
|
562
|
+
var totalColumn = eColIdx - colIdx + 1;
|
|
563
|
+
var sortRangeValuesHandler = function (value) {
|
|
564
|
+
if (value) {
|
|
565
|
+
if (value.toUpperCase() === 'TRUE' || value.toUpperCase() === 'FALSE') {
|
|
566
|
+
booleanColl_1.push(value);
|
|
567
|
+
colSort_1.push(value);
|
|
568
|
+
}
|
|
569
|
+
else if (isNaN(_this.parseDouble(value))) {
|
|
570
|
+
strColl_1.push(value);
|
|
571
|
+
colSort_1.push(value);
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
numColl_1.push(_this.parseDouble(value));
|
|
575
|
+
colSort_1.push(_this.parseDouble(value));
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
else if (value === '') {
|
|
579
|
+
emptyCellColl_1.push(_this.parseDouble(value).toString());
|
|
580
|
+
colSort_1.push(_this.parseDouble(value).toString());
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
if (argArr[3] === 'TRUE') {
|
|
584
|
+
for (var i = 0; i < totalColumn; i++) {
|
|
585
|
+
sortRangeValuesHandler(valueCollection[i + ((this.parseDouble(argArr[1]) - 1) * totalColumn)]);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (argArr[3] === 'FALSE') {
|
|
589
|
+
for (var i = 0; i < valueCollection.length; i++) {
|
|
590
|
+
sortRangeValuesHandler(valueCollection[i * totalColumn + this.parseDouble(argArr[1]) - 1]);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
594
|
+
var sortedNumColl = numColl_1.length > 0 ? sortCollection(numColl_1, order) : [];
|
|
595
|
+
var sortedStrColl = strColl_1.length > 0 ? sortCollection(strColl_1, order) : [];
|
|
596
|
+
var sortedBooleanColl = booleanColl_1.length > 0 ? sortCollection(booleanColl_1, order) : [];
|
|
597
|
+
var sortedVal = order === 'Ascending' ?
|
|
598
|
+
sortedNumColl.concat(sortedStrColl, sortedBooleanColl, emptyCellColl_1) :
|
|
599
|
+
sortedBooleanColl.concat(sortedStrColl, sortedNumColl, emptyCellColl_1);
|
|
600
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
601
|
+
var id = [];
|
|
602
|
+
for (var a = 0; a < sortedVal.length; a++) {
|
|
603
|
+
for (var b = 0; b < colSort_1.length; b++) {
|
|
604
|
+
if (JSON.stringify(sortedVal[a]) === JSON.stringify(colSort_1[b])) {
|
|
605
|
+
if (id.indexOf(b) === -1) {
|
|
606
|
+
id.push(b);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
var activeCell = void 0;
|
|
612
|
+
var sortActCell = void 0;
|
|
613
|
+
activeCell = sortActCell = this.parent.actCell;
|
|
614
|
+
if (activeCell) {
|
|
615
|
+
activeCell = activeCell.indexOf('!') > -1 ? activeCell.substring(activeCell.lastIndexOf('!') + 1) : activeCell;
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
activeCell = this.parent.actCell;
|
|
619
|
+
}
|
|
620
|
+
var actRowIdx = this.parent.rowIndex(activeCell);
|
|
621
|
+
var actColIdx = this.parent.colIndex(activeCell);
|
|
622
|
+
if (this.parent.dependencyLevel === 0) {
|
|
623
|
+
var isSpill = false;
|
|
624
|
+
var resultRows = (argArr[3] === 'TRUE') ? (eRowIdx - rowIdx + 1) : id.length;
|
|
625
|
+
var resultCols = (argArr[3] === 'TRUE') ? id.length : (eColIdx - colIdx + 1);
|
|
626
|
+
for (var rowOffset = 0; rowOffset < resultRows; rowOffset++) {
|
|
627
|
+
for (var colOffset = 0; colOffset < resultCols; colOffset++) {
|
|
628
|
+
if (this.checkSpill(actColIdx + colOffset, actRowIdx + rowOffset)) {
|
|
629
|
+
isSpill = true;
|
|
630
|
+
}
|
|
631
|
+
if (rowOffset === resultRows - 1 && colOffset === resultCols - 1) {
|
|
632
|
+
var endCell = getAlphalabel(actColIdx + colOffset) + (actRowIdx + rowOffset);
|
|
633
|
+
if (this.parent.sortRange.indexOf(sortActCell + ':' + endCell) === -1) {
|
|
634
|
+
this.parent.sortRange.push(sortActCell + ':' + endCell);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
if (isSpill) {
|
|
640
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.Spill];
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
else if (this.parent.dependencyLevel > 0 &&
|
|
644
|
+
this.parent.getValueFromArg(getAlphalabel(actColIdx) + actRowIdx, true).indexOf('#SPILL!') > -1) {
|
|
645
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.Spill];
|
|
646
|
+
}
|
|
647
|
+
if (argArr[3] === 'TRUE') {
|
|
648
|
+
for (var startRow = rowIdx, rowInc = 0; startRow <= eRowIdx; startRow++, rowInc++) {
|
|
649
|
+
for (var a = 0, colInc = 0; a < id.length; a++, colInc++) {
|
|
650
|
+
var cellValue = this.parent.getValueFromArg(sheetIdx + getAlphalabel(id[a] + colIdx) + startRow);
|
|
651
|
+
if (nestedFormula && cellValue !== '') {
|
|
652
|
+
values.push(cellValue);
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
cellValue = cellValue === '' ? '0' : cellValue;
|
|
656
|
+
var activeCell_1 = this.parent.cell;
|
|
657
|
+
if (activeCell_1) {
|
|
658
|
+
activeCell_1 = activeCell_1.indexOf('!') > -1 ? activeCell_1.substring(activeCell_1.lastIndexOf('!') + 1) :
|
|
659
|
+
activeCell_1;
|
|
660
|
+
var actRowIdx_1 = this.parent.rowIndex(activeCell_1);
|
|
661
|
+
var actColIdx_1 = this.parent.colIndex(activeCell_1);
|
|
662
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
663
|
+
this.parent.parentObject.setValueRowCol(this.parent.getSheetID(this.parent.grid) + 1, cellValue, actRowIdx_1 + rowInc, actColIdx_1 + colInc);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
result = this.parent.getValueFromArg(sheetIdx + getAlphalabel(id[0] + colIdx) + rowIdx);
|
|
668
|
+
}
|
|
669
|
+
if (argArr[3] === 'FALSE') {
|
|
670
|
+
for (var a = 0, rowInc = 0; a < id.length; a++, rowInc++) {
|
|
671
|
+
for (var startCol = colIdx, colInc = 0; startCol <= eColIdx; startCol++, colInc++) {
|
|
672
|
+
var value = this.parent.getValueFromArg(sheetIdx + getAlphalabel(startCol) + (id[a] + rowIdx));
|
|
673
|
+
if (nestedFormula && value !== '') {
|
|
674
|
+
values.push(value);
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
value = value === '' ? '0' : value;
|
|
678
|
+
var activeCell_2 = this.parent.cell;
|
|
679
|
+
if (activeCell_2) {
|
|
680
|
+
activeCell_2 = activeCell_2.indexOf('!') > -1 ? activeCell_2.substring(activeCell_2.lastIndexOf('!') + 1) :
|
|
681
|
+
activeCell_2;
|
|
682
|
+
var actColIdx_2 = this.parent.colIndex(activeCell_2);
|
|
683
|
+
var actRowIdx_2 = this.parent.rowIndex(activeCell_2);
|
|
684
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
685
|
+
this.parent.parentObject.setValueRowCol(this.parent.getSheetID(this.parent.grid) + 1, value, actRowIdx_2 + rowInc, actColIdx_2 + colInc);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
result = this.parent.getValueFromArg(sheetIdx + getAlphalabel(colIdx) + (id[0] + rowIdx));
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
else if (this.parent.isCellReference(argArr[0])) {
|
|
694
|
+
if (this.parent.dependencyCollection.indexOf(argArr[0]) === -1) {
|
|
695
|
+
if (!nestedFormula) {
|
|
696
|
+
this.parent.dependencyCollection.push(argArr[0]);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
this.clearDependency(argArr[0]);
|
|
701
|
+
}
|
|
702
|
+
result = this.parent.getValueFromArg(argArr[0]);
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
result = argArr[0].trim();
|
|
706
|
+
if (this.parent.getErrorStrings().indexOf(result) > -1) {
|
|
707
|
+
return result;
|
|
708
|
+
}
|
|
709
|
+
result = this.parent.removeTics(result);
|
|
710
|
+
}
|
|
711
|
+
if (nestedFormula) {
|
|
712
|
+
return values.join(',');
|
|
713
|
+
}
|
|
714
|
+
return result === '' ? '0' : result;
|
|
715
|
+
};
|
|
716
|
+
return ArrayFormulas;
|
|
717
|
+
}(FormulaModuleBase));
|
|
718
|
+
export { ArrayFormulas };
|