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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheet): pivot data spill (#3039)
Univerbf697b6f53d7
diff --git a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts b/packages/engine-formula/src/engine/reference-object/base-reference-object.tsindex d50e9e24e4..9c5a55a605 100644--- a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts+++ b/packages/engine-formula/src/engine/reference-object/base-reference-object.ts@@ -31,6 +31,7 @@ import {StringValueObject,} from '../value-object/primitive-object';import { getCellValue } from '../utils/cell';+import { getRuntimeFeatureCell } from '../utils/get-runtime-feature-cell';export type NodeValueType = BaseValueObject | BaseReferenceObject | AsyncObject | AsyncArrayObject;@@ -468,23 +469,7 @@ export class BaseReferenceObject extends ObjectClassType {}getRuntimeFeatureCellValue(row: number, column: number) {- const featureKeys = Object.keys(this._runtimeFeatureCellData);-- for (const featureId of featureKeys) {- const data = this._runtimeFeatureCellData[featureId];- const runtimeFeatureCellData = data?.[this.getUnitId()]?.[this.getSheetId()];- if (runtimeFeatureCellData == null) {- continue;- }-- const value = runtimeFeatureCellData.getValue(row, column);-- if (value == null) {- continue;- }-- return value;- }+ return getRuntimeFeatureCell(row, column, this.getSheetId(), this.getUnitId(), this._runtimeFeatureCellData);}getCellByPosition(row?: number, column?: number) {diff --git a/packages/engine-formula/src/engine/utils/get-runtime-feature-cell.ts b/packages/engine-formula/src/engine/utils/get-runtime-feature-cell.tsnew file mode 100644index 0000000000..bb428013ed--- /dev/null+++ b/packages/engine-formula/src/engine/utils/get-runtime-feature-cell.ts@@ -0,0 +1,37 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { IRuntimeUnitDataType } from '../../basics/common';++export function getRuntimeFeatureCell(row: number, column: number, sheetId: string, unitId: string, runtimeFeatureCellData: { [featureId: string]: IRuntimeUnitDataType }) {+ const featureKeys = Object.keys(runtimeFeatureCellData);++ for (const featureId of featureKeys) {+ const data = runtimeFeatureCellData[featureId];+ const CellData = data?.[unitId]?.[sheetId];+ if (CellData == null) {+ continue;+ }++ const value = CellData.getValue(row, column);++ if (value == null) {+ continue;+ }++ return value;+ }+}diff --git a/packages/engine-formula/src/services/runtime.service.ts b/packages/engine-formula/src/services/runtime.service.tsindex dff393a58a..ebd34c1008 100644--- a/packages/engine-formula/src/services/runtime.service.ts+++ b/packages/engine-formula/src/services/runtime.service.ts@@ -30,6 +30,7 @@ import type { BaseReferenceObject, FunctionVariantType } from '../engine/referenimport type { ArrayValueObject } from '../engine/value-object/array-value-object';import { type BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';import { objectValueToCellValue } from '../engine/utils/value-object';+import { getRuntimeFeatureCell } from '../engine/utils/get-runtime-feature-cell';import { IFormulaCurrentConfigService } from './current-data.service';/**@@ -668,10 +669,13 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime);const currentCell = unitData?.[formulaUnitId]?.[formulaSheetId]?.cellData?.getValue(r, c);+ const featureCell = this._getRuntimeFeatureCellValue(r, c, formulaSheetId, formulaUnitId);+if (!isNullCell(cell) ||(!isNullCell(arrayDataCell) && !this._isInArrayFormulaRange(unitArrayFormulaRange, r, c)) ||- !isNullCell(currentCell)+ !isNullCell(currentCell) ||+ !isNullCell(featureCell)) {return true;}@@ -681,6 +685,10 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimereturn false;}+ private _getRuntimeFeatureCellValue(row: number, column: number, sheetId: string, unitId: string) {+ return getRuntimeFeatureCell(row, column, sheetId, unitId, this._runtimeFeatureCellData);+ }+private _isInArrayFormulaRange(range: Nullable<IRange>, r: number, c: number) {if (range == null) {return false;