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: fix the issue that the style ID of the copied worksheet could not be found in collaboration (#5977)
wpxp1234561ad38720bc8c
diff --git a/packages/core/src/sheets/styles.ts b/packages/core/src/sheets/styles.tsindex 54a4e42c73..33e85b9ddf 100644--- a/packages/core/src/sheets/styles.ts+++ b/packages/core/src/sheets/styles.ts@@ -86,7 +86,8 @@ export class Styles {return this.add(data, styleObject);}- addCustomStyle(id: string, data: IStyleData): void {+ addCustomStyle(id: string, data: Nullable<IStyleData>): void {+ if (data == null) return;this._styles[id] = data;this._cacheMap.set(JSON.stringify(data), id);}diff --git a/packages/core/src/sheets/workbook.ts b/packages/core/src/sheets/workbook.tsindex 644465c980..6861857be5 100644--- a/packages/core/src/sheets/workbook.ts+++ b/packages/core/src/sheets/workbook.ts@@ -198,7 +198,7 @@ export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.UNIVERreturn this._styles;}- addStyles(styles: Record<string, IStyleData>): void {+ addStyles(styles: Record<string, Nullable<IStyleData>>): void {Object.entries(styles).forEach(([id, data]) => {this._styles.addCustomStyle(id, data);});diff --git a/packages/sheets/src/basics/interfaces/mutation-interface.ts b/packages/sheets/src/basics/interfaces/mutation-interface.tsindex 3f9cc17a1b..d4bc050c9f 100644--- a/packages/sheets/src/basics/interfaces/mutation-interface.ts+++ b/packages/sheets/src/basics/interfaces/mutation-interface.ts@@ -22,6 +22,7 @@ import type {IObjectMatrixPrimitiveType,IRange,IRowData,+ IStyleData,IWorksheetData,Nullable,} from '@univerjs/core';@@ -38,6 +39,7 @@ export interface IInsertSheetMutationParams {index: number;sheet: IWorksheetData;unitId: string;+ styles?: Record<string, Nullable<IStyleData>>;}/** Params of InsertRowMutation */diff --git a/packages/sheets/src/commands/mutations/insert-sheet.mutation.ts b/packages/sheets/src/commands/mutations/insert-sheet.mutation.tsindex 1b1f08d973..c2aeb96988 100644--- a/packages/sheets/src/commands/mutations/insert-sheet.mutation.ts+++ b/packages/sheets/src/commands/mutations/insert-sheet.mutation.ts@@ -15,12 +15,11 @@*/import type { IAccessor, IMutation } from '@univerjs/core';-import { CommandType, IUniverInstanceService } from '@univerjs/core';-import type {IInsertSheetMutationParams,IRemoveSheetMutationParams,} from '../../basics/interfaces/mutation-interface';+import { CommandType, IUniverInstanceService } from '@univerjs/core';/*** Generate undo mutation of a `InsertSheetMutation`@@ -43,12 +42,17 @@ export const InsertSheetMutation: IMutation<IInsertSheetMutationParams, boolean>type: CommandType.MUTATION,handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const { sheet, index, unitId } = params;+ const { sheet, index, unitId, styles } = params;const workbook = univerInstanceService.getUniverSheetInstance(unitId);if (!workbook) {return false;}+ // If the mutation contains styles, it means that the mutation is from collaboration and its styles need to be added to the workbook.+ if (styles) {+ workbook.addStyles(styles);+ }+return workbook.addWorksheet(sheet.id, index, sheet);},};