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(formula): fix formula calculation errors caused by setting the worksheet rows and columns count (#6668)

wpxp1234561f4b5aeb774c
diff --git a/packages/sheets/src/controllers/basic-worksheet.controller.ts b/packages/sheets/src/controllers/basic-worksheet.controller.ts
index 545cf9e4c2..3efda32d95 100644
--- a/packages/sheets/src/controllers/basic-worksheet.controller.ts
+++ b/packages/sheets/src/controllers/basic-worksheet.controller.ts
@@ -190,6 +190,11 @@ export class BasicWorksheetController extends Disposable implements IDisposable
) {
super();
+ /**
+ * Mutations that effect formula calculation should be registered here.
+ * Because these mutations should be synced to the worker (if the worker is enabled) to trigger the formula recalculation.
+ * SetWorksheetRowCountMutation and SetWorksheetColumnCountMutation effect reference node generation, so they should also be registered here to avoid generating incorrect reference nodes in the worker.
+ */
([
SetRangeValuesMutation,
InsertColMutation,
@@ -215,11 +220,18 @@ export class BasicWorksheetController extends Disposable implements IDisposable
MarkDirtyRowAutoHeightMutation,
CancelMarkDirtyRowAutoHeightMutation,
CopyWorksheetEndMutation,
+
+ SetWorksheetRowCountMutation,
+ SetWorksheetColumnCountMutation,
] as IMutation<object>[]).forEach((mutation) => {
this._commandService.registerCommand(mutation);
this._dataSyncPrimaryController?.registerSyncingMutations(mutation);
});
+ /**
+ * Worker do not need to know about the mutations that do not effect formula calculation, so set the config to true in the worker.
+ * Default is false, which means all mutations should be registered, so the main thread do not need to care about the config and just register all mutations.
+ */
const onlyRegisterFormulaRelatedMutations = this._configService.getConfig(ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY) ?? false;
if (!onlyRegisterFormulaRelatedMutations) {
[
@@ -314,9 +326,7 @@ export class BasicWorksheetController extends Disposable implements IDisposable
// SetWorksheetColIsAutoWidthCommand,
SetWorksheetRowCountCommand,
- SetWorksheetRowCountMutation,
SetWorksheetColumnCountCommand,
- SetWorksheetColumnCountMutation,
SelectRangeCommand,
SetSelectionsOperation,