From 7902a96de27955c7c00814a984c31c4f62ad0e5a Mon Sep 17 00:00:00 2001 From: Univer <68851825+DR-Univer@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:37:25 +0800 Subject: [PATCH] fix(formula): worker error (#1565) * fix(formula): worker error * fix(formula): merge interface --- packages/engine-formula/src/basics/common.ts | 8 +++--- packages/engine-formula/src/basics/runtime.ts | 25 ++++++++++++++++++- .../set-formula-calculation.mutation.ts | 4 +-- .../src/controller/calculate.controller.ts | 3 ++- .../calculate-result-apply.controller.ts | 2 +- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/packages/engine-formula/src/basics/common.ts b/packages/engine-formula/src/basics/common.ts index e0251ad62e..3428000b96 100644 --- a/packages/engine-formula/src/basics/common.ts +++ b/packages/engine-formula/src/basics/common.ts @@ -69,6 +69,10 @@ export interface IRuntimeUnitDataType { [unitId: string]: Nullable<{ [sheetId: string]: ObjectMatrix> }>; } +export interface IRuntimeUnitDataPrimitiveType { + [unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType> }>; +} + export interface IRuntimeOtherUnitDataType { [unitId: string]: Nullable<{ [sheetId: string]: Nullable<{ [formulaId: string]: ICellData }> }>; } @@ -93,9 +97,7 @@ export interface IFeatureDirtyRangeType { [unitId: string]: Nullable<{ [sheetId: string]: IRange[] }>; } -export interface IArrayFormulaUnitCellType { - [unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType> }>; -} +export interface IArrayFormulaUnitCellType extends IRuntimeUnitDataPrimitiveType {} export interface IFormulaData { [unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType }>; diff --git a/packages/engine-formula/src/basics/runtime.ts b/packages/engine-formula/src/basics/runtime.ts index e1ec434196..210d46acce 100644 --- a/packages/engine-formula/src/basics/runtime.ts +++ b/packages/engine-formula/src/basics/runtime.ts @@ -16,7 +16,7 @@ import { ObjectMatrix } from '@univerjs/core'; -import type { IArrayFormulaUnitCellType, IRuntimeUnitDataType } from './common'; +import type { IArrayFormulaUnitCellType, IRuntimeUnitDataPrimitiveType, IRuntimeUnitDataType } from './common'; export function convertUnitDataToRuntime(unitData: IArrayFormulaUnitCellType) { const arrayFormulaCellData: IRuntimeUnitDataType = {}; @@ -40,3 +40,26 @@ export function convertUnitDataToRuntime(unitData: IArrayFormulaUnitCellType) { return arrayFormulaCellData; } + +export function convertRuntimeToUnitData(unitData: IRuntimeUnitDataType) { + const unitPrimitiveData: IRuntimeUnitDataPrimitiveType = {}; + Object.keys(unitData).forEach((unitId) => { + const sheetData = unitData[unitId]; + + if (sheetData == null) { + return true; + } + + if (unitPrimitiveData[unitId] == null) { + unitPrimitiveData[unitId] = {}; + } + + Object.keys(sheetData).forEach((sheetId) => { + const cellData = sheetData[sheetId]; + + unitPrimitiveData[unitId]![sheetId] = cellData.getData(); + }); + }); + + return unitPrimitiveData; +} diff --git a/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts index 64bc1021ad..8d7d25195b 100644 --- a/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts +++ b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts @@ -22,7 +22,7 @@ import type { IDirtyUnitSheetNameMap, INumfmtItemMap, IRuntimeOtherUnitDataType, - IRuntimeUnitDataType, + IRuntimeUnitDataPrimitiveType, } from '../../basics/common'; import type { FormulaExecutedStateType, IExecutionInProgressParams } from '../../services/runtime.service'; @@ -64,7 +64,7 @@ export const SetFormulaCalculationNotificationMutation: IMutation