fix(paste): fix the style error when copying cells with conditional formatting, data validation, number formatting, etc. (#6326)

This commit is contained in:
wpxp123456
2025-12-17 16:03:09 +08:00
committed by GitHub
parent 5eef953855
commit 15456740cf
2 changed files with 10 additions and 2 deletions
@@ -261,7 +261,10 @@ export class SheetClipboardController extends RxDisposable {
}
const mergedCellByRowCol = currentSheet!.getMergedCell(row, col);
/**
* This is for generating the copied HTML, which requires all the styles applied to the cell, including conditional formatting, data validation, number format, etc.
* So here we use `getComposedCellStyle` to get the final style of the cell.
*/
const textStyle = currentSheet!.getComposedCellStyle(row, col);
let style = '';
@@ -665,7 +665,12 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
const cellMatrix = new ObjectMatrix<ICellDataWithSpanInfo>();
cachedMatrix.forValue((row, col, value) => {
const { row: actualRow, col: actualColumn } = mapFunc(row, col);
const style = worksheet?.getComposedCellStyle(actualRow, actualColumn);
/**
* This only needs to include a combination of default styles, row and column styles, and cell styles.
* Conditional formatting, data validation, and number format are not included here because they will be applied automatically after pasting.
* So here we use `getComposedCellStyleByCellData` to get the final style of the cell raw data.
*/
const style = worksheet?.getComposedCellStyleByCellData(actualRow, actualColumn, value);
const newValue = cloneCellDataWithSpanInfo(value)!;
newValue.s = style;
cellMatrix.setValue(row, col, newValue);