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: fix setRowCount setColumnCount command (#5028)

wpxp123456e0509790f5df
diff --git a/packages/sheets/src/commands/commands/set-worksheet-column-count.command.ts b/packages/sheets/src/commands/commands/set-worksheet-column-count.command.ts
index b9d8d63ee9..de47b2d82b 100644
--- a/packages/sheets/src/commands/commands/set-worksheet-column-count.command.ts
+++ b/packages/sheets/src/commands/commands/set-worksheet-column-count.command.ts
@@ -14,14 +14,13 @@
* limitations under the License.
*/
-import type { IAccessor, ICommand, Workbook } from '@univerjs/core';
+import type { IAccessor, ICommand } from '@univerjs/core';
import type { ISetWorksheetColumnCountMutationParams } from '../mutations/set-worksheet-column-count.mutation';
import {
CommandType,
ICommandService,
IUndoRedoService,
IUniverInstanceService,
- UniverInstanceType,
} from '@univerjs/core';
import { SetWorksheetColumnCountMutation, SetWorksheetColumnCountMutationFactory } from '../mutations/set-worksheet-column-count.mutation';
import { getSheetCommandTarget } from './utils/target-util';
@@ -37,15 +36,9 @@ export const SetWorksheetColumnCountCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
+ const target = getSheetCommandTarget(univerInstanceService, params);
if (!target) return false;
- const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
- if (!workbook) return false;
-
- const worksheet = workbook.getSheetBySheetId(subUnitId);
- if (!worksheet) return false;
-
const redoMutationParams: ISetWorksheetColumnCountMutationParams = {
unitId,
subUnitId,
diff --git a/packages/sheets/src/commands/commands/set-worksheet-row-count.command.ts b/packages/sheets/src/commands/commands/set-worksheet-row-count.command.ts
index 906666ffd5..9ed07600f6 100644
--- a/packages/sheets/src/commands/commands/set-worksheet-row-count.command.ts
+++ b/packages/sheets/src/commands/commands/set-worksheet-row-count.command.ts
@@ -14,14 +14,13 @@
* limitations under the License.
*/
-import type { IAccessor, ICommand, Workbook } from '@univerjs/core';
+import type { IAccessor, ICommand } from '@univerjs/core';
import type { ISetWorksheetRowCountMutationParams } from '../mutations/set-worksheet-row-count.mutation';
import {
CommandType,
ICommandService,
IUndoRedoService,
IUniverInstanceService,
- UniverInstanceType,
} from '@univerjs/core';
import { SetWorksheetRowCountMutation, SetWorksheetRowCountMutationFactory } from '../mutations/set-worksheet-row-count.mutation';
import { getSheetCommandTarget } from './utils/target-util';
@@ -37,15 +36,9 @@ export const SetWorksheetRowCountCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);
- const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
+ const target = getSheetCommandTarget(univerInstanceService, params);
if (!target) return false;
- const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
- if (!workbook) return false;
-
- const worksheet = workbook.getSheetBySheetId(subUnitId);
- if (!worksheet) return false;
-
const redoMutationParams: ISetWorksheetRowCountMutationParams = {
unitId,
subUnitId,
diff --git a/packages/sheets/src/commands/mutations/set-worksheet-column-count.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-column-count.mutation.ts
index 0d75d71aa5..399b2ffa1c 100644
--- a/packages/sheets/src/commands/mutations/set-worksheet-column-count.mutation.ts
+++ b/packages/sheets/src/commands/mutations/set-worksheet-column-count.mutation.ts
@@ -33,11 +33,10 @@ export const SetWorksheetColumnCountMutationFactory = (
throw new Error('[SetWorksheetColumnCountMutationFactory]: worksheet is null error!');
}
- const { worksheet } = target;
return {
unitId: params.unitId,
- subUnitId: worksheet.getSheetId(),
- columnCount: worksheet.getColumnCount(),
+ subUnitId: params.subUnitId,
+ columnCount: target.worksheet.getColumnCount(),
};
};
@@ -45,21 +44,11 @@ export const SetWorksheetColumnCountMutation: IMutation<ISetWorksheetColumnCount
id: 'sheet.mutation.set-worksheet-column-count',
type: CommandType.MUTATION,
handler: (accessor, params) => {
- const { unitId, subUnitId, columnCount } = params;
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const target = getSheetMutationTarget(univerInstanceService, params);
+ if (!target) return false;
- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(unitId);
-
- if (!workbook) {
- return false;
- }
-
- const worksheet = workbook.getSheetBySheetId(subUnitId);
-
- if (!worksheet) {
- return false;
- }
-
- worksheet.setColumnCount(columnCount);
+ target.worksheet.setColumnCount(params.columnCount);
return true;
},
diff --git a/packages/sheets/src/commands/mutations/set-worksheet-row-count.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-row-count.mutation.ts
index e82cd89b6e..a01b47d574 100644
--- a/packages/sheets/src/commands/mutations/set-worksheet-row-count.mutation.ts
+++ b/packages/sheets/src/commands/mutations/set-worksheet-row-count.mutation.ts
@@ -33,11 +33,10 @@ export const SetWorksheetRowCountMutationFactory = (
throw new Error('[SetWorksheetRowCountMutationFactory]: worksheet is null error!');
}
- const { worksheet } = target;
return {
unitId: params.unitId,
- subUnitId: worksheet.getSheetId(),
- rowCount: worksheet.getRowCount(),
+ subUnitId: params.subUnitId,
+ rowCount: target.worksheet.getRowCount(),
};
};
@@ -45,21 +44,11 @@ export const SetWorksheetRowCountMutation: IMutation<ISetWorksheetRowCountMutati
id: 'sheet.mutation.set-worksheet-row-count',
type: CommandType.MUTATION,
handler: (accessor, params) => {
- const { unitId, subUnitId, rowCount } = params;
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const target = getSheetMutationTarget(univerInstanceService, params);
+ if (!target) return false;
- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(unitId);
-
- if (!workbook) {
- return false;
- }
-
- const worksheet = workbook.getSheetBySheetId(subUnitId);
-
- if (!worksheet) {
- return false;
- }
-
- worksheet.setRowCount(rowCount);
+ target.worksheet.setRowCount(params.rowCount);
return true;
},