Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(formula): bound non-sheet other formulas (#7340)

Univer3543b5b54f3e
diff --git a/packages/engine-formula/src/engine/analysis/__tests__/dependency.spec.ts b/packages/engine-formula/src/engine/analysis/__tests__/dependency.spec.ts
index d61134969b..cff58119c6 100644
--- a/packages/engine-formula/src/engine/analysis/__tests__/dependency.spec.ts
+++ b/packages/engine-formula/src/engine/analysis/__tests__/dependency.spec.ts
@@ -189,6 +189,53 @@ describe('Test dependency', () => {
expect(tree2.refOffsetY).toEqual(2);
});
+ it('limits other formulas without sheet dimensions to one result slot', async () => {
+ const formulaId = 'formula.shape-unit_shape_shape_shape-1_test';
+ formulaCurrentConfigService.load({
+ formulaData: {},
+ arrayFormulaCellData: {},
+ arrayFormulaRange: {},
+ forceCalculate: false,
+ dirtyRanges: [],
+ dirtyNameMap: {},
+ dirtyDefinedNameMap: {},
+ dirtyUnitFeatureMap: {},
+ dirtyUnitOtherFormulaMap: {
+ 'shape-unit': {
+ shape: {
+ [formulaId]: true,
+ },
+ },
+ },
+ excludedCell: {},
+ allUnitData: {
+ [testUnitId]: testSheetData,
+ },
+ });
+
+ otherFormulaManagerService.batchRegister({
+ 'shape-unit': {
+ shape: {
+ [formulaId]: {
+ f: '=1',
+ ranges: [{
+ startRow: 0,
+ endRow: 2,
+ startColumn: 0,
+ endColumn: 2,
+ }],
+ },
+ },
+ },
+ });
+
+ const treeList = await formulaDependencyGenerator.generate();
+ const shapeTrees = treeList.filter((tree) => tree.formulaId === formulaId);
+
+ expect(shapeTrees).toHaveLength(1);
+ expect(shapeTrees[0]).toBeInstanceOf(FormulaDependencyTree);
+ });
+
it('should generate virtual dependency trees for shared formulas with offsets', async () => {
formulaCurrentConfigService.load({
formulaData: {
diff --git a/packages/engine-formula/src/engine/dependency/formula-dependency.ts b/packages/engine-formula/src/engine/dependency/formula-dependency.ts
index 06b76d630e..03f8030fef 100644
--- a/packages/engine-formula/src/engine/dependency/formula-dependency.ts
+++ b/packages/engine-formula/src/engine/dependency/formula-dependency.ts
@@ -296,8 +296,9 @@ export class FormulaDependencyGenerator extends Disposable implements IFormulaDe
}
const sheetSize = this._currentConfigService.getSheetRowColumnCount(unitId, subUnitId);
- const rowCount = sheetSize.rowCount > 0 ? sheetSize.rowCount : Infinity;
- const columnCount = sheetSize.columnCount > 0 ? sheetSize.columnCount : Infinity;
+ // A non-sheet other formula uses one virtual result slot at (0, 0).
+ const rowCount = sheetSize.rowCount > 0 ? sheetSize.rowCount : 1;
+ const columnCount = sheetSize.columnCount > 0 ? sheetSize.columnCount : 1;
const subFormulaDataKeys = Object.keys(subFormulaData);
for (const subFormulaDataId of subFormulaDataKeys) {