Skip to content

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.

fix(selection): clean up empty cell styles in copyRangeStyles function (#6184)

WEI ZHANG16fa81a7da84
diff --git a/packages/sheets/src/commands/commands/utils/selection-utils.ts b/packages/sheets/src/commands/commands/utils/selection-utils.ts
index 16c3e76f24..43a14a32c5 100644
--- a/packages/sheets/src/commands/commands/utils/selection-utils.ts
+++ b/packages/sheets/src/commands/commands/utils/selection-utils.ts
@@ -18,7 +18,7 @@ import type { ICellData, IInterceptor, IObjectMatrixPrimitiveType, IRange, ISele
import type { ISelectionWithStyle } from '../../../basics/selection';
import type { ISetSelectionsOperationParams } from '../../operations/selection.operation';
-import { RANGE_TYPE, Rectangle, selectionToArray } from '@univerjs/core';
+import { RANGE_TYPE, Rectangle, selectionToArray, Tools } from '@univerjs/core';
import { IgnoreRangeThemeInterceptorKey, RangeThemeInterceptorId } from '../../../services/sheet-interceptor/interceptor-const';
import { SetSelectionsOperation } from '../../operations/selection.operation';
@@ -272,6 +272,24 @@ export function copyRangeStyles(
cellValue[row][column] = { s: cell.s };
}
}
+
+ for (const row in cellValue) {
+ for (const col in cellValue[row]) {
+ const cell = cellValue[row][col];
+ if (cell.s && typeof cell.s === 'object' && Tools.isEmptyObject(cell.s)) {
+ delete cell.s;
+ }
+
+ if (Tools.isEmptyObject(cell)) {
+ delete cellValue[row][col];
+ }
+ }
+
+ if (Tools.isEmptyObject(cellValue[row])) {
+ delete cellValue[row];
+ }
+ }
+
return cellValue;
}