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): null value return not zero (#1851)
Univer87d8e207c97b
diff --git a/packages/engine-formula/src/services/runtime.service.ts b/packages/engine-formula/src/services/runtime.service.tsindex ab7cdbaff9..fd9d148cac 100644--- a/packages/engine-formula/src/services/runtime.service.ts+++ b/packages/engine-formula/src/services/runtime.service.ts@@ -642,8 +642,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeprivate _objectValueToCellValue(objectValue: Nullable<BaseValueObject>) {if (objectValue == null) {return {- v: 0,- t: CellValueType.NUMBER,+ v: null,};}if (objectValue.isError()) {diff --git a/packages/sheets-formula/src/controllers/array-formula-display.controller.ts b/packages/sheets-formula/src/controllers/array-formula-display.controller.tsindex 90b6dc022d..a5a0f0caa4 100644--- a/packages/sheets-formula/src/controllers/array-formula-display.controller.ts+++ b/packages/sheets-formula/src/controllers/array-formula-display.controller.ts@@ -111,6 +111,14 @@ export class ArrayFormulaDisplayController extends Disposable {};}+ if (cellData.v == null && cellData.t == null) {+ return next({ ...cell,+ ...cellData,+ v: 0,+ t: CellValueType.NUMBER,+ });+ }+return next({ ...cell, ...cellData });},})diff --git a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts b/packages/sheets-formula/src/controllers/formula-editor-show.controller.tsindex 73abb83fbf..5d9b4af700 100644--- a/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts+++ b/packages/sheets-formula/src/controllers/formula-editor-show.controller.ts@@ -16,6 +16,7 @@import type { ICellDataForSheetInterceptor, ICommandInfo, IRange, Nullable } from '@univerjs/core';import {+ CellValueType,ColorKit,Disposable,ICommandService,@@ -133,7 +134,7 @@ export class FormulaEditorShowController extends Disposable {arrayFormulaMatrixCell[unitId]?.[subUnitId]?.[row]?.[col] == null) {if (cellInfo) {- return cellInfo;+ return { ...value, ...cellInfo };}return next(value);@@ -185,7 +186,7 @@ export class FormulaEditorShowController extends Disposable {}if (cellInfo) {- return cellInfo;+ return { ...value, ...cellInfo };}return next(value);@@ -200,14 +201,21 @@ export class FormulaEditorShowController extends Disposable {this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {handler: (cell, location, next) => {- const { row, col, unitId, subUnitId } = location;+ // const { row, col, unitId, subUnitId } = location;- const arrayFormulaMatrixCell = this._formulaDataModel.getArrayFormulaCellData();+ // const arrayFormulaMatrixCell = this._formulaDataModel.getArrayFormulaCellData();- const arrayValue = arrayFormulaMatrixCell?.[unitId]?.[subUnitId]?.[row]?.[col];+ // const arrayValue = arrayFormulaMatrixCell?.[unitId]?.[subUnitId]?.[row]?.[col];- if (arrayValue) {- return next({ ...cell, ...arrayValue });+ // if (arrayValue) {+ // return next({ ...cell, ...arrayValue });+ // }++ if (cell && cell.v == null && cell.t == null && cell.f != null) {+ return next({ ...cell,+ v: 0,+ t: CellValueType.NUMBER,+ });}return next(cell);