@univerjs/engine-formula 0.5.0-alpha.0 → 0.5.0-beta.0

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/lib/es/index.js CHANGED
@@ -2463,6 +2463,13 @@ let Vs = class extends Oe {
2463
2463
  sheetNameMap: this._sheetIdToNameMap[e]
2464
2464
  };
2465
2465
  }
2466
+ getSheetRowColumnCount(a, e) {
2467
+ const t = this._univerInstanceService.getUnit(a), r = t == null ? void 0 : t.getSheetBySheetId(e), n = r == null ? void 0 : r.getSnapshot();
2468
+ if (!n)
2469
+ return { rowCount: 0, columnCount: 0 };
2470
+ const { rowCount: s, columnCount: o } = n;
2471
+ return { rowCount: s, columnCount: o };
2472
+ }
2466
2473
  load(a) {
2467
2474
  if (a.allUnitData && a.unitSheetNameMap && a.unitStylesData)
2468
2475
  this._unitData = a.allUnitData, this._unitStylesData = a.unitStylesData, this._sheetNameMap = a.unitSheetNameMap;
@@ -7627,7 +7634,10 @@ class Ff extends Qe {
7627
7634
  }
7628
7635
  _setRefInfo() {
7629
7636
  const { currentUnitId: a, currentSubUnitId: e, currentRow: t, currentColumn: r } = this._runtimeService;
7630
- this._functionExecutor.setRefInfo(a, e, t, r);
7637
+ if (this._functionExecutor.setRefInfo(a, e, t, r), this._functionExecutor.needsSheetRowColumnCount) {
7638
+ const { rowCount: n, columnCount: s } = this._currentConfigService.getSheetRowColumnCount(a, e);
7639
+ this._functionExecutor.setSheetRowColumnCount(n, s);
7640
+ }
7631
7641
  }
7632
7642
  _setRefData(a) {
7633
7643
  if (!a.isReferenceObject())
@@ -10059,6 +10069,8 @@ class V {
10059
10069
  A(this, "_sheetOrder");
10060
10070
  A(this, "_sheetNameMap");
10061
10071
  A(this, "_formulaDataModel");
10072
+ A(this, "_rowCount", -1);
10073
+ A(this, "_columnCount", -1);
10062
10074
  /**
10063
10075
  * Whether the function needs to expand the parameters
10064
10076
  */
@@ -10079,6 +10091,10 @@ class V {
10079
10091
  * Whether the function needs function methods in FormulaDataModel
10080
10092
  */
10081
10093
  A(this, "needsFormulaDataModel", !1);
10094
+ /**
10095
+ * Whether the function needs the number of rows and columns in the sheet
10096
+ */
10097
+ A(this, "needsSheetRowColumnCount", !1);
10082
10098
  /**
10083
10099
  * Minimum number of parameters
10084
10100
  */
@@ -10141,6 +10157,9 @@ class V {
10141
10157
  setFormulaDataModel(a) {
10142
10158
  this._formulaDataModel = a;
10143
10159
  }
10160
+ setSheetRowColumnCount(a, e) {
10161
+ this._rowCount = a, this._columnCount = e;
10162
+ }
10144
10163
  isAsync() {
10145
10164
  return !1;
10146
10165
  }
@@ -23088,6 +23107,7 @@ class FC extends V {
23088
23107
  super(...arguments);
23089
23108
  A(this, "minParams", 0);
23090
23109
  A(this, "maxParams", 5);
23110
+ A(this, "needsSheetRowColumnCount", !0);
23091
23111
  }
23092
23112
  calculate(e, t, r, n, s) {
23093
23113
  if (e != null && e.isError())
@@ -23186,21 +23206,26 @@ class FC extends V {
23186
23206
  return {
23187
23207
  errorObject: g.create(h.CALC)
23188
23208
  };
23189
- if (o < 0 || u < 0)
23209
+ const c = this._rowCount - this.row, l = this._columnCount - this.column;
23210
+ if (o < 0 || u < 0 || o * u > 10 ** 7)
23190
23211
  return {
23191
23212
  errorObject: g.create(h.VALUE)
23192
23213
  };
23193
- const c = +r.getValue(), l = +n.getValue(), f = +s.getValue();
23194
- return c > l ? {
23214
+ if (o > c || u > l)
23215
+ return {
23216
+ errorObject: g.create(h.REF)
23217
+ };
23218
+ const f = +r.getValue(), m = +n.getValue(), d = +s.getValue();
23219
+ return f > m ? {
23195
23220
  errorObject: g.create(h.VALUE)
23196
- } : f && (!Number.isInteger(c) || !Number.isInteger(l)) ? {
23221
+ } : d && (!Number.isInteger(f) || !Number.isInteger(m)) ? {
23197
23222
  errorObject: g.create(h.VALUE)
23198
23223
  } : {
23199
23224
  rowsValue: o,
23200
23225
  columnsValue: u,
23201
- minValue: c,
23202
- maxValue: l,
23203
- wholeNumberValue: f
23226
+ minValue: f,
23227
+ maxValue: m,
23228
+ wholeNumberValue: d
23204
23229
  };
23205
23230
  }
23206
23231
  }
@@ -23372,6 +23397,7 @@ class qC extends V {
23372
23397
  super(...arguments);
23373
23398
  A(this, "minParams", 1);
23374
23399
  A(this, "maxParams", 4);
23400
+ A(this, "needsSheetRowColumnCount", !0);
23375
23401
  }
23376
23402
  calculate(e, t, r, n) {
23377
23403
  let s = e, o = t != null ? t : y.create(1), u = r != null ? r : y.create(1), c = n != null ? n : y.create(1);
@@ -23397,17 +23423,20 @@ class qC extends V {
23397
23423
  if (u)
23398
23424
  return c;
23399
23425
  const [f, m, d, C] = l, _ = Math.floor(+f.getValue()), E = Math.floor(+m.getValue()), b = +d.getValue(), R = +C.getValue();
23400
- if (_ < 0 || E < 0)
23426
+ if (_ < 0 || E < 0 || _ * E > 10 ** 7)
23401
23427
  return g.create(h.VALUE);
23402
23428
  if (_ === 0 || E === 0)
23403
23429
  return g.create(h.CALC);
23404
- const p = [];
23405
- for (let N = 0; N < _; N++) {
23406
- p[N] = [];
23407
- for (let M = 0; M < E; M++)
23408
- p[N][M] = b + (N * E + M) * R;
23430
+ const p = this._rowCount - this.row, N = this._columnCount - this.column;
23431
+ if (_ > p || E > N)
23432
+ return g.create(h.REF);
23433
+ const M = [];
23434
+ for (let D = 0; D < _; D++) {
23435
+ M[D] = [];
23436
+ for (let w = 0; w < E; w++)
23437
+ M[D][w] = b + (D * E + w) * R;
23409
23438
  }
23410
- return s > 1 || o > 1 ? y.create(p[0][0]) : K.createByArray(p);
23439
+ return s > 1 || o > 1 ? y.create(M[0][0]) : K.createByArray(M);
23411
23440
  }
23412
23441
  }
23413
23442
  class XC extends V {
@@ -18,6 +18,8 @@ export declare class BaseFunction {
18
18
  private _sheetOrder;
19
19
  private _sheetNameMap;
20
20
  protected _formulaDataModel: Nullable<FormulaDataModel>;
21
+ protected _rowCount: number;
22
+ protected _columnCount: number;
21
23
  /**
22
24
  * Whether the function needs to expand the parameters
23
25
  */
@@ -38,6 +40,10 @@ export declare class BaseFunction {
38
40
  * Whether the function needs function methods in FormulaDataModel
39
41
  */
40
42
  needsFormulaDataModel: boolean;
43
+ /**
44
+ * Whether the function needs the number of rows and columns in the sheet
45
+ */
46
+ needsSheetRowColumnCount: boolean;
41
47
  /**
42
48
  * Minimum number of parameters
43
49
  */
@@ -76,6 +82,7 @@ export declare class BaseFunction {
76
82
  };
77
83
  }): void;
78
84
  setFormulaDataModel(_formulaDataModel: FormulaDataModel): void;
85
+ setSheetRowColumnCount(rowCount: number, columnCount: number): void;
79
86
  isAsync(): boolean;
80
87
  isAddress(): boolean;
81
88
  isCustom(): boolean;
@@ -4,6 +4,7 @@ import { BaseFunction } from '../../base-function';
4
4
  export declare class Randarray extends BaseFunction {
5
5
  minParams: number;
6
6
  maxParams: number;
7
+ needsSheetRowColumnCount: boolean;
7
8
  calculate(rows?: BaseValueObject, columns?: BaseValueObject, min?: BaseValueObject, max?: BaseValueObject, wholeNumber?: BaseValueObject): BaseValueObject | ArrayValueObject;
8
9
  private _calculateResult;
9
10
  private _calculateSingleCell;
@@ -1,8 +1,9 @@
1
- import { BaseFunction } from '../../base-function';
2
1
  import { BaseValueObject } from '../../../engine/value-object/base-value-object';
2
+ import { BaseFunction } from '../../base-function';
3
3
  export declare class Sequence extends BaseFunction {
4
4
  minParams: number;
5
5
  maxParams: number;
6
+ needsSheetRowColumnCount: boolean;
6
7
  calculate(rows: BaseValueObject, columns?: BaseValueObject, start?: BaseValueObject, step?: BaseValueObject): BaseValueObject;
7
8
  private _getResult;
8
9
  }
@@ -45,6 +45,10 @@ export interface IFormulaCurrentConfigService {
45
45
  [sheetId: string]: string;
46
46
  };
47
47
  };
48
+ getSheetRowColumnCount(unitId: string, sheetId: string): {
49
+ rowCount: number;
50
+ columnCount: number;
51
+ };
48
52
  }
49
53
  export declare class FormulaCurrentConfigService extends Disposable implements IFormulaCurrentConfigService {
50
54
  private readonly _univerInstanceService;
@@ -94,6 +98,10 @@ export declare class FormulaCurrentConfigService extends Disposable implements I
94
98
  [sheetId: string]: string;
95
99
  };
96
100
  };
101
+ getSheetRowColumnCount(unitId: string, sheetId: string): {
102
+ rowCount: number;
103
+ columnCount: number;
104
+ };
97
105
  load(config: IFormulaDatasetConfig): void;
98
106
  getDirtyData(): IFormulaDirtyData;
99
107
  loadDirtyRangesAndExcludedCell(dirtyRanges: IUnitRange[], excludedCell?: IUnitExcludedCell): void;