@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.
Files changed (173) hide show
  1. package/.eslintrc.json +263 -0
  2. package/README.md +132 -0
  3. package/base.d.ts +4 -0
  4. package/base.js +4 -0
  5. package/common.d.ts +4 -0
  6. package/common.js +4 -0
  7. package/dist/ej2-calculate.umd.min.js +11 -0
  8. package/dist/ej2-calculate.umd.min.js.map +1 -0
  9. package/dist/es6/ej2-calculate.es2015.js +24801 -0
  10. package/dist/es6/ej2-calculate.es2015.js.map +1 -0
  11. package/dist/es6/ej2-calculate.es5.js +27229 -0
  12. package/dist/es6/ej2-calculate.es5.js.map +1 -0
  13. package/dist/global/ej2-calculate.min.js +11 -0
  14. package/dist/global/ej2-calculate.min.js.map +1 -0
  15. package/dist/global/index.d.ts +14 -0
  16. package/formulas.d.ts +4 -0
  17. package/formulas.js +4 -0
  18. package/index.d.ts +4 -0
  19. package/index.js +4 -0
  20. package/license +10 -0
  21. package/package.json +30 -0
  22. package/src/base/calculate-model.d.ts +4 -0
  23. package/src/base/calculate-model.js +0 -0
  24. package/src/base/calculate.d.ts +1105 -0
  25. package/src/base/calculate.js +4720 -0
  26. package/src/base/index.d.ts +8 -0
  27. package/src/base/index.js +7 -0
  28. package/src/base/parser.d.ts +208 -0
  29. package/src/base/parser.js +1512 -0
  30. package/src/common/address.d.ts +59 -0
  31. package/src/common/address.js +96 -0
  32. package/src/common/cell-ref.d.ts +32 -0
  33. package/src/common/cell-ref.js +112 -0
  34. package/src/common/common.d.ts +44 -0
  35. package/src/common/common.js +134 -0
  36. package/src/common/enum.d.ts +94 -0
  37. package/src/common/enum.js +97 -0
  38. package/src/common/index.d.ts +9 -0
  39. package/src/common/index.js +8 -0
  40. package/src/common/interface.d.ts +122 -0
  41. package/src/common/interface.js +0 -0
  42. package/src/common/l10n.d.ts +24 -0
  43. package/src/common/l10n.js +54 -0
  44. package/src/common/number-date.d.ts +26 -0
  45. package/src/common/number-date.js +38 -0
  46. package/src/common/sheet-info.d.ts +10 -0
  47. package/src/common/sheet-info.js +17 -0
  48. package/src/common/sort.d.ts +17 -0
  49. package/src/common/sort.js +44 -0
  50. package/src/formulas/array.d.ts +47 -0
  51. package/src/formulas/array.js +718 -0
  52. package/src/formulas/basic.d.ts +47 -0
  53. package/src/formulas/basic.js +181 -0
  54. package/src/formulas/complex-numbers.d.ts +207 -0
  55. package/src/formulas/complex-numbers.js +549 -0
  56. package/src/formulas/database.d.ts +152 -0
  57. package/src/formulas/database.js +579 -0
  58. package/src/formulas/date-time-extra.d.ts +97 -0
  59. package/src/formulas/date-time-extra.js +415 -0
  60. package/src/formulas/date-time-intl.d.ts +57 -0
  61. package/src/formulas/date-time-intl.js +309 -0
  62. package/src/formulas/date-time.d.ts +164 -0
  63. package/src/formulas/date-time.js +1021 -0
  64. package/src/formulas/engineering-base.d.ts +150 -0
  65. package/src/formulas/engineering-base.js +404 -0
  66. package/src/formulas/engineering-bessel.d.ts +65 -0
  67. package/src/formulas/engineering-bessel.js +167 -0
  68. package/src/formulas/engineering-convert.d.ts +35 -0
  69. package/src/formulas/engineering-convert.js +120 -0
  70. package/src/formulas/engineering-misc.d.ts +64 -0
  71. package/src/formulas/engineering-misc.js +168 -0
  72. package/src/formulas/financial-amortization-ecma.d.ts +87 -0
  73. package/src/formulas/financial-amortization-ecma.js +288 -0
  74. package/src/formulas/financial-annuity.d.ts +104 -0
  75. package/src/formulas/financial-annuity.js +419 -0
  76. package/src/formulas/financial-bond-helpers.d.ts +106 -0
  77. package/src/formulas/financial-bond-helpers.js +190 -0
  78. package/src/formulas/financial-cashflow.d.ts +47 -0
  79. package/src/formulas/financial-cashflow.js +203 -0
  80. package/src/formulas/financial-coupons.d.ts +227 -0
  81. package/src/formulas/financial-coupons.js +810 -0
  82. package/src/formulas/financial-depreciation.d.ts +64 -0
  83. package/src/formulas/financial-depreciation.js +247 -0
  84. package/src/formulas/financial-rates.d.ts +54 -0
  85. package/src/formulas/financial-rates.js +140 -0
  86. package/src/formulas/financial-securities.d.ts +126 -0
  87. package/src/formulas/financial-securities.js +488 -0
  88. package/src/formulas/formula-math-helpers.d.ts +212 -0
  89. package/src/formulas/formula-math-helpers.js +599 -0
  90. package/src/formulas/formula-module-base.d.ts +54 -0
  91. package/src/formulas/formula-module-base.js +125 -0
  92. package/src/formulas/formula-owner.d.ts +17 -0
  93. package/src/formulas/formula-owner.js +0 -0
  94. package/src/formulas/index.d.ts +68 -0
  95. package/src/formulas/index.js +67 -0
  96. package/src/formulas/information-advanced.d.ts +44 -0
  97. package/src/formulas/information-advanced.js +157 -0
  98. package/src/formulas/information-ecma.d.ts +33 -0
  99. package/src/formulas/information-ecma.js +88 -0
  100. package/src/formulas/information-extra.d.ts +146 -0
  101. package/src/formulas/information-extra.js +351 -0
  102. package/src/formulas/information.d.ts +34 -0
  103. package/src/formulas/information.js +78 -0
  104. package/src/formulas/logical-extra.d.ts +75 -0
  105. package/src/formulas/logical-extra.js +217 -0
  106. package/src/formulas/logical.d.ts +83 -0
  107. package/src/formulas/logical.js +296 -0
  108. package/src/formulas/lookup-array.d.ts +98 -0
  109. package/src/formulas/lookup-array.js +364 -0
  110. package/src/formulas/lookup-ref-extra.d.ts +64 -0
  111. package/src/formulas/lookup-ref-extra.js +180 -0
  112. package/src/formulas/lookup-ref.d.ts +84 -0
  113. package/src/formulas/lookup-ref.js +263 -0
  114. package/src/formulas/lookup.d.ts +114 -0
  115. package/src/formulas/lookup.js +881 -0
  116. package/src/formulas/math-aggregate.d.ts +74 -0
  117. package/src/formulas/math-aggregate.js +376 -0
  118. package/src/formulas/math-ceiling-ecma.d.ts +42 -0
  119. package/src/formulas/math-ceiling-ecma.js +123 -0
  120. package/src/formulas/math-combinatorics.d.ts +75 -0
  121. package/src/formulas/math-combinatorics.js +290 -0
  122. package/src/formulas/math-misc.d.ts +164 -0
  123. package/src/formulas/math-misc.js +889 -0
  124. package/src/formulas/math-number.d.ts +76 -0
  125. package/src/formulas/math-number.js +261 -0
  126. package/src/formulas/math-rounding.d.ts +115 -0
  127. package/src/formulas/math-rounding.js +728 -0
  128. package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
  129. package/src/formulas/math-trig-hyperbolic.js +113 -0
  130. package/src/formulas/math-trig.d.ts +165 -0
  131. package/src/formulas/math-trig.js +334 -0
  132. package/src/formulas/matrix-base.d.ts +13 -0
  133. package/src/formulas/matrix-base.js +169 -0
  134. package/src/formulas/matrix.d.ts +64 -0
  135. package/src/formulas/matrix.js +161 -0
  136. package/src/formulas/regression-ecma.d.ts +66 -0
  137. package/src/formulas/regression-ecma.js +234 -0
  138. package/src/formulas/statistical-advanced.d.ts +125 -0
  139. package/src/formulas/statistical-advanced.js +756 -0
  140. package/src/formulas/statistical-correlation.d.ts +75 -0
  141. package/src/formulas/statistical-correlation.js +198 -0
  142. package/src/formulas/statistical-dispersion.d.ts +108 -0
  143. package/src/formulas/statistical-dispersion.js +337 -0
  144. package/src/formulas/statistical-distribution-extended.d.ts +176 -0
  145. package/src/formulas/statistical-distribution-extended.js +668 -0
  146. package/src/formulas/statistical-distribution.d.ts +104 -0
  147. package/src/formulas/statistical-distribution.js +368 -0
  148. package/src/formulas/statistical-ecma.d.ts +95 -0
  149. package/src/formulas/statistical-ecma.js +392 -0
  150. package/src/formulas/statistical-extended.d.ts +136 -0
  151. package/src/formulas/statistical-extended.js +340 -0
  152. package/src/formulas/statistical-ifs.d.ts +46 -0
  153. package/src/formulas/statistical-ifs.js +180 -0
  154. package/src/formulas/statistical-moments.d.ts +84 -0
  155. package/src/formulas/statistical-moments.js +269 -0
  156. package/src/formulas/statistical-percentile.d.ts +56 -0
  157. package/src/formulas/statistical-percentile.js +195 -0
  158. package/src/formulas/statistical-sample-base.d.ts +14 -0
  159. package/src/formulas/statistical-sample-base.js +124 -0
  160. package/src/formulas/statistical.d.ts +135 -0
  161. package/src/formulas/statistical.js +542 -0
  162. package/src/formulas/text-advanced.d.ts +64 -0
  163. package/src/formulas/text-advanced.js +222 -0
  164. package/src/formulas/text-ecma.d.ts +54 -0
  165. package/src/formulas/text-ecma.js +106 -0
  166. package/src/formulas/text-extra.d.ts +216 -0
  167. package/src/formulas/text-extra.js +657 -0
  168. package/src/formulas/text.d.ts +125 -0
  169. package/src/formulas/text.js +628 -0
  170. package/src/global.js +1 -0
  171. package/src/index.d.ts +14 -0
  172. package/src/index.js +14 -0
  173. package/tslint.json +111 -0
