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: fix custom formula service not handle other units

Wenzhao Hud4b3767b7c78
diff --git a/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts b/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts
index 9f7344a54c..bfb921fee1 100644
--- a/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts
+++ b/packages/sheets-data-validation/src/services/dv-custom-formula.service.ts
@@ -15,7 +15,7 @@
*/
import type { IRange, ISheetDataValidationRule } from '@univerjs/core';
-import { DataValidationType, Disposable, Inject, isFormulaString, ObjectMatrix, Range } from '@univerjs/core';
+import { DataValidationType, Disposable, Inject, isFormulaString, IUniverInstanceService, ObjectMatrix, Range, UniverInstanceType } from '@univerjs/core';
import { isFormulaTransformable, LexerTreeBuilder, transformFormula } from '@univerjs/engine-formula';
import { DataValidationModel } from '@univerjs/data-validation';
import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';
@@ -60,6 +60,7 @@ export class DataValidationCustomFormulaService extends Disposable {
private _formulaCellMap: Map<UnitId, Map<SubUnitId, Map<FormulaId, ICellData>>> = new Map();
constructor(
+ @IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,
@Inject(RegisterOtherFormulaService) private _registerOtherFormulaService: RegisterOtherFormulaService,
@Inject(LexerTreeBuilder) private _lexerTreeBuilder: LexerTreeBuilder,
@Inject(DataValidationModel) private readonly _dataValidationModel: DataValidationModel,
@@ -74,6 +75,10 @@ export class DataValidationCustomFormulaService extends Disposable {
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
for (const unitId in resultMap) {
const unitMap = resultMap[unitId];
+
+ const type = this._instanceSrv.getUnitType(unitId);
+ if (type !== UniverInstanceType.UNIVER_SHEET) continue;
+
for (const subUnitId in unitMap) {
const results = unitMap[subUnitId];
const { formulaCellMap, ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);