diff --git a/packages/core/src/sheets/worksheet.ts b/packages/core/src/sheets/worksheet.ts index 5f30ac47346..01c74f6bd9f 100644 --- a/packages/core/src/sheets/worksheet.ts +++ b/packages/core/src/sheets/worksheet.ts @@ -214,6 +214,24 @@ export class Worksheet { return this._styles.get(style); } + /** + * Get the default style for cell. + * @param {number} row The row index. + * @param {number} col The column index. + * @param {boolean} [isRowStylePrecedeColumnStyle] The priority of row style and column style + * @returns {Nullable} The default style for cell + */ + getCellDefaultStyle(row: number, col: number, isRowStylePrecedeColumnStyle?: boolean): Nullable { + const columnStyle = this.getColumnStyle(col) as Nullable; + const rowStyle = this.getRowStyle(row) as Nullable; + const defaultStyle = this.getDefaultCellStyleInternal(); + if (isRowStylePrecedeColumnStyle) { + return composeStyles(defaultStyle, rowStyle, columnStyle); + } else { + return composeStyles(defaultStyle, columnStyle, rowStyle); + } + } + /** * Set Default Style, if the style has been set, all cells style will be base on this style. * @param {Nullable} style The style to be set as default style diff --git a/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts b/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts index fab46348687..5feb367b535 100644 --- a/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts +++ b/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts @@ -84,6 +84,7 @@ interface ICellDocumentModelOption { isDeepClone?: boolean; displayRawFormula?: boolean; ignoreTextRotation?: boolean; + cellDefaultStyle?: Nullable; } const DEFAULT_CELL_DOCUMENT_MODEL_OPTION: ICellDocumentModelOption = { @@ -849,11 +850,12 @@ export class SpreadsheetSkeleton extends SheetSkeleton { * @deprecated use same method in worksheet. * @param cell */ - getCellDocumentModelWithFormula(cell: ICellData): Nullable { + getCellDocumentModelWithFormula(cell: ICellData, cellDefaultStyle: Nullable): Nullable { return this._getCellDocumentModel(cell, { isDeepClone: true, displayRawFormula: true, ignoreTextRotation: true, + cellDefaultStyle, }); } @@ -876,7 +878,7 @@ export class SpreadsheetSkeleton extends SheetSkeleton { ...options, }; - const style = this._styles.getStyleByCell(cell); + const style = { ...options.cellDefaultStyle, ...this._styles.getStyleByCell(cell) }; if (!cell) return; diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.ts index 6604909b668..24a8ea48641 100644 --- a/packages/sheets-ui/src/services/editor-bridge.service.ts +++ b/packages/sheets-ui/src/services/editor-bridge.service.ts @@ -355,8 +355,9 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ worksheet.getCell(startRow, startColumn), location ); + const cellDefaultStyle = worksheet.getCellDefaultStyle(startRow, startColumn, skeleton.isRowStylePrecedeColumnStyle); - documentLayoutObject = cell && skeleton.getCellDocumentModelWithFormula(cell); + documentLayoutObject = cell && skeleton.getCellDocumentModelWithFormula(cell, cellDefaultStyle); // Rewrite the cellValueType to STRING to avoid render the value on the right side when number type. const renderConfig = documentLayoutObject?.documentModel?.documentStyle.renderConfig;