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(formula): use different isNullCell for formula modules (#4395)
Wenzhao Hu72e81922a0ec
diff --git a/packages/core/src/sheets/typedef.ts b/packages/core/src/sheets/typedef.tsindex c087e43322..b74381ee69 100644--- a/packages/core/src/sheets/typedef.ts+++ b/packages/core/src/sheets/typedef.ts@@ -328,7 +328,7 @@ export function isNullCell(cell: Nullable<ICellData>) {return true;}- const { v, f, si, p, s, custom } = cell;+ const { v, f, si, p, custom } = cell;if (!(v == null || (typeof v === 'string' && v.length === 0))) {return false;diff --git a/packages/engine-formula/src/basics/is-null-cell.ts b/packages/engine-formula/src/basics/is-null-cell.tsnew file mode 100644index 0000000000..a853428aa2--- /dev/null+++ b/packages/engine-formula/src/basics/is-null-cell.ts@@ -0,0 +1,45 @@+/**+ * 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 { ICellData, Nullable } from '@univerjs/core';++/**+ * Examine if a cell is empty (null) in the formula-related modules. This is not+ * interchangable with {@link isNullCell} from the core package, because for+ * formulas, "custom" field is meaningless.+ */+export function isNullCellForFormula(cell: Nullable<ICellData>) {+ if (cell == null) {+ return true;+ }++ const { v, f, si, p } = cell;++ if (!(v == null || (typeof v === 'string' && v.length === 0))) {+ return false;+ }++ if ((f != null && f.length > 0) || (si != null && si.length > 0)) {+ return false;+ }++ if (p != null) {+ return false;+ }++ return true;+}+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 bc0ff7b63e..88008592f5 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@@ -17,9 +17,10 @@import type { ICellData, IRange, Nullable } from '@univerjs/core';import type { IRuntimeUnitDataType, IUnitData, IUnitSheetNameMap, IUnitStylesData } from '../../basics/common';-import { CellValueType, isNullCell, moveRangeByOffset } from '@univerjs/core';+import { CellValueType, moveRangeByOffset } from '@univerjs/core';import { FormulaAstLRU } from '../../basics/cache-lru';import { ERROR_TYPE_SET, ErrorType } from '../../basics/error-type';+import { isNullCellForFormula } from '../../basics/is-null-cell';import { ObjectClassType } from '../../basics/object-class-type';import { getCellValue } from '../utils/cell';import { getRuntimeFeatureCell } from '../utils/get-runtime-feature-cell';@@ -167,7 +168,7 @@ export class BaseReferenceObject extends ObjectClassType {const cell = this.getCellData(r, c)!;let result: Nullable<boolean> = false;- if (isNullCell(cell)) {+ if (isNullCellForFormula(cell)) {result = callback(null, r, c);continue;}diff --git a/packages/engine-formula/src/services/runtime.service.ts b/packages/engine-formula/src/services/runtime.service.tsindex 806487e20e..75314dceeb 100644--- a/packages/engine-formula/src/services/runtime.service.ts+++ b/packages/engine-formula/src/services/runtime.service.ts@@ -21,16 +21,14 @@ import type {IRuntimeOtherUnitDataType,IRuntimeUnitDataType,} from '../basics/common';-import type { BaseAstNode } from '../engine/ast-node/base-ast-node';import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';import type { ArrayValueObject } from '../engine/value-object/array-value-object';-import { createIdentifier, Disposable, isNullCell, ObjectMatrix } from '@univerjs/core';+import { createIdentifier, Disposable, ObjectMatrix } from '@univerjs/core';import { isInDirtyRange } from '../basics/dirty';import { ErrorType } from '../basics/error-type';-+import { isNullCellForFormula } from '../basics/is-null-cell';import { getRuntimeFeatureCell } from '../engine/utils/get-runtime-feature-cell';-import { clearNumberFormatTypeCache, clearStringToNumberPatternCache } from '../engine/utils/numfmt-kit';import { clearReferenceToRangeCache } from '../engine/utils/reference-cache';import { objectValueToCellValue } from '../engine/utils/value-object';@@ -700,10 +698,10 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime// arrayDataCell may display 0 as {v: null}. Although it is an empty cell, it is considered to have a value.if (- !isNullCell(cell) ||+ !isNullCellForFormula(cell) ||this._isInOtherArrayFormulaRange(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, r, c) ||- !isNullCell(currentCell) ||- !isNullCell(featureCell)+ !isNullCellForFormula(currentCell) ||+ !isNullCellForFormula(featureCell)) {return true;}