Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ export class FormulaDependencyGenerator extends Disposable implements IFormulaDe
tree.rowCount,
tree.columnCount,
tree.subUnitId,
tree.unitId
tree.unitId,
tree.type
);

const rangeList = await this._getRangeListByNode({
Expand Down Expand Up @@ -1039,7 +1040,8 @@ export class FormulaDependencyGenerator extends Disposable implements IFormulaDe
tree.rowCount,
tree.columnCount,
tree.subUnitId,
tree.unitId
tree.unitId,
tree.type
);

const dirtyRanges: IUnitRange[] = [];
Expand Down Expand Up @@ -1092,7 +1094,8 @@ export class FormulaDependencyGenerator extends Disposable implements IFormulaDe
tree.rowCount,
tree.columnCount,
tree.subUnitId,
tree.unitId
tree.unitId,
tree.type
);

let value: FunctionVariantType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { ObjectMatrix } from '@univerjs/core';
import { describe, expect, it } from 'vitest';
import { ErrorType } from '../../basics/error-type';
import { FormulaDependencyTreeType } from '../../engine/dependency/dependency-tree';
import { createNewArray } from '../../engine/utils/array-object';
import { NumberValueObject, StringValueObject } from '../../engine/value-object/primitive-object';
import { FormulaExecutedStateType, FormulaExecuteStageType, FormulaRuntimeService } from '../runtime.service';
Expand Down Expand Up @@ -402,6 +403,18 @@ describe('FormulaRuntimeService', () => {
expect(runtime.getDependencyTreeModelData()).toEqual([{ treeId: 1 }]);
});

it('should collect embedded array refs only for normal worksheet formulas', () => {
const { runtime } = createRuntimeService();

runtime.setCurrent(1, 2, 20, 20, 'sheet', 'unit', FormulaDependencyTreeType.OTHER_FORMULA);
runtime.setUnitArrayFormulaEmbeddedMap();
expect(runtime.getUnitArrayFormulaEmbeddedMap().unit?.sheet?.[1]?.[2]).toBeUndefined();

runtime.setCurrent(4, 5, 20, 20, 'sheet', 'unit', FormulaDependencyTreeType.NORMAL_FORMULA);
runtime.setUnitArrayFormulaEmbeddedMap();
expect(runtime.getUnitArrayFormulaEmbeddedMap().unit?.sheet?.[4]?.[5]).toBe(true);
});

it('should evaluate helper methods for range, overlap and dirty checks', () => {
const { runtime, arrayFormulaRange } = createRuntimeService();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ export class CalculateFormulaService extends Disposable implements ICalculateFor
tree.rowCount,
tree.columnCount,
tree.subUnitId,
tree.unitId
tree.unitId,
tree.type
);

let value: FunctionVariantType;
Expand Down
21 changes: 19 additions & 2 deletions packages/engine-formula/src/services/runtime.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { createIdentifier, Disposable, isNullCell, ObjectMatrix } from '@univerj
import { isInDirtyRange } from '../basics/dirty';
import { ErrorType } from '../basics/error-type';
import { CELL_INVERTED_INDEX_CACHE } from '../basics/inverted-index-cache';
import { FormulaDependencyTreeType } from '../engine/dependency/dependency-tree';
import { FORMULA_REF_TO_ARRAY_CACHE } from '../engine/reference-object/base-reference-object';
import { getRuntimeFeatureCell } from '../engine/utils/get-runtime-feature-cell';
import { clearNumberFormatTypeCache, clearStringToNumberPatternCache } from '../engine/utils/numfmt-kit';
Expand Down Expand Up @@ -112,7 +113,8 @@ export interface IFormulaRuntimeService {
rowCount: number,
columnCount: number,
sheetId: string,
unitId: string
unitId: string,
formulaType?: FormulaDependencyTreeType
): void;

registerFunctionDefinitionPrivacyVar(lambdaId: string, lambdaVar: Map<string, Nullable<BaseAstNode>>): void;
Expand Down Expand Up @@ -211,6 +213,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime

private _currentSubUnitId: string = '';
private _currentUnitId: string = '';
private _currentFormulaType: FormulaDependencyTreeType = FormulaDependencyTreeType.NORMAL_FORMULA;

private _runtimeData: IRuntimeUnitDataType = {};

Expand Down Expand Up @@ -405,13 +408,22 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
clearReferenceToRangeCache();
}

setCurrent(row: number, column: number, rowCount: number, columnCount: number, sheetId: string, unitId: string) {
setCurrent(
row: number,
column: number,
rowCount: number,
columnCount: number,
sheetId: string,
unitId: string,
formulaType: FormulaDependencyTreeType = FormulaDependencyTreeType.NORMAL_FORMULA
) {
this._currentRow = row;
this._currentColumn = column;
this._currentRowCount = rowCount;
this._currentColumnCount = columnCount;
this._currentSubUnitId = sheetId;
this._currentUnitId = unitId;
this._currentFormulaType = formulaType;
}

clearFunctionDefinitionPrivacyVar() {
Expand Down Expand Up @@ -723,6 +735,11 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
const rowIndex = this._currentRow;
const columnIndex = this._currentColumn;

// Embedded array refs are worksheet cell metadata; other formula results stay in unitOtherData.
if (this._currentFormulaType !== FormulaDependencyTreeType.NORMAL_FORMULA) {
return;
}

const arrayFormulaEmbeddedMap = this._unitArrayFormulaEmbeddedMap;
if (arrayFormulaEmbeddedMap[unitId] == null) {
arrayFormulaEmbeddedMap[unitId] = {};
Expand Down
Loading