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.

chore(example): run d locale english error

Dushusir73295955a7b3
diff --git a/examples/univer-vanilla-ts/src/main.tsx b/examples/univer-vanilla-ts/src/main.tsx
index fb897806d6..d5f20fc0e4 100644
--- a/examples/univer-vanilla-ts/src/main.tsx
+++ b/examples/univer-vanilla-ts/src/main.tsx
@@ -62,7 +62,12 @@ const univerSheetDown = UniverSheet.newInstance();
univerSheetDown.installPlugin(new RenderEngine());
univerSheetDown.installPlugin(new UniverComponentSheet());
-univerSheetDown.installPlugin(new SheetPlugin());
+univerSheetDown.installPlugin(
+ new SheetPlugin({
+ container: 'universheet-demo-down',
+ })
+);
+univerSheetDown.installPlugin(new BaseComponentPlugin());
univerSheetDown.installPlugin(new NumfmtPlugin());
FormulaPlugin.create().installTo(univerSheetDown);
diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
index 3563dc31c6..f44eabe194 100644
--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
@@ -4,13 +4,11 @@ import {
BaseActionExtension,
BaseActionExtensionFactory,
Command,
- ICellData,
ISetRangeDataActionData,
isFormulaString,
ISheetActionData,
IUnitRange,
ObjectMatrix,
- ObjectMatrixPrimitiveType,
Tools,
} from '@univer/core';
import { FormulaPlugin } from '../../FormulaPlugin';
@@ -24,7 +22,6 @@ export class FormulaActionExtension extends BaseActionExtension<ISetRangeDataAct
const formulaData = Tools.deepClone(formulaDataModel.getFormulaData());
const unitId = this._plugin.getContext().getWorkBook().getUnitId();
const sheetId = this.actionData.sheetId;
- const rangeData = this.actionData.rangeData;
const commandManager = this._plugin.getContext().getCommandManager();
const workBook = this._plugin.getContext().getWorkBook();
@@ -39,27 +36,10 @@ export class FormulaActionExtension extends BaseActionExtension<ISetRangeDataAct
return;
}
- // a range TODO api will trigger here
- if (!isNaN(parseInt(Object.keys(cellValue)[0]))) {
- const rangeMatrix = new ObjectMatrix(cellValue as ObjectMatrixPrimitiveType<ICellData>);
-
- // update formula string
- rangeMatrix.forValue((r, c, cell) => {
- const formulaString = cell.m;
- if (isFormulaString(formulaString)) {
- cellData.setValue(r, c, {
- formula: formulaString,
- row: r,
- column: c,
- sheetId,
- });
- }
- });
- }
- // a cell
- else {
- const { startRow: r, startColumn: c } = rangeData;
- let cell: ICellData = cellValue;
+ const rangeMatrix = new ObjectMatrix(cellValue);
+
+ // update formula string
+ rangeMatrix.forValue((r, c, cell) => {
const formulaString = cell.m;
if (isFormulaString(formulaString)) {
cellData.setValue(r, c, {
@@ -69,58 +49,66 @@ export class FormulaActionExtension extends BaseActionExtension<ISetRangeDataAct
sheetId,
});
}
- const unitRange: IUnitRange[] = [
- {
- unitId,
- sheetId,
- rangeData,
- },
- ];
-
- // cell.v = 55;
- // cell.t = 1;
-
- engine.execute(unitId, formulaData, formulaController.toInterpreterCalculateProps(), false, unitRange).then((data) => {
- const { sheetData, arrayFormulaData } = data;
- const sheetIds = Object.keys(sheetData);
- sheetIds.forEach((sheetId) => {
- const cellData = sheetData[sheetId];
- cellData.forValue((r, c, value) => {});
- });
-
- //下面是错误的逻辑
- const cellCalculate = sheetData[sheetId].getValue(r, c) as ICellData;
+ });
+
+ const unitRange: IUnitRange[] = [
+ {
+ unitId,
+ sheetId,
+ rangeData: rangeMatrix.getDataRange(),
+ },
+ ];
+
+ engine.execute(unitId, formulaData, formulaController.toInterpreterCalculateProps(), false, unitRange).then((data) => {
+ const { sheetData, arrayFormulaData } = data;
+
+ if (!sheetData) {
+ console.error('No sheetData from Formula Engine!');
+ return;
+ }
+ const sheetIds = Object.keys(sheetData);
+
+ // Update each calculated value, possibly involving all cells
+ const actionDatas: ISetRangeDataActionData[] = [];
+ sheetIds.forEach((sheetId) => {
+ const cellData = sheetData[sheetId];
+ cellData.forValue((r, c, value) => {
+ const cellCalculate = cellData.getValue(r, c);
+
+ // cell.v = cellCalculate?.v;
+ // cell.t = cellCalculate?.t;
+ if (cellCalculate && cellCalculate.p) {
+ delete cellCalculate.p;
+ }
+
+ if (cellCalculate && Number.isNaN(cellCalculate.v)) {
+ cellCalculate.v = 0;
+ }
+
+ const action = {
+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
+ sheetId,
+ cellValue: {
+ [r]: {
+ [c]: cellCalculate || {},
+ },
+ },
+ };
- // cell.v = cellCalculate?.v;
- // cell.t = cellCalculate?.t;
- if (cellCalculate && cellCalculate.p) {
- delete cellCalculate.p;
- }
+ const actionData = ActionOperation.make<ISetRangeDataActionData>(action).removeCollaboration().removeUndo().removeExtension().getAction();
+ actionDatas.push(actionData);
+ });
+ });
- if (cellCalculate && Number.isNaN(cellCalculate.v)) {
- cellCalculate.v = 0;
- }
+ const setFormulaDataAction = {
+ actionName: PLUGIN_ACTION_NAMES.SET_FORMULA_RANGE_DATA_ACTION,
+ sheetId: this.actionData.sheetId,
+ formulaData,
+ };
- const action: ISetRangeDataActionData = {
- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
- sheetId,
- cellValue: {
- [r]: {
- [c]: cellCalculate,
- },
- },
- };
-
- const setFormulaDataAction = {
- actionName: PLUGIN_ACTION_NAMES.SET_FORMULA_RANGE_DATA_ACTION,
- sheetId: this.actionData.sheetId,
- formulaData,
- };
- const actionData = ActionOperation.make<ISetRangeDataActionData>(action).removeCollaboration().removeUndo().getAction();
- const command = new Command({ WorkBookUnit: workBook }, actionData, setFormulaDataAction);
- commandManager.invoke(command);
- });
- }
+ const command = new Command({ WorkBookUnit: workBook }, ...actionDatas, setFormulaDataAction);
+ commandManager.invoke(command);
+ });
}
}
diff --git a/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts b/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts
index 2a1bbb22f1..1252e60d5f 100644
--- a/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts
+++ b/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts
@@ -14,6 +14,11 @@ export function firstLoader(formulaController: FormulaController) {
sheetDataPromise.then((data) => {
if (!data) return;
const { sheetData, arrayFormulaData } = data;
+
+ if (!sheetData) {
+ return;
+ }
+
const sheetIds = Object.keys(sheetData);
const actionList: ISetRangeDataActionData[] = [];
@@ -32,7 +37,7 @@ export function firstLoader(formulaController: FormulaController) {
},
};
- actionList.push(ActionOperation.make<ISetRangeDataActionData>(action).removeCollaboration().removeUndo().getAction());
+ actionList.push(ActionOperation.make<ISetRangeDataActionData>(action).removeCollaboration().removeUndo().removeExtension().getAction());
});
}