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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(paste): fix copy and paste of data in pivot table rendering (#6693)
wpxp123456bd84cd37d3c7
diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.tsindex 50a043da84..797069f6e5 100644--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts@@ -455,6 +455,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardconst discreteRange: IDiscreteRange = { rows: [], cols: [] };const handleMatrixOnCellHook = copyHookType === PREDEFINED_HOOK_NAME_COPY.SPECIAL_COPY_FORMULA_ONLY ? hooks.find((h) => h.handleMatrixOnCell) : undefined;+ const getCellValueBySpecialMatrixHooks = hooks.filter((h) => h.getCellValueBySpecialMatrix);for (let r = startRow; r <= endRow; r++) {if (filteredRows.has(r)) {@@ -467,7 +468,10 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardcontinue;}- const cellData = matrix.getValue(r, c);+ const cellData = getCellValueBySpecialMatrixHooks.reduce<ICellDataWithSpanAndDisplay | undefined>(+ (acc, hook) => acc || hook.getCellValueBySpecialMatrix!(r, c),+ undefined+ ) || matrix.getValue(r, c);if (cellData) {const newCellData = cloneCellDataWithSpanAndDisplay(cellData)!;plainMatrix.setValue(rowIndex - startRow, c - startColumn, {@@ -679,7 +683,9 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardconst cellData = worksheet?.getCellRaw(actualRow, actualColumn);const style = worksheet?.getComposedCellStyleByCellData(actualRow, actualColumn, cellData);const newValue = cloneCellDataWithSpanInfo(value)!;- newValue.s = style;+ if (style && Object.keys(style).length > 0) {+ newValue.s = style;+ }cellMatrix.setValue(row, col, newValue);if (value.colSpan || value.rowSpan) {diff --git a/packages/sheets-ui/src/services/clipboard/type.ts b/packages/sheets-ui/src/services/clipboard/type.tsindex 6102b85876..eb61bdaa04 100644--- a/packages/sheets-ui/src/services/clipboard/type.ts+++ b/packages/sheets-ui/src/services/clipboard/type.ts@@ -265,6 +265,18 @@ export interface ISheetClipboardHook {matrixFragment: ObjectMatrix<ICellDataWithSpanInfo>,plainMatrix: ObjectMatrix<ICellDataWithSpanAndDisplay>): void;++ /**+ * If the hook is provided with `getCellValueBySpecialMatrix`, then should be used first to get cell value when copying.+ */+ getCellValueBySpecialMatrix?(+ row: number,+ column: number,+ options?: {+ unitId?: string;+ subUnitId?: string;+ }+ ): ICellDataWithSpanAndDisplay | undefined;}export interface ICopyOptions {