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: clear array formula (#6159)

Dushusirc3d52d2b7c31
diff --git a/packages/sheets-formula/src/controllers/utils/__tests__/ref-range-formula.spec.ts b/packages/sheets-formula/src/controllers/utils/__tests__/ref-range-formula.spec.ts
index 0d867a6634..3d54932524 100644
--- a/packages/sheets-formula/src/controllers/utils/__tests__/ref-range-formula.spec.ts
+++ b/packages/sheets-formula/src/controllers/utils/__tests__/ref-range-formula.spec.ts
@@ -112,6 +112,7 @@ describe('Ref range formula test', () => {
x: 0,
y: 1,
},
+ 3: null,
},
};
@@ -129,6 +130,7 @@ describe('Ref range formula test', () => {
f: null,
si: 'id2',
},
+ 3: null,
},
};
expect(formulaDataToCellData(formulaData)).toStrictEqual(cellData);
diff --git a/packages/sheets-formula/src/controllers/utils/ref-range-formula.ts b/packages/sheets-formula/src/controllers/utils/ref-range-formula.ts
index e75f536141..4303b7f01c 100644
--- a/packages/sheets-formula/src/controllers/utils/ref-range-formula.ts
+++ b/packages/sheets-formula/src/controllers/utils/ref-range-formula.ts
@@ -590,7 +590,8 @@ function getUndoFormulaData(rangeList: IRangeChange[], oldFormulaMatrix: ObjectM
*/
export function formulaDataItemToCellData(formulaDataItem: Nullable<IFormulaDataItem>): Nullable<ICellData> {
if (formulaDataItem == null) {
- return;
+ // null presents clearing cell content
+ return null;
}
const { f, si, x = 0, y = 0 } = formulaDataItem;
const checkFormulaString = isFormulaString(f);
@@ -637,7 +638,8 @@ export function formulaDataToCellData(formulaData: IObjectMatrixPrimitiveType<IF
const cellDataItem = formulaDataItemToCellData(formulaDataItem);
// Originally matrix clone would filter out undefined, but after changing to getMatrix, you need to filter manually here
- if (!cellDataItem) {
+ // Filter out meaningless undefined, but consider null meaningful because null represents clearing cell content
+ if (cellDataItem === undefined) {
return;
}