From 84dbabbab4c59de95fa90f104afb338fd6ddf5ab Mon Sep 17 00:00:00 2001 From: wpxp123456 <2677556700@qq.com> Date: Wed, 7 Jan 2026 20:18:26 +0800 Subject: [PATCH] fix(editor): fix the issue of incorrect cell styles after editing (#6435) --- packages/core/src/sheets/worksheet.ts | 30 ++++++++++++++++++- .../editor/editing.render-controller.ts | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/core/src/sheets/worksheet.ts b/packages/core/src/sheets/worksheet.ts index 28983b40cc..adfa753953 100644 --- a/packages/core/src/sheets/worksheet.ts +++ b/packages/core/src/sheets/worksheet.ts @@ -28,6 +28,7 @@ import { createRowColIter } from '../shared/row-col-iter'; import { generateRandomId } from '../shared/tools'; import { DEFAULT_STYLES } from '../types/const'; import { CellValueType } from '../types/enum'; +import { cloneWorksheetData } from './clone'; import { ColumnManager } from './column-manager'; import { Range } from './range'; import { RowManager } from './row-manager'; @@ -36,7 +37,6 @@ import { SpanModel } from './span-model'; import { CellModeEnum } from './typedef'; import { addLinkToDocumentModel, createDocumentModelWithStyle, DEFAULT_PADDING_DATA, extractOtherStyle, getFontFormat, isNotNullOrUndefined } from './util'; import { SheetViewModel } from './view-model'; -import { cloneWorksheetData } from './clone'; export interface IDocumentLayoutObject { documentModel: Nullable; @@ -290,6 +290,34 @@ export class Worksheet { : composeStyles(defaultStyle, rowStyle, colStyle, cellData?.themeStyle, cellStyle); } + /** + * Get the composed style of the cell without its own style. + * @param {number} row The row index of the cell + * @param {number} col The column index of the cell + * @param {Nullable} [cellData] The cell data of the cell. + * @param {boolean} [rowPriority] If true, row style will precede column style, otherwise use this._isRowStylePrecedeColumnStyle + * @returns {IStyleData} The composed style of the cell without its own style + */ + getComposedCellStyleWithoutSelf(row: number, col: number, cellData?: Nullable, rowPriority?: boolean): IStyleData { + const composedCellStyle = cellData === undefined + ? this.getComposedCellStyle(row, col, rowPriority) + : this.getComposedCellStyleByCellData(row, col, cellData, rowPriority); + + const cellDataRaw = this.getCellRaw(row, col); + if (!cellDataRaw || !cellDataRaw.s) return composedCellStyle; + + const style = typeof cellDataRaw.s === 'string' ? this._styles.get(cellDataRaw.s) : cellDataRaw.s; + if (!style) return composedCellStyle; + + for (const key in style) { + if (key in composedCellStyle) { + delete composedCellStyle[key as keyof IStyleData]; + } + } + + return composedCellStyle; + } + /** * Returns WorkSheet Cell Data Matrix * @returns WorkSheet Cell Data Matrix diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts index 26d306cb7f..f942e9f597 100644 --- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts +++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts @@ -627,7 +627,7 @@ export class EditingRenderController extends Disposable { } // Remove the same style attributes that have been set by composed style in the cell data. - this._removeComposedCellStyleInCellData(cellData, worksheet.getComposedCellStyle(row, column)); + this._removeComposedCellStyleInCellData(cellData, worksheet.getComposedCellStyleWithoutSelf(row, column)); const finalCell = this._sheetInterceptorService.onWriteCell(workbook, worksheet, row, column, cellData) as ICellData; if (Tools.diffValue(cleanCellDataObject(finalCell), cleanCellDataObject(worksheet.getCellRaw(row, column)))) {