fix(editor): fix the issue of incorrect cell styles after editing (#6435)

This commit is contained in:
wpxp123456
2026-01-07 20:18:26 +08:00
committed by GitHub
parent 8e4165d998
commit 84dbabbab4
2 changed files with 30 additions and 2 deletions
+29 -1
View File
@@ -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<DocumentDataModel>;
@@ -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<ICellDataForSheetInterceptor>} [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<ICellDataForSheetInterceptor>, 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
@@ -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)))) {