@@ -0,0 +1,180 @@
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 { isNullOrUndefined } from '@syncfusion/ej2-base';
16
+ import { FormulaModuleBase } from './formula-module-base';
17
+ /**
18
+ * Supplementary reference helpers for row/column indexing and dynamic range resolution.
19
+ *
20
+ * Registered functions: INDIRECT, AREAS, FORMULATEXT, ISREF.
21
+ *
22
+ * @hidden
23
+ */
24
+ var LookupRefExtraFormulas = /** @class */ (function (_super) {
25
+ __extends(LookupRefExtraFormulas, _super);
26
+ /**
27
+ * @hidden
28
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
29
+ */
30
+ function LookupRefExtraFormulas(owner) {
31
+ var _this = _super.call(this, owner) || this;
32
+ /** Formula definitions registered with {@link BasicFormulas}. */
33
+ _this.formulas = [
34
+ { formulaName: 'INDIRECT', category: 'Lookup & Reference', description: 'Returns a reference indicated by a text value.' },
35
+ { formulaName: 'AREAS', category: 'Lookup & Reference', description: 'Returns the number of areas in a reference.' },
36
+ { formulaName: 'FORMULATEXT', category: 'Lookup & Reference', description: 'Returns the formula in a cell as text.' },
37
+ { formulaName: 'ISREF', category: 'Information', description: 'Returns TRUE if the value is a reference.' }
38
+ ];
39
+ return _this;
40
+ }
41
+ /**
42
+ * Returns a reference indicated by a text value.
43
+ *
44
+ * Excel: `INDIRECT(...)`.
45
+ *
46
+ * @hidden
47
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
48
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * engine.computeFormula('=INDIRECT(1)');
53
+ * ```
54
+ */
55
+ LookupRefExtraFormulas.prototype.ComputeINDIRECT = function () {
56
+ var args = [];
57
+ for (var _i = 0; _i < arguments.length; _i++) {
58
+ args[_i] = arguments[_i];
59
+ }
60
+ var errCollection = this.parent.getErrorStrings();
61
+ if (isNullOrUndefined(args) || args.length < 1 || args.length > 2) {
62
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
63
+ }
64
+ var refText = this.resolveTextArg(args[0]);
65
+ if (errCollection.indexOf(refText) > -1) {
66
+ return refText;
67
+ }
68
+ refText = refText.split('$').join('');
69
+ var a1Style = true;
70
+ if (args.length === 2) {
71
+ var style = this.resolveNumberArg(args[1]);
72
+ if (typeof style === 'string') {
73
+ return style;
74
+ }
75
+ a1Style = style !== 0;
76
+ }
77
+ if (!a1Style) {
78
+ return errCollection[CommonErrors.Value];
79
+ }
80
+ if (!this.parent.isCellReference(refText.split(':')[0])) {
81
+ return errCollection[CommonErrors.Ref];
82
+ }
83
+ if (refText.indexOf(':') > -1) {
84
+ var cells = this.parent.getCellCollection(refText);
85
+ var list = Array.isArray(cells) ? cells : [cells];
86
+ var values = [];
87
+ for (var i = 0; i < list.length; i++) {
88
+ var val = this.parent.getValueFromArg(list[i]);
89
+ if (errCollection.indexOf(val) > -1) {
90
+ return val;
91
+ }
92
+ values.push(val);
93
+ }
94
+ return values.join(this.parent.getParseArgumentSeparator());
95
+ }
96
+ return this.parent.getValueFromArg(refText);
97
+ };
98
+ /**
99
+ * Returns the number of areas in a reference.
100
+ *
101
+ * Excel: `AREAS(...)`.
102
+ *
103
+ * @hidden
104
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
105
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
106
+ */
107
+ LookupRefExtraFormulas.prototype.ComputeAREAS = function () {
108
+ var args = [];
109
+ for (var _i = 0; _i < arguments.length; _i++) {
110
+ args[_i] = arguments[_i];
111
+ }
112
+ var errCollection = this.parent.getErrorStrings();
113
+ if (isNullOrUndefined(args) || args.length !== 1) {
114
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
115
+ }
116
+ var ref = args[0].split('$').join('');
117
+ if (!this.parent.isCellReference(ref.split(':')[0]) && ref.indexOf('(') === -1) {
118
+ return errCollection[CommonErrors.Value];
119
+ }
120
+ if (ref.indexOf(',') > -1) {
121
+ return ref.split(',').length.toString();
122
+ }
123
+ return '1';
124
+ };
125
+ /**
126
+ * Returns the formula in a cell as text.
127
+ *
128
+ * Excel: `FORMULATEXT(...)`.
129
+ *
130
+ * @hidden
131
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
132
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
133
+ */
134
+ LookupRefExtraFormulas.prototype.ComputeFORMULATEXT = function () {
135
+ var args = [];
136
+ for (var _i = 0; _i < arguments.length; _i++) {
137
+ args[_i] = arguments[_i];
138
+ }
139
+ var errCollection = this.parent.getErrorStrings();
140
+ if (isNullOrUndefined(args) || args.length !== 1) {
141
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
142
+ }
143
+ var ref = args[0].split('$').join('');
144
+ if (!this.parent.isCellReference(ref)) {
145
+ return errCollection[CommonErrors.Value];
146
+ }
147
+ var sheetPrefix = ref.indexOf('!') > -1 ? ref.substring(0, ref.lastIndexOf('!') + 1) : '';
148
+ var cell = ref.indexOf('!') > -1 ? ref.substring(ref.lastIndexOf('!') + 1) : ref;
149
+ var key = '!' + this.parent.getSheetID(this.parent.grid) + '!' + cell;
150
+ var fullKey = sheetPrefix ? ref : key;
151
+ var infoTable = this.parent.getFormulaInfoTable();
152
+ var lookupKey = sheetPrefix ? fullKey : key;
153
+ if (infoTable.has(lookupKey)) {
154
+ return infoTable.get(lookupKey).getFormulaText();
155
+ }
156
+ return errCollection[CommonErrors.NA];
157
+ };
158
+ /**
159
+ * Returns TRUE if the value is a reference.
160
+ *
161
+ * Excel: `ISREF(...)`.
162
+ *
163
+ * @hidden
164
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
165
+ * @returns {boolean} - Boolean result, nested-formula numeric string (`"0"`/`"1"`), or an Excel error token.
166
+ */
167
+ LookupRefExtraFormulas.prototype.ComputeISREF = function () {
168
+ var args = [];
169
+ for (var _i = 0; _i < arguments.length; _i++) {
170
+ args[_i] = arguments[_i];
171
+ }
172
+ if (isNullOrUndefined(args) || args.length !== 1) {
173
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
174
+ }
175
+ var ref = args[0].split('$').join('');
176
+ return this.parent.isCellReference(ref.split(':')[0]);
177
+ };
178
+ return LookupRefExtraFormulas;
179
+ }(FormulaModuleBase));
180
+ export { LookupRefExtraFormulas };
@@ -0,0 +1,84 @@
1
+ import { IBasicFormula } from '../common/index';
2
+ import { FormulaOwner } from './formula-owner';
3
+ import { FormulaModuleBase } from './formula-module-base';
4
+ /**
5
+ * Cell and range reference utilities: ADDRESS, INDIRECT, OFFSET, and sheet-aware lookups.
6
+ *
7
+ * Registered functions: ROW, ROWS, COLUMN, COLUMNS, HYPERLINK, OFFSET.
8
+ *
9
+ * @hidden
10
+ */
11
+ export declare class LookupRefFormulas extends FormulaModuleBase {
12
+ /** Formula definitions registered with {@link BasicFormulas}. */
13
+ formulas: IBasicFormula[];
14
+ /**
15
+ * @hidden
16
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
17
+ */
18
+ constructor(owner: FormulaOwner);
19
+ /**
20
+ * Returns the row number of a reference.
21
+ *
22
+ * Excel: `ROW(...)`.
23
+ *
24
+ * @hidden
25
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
26
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * engine.computeFormula('=ROW(1)');
31
+ * ```
32
+ */
33
+ ComputeROW(...args: string[]): string | number;
34
+ /**
35
+ * Returns the column number of a reference.
36
+ *
37
+ * Excel: `COLUMN(...)`.
38
+ *
39
+ * @hidden
40
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
41
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
42
+ */
43
+ ComputeCOLUMN(...args: string[]): string | number;
44
+ /**
45
+ * Returns the number of rows in a reference.
46
+ *
47
+ * Excel: `ROWS(...)`.
48
+ *
49
+ * @hidden
50
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
51
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
52
+ */
53
+ ComputeROWS(...args: string[]): string | number;
54
+ /**
55
+ * Returns the number of columns in a reference.
56
+ *
57
+ * Excel: `COLUMNS(...)`.
58
+ *
59
+ * @hidden
60
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
61
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
62
+ */
63
+ ComputeCOLUMNS(...args: string[]): string | number;
64
+ /**
65
+ * Creates a shortcut that opens a document on a network server, intranet, or Internet.
66
+ *
67
+ * Excel: `HYPERLINK(...)`.
68
+ *
69
+ * @hidden
70
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
71
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
72
+ */
73
+ ComputeHYPERLINK(...args: string[]): string;
74
+ /**
75
+ * Returns a reference offset from a given reference.
76
+ *
77
+ * Excel: `OFFSET(...)`.
78
+ *
79
+ * @hidden
80
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
81
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
82
+ */
83
+ ComputeOFFSET(...args: string[]): string | number;
84
+ }
@@ -0,0 +1,263 @@
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 { isNullOrUndefined } from '@syncfusion/ej2-base';
16
+ import { getAlphalabel } from '../base/index';
17
+ import { FormulaModuleBase } from './formula-module-base';
18
+ /**
19
+ * Cell and range reference utilities: ADDRESS, INDIRECT, OFFSET, and sheet-aware lookups.
20
+ *
21
+ * Registered functions: ROW, ROWS, COLUMN, COLUMNS, HYPERLINK, OFFSET.
22
+ *
23
+ * @hidden
24
+ */
25
+ var LookupRefFormulas = /** @class */ (function (_super) {
26
+ __extends(LookupRefFormulas, _super);
27
+ /**
28
+ * @hidden
29
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
30
+ */
31
+ function LookupRefFormulas(owner) {
32
+ var _this = _super.call(this, owner) || this;
33
+ /** Formula definitions registered with {@link BasicFormulas}. */
34
+ _this.formulas = [
35
+ { formulaName: 'ROW', category: 'Lookup & Reference', description: 'Returns the row number of a reference.' },
36
+ { formulaName: 'ROWS', category: 'Lookup & Reference', description: 'Returns the number of rows in a reference.' },
37
+ { formulaName: 'COLUMN', category: 'Lookup & Reference', description: 'Returns the column number of a reference.' },
38
+ { formulaName: 'COLUMNS', category: 'Lookup & Reference', description: 'Returns the number of columns in a reference.' },
39
+ { formulaName: 'HYPERLINK', category: 'Lookup & Reference', description: 'Creates a shortcut that opens a document on a network server, intranet, or Internet.' },
40
+ { formulaName: 'OFFSET', category: 'Lookup & Reference', description: 'Returns a reference offset from a given reference.' }
41
+ ];
42
+ return _this;
43
+ }
44
+ /**
45
+ * Returns the row number of a reference.
46
+ *
47
+ * Excel: `ROW(...)`.
48
+ *
49
+ * @hidden
50
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
51
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * engine.computeFormula('=ROW(1)');
56
+ * ```
57
+ */
58
+ LookupRefFormulas.prototype.ComputeROW = function () {
59
+ var args = [];
60
+ for (var _i = 0; _i < arguments.length; _i++) {
61
+ args[_i] = arguments[_i];
62
+ }
63
+ if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
64
+ var act = this.parent.actCell || this.parent.cell || 'A1';
65
+ var cell = act.indexOf('!') > -1 ? act.substring(act.lastIndexOf('!') + 1) : act;
66
+ return this.parent.rowIndex(cell).toString();
67
+ }
68
+ if (args.length !== 1) {
69
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
70
+ }
71
+ var ref = args[0].split('$').join('');
72
+ if (!this.parent.isCellReference(ref.split(':')[0])) {
73
+ return this.parent.getErrorStrings()[CommonErrors.Value];
74
+ }
75
+ var first = ref.indexOf(':') > -1 ? ref.split(':')[0] : ref;
76
+ var stripped = first.indexOf('!') > -1 ? first.substring(first.lastIndexOf('!') + 1) : first;
77
+ return this.parent.rowIndex(stripped).toString();
78
+ };
79
+ /**
80
+ * Returns the column number of a reference.
81
+ *
82
+ * Excel: `COLUMN(...)`.
83
+ *
84
+ * @hidden
85
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
86
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
87
+ */
88
+ LookupRefFormulas.prototype.ComputeCOLUMN = function () {
89
+ var args = [];
90
+ for (var _i = 0; _i < arguments.length; _i++) {
91
+ args[_i] = arguments[_i];
92
+ }
93
+ if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
94
+ var act = this.parent.actCell || this.parent.cell || 'A1';
95
+ var cell = act.indexOf('!') > -1 ? act.substring(act.lastIndexOf('!') + 1) : act;
96
+ return this.parent.colIndex(cell).toString();
97
+ }
98
+ if (args.length !== 1) {
99
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
100
+ }
101
+ var ref = args[0].split('$').join('');
102
+ if (!this.parent.isCellReference(ref.split(':')[0])) {
103
+ return this.parent.getErrorStrings()[CommonErrors.Value];
104
+ }
105
+ var first = ref.indexOf(':') > -1 ? ref.split(':')[0] : ref;
106
+ var stripped = first.indexOf('!') > -1 ? first.substring(first.lastIndexOf('!') + 1) : first;
107
+ return this.parent.colIndex(stripped).toString();
108
+ };
109
+ /**
110
+ * Returns the number of rows in a reference.
111
+ *
112
+ * Excel: `ROWS(...)`.
113
+ *
114
+ * @hidden
115
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
116
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
117
+ */
118
+ LookupRefFormulas.prototype.ComputeROWS = function () {
119
+ var args = [];
120
+ for (var _i = 0; _i < arguments.length; _i++) {
121
+ args[_i] = arguments[_i];
122
+ }
123
+ if (isNullOrUndefined(args) || args.length !== 1 || args[0] === '') {
124
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
125
+ }
126
+ var ref = args[0].split('$').join('');
127
+ if (ref.indexOf(':') === -1) {
128
+ if (!this.parent.isCellReference(ref)) {
129
+ return this.parent.getErrorStrings()[CommonErrors.Value];
130
+ }
131
+ return '1';
132
+ }
133
+ var parts = ref.split(':');
134
+ var a = parts[0].indexOf('!') > -1 ? parts[0].substring(parts[0].lastIndexOf('!') + 1) : parts[0];
135
+ var b = parts[1].indexOf('!') > -1 ? parts[1].substring(parts[1].lastIndexOf('!') + 1) : parts[1];
136
+ return (Math.abs(this.parent.rowIndex(b) - this.parent.rowIndex(a)) + 1).toString();
137
+ };
138
+ /**
139
+ * Returns the number of columns in a reference.
140
+ *
141
+ * Excel: `COLUMNS(...)`.
142
+ *
143
+ * @hidden
144
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
145
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
146
+ */
147
+ LookupRefFormulas.prototype.ComputeCOLUMNS = function () {
148
+ var args = [];
149
+ for (var _i = 0; _i < arguments.length; _i++) {
150
+ args[_i] = arguments[_i];
151
+ }
152
+ if (isNullOrUndefined(args) || args.length !== 1 || args[0] === '') {
153
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
154
+ }
155
+ var ref = args[0].split('$').join('');
156
+ if (ref.indexOf(':') === -1) {
157
+ if (!this.parent.isCellReference(ref)) {
158
+ return this.parent.getErrorStrings()[CommonErrors.Value];
159
+ }
160
+ return '1';
161
+ }
162
+ var parts = ref.split(':');
163
+ var a = parts[0].indexOf('!') > -1 ? parts[0].substring(parts[0].lastIndexOf('!') + 1) : parts[0];
164
+ var b = parts[1].indexOf('!') > -1 ? parts[1].substring(parts[1].lastIndexOf('!') + 1) : parts[1];
165
+ return (Math.abs(this.parent.colIndex(b) - this.parent.colIndex(a)) + 1).toString();
166
+ };
167
+ /**
168
+ * Creates a shortcut that opens a document on a network server, intranet, or Internet.
169
+ *
170
+ * Excel: `HYPERLINK(...)`.
171
+ *
172
+ * @hidden
173
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
174
+ * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
175
+ */
176
+ LookupRefFormulas.prototype.ComputeHYPERLINK = function () {
177
+ var args = [];
178
+ for (var _i = 0; _i < arguments.length; _i++) {
179
+ args[_i] = arguments[_i];
180
+ }
181
+ var errCollection = this.parent.getErrorStrings();
182
+ if (isNullOrUndefined(args) || args.length < 1 || args.length > 2) {
183
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
184
+ }
185
+ var link = this.resolveTextArg(args[0]);
186
+ if (errCollection.indexOf(link) > -1) {
187
+ return link;
188
+ }
189
+ if (args.length === 2) {
190
+ var friendly = this.resolveTextArg(args[1]);
191
+ if (errCollection.indexOf(friendly) > -1) {
192
+ return friendly;
193
+ }
194
+ return friendly;
195
+ }
196
+ return link;
197
+ };
198
+ /**
199
+ * Returns a reference offset from a given reference.
200
+ *
201
+ * Excel: `OFFSET(...)`.
202
+ *
203
+ * @hidden
204
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
205
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
206
+ */
207
+ LookupRefFormulas.prototype.ComputeOFFSET = function () {
208
+ var args = [];
209
+ for (var _i = 0; _i < arguments.length; _i++) {
210
+ args[_i] = arguments[_i];
211
+ }
212
+ var errCollection = this.parent.getErrorStrings();
213
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 5) {
214
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
215
+ }
216
+ var ref = args[0].split('$').join('');
217
+ if (!this.parent.isCellReference(ref.split(':')[0])) {
218
+ return errCollection[CommonErrors.Value];
219
+ }
220
+ var rows = this.resolveNumberArg(args[1]);
221
+ var cols = this.resolveNumberArg(args[2]);
222
+ if (typeof rows === 'string') {
223
+ return rows;
224
+ }
225
+ if (typeof cols === 'string') {
226
+ return cols;
227
+ }
228
+ var height = 1;
229
+ var width = 1;
230
+ if (args.length >= 4 && args[3] !== '') {
231
+ var h = this.resolveNumberArg(args[3]);
232
+ if (typeof h === 'string') {
233
+ return h;
234
+ }
235
+ height = Math.floor(h);
236
+ }
237
+ if (args.length === 5 && args[4] !== '') {
238
+ var w = this.resolveNumberArg(args[4]);
239
+ if (typeof w === 'string') {
240
+ return w;
241
+ }
242
+ width = Math.floor(w);
243
+ }
244
+ if (height < 1 || width < 1) {
245
+ return errCollection[CommonErrors.Ref];
246
+ }
247
+ var first = ref.indexOf(':') > -1 ? ref.split(':')[0] : ref;
248
+ var sheet = first.indexOf('!') > -1 ? first.substring(0, first.lastIndexOf('!') + 1) : '';
249
+ var cell = first.indexOf('!') > -1 ? first.substring(first.lastIndexOf('!') + 1) : first;
250
+ var baseRow = this.parent.rowIndex(cell) + Math.floor(rows);
251
+ var baseCol = this.parent.colIndex(cell) + Math.floor(cols);
252
+ if (baseRow < 1 || baseCol < 1) {
253
+ return errCollection[CommonErrors.Ref];
254
+ }
255
+ var start = sheet + getAlphalabel(baseCol) + baseRow;
256
+ if (height === 1 && width === 1) {
257
+ return this.parent.getValueFromArg(start);
258
+ }
259
+ return this.parent.getValueFromArg(start) || start;
260
+ };
261
+ return LookupRefFormulas;
262
+ }(FormulaModuleBase));
263
+ export { LookupRefFormulas };
@@ -0,0 +1,114 @@
1
+ import { IBasicFormula } from '../common/index';
2
+ import { FormulaOwner } from './formula-owner';
3
+ import { FormulaModuleBase } from './formula-module-base';
4
+ /**
5
+ * Vertical and horizontal table lookups (VLOOKUP, HLOOKUP) and reference indexing.
6
+ *
7
+ * Registers 9 functions including CHOOSE, INDEX, MATCH, LOOKUP, VLOOKUP, and others.
8
+ *
9
+ * @hidden
10
+ */
11
+ export declare class LookupFormulas extends FormulaModuleBase {
12
+ /** Formula definitions registered with {@link BasicFormulas}. */
13
+ formulas: IBasicFormula[];
14
+ /**
15
+ * @hidden
16
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
17
+ */
18
+ constructor(owner: FormulaOwner);
19
+ /**
20
+ * Returns a value from a list, given an index number.
21
+ *
22
+ * Excel: `CHOOSE(...)`.
23
+ *
24
+ * @hidden
25
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
26
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * engine.computeFormula('=CHOOSE(1)');
31
+ * ```
32
+ */
33
+ ComputeCHOOSE(...args: string[]): string | number;
34
+ /**
35
+ * Returns a value from a table, given a row and column number.
36
+ *
37
+ * Excel: `INDEX(...)`.
38
+ *
39
+ * @hidden
40
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
41
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
42
+ */
43
+ ComputeINDEX(...args: string[]): string | number;
44
+ /**
45
+ * Returns the relative position of an checked item in range that matches a specified value in a specified order.
46
+ *
47
+ * Excel: `MATCH(...)`.
48
+ *
49
+ * @hidden
50
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
51
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
52
+ */
53
+ ComputeMATCH(...args: string[]): string | number;
54
+ /**
55
+ * Looks for a value in a one-row or one-column range, then returns a value from the same position in a second one-row or one-column range.
56
+ *
57
+ * Excel: `LOOKUP(...)`.
58
+ *
59
+ * @hidden
60
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
61
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
62
+ */
63
+ ComputeLOOKUP(...args: string[]): string | number;
64
+ /**
65
+ * Looks for a specific value in the first column of a lookup range and returns a corresponding value from a different column within the same row.
66
+ *
67
+ * Excel: `VLOOKUP(...)`.
68
+ *
69
+ * @hidden
70
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
71
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
72
+ */
73
+ ComputeVLOOKUP(...args: string[]): string | number;
74
+ /**
75
+ * Looks for a value in the top row of the array of values and then returns a value in the same column from a row in the array that you specify.
76
+ *
77
+ * Excel: `HLOOKUP(...)`.
78
+ *
79
+ * @hidden
80
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
81
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
82
+ */
83
+ ComputeHLOOKUP(...args: string[]): string | number;
84
+ /**
85
+ * Returns a cell reference as text, given specified row and column numbers.
86
+ *
87
+ * Excel: `ADDRESS(...)`.
88
+ *
89
+ * @hidden
90
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
91
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
92
+ */
93
+ ComputeADDRESS(...args: string[]): string | number;
94
+ /**
95
+ * Returns a subtotal in a list or database.
96
+ *
97
+ * Excel: `SUBTOTAL(...)`.
98
+ *
99
+ * @hidden
100
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
101
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
102
+ */
103
+ ComputeSUBTOTAL(...args: string[]): string | number;
104
+ /**
105
+ * Converts a value to text in specified number format.
106
+ *
107
+ * Excel: `TEXT(...)`.
108
+ *
109
+ * @hidden
110
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
111
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
112
+ */
113
+ ComputeTEXT(...args: string[]): string | number;
114
+ }