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(sheet): fix some copy/paste bugs (#1754)

ybzky496dcb8c2f68
diff --git a/packages/core/src/shared/clipboard.ts b/packages/core/src/shared/clipboard.ts
new file mode 100644
index 0000000000..e2f616b37e
--- /dev/null
+++ b/packages/core/src/shared/clipboard.ts
@@ -0,0 +1,166 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { BaselineOffset, BooleanNumber } from '../types/enum';
+import type { IDocumentBody, ITextRun } from '../types/interfaces';
+import { Tools } from './tools';
+
+export function getBodySliceHtml(body: IDocumentBody, startIndex: number, endIndex: number) {
+ const { dataStream, textRuns = [] } = body;
+ let cursorIndex = startIndex;
+ const spanList: string[] = [];
+
+ for (const textRun of textRuns) {
+ const { st, ed } = textRun;
+ if (Tools.hasIntersectionBetweenTwoRanges(startIndex, endIndex, st, ed)) {
+ if (st > cursorIndex) {
+ spanList.push(dataStream.slice(cursorIndex, st));
+
+ spanList.push(covertTextRunToHtml(dataStream, {
+ ...textRun,
+ ed: Math.min(ed, endIndex),
+ }));
+ } else {
+ spanList.push(covertTextRunToHtml(dataStream, {
+ ...textRun,
+ st: cursorIndex,
+ ed: Math.min(ed, endIndex),
+ }));
+ }
+ }
+
+ cursorIndex = Math.max(startIndex, Math.min(ed, endIndex));
+ }
+
+ if (cursorIndex !== endIndex) {
+ spanList.push(dataStream.slice(cursorIndex, endIndex));
+ }
+
+ return spanList.join('');
+}
+
+export function convertBodyToHtml(body: IDocumentBody, withParagraphInfo: boolean = true): string {
+ if (withParagraphInfo && body.paragraphs?.length) {
+ const { dataStream, paragraphs = [] } = body;
+ let result = '';
+ let cursorIndex = -1;
+ for (const paragraph of paragraphs) {
+ const { startIndex, paragraphStyle = {} } = paragraph;
+ const { spaceAbove, spaceBelow, lineSpacing } = paragraphStyle;
+ const style = [];
+
+ if (spaceAbove != null) {
+ if (typeof spaceAbove === 'number') {
+ style.push(`margin-top: ${spaceAbove}px`);
+ } else {
+ style.push(`margin-top: ${spaceAbove.v}px`);
+ }
+ }
+
+ if (spaceBelow != null) {
+ if (typeof spaceBelow === 'number') {
+ style.push(`margin-bottom: ${spaceBelow}px`);
+ } else {
+ style.push(`margin-bottom: ${spaceBelow.v}px`);
+ }
+ }
+
+ if (lineSpacing != null) {
+ style.push(`line-height: ${lineSpacing}`);
+ }
+
+ if (startIndex > cursorIndex + 1) {
+ result += `<p class="UniverNormal" ${style.length ? `style="${style.join('; ')};"` : ''
+ }>${getBodySliceHtml(body, cursorIndex + 1, startIndex)}</p>`;
+ } else {
+ result += `<p class="UniverNormal" ${style.length ? `style="${style.join('; ')};"` : ''
+ }></p>`;
+ }
+
+ cursorIndex = startIndex;
+ }
+
+ if (cursorIndex !== dataStream.length) {
+ result += getBodySliceHtml(body, cursorIndex, dataStream.length);
+ }
+
+ return result;
+ } else {
+ return getBodySliceHtml(body, 0, body.dataStream.length);
+ }
+}
+
+export function covertTextRunToHtml(dataStream: string, textRun: ITextRun): string {
+ const { st: start, ed, ts = {} } = textRun;
+ const { ff, fs, it, bl, ul, st, ol, bg, cl, va } = ts;
+
+ let html = dataStream.slice(start, ed);
+ const style: string[] = [];
+
+ // italic
+ if (it === BooleanNumber.TRUE) {
+ html = `<i>${html}</i>`;
+ }
+
+ // subscript and superscript
+ if (va === BaselineOffset.SUPERSCRIPT) {
+ html = `<sup>${html}</sup>`;
+ } else if (va === BaselineOffset.SUBSCRIPT) {
+ html = `<sub>${html}</sub>`;
+ }
+
+ // underline
+ if (ul?.s === BooleanNumber.TRUE) {
+ html = `<u>${html}</u>`;
+ }
+
+ // strick-through
+ if (st?.s === BooleanNumber.TRUE) {
+ html = `<s>${html}</s>`;
+ }
+
+ // bold
+ if (bl === BooleanNumber.TRUE) {
+ html = `<strong>${html}</strong>`;
+ }
+
+ // font family
+ if (ff) {
+ style.push(`font-family: ${ff}`);
+ }
+
+ // font color
+ if (cl) {
+ style.push(`color: ${cl.rgb}`);
+ }
+
+ // font size
+ if (fs) {
+ style.push(`font-size: ${fs}pt`);
+ }
+
+ // overline
+ if (ol) {
+ style.push('text-decoration: overline');
+ }
+
+ // background color
+ if (bg) {
+ style.push(`background: ${bg.rgb}`);
+ }
+
+ return style.length ? `<span style="${style.join('; ')};">${html}</span>` : html;
+}
diff --git a/packages/core/src/shared/common.ts b/packages/core/src/shared/common.ts
index 2763198510..84776b1080 100644
--- a/packages/core/src/shared/common.ts
+++ b/packages/core/src/shared/common.ts
@@ -508,6 +508,8 @@ export function getBorderStyleType(type: string) {
str = BorderStyleTypes.MEDIUM_DASH_DOT_DOT;
} else if (type === '1.5pt solid') {
str = BorderStyleTypes.THICK;
+ } else if (!type.includes('none')) {
+ str = BorderStyleTypes.THIN;
} else {
return BorderStyleTypes.NONE;
}
diff --git a/packages/core/src/shared/index.ts b/packages/core/src/shared/index.ts
index 6817c4b888..12e85c184c 100644
--- a/packages/core/src/shared/index.ts
+++ b/packages/core/src/shared/index.ts
@@ -38,5 +38,6 @@ export * from './sort-rules';
export * from './tools';
export * from './types';
export * from './debounce';
+export * from './clipboard';
export { queryObjectMatrix } from './object-matrix-query';
export { moveRangeByOffset } from './range';
diff --git a/packages/engine-numfmt/src/type.ts b/packages/engine-numfmt/src/type.ts
index db386ba3ff..6e35d14d3c 100644
--- a/packages/engine-numfmt/src/type.ts
+++ b/packages/engine-numfmt/src/type.ts
@@ -246,7 +246,7 @@ type LocaleTag =
| 'th'
| 'tr';
-interface ParsedReturnType {
+export interface ParsedReturnType {
/**
* The parsed value. For dates, this will be an Excel style serial date unless the nativeDate option is used.
*/
diff --git a/packages/engine-render/src/components/sheets/extensions/border.ts b/packages/engine-render/src/components/sheets/extensions/border.ts
index 2c807533f3..4126897f1f 100644
--- a/packages/engine-render/src/components/sheets/extensions/border.ts
+++ b/packages/engine-render/src/components/sheets/extensions/border.ts
@@ -14,7 +14,8 @@
* limitations under the License.
*/
-import type { BorderStyleTypes, IRange, IScale, ObjectMatrix } from '@univerjs/core';
+import type { IRange, IScale, ObjectMatrix } from '@univerjs/core';
+import { BorderStyleTypes } from '@univerjs/core';
import { BORDER_TYPE, COLOR_BLACK_RGB, FIX_ONE_PIXEL_BLUR_OFFSET } from '../../../basics/const';
import { drawDiagonalLineByBorderType, drawLineByBorderType, getLineWidth, setLineType } from '../../../basics/draw';
@@ -95,6 +96,10 @@ export class Border extends SheetExtension {
for (const key in borderCaches) {
const { type, style, color } = borderCaches[key] as BorderCacheItem;
+ if (style === BorderStyleTypes.NONE) {
+ continue;
+ }
+
let startY = cellStartY;
let endY = cellEndY;
let startX = cellStartX;
diff --git a/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts b/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts
index 9ec97b9b85..6b2bc040bd 100644
--- a/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts
+++ b/packages/sheets-formula/src/controllers/__tests__/formula-clipboard.controller.spec.ts
@@ -19,7 +19,7 @@ import { ICommandService, IUniverInstanceService, ObjectMatrix } from '@univerjs
import { Lexer } from '@univerjs/engine-formula';
import { type ISetRangeValuesMutationParams, SetRangeValuesMutation } from '@univerjs/sheets';
import type { ICellDataWithSpanInfo } from '@univerjs/sheets-ui';
-import { COPY_TYPE, ISelectionRenderService, SelectionRenderService } from '@univerjs/sheets-ui';
+import { COPY_TYPE, ISelectionRenderService, PREDEFINED_HOOK_NAME, SelectionRenderService } from '@univerjs/sheets-ui';
import type { Injector } from '@wendellhu/redi';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
@@ -101,6 +101,7 @@ describe('Test paste with formula', () => {
rangeType: 0,
},
copyType: COPY_TYPE.COPY,
+ pasteType: PREDEFINED_HOOK_NAME.DEFAULT_PASTE,
};
const result = {
@@ -331,6 +332,7 @@ describe('Test paste with formula', () => {
endColumn: 8,
rangeType: 0,
},
+ pasteType: PREDEFINED_HOOK_NAME.DEFAULT_PASTE,
};
const result = {
diff --git a/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts b/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts
index ab6839ff0f..e857bd66da 100644
--- a/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts
+++ b/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts
@@ -29,7 +29,7 @@ import { Lexer } from '@univerjs/engine-formula';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '@univerjs/sheets';
import type { ICellDataWithSpanInfo, ICopyPastePayload, ISheetClipboardHook, ISheetRangeLocation } from '@univerjs/sheets-ui';
-import { COPY_TYPE, ISheetClipboardService } from '@univerjs/sheets-ui';
+import { COPY_TYPE, ISheetClipboardService, PREDEFINED_HOOK_NAME } from '@univerjs/sheets-ui';
import type { IAccessor } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
@@ -86,6 +86,7 @@ export class FormulaClipboardController extends Disposable {
const copyInfo = {
copyType: payload.copyType || COPY_TYPE.COPY,
copyRange: pasteFrom?.range,
+ pasteType: payload.pasteType,
};
const pastedRange = pasteTo.range;
const matrix = data;
@@ -115,6 +116,7 @@ export function getSetCellFormulaMutations(
copyInfo: {
copyType: COPY_TYPE;
copyRange?: IRange;
+ pasteType: string;
},
lexer: Lexer,
isSpecialPaste = false
@@ -162,7 +164,7 @@ export function getSetCellFormulaMutations(
valueObject.f = null;
valueObject.v = null;
valueObject.p = null;
- } else if (isFormulaString(originalFormula)) {
+ } else if (isFormulaString(originalFormula) && copyInfo.pasteType === PREDEFINED_HOOK_NAME.DEFAULT_PASTE) {
const rowIndex = row % copyRowLength;
const colIndex = col % copyColumnLength;
diff --git a/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts
index 1a3cbce3f5..8cd3e077bd 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts
@@ -34,9 +34,11 @@ import {
SetNumfmtMutation,
transformCellsToRange,
} from '@univerjs/sheets';
+import type { ICellDataWithSpanInfo } from '@univerjs/sheets-ui';
import { COPY_TYPE, getRepeatRange, ISheetClipboardService, PREDEFINED_HOOK_NAME } from '@univerjs/sheets-ui';
import { Inject, Injector } from '@wendellhu/redi';
+import numfmt from '@univerjs/engine-numfmt';
import { SHEET_NUMFMT_PLUGIN } from '../base/const/PLUGIN_NAME';
import { mergeNumfmtMutations } from '../utils/mutation';
@@ -69,7 +71,8 @@ export class NumfmtCopyPasteController extends Disposable {
const { copyType = COPY_TYPE.COPY, pasteType } = payload;
const { range: copyRange } = pasteFrom || {};
const { range: pastedRange } = pasteTo;
- return this._generateNumfmtMutations(pastedRange, { copyType, pasteType, copyRange });
+ const res = this._generateNumfmtMutations(pastedRange, { copyType, pasteType, copyRange, data });
+ return res;
},
})
);
@@ -115,12 +118,14 @@ export class NumfmtCopyPasteController extends Disposable {
copyType: COPY_TYPE;
copyRange?: IRange;
pasteType: string;
+ data: ObjectMatrix<ICellDataWithSpanInfo>;
}
) {
const workbook = this._univerInstanceService.getCurrentUniverSheetInstance()!;
const sheet = workbook.getActiveSheet();
const unitId = workbook.getUnitId();
const subUnitId = sheet.getSheetId();
+ const numfmtModel = this._numfmtService.getModel(unitId, subUnitId);
if (copyInfo.copyType === COPY_TYPE.CUT) {
// This do not need to deal with clipping.
// move range had handle this case .
@@ -128,6 +133,51 @@ export class NumfmtCopyPasteController extends Disposable {
this._copyInfo = null;
return { redos: [], undos: [] };
}
+ if (!copyInfo.copyRange && copyInfo.data) {
+ const removeRedos: IRemoveNumfmtMutationParams = { unitId, subUnitId, ranges: [] };
+ const cells: ISetCellsNumfmt = [];
+ Range.foreach(pastedRange, (row, col) => {
+ if (this._numfmtService.getValue(unitId, subUnitId, row, col, numfmtModel!)) {
+ removeRedos.ranges.push({ startRow: row, startColumn: col, endRow: row, endColumn: col });
+ }
+ });
+ copyInfo.data.forValue((row, col, value) => {
+ const content = String(value.v);
+
+ const dateInfo = numfmt.parseDate(content) || numfmt.parseTime(content) || numfmt.parseNumber(content);
+ const isTranslateDate = !!dateInfo;
+ if (isTranslateDate) {
+ if (dateInfo && dateInfo.z) {
+ cells.push({
+ row: pastedRange.startRow + row,
+ col: pastedRange.startColumn + col,
+ pattern: dateInfo.z || '',
+ type: 'date',
+ });
+ }
+ }
+ });
+ const setRedos = transformCellsToRange(unitId, subUnitId, cells);
+ Object.keys(setRedos.values).forEach((key) => {
+ const v = setRedos.values[key];
+ v.ranges = rangeMerge(v.ranges);
+ });
+
+ removeRedos.ranges = rangeMerge(removeRedos.ranges);
+ const undos = [
+ ...factorySetNumfmtUndoMutation(this._injector, setRedos),
+ ...factoryRemoveNumfmtUndoMutation(this._injector, removeRedos),
+ ];
+
+ return {
+ redos: [
+ { id: RemoveNumfmtMutation.id, params: removeRedos },
+ { id: SetNumfmtMutation.id, params: setRedos },
+ ],
+ undos: mergeNumfmtMutations(undos),
+ };
+ }
+
if (!this._copyInfo || !this._copyInfo.matrix.getSizeOf() || !copyInfo.copyRange) {
return { redos: [], undos: [] };
}
@@ -139,10 +189,11 @@ export class NumfmtCopyPasteController extends Disposable {
) {
return { redos: [], undos: [] };
}
+
const repeatRange = getRepeatRange(copyInfo.copyRange, pastedRange, true);
const cells: ISetCellsNumfmt = [];
const removeRedos: IRemoveNumfmtMutationParams = { unitId, subUnitId, ranges: [] };
- const numfmtModel = this._numfmtService.getModel(unitId, subUnitId);
+
// Clears the destination area data format
Range.foreach(pastedRange, (row, col) => {
if (this._numfmtService.getValue(unitId, subUnitId, row, col, numfmtModel!)) {
diff --git a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
index 6657699eb5..cd6a98f90d 100644
--- a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
@@ -27,6 +27,7 @@ import type {
} from '@univerjs/core';
import {
BooleanNumber,
+ convertBodyToHtml,
DEFAULT_WORKSHEET_COLUMN_WIDTH,
DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY,
DEFAULT_WORKSHEET_ROW_HEIGHT,
@@ -35,6 +36,7 @@ import {
ICommandService,
IConfigService,
IContextService,
+ isFormulaString,
IUniverInstanceService,
LifecycleStages,
LocaleService,
@@ -163,6 +165,9 @@ export class SheetClipboardController extends RxDisposable {
},
onCopyCellContent(row: number, col: number): string {
const cell = currentSheet!.getCell(row, col);
+ if (cell?.p?.body?.paragraphs || cell?.p?.body?.textRuns) {
+ return convertBodyToHtml(cell.p.body);
+ }
const content = cell ? extractPureTextFromCell(cell) : '';
return content;
},
@@ -177,6 +182,9 @@ export class SheetClipboardController extends RxDisposable {
// TODO@wzhudev: should deprecate Range and
// use worksheet.getStyle()
const range = currentSheet!.getRange(row, col);
+
+ const mergedCellByRowCol = currentSheet!.getMergedCell(row, col);
+
const textStyle = range.getTextStyle();
// const color = range.getFontColor();
// const backgroundColor = range.getBackground();
@@ -214,6 +222,21 @@ export class SheetClipboardController extends RxDisposable {
style = handleStyleToString(textStyle);
}
+ if (mergedCellByRowCol) {
+ const endRow = mergedCellByRowCol.endRow;
+ const endColumn = mergedCellByRowCol.endColumn;
+ const lastRange = currentSheet!.getRange(endRow, endColumn);
+ const lastTextStyle = lastRange.getTextStyle();
+ if (lastTextStyle) {
+ const lastStyle = handleStyleToString(lastTextStyle);
+ if (style) {
+ style += lastStyle ? `;${lastStyle}` : '';
+ } else {
+ style = lastStyle;
+ }
+ }
+ }
+
if (style) {
properties.style = style;
}
@@ -277,8 +300,10 @@ export class SheetClipboardController extends RxDisposable {
// if the range is outside ot the worksheet's boundary, we should add rows
const maxRow = currentSheet!.getMaxRows();
- const addingRowsCount = range.endRow - maxRow;
+ const addingRowsCount = range.endRow - maxRow + 1;
const existingRowsCount = rowProperties.length - addingRowsCount;
+
+ const rowManager = currentSheet!.getRowManager();
if (addingRowsCount > 0) {
const rowInfo: IObjectArrayPrimitiveType<IRowData> = {};
rowProperties.slice(existingRowsCount).forEach((property, index) => {
@@ -325,6 +350,7 @@ export class SheetClipboardController extends RxDisposable {
// get row height of existing rows
// TODO When Excel pasted, there was no width height, Do we still need to set the height?
const rowHeight: IObjectArrayPrimitiveType<number> = {};
+ const originRowHeight: IObjectArrayPrimitiveType<number> = {};
rowProperties.slice(0, existingRowsCount).forEach((property, index) => {
const { style, height: propertyHeight } = property;
if (style) {
@@ -344,7 +370,19 @@ export class SheetClipboardController extends RxDisposable {
rowHeight[index + range.startRow] = height;
} else if (propertyHeight) {
- rowHeight[index + range.startRow] = Number.parseFloat(propertyHeight);
+ const rowConfigBeforePaste = rowManager.getRow(range.startRow + index);
+ const willSetHeight = Number.parseFloat(propertyHeight);
+ if (rowConfigBeforePaste) {
+ const { h = DEFAULT_WORKSHEET_ROW_HEIGHT, ah = 0 } = rowConfigBeforePaste;
+ const nowRowHeight = Math.max(h, ah);
+ if (willSetHeight > nowRowHeight) {
+ rowHeight[index + range.startRow] = willSetHeight;
+ originRowHeight[index + range.startRow] = nowRowHeight;
+ }
+ } else {
+ rowHeight[index + range.startRow] = willSetHeight;
+ originRowHeight[index + range.startRow] = rowManager.getRow(range.startRow + index)?.h ?? DEFAULT_WORKSHEET_ROW_HEIGHT;
+ }
}
});
@@ -360,11 +398,17 @@ export class SheetClipboardController extends RxDisposable {
params: setRowPropertyMutation,
});
- // TODO: add undo mutations but we cannot do it now because underlying mechanism is not ready
+ undoMutations.push({
+ id: SetWorksheetRowHeightMutation.id,
+ params: {
+ ...setRowPropertyMutation,
+ rowHeight: 20,
+ },
+ });
return {
redos: redoMutations,
- undos: [] || undoMutations,
+ undos: undoMutations,
};
},
@@ -375,7 +419,7 @@ export class SheetClipboardController extends RxDisposable {
// if the range is outside ot the worksheet's boundary, we should add rows
const maxColumn = currentSheet!.getMaxColumns();
- const addingColsCount = range.endColumn - maxColumn;
+ const addingColsCount = range.endColumn - maxColumn + 1;
const existingColsCount = colProperties.length - addingColsCount;
const defaultColumnWidth = self._configService.getConfig<number>(DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY) ?? DEFAULT_WORKSHEET_COLUMN_WIDTH;
@@ -463,13 +507,23 @@ export class SheetClipboardController extends RxDisposable {
},
};
} else {
- cellValue = {
- [range.startRow]: {
- [range.startColumn]: {
- v: text,
+ if (isFormulaString(text)) {
+ cellValue = {
+ [range.startRow]: {
+ [range.startColumn]: {
+ f: text,
+ },
},
- },
- };
+ };
+ } else {
+ cellValue = {
+ [range.startRow]: {
+ [range.startColumn]: {
+ v: text,
+ },
+ },
+ };
+ }
}
const setRangeValuesParams: ISetRangeValuesMutationParams = {
@@ -520,9 +574,8 @@ export class SheetClipboardController extends RxDisposable {
specialPasteInfo: {
label: 'specialPaste.value',
},
- onPasteCells: (pasteFrom, pasteTo, data, pasteType) => {
- const workbook = self._currentUniverSheet.getCurrentUniverSheetInstance()!;
- return getSetCellValueMutations(pasteTo, data, accessor);
+ onPasteCells: (pasteFrom, pasteTo, data) => {
+ return getSetCellValueMutations(pasteTo, pasteFrom, data, accessor);
},
};
const specialPasteFormatHook: ISheetClipboardHook = {
@@ -530,8 +583,7 @@ export class SheetClipboardController extends RxDisposable {
specialPasteInfo: {
label: 'specialPaste.format',
},
- onPasteCells(pasteFrom, pasteTo, matrix, pasteType) {
- const workbook = self._currentUniverSheet.getCurrentUniverSheetInstance()!;
+ onPasteCells(pasteFrom, pasteTo, matrix) {
const redoMutationsInfo: IMutationInfo[] = [];
const undoMutationsInfo: IMutationInfo[] = [];
diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.ts
index 972b22bd13..5bd473ac2c 100644
--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts
@@ -39,6 +39,7 @@ import {
} from '@univerjs/sheets';
import type { IAccessor } from '@wendellhu/redi';
+import numfmt from '@univerjs/engine-numfmt';
import type { ICellDataWithSpanInfo, ICopyPastePayload, ISheetRangeLocation } from '../../services/clipboard/type';
import { COPY_TYPE } from '../../services/clipboard/type';
@@ -64,7 +65,7 @@ export function getDefaultOnPasteCellMutations(
undoMutationsInfo.push(...clearStyleUndos);
// set values
- const { undos: setValuesUndos, redos: setValuesRedos } = getSetCellValueMutations(pasteTo, data, accessor);
+ const { undos: setValuesUndos, redos: setValuesRedos } = getSetCellValueMutations(pasteTo, pasteFrom, data, accessor);
redoMutationsInfo.push(...setValuesRedos);
undoMutationsInfo.push(...setValuesUndos);
@@ -277,6 +278,7 @@ export function getMoveRangeMutations(
export function getSetCellValueMutations(
pasteTo: ISheetRangeLocation,
+ pasteFrom: Nullable<ISheetRangeLocation>,
matrix: ObjectMatrix<ICellDataWithSpanInfo>,
accessor: IAccessor
) {
@@ -287,13 +289,24 @@ export function getSetCellValueMutations(
const valueMatrix = new ObjectMatrix<ICellData>();
matrix.forValue((row, col, value) => {
- valueMatrix.setValue(row + startRow, col + startColumn, Tools.deepClone(value));
+ if (!value.p && value.v && !pasteFrom) {
+ const content = String(value.v);
+ const numfmtValue = numfmt.parseDate(content) || numfmt.parseTime(content) || numfmt.parseNumber(content);
+ if (numfmtValue?.v && typeof numfmtValue.v === 'number') {
+ value.v = numfmtValue.v;
+ }
+ }
+ if (value.p?.body) {
+ valueMatrix.setValue(row + startRow, col + startColumn, Tools.deepClone({ p: value.p, v: value.v }));
+ } else {
+ valueMatrix.setValue(row + startRow, col + startColumn, Tools.deepClone({ v: value.v }));
+ }
});
// set cell value and style
const setValuesMutation: ISetRangeValuesMutationParams = {
unitId,
subUnitId,
- cellValue: valueMatrix.getData(),
+ cellValue: Tools.deepClone(valueMatrix.getMatrix()),
};
redoMutationsInfo.push({
@@ -341,7 +354,7 @@ export function getSetCellStyleMutations(
const setValuesMutation: ISetRangeValuesMutationParams = {
unitId,
subUnitId,
- cellValue: valueMatrix.getData(),
+ cellValue: Tools.deepClone(valueMatrix.getMatrix()),
};
redoMutationsInfo.push({
@@ -389,7 +402,7 @@ export function getClearCellStyleMutations(
const clearMutation: ISetRangeValuesMutationParams = {
subUnitId,
unitId,
- cellValue: clearStyleMatrix.getData(),
+ cellValue: Tools.deepClone(clearStyleMatrix.getMatrix()),
};
redoMutationsInfo.push({
id: SetRangeValuesMutation.id,
@@ -420,11 +433,10 @@ export function getClearAndSetMergeMutations(
const undoMutationsInfo: IMutationInfo[] = [];
const { unitId, subUnitId, range } = pasteTo;
const { startColumn, startRow, endColumn, endRow } = range;
- let hasMerge = false;
const mergeRangeData: IRange[] = [];
matrix.forValue((row, col, value) => {
- if (value.rowSpan) {
+ if (value.rowSpan && value.rowSpan > 1) {
const colSpan = value.colSpan || 1;
const mergeRange = {
startRow: startRow + row,
@@ -433,8 +445,7 @@ export function getClearAndSetMergeMutations(
endColumn: startColumn + col + colSpan - 1,
};
mergeRangeData.push(mergeRange);
- hasMerge = true;
- } else if (value.colSpan) {
+ } else if (value.colSpan && value.colSpan > 1) {
const rowSpan = value.rowSpan || 1;
const mergeRange = {
startRow: startRow + row,
@@ -443,43 +454,40 @@ export function getClearAndSetMergeMutations(
endColumn: startColumn + col + value.colSpan - 1,
};
mergeRangeData.push(mergeRange);
- hasMerge = true;
}
});
// clear merge
// remove current range's all merged Cell
- if (hasMerge) {
- // get all merged cells
- const currentService = accessor.get(IUniverInstanceService) as IUniverInstanceService;
- const workbook = currentService.getUniverSheetInstance(unitId);
- const worksheet = workbook?.getSheetBySheetId(subUnitId);
- if (workbook && worksheet) {
- const mergeData = worksheet.getMergeData();
- const mergedCellsInRange = mergeData.filter((rect) =>
- Rectangle.intersects({ startRow, startColumn, endRow, endColumn }, rect)
- );
+ // get all merged cells
+ const currentService = accessor.get(IUniverInstanceService) as IUniverInstanceService;
+ const workbook = currentService.getUniverSheetInstance(unitId);
+ const worksheet = workbook?.getSheetBySheetId(subUnitId);
+ if (workbook && worksheet) {
+ const mergeData = worksheet.getMergeData();
+ const mergedCellsInRange = mergeData.filter((rect) =>
+ Rectangle.intersects({ startRow, startColumn, endRow, endColumn }, rect)
+ );
- const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {
- unitId,
- subUnitId,
- ranges: mergedCellsInRange,
- };
- redoMutationsInfo.push({
- id: RemoveWorksheetMergeMutation.id,
- params: removeMergeMutationParams,
- });
+ const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {
+ unitId,
+ subUnitId,
+ ranges: mergedCellsInRange,
+ };
+ redoMutationsInfo.push({
+ id: RemoveWorksheetMergeMutation.id,
+ params: removeMergeMutationParams,
+ });
- const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(
- accessor,
- removeMergeMutationParams
- );
+ const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveMergeUndoMutationFactory(
+ accessor,
+ removeMergeMutationParams
+ );
- undoMutationsInfo.push({
- id: AddWorksheetMergeMutation.id,
- params: undoRemoveMergeMutationParams,
- });
- }
+ undoMutationsInfo.push({
+ id: AddWorksheetMergeMutation.id,
+ params: undoRemoveMergeMutationParams,
+ });
}
// set merged cell info
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-alignment.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-alignment.spec.ts
new file mode 100644
index 0000000000..79fd8c8c2d
--- /dev/null
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-alignment.spec.ts
@@ -0,0 +1,177 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ICellData, IStyleData, Nullable, Univer } from '@univerjs/core';
+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';
+import {
+ AddWorksheetMergeMutation,
+ NORMAL_SELECTION_PLUGIN_NAME,
+ RemoveWorksheetMergeMutation,
+ SelectionManagerService,
+ SetRangeValuesMutation,
+ SetSelectionsOperation,
+ SetWorksheetColWidthMutation,
+ SetWorksheetRowHeightMutation,
+} from '@univerjs/sheets';
+import type { Injector } from '@wendellhu/redi';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { ISheetClipboardService } from '../clipboard.service';
+import { SheetSkeletonManagerService } from '../../sheet-skeleton-manager.service';
+import { clipboardTestBed } from './clipboard-test-bed';
+import { alignmentSampleByExcel, alignmentSampleByGoogle, alignmentSampleByUniver } from './constant';
+
+describe('Test clipboard', () => {
+ let univer: Univer;
+ let get: Injector['get'];
+ let commandService: ICommandService;
+ let sheetClipboardService: ISheetClipboardService;
+ let sheetSkeletonManagerService: SheetSkeletonManagerService;
+
+ let getValues: (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ) => Array<Array<Nullable<ICellData>>> | undefined;
+
+ let getStyles: (key: Nullable<string | IStyleData>) => Nullable<IStyleData>;
+
+ beforeEach(async () => {
+ const testBed = clipboardTestBed({
+ id: 'test',
+ appVersion: '3.0.0-alpha',
+ sheets: {
+ sheet1: {
+ id: 'sheet1',
+ cellData: {
+ 0: {
+ 0: {
+ v: 1,
+ },
+ },
+ },
+ },
+ },
+ locale: LocaleType.ZH_CN,
+ name: '',
+ sheetOrder: [],
+ styles: {},
+ });
+ univer = testBed.univer;
+ get = testBed.get;
+
+ commandService = get(ICommandService);
+ commandService.registerCommand(SetRangeValuesMutation);
+ commandService.registerCommand(SetWorksheetRowHeightMutation);
+ commandService.registerCommand(SetWorksheetColWidthMutation);
+ commandService.registerCommand(AddWorksheetMergeMutation);
+ commandService.registerCommand(RemoveWorksheetMergeMutation);
+ commandService.registerCommand(SetSelectionsOperation);
+ sheetSkeletonManagerService = get(SheetSkeletonManagerService);
+ sheetClipboardService = get(ISheetClipboardService);
+
+ getValues = (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ): Array<Array<Nullable<ICellData>>> | undefined =>
+ get(IUniverInstanceService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getRange(startRow, startColumn, endRow, endColumn)
+ .getValues();
+
+ getStyles = (key) => {
+ if (!key) return;
+ const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();
+ return styles?.get(key);
+ };
+ });
+
+ afterEach(() => {
+ univer?.dispose();
+ });
+
+ describe('Test paste from external ', () => {
+ beforeEach(() => {
+ const selectionManager = get(SelectionManagerService);
+
+ selectionManager.setCurrentSelection({
+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ const startRow = 1;
+ const startColumn = 1;
+ const endRow = 1;
+ const endColumn = 1;
+
+ selectionManager.add([
+ {
+ range: { startRow, startColumn, endRow, endColumn, rangeType: RANGE_TYPE.NORMAL },
+ primary: null,
+ style: null,
+ },
+ ]);
+
+ sheetSkeletonManagerService.setCurrent({
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ });
+ it('test font style paste from excel', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(alignmentSampleByExcel);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+ expect(getStyles(cellData.getValue(1, 1)?.s)?.ht).toBe(1);
+ expect(getStyles(cellData.getValue(1, 2)?.s)?.ht).toBe(3);
+ expect(getStyles(cellData.getValue(1, 3)?.s)?.ht).toBe(2);
+ expect(getStyles(cellData.getValue(1, 4)?.s)?.vt).toBe(1);
+ expect(getStyles(cellData.getValue(1, 5)?.s)?.vt).toBe(3);
+ expect(getStyles(cellData.getValue(1, 6)?.s)?.vt).toBe(2);
+ });
+
+ it('test font style paste from google', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(alignmentSampleByGoogle);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+ expect(getStyles(cellData.getValue(1, 2)?.s)?.ht).toBe(3);
+ expect(getStyles(cellData.getValue(1, 3)?.s)?.ht).toBe(2);
+ expect(getStyles(cellData.getValue(1, 4)?.s)?.vt).toBe(1);
+ expect(getStyles(cellData.getValue(1, 5)?.s)?.vt).toBe(3);
+ expect(getStyles(cellData.getValue(1, 6)?.s)?.vt).toBe(2);
+ });
+
+ it('test font style paste from univer', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(alignmentSampleByUniver);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+ expect(getStyles(cellData.getValue(1, 2)?.s)?.ht).toBe(3);
+ expect(getStyles(cellData.getValue(1, 3)?.s)?.ht).toBe(2);
+ expect(getStyles(cellData.getValue(1, 4)?.s)?.vt).toBe(1);
+ expect(getStyles(cellData.getValue(1, 5)?.s)?.vt).toBe(3);
+ expect(getStyles(cellData.getValue(1, 6)?.s)?.vt).toBe(2);
+ });
+ });
+});
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-border.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-border.spec.ts
new file mode 100644
index 0000000000..cf5b76dbe4
--- /dev/null
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-border.spec.ts
@@ -0,0 +1,289 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IBorderData, ICellData, IStyleData, Nullable, Univer } from '@univerjs/core';
+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';
+import {
+ AddWorksheetMergeMutation,
+ NORMAL_SELECTION_PLUGIN_NAME,
+ RemoveWorksheetMergeMutation,
+ SelectionManagerService,
+ SetRangeValuesMutation,
+ SetSelectionsOperation,
+ SetWorksheetColWidthMutation,
+ SetWorksheetRowHeightMutation,
+} from '@univerjs/sheets';
+import type { Injector } from '@wendellhu/redi';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { ISheetClipboardService } from '../clipboard.service';
+import { SheetSkeletonManagerService } from '../../sheet-skeleton-manager.service';
+import { clipboardTestBed } from './clipboard-test-bed';
+import { borderSampleByExcel, borderSampleByGoogle, borderSampleByUniver } from './constant';
+
+describe('Test clipboard', () => {
+ let univer: Univer;
+ let get: Injector['get'];
+ let commandService: ICommandService;
+ let sheetClipboardService: ISheetClipboardService;
+ let sheetSkeletonManagerService: SheetSkeletonManagerService;
+
+ let getValues: (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ) => Array<Array<Nullable<ICellData>>> | undefined;
+
+ let getStyles: (key: Nullable<string | IStyleData>) => Nullable<IStyleData>;
+ let convertColor: (color: Nullable<string>) => string;
+
+ beforeEach(async () => {
+ const testBed = clipboardTestBed({
+ id: 'test',
+ appVersion: '3.0.0-alpha',
+ sheets: {
+ sheet1: {
+ id: 'sheet1',
+ cellData: {
+ 0: {
+ 0: {
+ v: 1,
+ },
+ },
+ },
+ },
+ },
+ locale: LocaleType.ZH_CN,
+ name: '',
+ sheetOrder: [],
+ styles: {},
+ });
+ univer = testBed.univer;
+ get = testBed.get;
+
+ commandService = get(ICommandService);
+ commandService.registerCommand(SetRangeValuesMutation);
+ commandService.registerCommand(SetWorksheetRowHeightMutation);
+ commandService.registerCommand(SetWorksheetColWidthMutation);
+ commandService.registerCommand(AddWorksheetMergeMutation);
+ commandService.registerCommand(RemoveWorksheetMergeMutation);
+ commandService.registerCommand(SetSelectionsOperation);
+ sheetSkeletonManagerService = get(SheetSkeletonManagerService);
+ sheetClipboardService = get(ISheetClipboardService);
+
+ getValues = (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ): Array<Array<Nullable<ICellData>>> | undefined =>
+ get(IUniverInstanceService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getRange(startRow, startColumn, endRow, endColumn)
+ .getValues();
+
+ getStyles = (key) => {
+ if (!key) return;
+ const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();
+ return styles?.get(key);
+ };
+
+ convertColor = (color) => {
+ if (!color) return '';
+ if (color === 'black' || color === '#000000') {
+ return 'rgb(0,0,0)';
+ }
+ return color;
+ };
+ });
+
+ afterEach(() => {
+ univer?.dispose();
+ });
+
+ describe('Test paste from external ', () => {
+ beforeEach(() => {
+ const selectionManager = get(SelectionManagerService);
+
+ selectionManager.setCurrentSelection({
+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ const startRow = 1;
+ const startColumn = 1;
+ const endRow = 1;
+ const endColumn = 1;
+
+ selectionManager.add([
+ {
+ range: { startRow, startColumn, endRow, endColumn, rangeType: RANGE_TYPE.NORMAL },
+ primary: null,
+ style: null,
+ },
+ ]);
+
+ sheetSkeletonManagerService.setCurrent({
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ });
+ it('test font style paste from excel', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(borderSampleByExcel);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+
+ const convertBorderColor = (border: Nullable<IBorderData>) => {
+ if (!border) return '';
+ if (border.b) {
+ border.b.cl.rgb = convertColor(border.b.cl.rgb);
+ }
+ if (border.l) {
+ border.l.cl.rgb = convertColor(border.l.cl.rgb);
+ }
+ if (border.r) {
+ border.r.cl.rgb = convertColor(border.r.cl.rgb);
+ }
+ if (border.t) {
+ border.t.cl.rgb = convertColor(border.t.cl.rgb);
+ }
+ return border;
+ };
+
+ expect(convertBorderColor(getStyles(cellData.getValue(2, 2)?.s)?.bd)).toStrictEqual({
+ b: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ l: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ r: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ t: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+
+ expect(worksheet.getMergeData().length).toBe(1);
+ expect(convertBorderColor(getStyles(cellData.getValue(9, 2)?.s)?.bd)).toStrictEqual({
+ l: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ t: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ expect(convertBorderColor(getStyles(cellData.getValue(13, 2)?.s)?.bd)).toStrictEqual({
+ l: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ b: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ expect(convertBorderColor(getStyles(cellData.getValue(9, 3)?.s)?.bd)).toStrictEqual({
+ r: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ t: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ expect(convertBorderColor(getStyles(cellData.getValue(13, 3)?.s)?.bd)).toStrictEqual({
+ r: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ b: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ });
+
+ it('test font style paste from google', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(borderSampleByGoogle);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+
+ const convertBorderColor = (border: Nullable<IBorderData>) => {
+ if (!border) return '';
+ if (border.b) {
+ border.b.cl.rgb = convertColor(border.b.cl.rgb);
+ }
+ if (border.l) {
+ border.l.cl.rgb = convertColor(border.l.cl.rgb);
+ }
+ if (border.r) {
+ border.r.cl.rgb = convertColor(border.r.cl.rgb);
+ }
+ if (border.t) {
+ border.t.cl.rgb = convertColor(border.t.cl.rgb);
+ }
+ return border;
+ };
+
+ expect(worksheet.getMergeData().length).toBe(1);
+ expect(convertBorderColor(getStyles(cellData.getValue(9, 2)?.s)?.bd)).toStrictEqual({
+ l: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ t: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ expect(convertBorderColor(getStyles(cellData.getValue(13, 2)?.s)?.bd)).toStrictEqual({
+ l: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ b: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ expect(convertBorderColor(getStyles(cellData.getValue(9, 3)?.s)?.bd)).toStrictEqual({
+ r: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ t: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ expect(convertBorderColor(getStyles(cellData.getValue(13, 3)?.s)?.bd)).toStrictEqual({
+ r: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ b: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ });
+
+ it('test font style paste from univer', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(borderSampleByUniver);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+
+ const convertBorderColor = (border: Nullable<IBorderData>) => {
+ if (!border) return '';
+ if (border.b) {
+ border.b.cl.rgb = convertColor(border.b.cl.rgb);
+ }
+ if (border.l) {
+ border.l.cl.rgb = convertColor(border.l.cl.rgb);
+ }
+ if (border.r) {
+ border.r.cl.rgb = convertColor(border.r.cl.rgb);
+ }
+ if (border.t) {
+ border.t.cl.rgb = convertColor(border.t.cl.rgb);
+ }
+ return border;
+ };
+
+ expect(convertBorderColor(getStyles(cellData.getValue(2, 2)?.s)?.bd)).toStrictEqual({
+ b: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ l: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ r: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ t: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+
+ expect(worksheet.getMergeData().length).toBe(1);
+ expect(convertBorderColor(getStyles(cellData.getValue(9, 2)?.s)?.bd)).toStrictEqual({
+ l: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ t: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ expect(convertBorderColor(getStyles(cellData.getValue(13, 2)?.s)?.bd)).toStrictEqual({
+ l: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ b: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ expect(convertBorderColor(getStyles(cellData.getValue(9, 3)?.s)?.bd)).toStrictEqual({
+ r: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ t: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ expect(convertBorderColor(getStyles(cellData.getValue(13, 3)?.s)?.bd)).toStrictEqual({
+ r: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ b: { cl: { rgb: 'rgb(0,0,0)' }, s: 1 },
+ });
+ });
+ });
+});
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-font.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-font.spec.ts
new file mode 100644
index 0000000000..783ca1319d
--- /dev/null
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-font.spec.ts
@@ -0,0 +1,248 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ICellData, IStyleData, Nullable, Univer } from '@univerjs/core';
+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';
+import {
+ AddWorksheetMergeMutation,
+ NORMAL_SELECTION_PLUGIN_NAME,
+ RemoveWorksheetMergeMutation,
+ SelectionManagerService,
+ SetRangeValuesMutation,
+ SetSelectionsOperation,
+ SetWorksheetColWidthMutation,
+ SetWorksheetRowHeightMutation,
+} from '@univerjs/sheets';
+import type { Injector } from '@wendellhu/redi';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { ISheetClipboardService } from '../clipboard.service';
+import { SheetSkeletonManagerService } from '../../sheet-skeleton-manager.service';
+import { clipboardTestBed } from './clipboard-test-bed';
+import { fontSampleByExcel, fontSampleByGoogle, fontSampleByUniver } from './constant';
+
+describe('Test clipboard', () => {
+ let univer: Univer;
+ let get: Injector['get'];
+ let commandService: ICommandService;
+ let sheetClipboardService: ISheetClipboardService;
+ let sheetSkeletonManagerService: SheetSkeletonManagerService;
+
+ let getValues: (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ) => Array<Array<Nullable<ICellData>>> | undefined;
+
+ let getStyles: (key: Nullable<string | IStyleData>) => Nullable<IStyleData>;
+ let convertColor: (color: Nullable<string>) => string;
+
+ beforeEach(async () => {
+ const testBed = clipboardTestBed({
+ id: 'test',
+ appVersion: '3.0.0-alpha',
+ sheets: {
+ sheet1: {
+ id: 'sheet1',
+ cellData: {
+ 0: {
+ 0: {
+ v: 1,
+ },
+ },
+ },
+ },
+ },
+ locale: LocaleType.ZH_CN,
+ name: '',
+ sheetOrder: [],
+ styles: {},
+ });
+ univer = testBed.univer;
+ get = testBed.get;
+
+ commandService = get(ICommandService);
+ commandService.registerCommand(SetRangeValuesMutation);
+ commandService.registerCommand(SetWorksheetRowHeightMutation);
+ commandService.registerCommand(SetWorksheetColWidthMutation);
+ commandService.registerCommand(AddWorksheetMergeMutation);
+ commandService.registerCommand(RemoveWorksheetMergeMutation);
+ commandService.registerCommand(SetSelectionsOperation);
+ sheetSkeletonManagerService = get(SheetSkeletonManagerService);
+ sheetClipboardService = get(ISheetClipboardService);
+
+ getValues = (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ): Array<Array<Nullable<ICellData>>> | undefined =>
+ get(IUniverInstanceService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getRange(startRow, startColumn, endRow, endColumn)
+ .getValues();
+
+ getStyles = (key) => {
+ if (!key) return;
+ const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();
+ return styles?.get(key);
+ };
+
+ convertColor = (color) => {
+ if (!color) return '';
+ if (color === 'yellow' || color === '#ffff00') {
+ return 'rgb(255,255,0)';
+ }
+ return color;
+ };
+ });
+
+ afterEach(() => {
+ univer?.dispose();
+ });
+
+ describe('Test paste from external ', () => {
+ beforeEach(() => {
+ const selectionManager = get(SelectionManagerService);
+
+ selectionManager.setCurrentSelection({
+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ const startRow = 1;
+ const startColumn = 1;
+ const endRow = 1;
+ const endColumn = 1;
+
+ selectionManager.add([
+ {
+ range: { startRow, startColumn, endRow, endColumn, rangeType: RANGE_TYPE.NORMAL },
+ primary: null,
+ style: null,
+ },
+ ]);
+
+ sheetSkeletonManagerService.setCurrent({
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ });
+ it('test font style paste from excel', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(fontSampleByExcel);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+ // font bold
+ expect(cellData.getValue(1, 1)?.v).toBe('B');
+ expect(getStyles(cellData.getValue(1, 1)?.s)?.bl).toBe(1);
+ // font italic
+ expect(cellData.getValue(2, 1)?.v).toBe('I');
+ expect(getStyles(cellData.getValue(2, 1)?.s)?.it).toBe(1);
+ // font underline
+ expect(cellData.getValue(3, 1)?.v).toBe('U');
+ expect(getStyles(cellData.getValue(3, 1)?.s)?.ul?.s).toBe(1);
+ // font line-through
+ expect(cellData.getValue(4, 1)?.v).toBe('S');
+ expect(cellData.getValue(4, 1)?.p?.body?.textRuns?.[0].ts?.st?.s).toBe(1);
+
+ // font-size
+ expect(cellData.getValue(6, 1)?.v).toBe('font-size:12');
+ expect(cellData.getValue(7, 1)?.v).toBe('font-size:18');
+ expect(getStyles(cellData.getValue(7, 1)?.s)?.fs).toBe(18);
+ // font-color
+ expect(cellData.getValue(8, 1)?.v).toBe('color');
+ expect(convertColor(getStyles(cellData.getValue(8, 1)?.s)?.cl?.rgb)).toBe('rgb(255,255,0)');
+ // background
+ expect(cellData.getValue(9, 1)?.v).toBe('background');
+ // todo@yuanbin Why is the color format obtained in the test not rgb?
+ // font-family
+ expect(cellData.getValue(10, 1)?.v).toBe('font-family');
+ expect(getStyles(cellData.getValue(10, 1)?.s)?.ff).toBe('仿宋');
+ });
+
+ it('test font style paste from google', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(fontSampleByGoogle);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+ // font bold
+ expect(cellData.getValue(1, 1)?.v).toBe('B');
+ expect(getStyles(cellData.getValue(1, 1)?.s)?.bl).toBe(1);
+ // font italic
+ expect(cellData.getValue(2, 1)?.v).toBe('I');
+ expect(getStyles(cellData.getValue(2, 1)?.s)?.it).toBe(1);
+ // font underline
+ expect(cellData.getValue(3, 1)?.v).toBe('U');
+ expect(getStyles(cellData.getValue(3, 1)?.s)?.ul?.s).toBe(1);
+ // font line-through
+ expect(cellData.getValue(4, 1)?.v).toBe('S');
+ expect(getStyles(cellData.getValue(4, 1)?.s)?.st?.s).toBe(1);
+
+ // font-size
+ expect(cellData.getValue(5, 1)?.v).toBe('font-size:12');
+ expect(cellData.getValue(6, 1)?.v).toBe('font-size:18');
+ expect(getStyles(cellData.getValue(6, 1)?.s)?.fs).toBe(18);
+ // font-color
+ expect(cellData.getValue(7, 1)?.v).toBe('color');
+ expect(convertColor(getStyles(cellData.getValue(7, 1)?.s)?.cl?.rgb)).toBe('rgb(255,255,0)');
+ // background
+ expect(cellData.getValue(8, 1)?.v).toBe('background');
+ expect(convertColor(getStyles(cellData.getValue(8, 1)?.s)?.bg?.rgb)).toBe('rgb(255,255,0)');
+ // font-family
+ expect(cellData.getValue(9, 1)?.v).toBe('font-family');
+ expect(getStyles(cellData.getValue(9, 1)?.s)?.ff).toBe('Hei');
+ });
+
+ it('test font style paste from univer', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(fontSampleByUniver);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+ // font bold
+ expect(cellData.getValue(1, 1)?.v).toBe('B');
+ expect(getStyles(cellData.getValue(1, 1)?.s)?.bl).toBe(1);
+ // font italic
+ expect(cellData.getValue(2, 1)?.v).toBe('I');
+ expect(getStyles(cellData.getValue(2, 1)?.s)?.it).toBe(1);
+ // font underline
+ expect(cellData.getValue(3, 1)?.v).toBe('U');
+ expect(getStyles(cellData.getValue(3, 1)?.s)?.ul?.s).toBe(1);
+ // font line-through
+ expect(cellData.getValue(4, 1)?.v).toBe('S');
+ expect(getStyles(cellData.getValue(4, 1)?.s)?.st?.s).toBe(1);
+
+ // font-size
+ expect(cellData.getValue(5, 1)?.v).toBe('font-size:12');
+ expect(cellData.getValue(6, 1)?.v).toBe('font-size:18');
+ expect(getStyles(cellData.getValue(6, 1)?.s)?.fs).toBe(18);
+ // font-color
+ expect(cellData.getValue(7, 1)?.v).toBe('color');
+ expect(convertColor(getStyles(cellData.getValue(7, 1)?.s)?.cl?.rgb)).toBe('rgb(255,255,0)');
+ // background
+ expect(cellData.getValue(8, 1)?.v).toBe('background');
+ expect(convertColor(getStyles(cellData.getValue(8, 1)?.s)?.bg?.rgb)).toBe('rgb(255,255,0)');
+ // font-family
+ expect(cellData.getValue(9, 1)?.v).toBe('font-family');
+ expect(getStyles(cellData.getValue(9, 1)?.s)?.ff).toBe('SimSun');
+ });
+ });
+});
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.ts
new file mode 100644
index 0000000000..6030de86a5
--- /dev/null
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.ts
@@ -0,0 +1,208 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ICellData, IStyleData, Nullable, Univer } from '@univerjs/core';
+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';
+import {
+ AddWorksheetMergeMutation,
+ MoveRangeMutation,
+ NORMAL_SELECTION_PLUGIN_NAME,
+ RemoveWorksheetMergeMutation,
+ SelectionManagerService,
+ SetRangeValuesMutation,
+ SetSelectionsOperation,
+ SetWorksheetColWidthMutation,
+ SetWorksheetRowHeightMutation,
+} from '@univerjs/sheets';
+import type { Injector } from '@wendellhu/redi';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { ISheetClipboardService } from '../clipboard.service';
+import { SheetSkeletonManagerService } from '../../sheet-skeleton-manager.service';
+import { clipboardTestBed } from './clipboard-test-bed';
+import { excelSample } from './constant';
+
+describe('Test clipboard', () => {
+ let univer: Univer;
+ let get: Injector['get'];
+ let commandService: ICommandService;
+ let sheetClipboardService: ISheetClipboardService;
+ let sheetSkeletonManagerService: SheetSkeletonManagerService;
+
+ let getValues: (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ) => Array<Array<Nullable<ICellData>>> | undefined;
+
+ let getStyles: (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ) => Array<Array<Nullable<IStyleData>>> | undefined;
+
+ beforeEach(async () => {
+ const testBed = clipboardTestBed({
+ id: 'test',
+ appVersion: '3.0.0-alpha',
+ sheets: {
+ sheet1: {
+ id: 'sheet1',
+ cellData: {
+ 0: {
+ 0: {
+ v: 1,
+ },
+ },
+ },
+ },
+ },
+ locale: LocaleType.ZH_CN,
+ name: '',
+ sheetOrder: [],
+ styles: {},
+ });
+ univer = testBed.univer;
+ get = testBed.get;
+
+ commandService = get(ICommandService);
+ commandService.registerCommand(SetRangeValuesMutation);
+ commandService.registerCommand(SetWorksheetRowHeightMutation);
+ commandService.registerCommand(SetWorksheetColWidthMutation);
+ commandService.registerCommand(AddWorksheetMergeMutation);
+ commandService.registerCommand(RemoveWorksheetMergeMutation);
+ commandService.registerCommand(SetSelectionsOperation);
+ commandService.registerCommand(MoveRangeMutation);
+
+ sheetSkeletonManagerService = get(SheetSkeletonManagerService);
+ sheetClipboardService = get(ISheetClipboardService);
+
+ getValues = (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ): Array<Array<Nullable<ICellData>>> | undefined =>
+ get(IUniverInstanceService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getRange(startRow, startColumn, endRow, endColumn)
+ .getValues();
+
+ getStyles = (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ): Array<Array<Nullable<IStyleData>>> | undefined => {
+ const values = getValues(startRow, startColumn, endRow, endColumn);
+ const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();
+ if (values && styles) {
+ return values.map((row) => row.map((cell) => styles.getStyleByCell(cell)));
+ }
+ };
+ });
+
+ afterEach(() => {
+ univer?.dispose();
+ });
+
+ describe('Test paste from excel ', () => {
+ beforeEach(() => {
+ const selectionManager = get(SelectionManagerService);
+
+ selectionManager.setCurrentSelection({
+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ const startRow = 1;
+ const startColumn = 1;
+ const endRow = 1;
+ const endColumn = 1;
+
+ selectionManager.add([
+ {
+ range: { startRow, startColumn, endRow, endColumn, rangeType: RANGE_TYPE.NORMAL },
+ primary: null,
+ style: null,
+ },
+ ]);
+
+ sheetSkeletonManagerService.setCurrent({
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ });
+ it('test style with paste cell style', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(excelSample);
+ expect(res).toBeTruthy();
+ expect(worksheet.getMergeData().length).toBe(3);
+ expect(getValues(2, 2, 2, 2)?.[0]?.[0]?.v).toEqual('Univer');
+ expect(getStyles(2, 2, 2, 2)?.[0]?.[0]).toStrictEqual({
+ bl: 1, cl: { rgb: 'black' }, ff: '等线', fs: 12, ht: 0, it: 1, vt: 2,
+ });
+ });
+
+ it('test style with paste rich text style', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(excelSample);
+ expect(res).toBeTruthy();
+ expect(getValues(2, 3, 2, 3)?.[0]?.[0]?.v).toEqual('Univer');
+ const cellStyle = getStyles(2, 3, 2, 3)?.[0]?.[0];
+ expect(cellStyle?.vt).toBe(2);
+ expect(cellStyle?.bg).toStrictEqual({ rgb: 'rgb(15,158,213)' });
+ const richTextStyle = getValues(2, 3, 2, 3)?.[0]?.[0]?.p;
+ expect(richTextStyle?.body?.dataStream).toBe('Univer\r\n');
+ expect(richTextStyle?.body?.paragraphs).toStrictEqual([{ startIndex: 6 }]);
+ expect(richTextStyle?.body?.textRuns).toStrictEqual([
+ {
+ st: 1, ed: 4, ts: {
+ cl:
+ { rgb: 'rgb(218,233,248)' },
+ ff: '等线', fs: 28, it: 1, bl: 1,
+ },
+ },
+ {
+ ed: 6, st: 4, ts: { fs: 12, ff: '等线', cl: { rgb: 'rgb(0,0,0)' } },
+ },
+ ]);
+ });
+
+ it('test numfmt with paste', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(excelSample);
+ expect(res).toBeTruthy();
+ const cellValue = getValues(15, 2, 15, 2)?.[0]?.[0];
+ expect(cellValue?.v).toEqual(45607);
+ });
+
+ it('test formula with paste', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste('', '=SUM(A1');
+ expect(res).toBeTruthy();
+ const cellValue = getValues(1, 1, 1, 1)?.[0]?.[0];
+ expect(cellValue?.f).toEqual('=SUM(A1');
+ });
+ });
+});
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-google.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-google.spec.ts
new file mode 100644
index 0000000000..aefc939d89
--- /dev/null
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-google.spec.ts
@@ -0,0 +1,213 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ICellData, IStyleData, Nullable, Univer } from '@univerjs/core';
+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';
+import {
+ AddWorksheetMergeMutation,
+ MoveRangeMutation,
+ NORMAL_SELECTION_PLUGIN_NAME,
+ RemoveWorksheetMergeMutation,
+ SelectionManagerService,
+ SetRangeValuesMutation,
+ SetSelectionsOperation,
+ SetWorksheetColWidthMutation,
+ SetWorksheetRowHeightMutation,
+} from '@univerjs/sheets';
+import type { Injector } from '@wendellhu/redi';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { ISheetClipboardService } from '../clipboard.service';
+
+import { SheetSkeletonManagerService } from '../../sheet-skeleton-manager.service';
+
+import { clipboardTestBed } from './clipboard-test-bed';
+
+import { googleSample } from './constant';
+
+describe('Test clipboard', () => {
+ let univer: Univer;
+ let get: Injector['get'];
+ let commandService: ICommandService;
+ let sheetClipboardService: ISheetClipboardService;
+ let sheetSkeletonManagerService: SheetSkeletonManagerService;
+
+ let getValues: (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ) => Array<Array<Nullable<ICellData>>> | undefined;
+
+ let getStyles: (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ) => Array<Array<Nullable<IStyleData>>> | undefined;
+
+ beforeEach(async () => {
+ const testBed = clipboardTestBed({
+ id: 'test',
+ appVersion: '3.0.0-alpha',
+ sheets: {
+ sheet1: {
+ id: 'sheet1',
+ cellData: {
+ 0: {
+ 0: { v: 1 },
+ },
+ },
+ },
+ },
+ locale: LocaleType.ZH_CN,
+ name: '',
+ sheetOrder: [],
+ styles: {},
+ });
+ univer = testBed.univer;
+ get = testBed.get;
+
+ commandService = get(ICommandService);
+ commandService.registerCommand(SetRangeValuesMutation);
+ commandService.registerCommand(SetWorksheetRowHeightMutation);
+ commandService.registerCommand(SetWorksheetColWidthMutation);
+ commandService.registerCommand(AddWorksheetMergeMutation);
+ commandService.registerCommand(RemoveWorksheetMergeMutation);
+ commandService.registerCommand(SetSelectionsOperation);
+ commandService.registerCommand(MoveRangeMutation);
+
+ sheetSkeletonManagerService = get(SheetSkeletonManagerService);
+ sheetClipboardService = get(ISheetClipboardService);
+
+ getValues = (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ): Array<Array<Nullable<ICellData>>> | undefined =>
+ get(IUniverInstanceService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getRange(startRow, startColumn, endRow, endColumn)
+ .getValues();
+
+ getStyles = (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ): Array<Array<Nullable<IStyleData>>> | undefined => {
+ const values = getValues(startRow, startColumn, endRow, endColumn);
+ const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();
+ if (values && styles) {
+ return values.map((row) => row.map((cell) => styles.getStyleByCell(cell)));
+ }
+ };
+ });
+
+ afterEach(() => {
+ univer?.dispose();
+ });
+
+ describe('Test paste from Google Sheet ', () => {
+ beforeEach(() => {
+ const selectionManager = get(SelectionManagerService);
+
+ selectionManager.setCurrentSelection({
+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ const startRow = 1;
+ const startColumn = 1;
+ const endRow = 1;
+ const endColumn = 1;
+
+ selectionManager.add([
+ {
+ range: { startRow, startColumn, endRow, endColumn, rangeType: RANGE_TYPE.NORMAL },
+ primary: null,
+ style: null,
+ },
+ ]);
+
+ sheetSkeletonManagerService.setCurrent({
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ });
+ it('test style with paste cell style', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(googleSample);
+ expect(res).toBeTruthy();
+ expect(worksheet.getMergeData().length).toBe(3);
+ expect(getValues(2, 2, 2, 2)?.[0]?.[0]?.v).toEqual('Univer');
+ expect(getStyles(2, 2, 2, 2)?.[0]?.[0]).toStrictEqual({ vt: 3, bl: 1, it: 1 });
+ });
+
+ it('test style with paste rich text style', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(googleSample);
+ expect(res).toBeTruthy();
+ expect(getValues(2, 3, 2, 3)?.[0]?.[0]?.v).toEqual('univer');
+ const cellStyle = getStyles(2, 3, 2, 3)?.[0]?.[0];
+ expect(cellStyle?.vt).toBe(3);
+ expect(cellStyle?.bg).toStrictEqual({ rgb: 'rgb(255,0,0)' });
+ const richTextStyle = getValues(2, 3, 2, 3)?.[0]?.[0]?.p;
+ expect(richTextStyle?.body?.dataStream).toBe('univer\r\n');
+ expect(richTextStyle?.body?.paragraphs).toStrictEqual([{ startIndex: 6 }]);
+ expect(richTextStyle?.body?.textRuns).toStrictEqual([
+ { ed: 1, st: 0, ts: { fs: 9.75, ff: 'Arial' } },
+ {
+ st: 1, ed: 4, ts: {
+ cl:
+ { rgb: 'rgb(217,210,233)' },
+ ff: 'Arial', fs: 17.25, it: 1,
+ },
+ },
+ {
+ ed: 6, st: 4, ts: { fs: 9.75, ff: 'Arial' },
+ },
+ ]);
+ });
+
+ it('test numfmt with paste', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(googleSample);
+ expect(res).toBeTruthy();
+ const cellValue = getValues(14, 2, 14, 2)?.[0]?.[0];
+ expect(cellValue?.v).toEqual(45607);
+ });
+
+ it('test merge style with paste', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(googleSample);
+ expect(res).toBeTruthy();
+ expect(worksheet.getMergeData().length).toBe(3);
+ expect(worksheet.getMergedCell(9, 2)).toStrictEqual({ startRow: 9, endRow: 12, startColumn: 2, endColumn: 2 });
+ expect(getStyles(8, 2, 8, 2)?.[0]?.[0]?.bd?.b).toStrictEqual({ cl: { rgb: '#000000' }, s: 1 });
+ expect(getStyles(9, 2, 9, 2)?.[0]?.[0]?.bd?.r).toStrictEqual({ cl: { rgb: '#000000' }, s: 1 });
+ expect(getStyles(9, 1, 9, 1)?.[0]?.[0]?.bd?.r).toStrictEqual({ cl: { rgb: '#000000' }, s: 1 });
+ expect(getStyles(12, 2, 12, 2)?.[0]?.[0]?.bd?.r).toStrictEqual({ cl: { rgb: '#000000' }, s: 1 });
+ expect(getStyles(12, 2, 12, 2)?.[0]?.[0]?.bd?.b).toStrictEqual({ cl: { rgb: '#000000' }, s: 1 });
+ });
+ });
+});
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-rotate.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-rotate.spec.ts
new file mode 100644
index 0000000000..e34b4cda00
--- /dev/null
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-rotate.spec.ts
@@ -0,0 +1,161 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ICellData, IStyleData, Nullable, Univer } from '@univerjs/core';
+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';
+import {
+ AddWorksheetMergeMutation,
+ NORMAL_SELECTION_PLUGIN_NAME,
+ RemoveWorksheetMergeMutation,
+ SelectionManagerService,
+ SetRangeValuesMutation,
+ SetSelectionsOperation,
+ SetWorksheetColWidthMutation,
+ SetWorksheetRowHeightMutation,
+} from '@univerjs/sheets';
+import type { Injector } from '@wendellhu/redi';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { ISheetClipboardService } from '../clipboard.service';
+import { SheetSkeletonManagerService } from '../../sheet-skeleton-manager.service';
+import { clipboardTestBed } from './clipboard-test-bed';
+import { rotateSampleByUniver } from './constant';
+
+describe('Test clipboard', () => {
+ let univer: Univer;
+ let get: Injector['get'];
+ let commandService: ICommandService;
+ let sheetClipboardService: ISheetClipboardService;
+ let sheetSkeletonManagerService: SheetSkeletonManagerService;
+
+ let getValues: (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ) => Array<Array<Nullable<ICellData>>> | undefined;
+
+ let getStyles: (key: Nullable<string | IStyleData>) => Nullable<IStyleData>;
+ let convertColor: (color: Nullable<string>) => string;
+
+ beforeEach(async () => {
+ const testBed = clipboardTestBed({
+ id: 'test',
+ appVersion: '3.0.0-alpha',
+ sheets: {
+ sheet1: {
+ id: 'sheet1',
+ cellData: {
+ 0: {
+ 0: {
+ v: 1,
+ },
+ },
+ },
+ },
+ },
+ locale: LocaleType.ZH_CN,
+ name: '',
+ sheetOrder: [],
+ styles: {},
+ });
+ univer = testBed.univer;
+ get = testBed.get;
+
+ commandService = get(ICommandService);
+ commandService.registerCommand(SetRangeValuesMutation);
+ commandService.registerCommand(SetWorksheetRowHeightMutation);
+ commandService.registerCommand(SetWorksheetColWidthMutation);
+ commandService.registerCommand(AddWorksheetMergeMutation);
+ commandService.registerCommand(RemoveWorksheetMergeMutation);
+ commandService.registerCommand(SetSelectionsOperation);
+ sheetSkeletonManagerService = get(SheetSkeletonManagerService);
+ sheetClipboardService = get(ISheetClipboardService);
+
+ getValues = (
+ startRow: number,
+ startColumn: number,
+ endRow: number,
+ endColumn: number
+ ): Array<Array<Nullable<ICellData>>> | undefined =>
+ get(IUniverInstanceService)
+ .getUniverSheetInstance('test')
+ ?.getSheetBySheetId('sheet1')
+ ?.getRange(startRow, startColumn, endRow, endColumn)
+ .getValues();
+
+ getStyles = (key) => {
+ if (!key) return;
+ const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();
+ return styles?.get(key);
+ };
+
+ convertColor = (color) => {
+ if (!color) return '';
+ if (color === 'black' || color === '#000000') {
+ return 'rgb(0,0,0)';
+ }
+ return color;
+ };
+ });
+
+ afterEach(() => {
+ univer?.dispose();
+ });
+
+ describe('Test paste from univer ', () => {
+ beforeEach(() => {
+ const selectionManager = get(SelectionManagerService);
+
+ selectionManager.setCurrentSelection({
+ pluginName: NORMAL_SELECTION_PLUGIN_NAME,
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ const startRow = 1;
+ const startColumn = 1;
+ const endRow = 1;
+ const endColumn = 1;
+
+ selectionManager.add([
+ {
+ range: { startRow, startColumn, endRow, endColumn, rangeType: RANGE_TYPE.NORMAL },
+ primary: null,
+ style: null,
+ },
+ ]);
+
+ sheetSkeletonManagerService.setCurrent({
+ unitId: 'test',
+ sheetId: 'sheet1',
+ });
+ });
+ it('test font style paste from univer', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+ const res = await sheetClipboardService.legacyPaste(rotateSampleByUniver);
+ expect(res).toBeTruthy();
+ const cellData = worksheet.getCellMatrix();
+ expect(getStyles(cellData.getValue(1, 1)?.s)?.tr?.a).toBeFalsy();
+ expect(getStyles(cellData.getValue(2, 1)?.s)?.tr?.a).toBe(-45);
+ expect(getStyles(cellData.getValue(3, 1)?.s)?.tr?.a).toBe(45);
+ expect(getStyles(cellData.getValue(4, 1)?.s)?.tr).toStrictEqual(
+ { a: 0, v: 1 });
+ expect(getStyles(cellData.getValue(5, 1)?.s)?.tr?.a).toBe(-90);
+ expect(getStyles(cellData.getValue(6, 1)?.s)?.tr?.a).toBe(90);
+ });
+ });
+});
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-service.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-service.spec.ts
index b5637b029c..ab53f2741e 100644
--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-service.spec.ts
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-service.spec.ts
@@ -163,8 +163,8 @@ describe('Test clipboard', () => {
const rowHeight = rowManager?.getRowData()?.[0].h;
const columnManager = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1')?.getColumnManager();
const columnWidth = columnManager?.getColumnData()?.[0].w;
- expect (columnWidth).toBe(73);
- expect (rowHeight).toBe(81);
+ expect(columnWidth).toBe(73);
+ expect(rowHeight).toBe(81);
expect(values && values[0][0]?.v).toBe('row1col2');
expect(styles && styles[0][0]).toStrictEqual({
bg: { rgb: 'rgb(255,0,0)' },
@@ -476,19 +476,8 @@ describe('Test clipboard', () => {
},
]);
- await sheetClipboardService.paste(clipboardItem);
- const values = getValues(startRow, startColumn, endRow, endColumn);
- const styles = getStyles(startRow, startColumn, endRow, endColumn);
- const mergedCells = getMergedCells(startRow, startColumn, endRow, endColumn);
-
- expect(values && values[0][0]?.v).toBe('row1col2');
- expect(styles && styles[0][0]).toBe(undefined);
- expect(mergedCells && mergedCells[0]).toStrictEqual({
- startRow,
- startColumn,
- endRow,
- endColumn,
- });
+ const res = await sheetClipboardService.paste(clipboardItem);
+ expect(res).toBeFalsy();
});
it('The current selection is a merged cell of 1 row and 4 columns.', async () => {
@@ -514,23 +503,8 @@ describe('Test clipboard', () => {
},
]);
- await sheetClipboardService.paste(clipboardItem);
- const values = getValues(startRow, startColumn, endRow, endColumn);
- const styles = getStyles(startRow, startColumn, endRow, endColumn);
- const mergedCells = getMergedCells(startRow, startColumn, endRow, endColumn);
-
- expect(values && values[0][0]?.v).toBe('row1col2');
- expect(styles && styles[0][0]).toStrictEqual({
- bg: { rgb: 'rgb(255,0,0)' },
- ht: 2,
- vt: 2,
- });
- expect(mergedCells && mergedCells[0]).toStrictEqual({
- startRow,
- startColumn,
- endRow,
- endColumn: endColumn - 2,
- });
+ const res = await sheetClipboardService.paste(clipboardItem);
+ expect(res).toBeFalsy();
});
it('The current selection is a merged cell of 2 rows and 2 columns.', async () => {
@@ -556,29 +530,8 @@ describe('Test clipboard', () => {
},
]);
- await sheetClipboardService.paste(clipboardItem);
- const values = getValues(startRow, startColumn, endRow, endColumn);
- const styles = getStyles(startRow, startColumn, endRow, endColumn);
- const mergedCells = getMergedCells(startRow, startColumn, endRow, endColumn);
-
- expect(values && values[0][0]?.v).toBe('row1col2');
- expect(styles && styles[0][0]).toStrictEqual({
- bg: { rgb: 'rgb(255,0,0)' },
- ht: 2,
- vt: 2,
- });
- expect(mergedCells && mergedCells[0]).toStrictEqual({
- startRow,
- startColumn,
- endRow: endRow - 1,
- endColumn,
- });
- expect(mergedCells && mergedCells[1]).toStrictEqual({
- startRow: startRow + 1,
- startColumn,
- endRow,
- endColumn,
- });
+ const res = await sheetClipboardService.paste(clipboardItem);
+ expect(res).toBeFalsy();
});
it('The current selection is a merged cell of 1 row and 2 columns, with 1 ordinary cell', async () => {
@@ -648,29 +601,9 @@ describe('Test clipboard', () => {
// alert = true;
// });
- await sheetClipboardService.paste(clipboardItem);
+ const res = await sheetClipboardService.paste(clipboardItem);
+ expect(res).toBeFalsy();
// expect(alert).toBe(true);
-
- const values = getValues(startRow, startColumn, endRow, endColumn);
- const styles = getStyles(startRow, startColumn, endRow, endColumn);
- const mergedCells = getMergedCells(startRow, startColumn, endRow, endColumn);
-
- expect(values && values[0][0]?.v).toBe(undefined);
- expect(styles && styles[0][0]).toBe(undefined);
- expect(mergedCells).toStrictEqual([
- {
- startRow: 11,
- startColumn: 5,
- endRow: 12,
- endColumn: 6,
- },
- {
- startRow: 11,
- startColumn: 7,
- endRow: 12,
- endColumn: 7,
- },
- ]);
});
});
@@ -698,20 +631,8 @@ describe('Test clipboard', () => {
},
]);
- await sheetClipboardService.paste(clipboardItem);
-
- const values = getValues(startRow, startColumn, endRow, endColumn);
- const styles = getStyles(startRow, startColumn, endRow, endColumn);
- const mergedCells = getMergedCells(startRow, startColumn, endRow, endColumn);
-
- expect(values && values[0][0]?.v).toBe('row1col2');
-
- expect(mergedCells && mergedCells[0]).toStrictEqual({
- startRow,
- startColumn,
- endRow,
- endColumn,
- });
+ const res = await sheetClipboardService.paste(clipboardItem);
+ expect(res).toBeFalsy();
});
it('The current selection is a merged cell of 1 row and 2 columns, with a merged cell of 2 rows and 2 columns', async () => {
const selectionManager = get(SelectionManagerService);
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts
index cd61df8112..3dd3f7e54b 100644
--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts
@@ -29,6 +29,7 @@ import {
import type { Dependency, IDisposable } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
+import { CalculateFormulaService, DefinedNamesService, FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, IDefinedNamesService, IFormulaCurrentConfigService, IFormulaRuntimeService, LexerTreeBuilder } from '@univerjs/engine-formula';
import { SheetClipboardController } from '../../../controllers/clipboard/clipboard.controller';
import { IMarkSelectionService } from '../../mark-selection/mark-selection.service';
import { ISelectionRenderService, SelectionRenderService } from '../../selection/selection-render.service';
@@ -548,6 +549,12 @@ export function clipboardTestBed(workbookConfig?: IWorkbookData, dependencies?:
const sheetClipboardController = injector.createInstance(SheetClipboardController);
injector.add([SheetClipboardController, { useValue: sheetClipboardController }]);
injector.add([SheetInterceptorService]);
+ injector.add([CalculateFormulaService]);
+ injector.add([FormulaDataModel]);
+ injector.add([LexerTreeBuilder]);
+ injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);
+ injector.add([IFormulaRuntimeService, { useClass: FormulaRuntimeService }]);
+ injector.add([IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }]);
dependencies?.forEach((d) => injector.add(d));
}
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/constant.ts b/packages/sheets-ui/src/services/clipboard/__tests__/constant.ts
new file mode 100644
index 0000000000..da1e7b0a2d
--- /dev/null
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/constant.ts
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export const excelSample = '<html xmlns:v="urn:schemas-microsoft-com:vml"\r\nxmlns:o="urn:schemas-microsoft-com:office:office"\r\nxmlns:x="urn:schemas-microsoft-com:office:excel"\r\nxmlns="http://www.w3.org/TR/REC-html40">\r\n\r\n<head>\r\n<meta http-equiv=Content-Type content="text/html; charset=utf-8">\r\n<meta name=ProgId content=Excel.Sheet>\r\n<meta name=Generator content="Microsoft Excel 15">\r\n<link id=Main-File rel=Main-File\r\nhref="file:////Users/yuanbin/Library/Group%20Containers/UBF8T346G9.Office/TemporaryItems/msohtmlclip/clip.htm">\r\n<link rel=File-List\r\nhref="file:////Users/yuanbin/Library/Group%20Containers/UBF8T346G9.Office/TemporaryItems/msohtmlclip/clip_filelist.xml">\r\n<style>\r\n\x3C!--table\r\n\t{mso-displayed-decimal-separator:"\\.";\r\n\tmso-displayed-thousand-separator:"\\,";}\r\n@page\r\n\t{margin:.75in .7in .75in .7in;\r\n\tmso-header-margin:.3in;\r\n\tmso-footer-margin:.3in;}\r\n.font0\r\n\t{color:black;\r\n\tfont-size:12.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;}\r\n.font5\r\n\t{color:windowtext;\r\n\tfont-size:9.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;}\r\n.font6\r\n\t{color:#DAE9F8;\r\n\tfont-size:28.0pt;\r\n\tfont-weight:700;\r\n\tfont-style:italic;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;}\r\ntr\r\n\t{mso-height-source:auto;\r\n\tmso-ruby-visibility:none;}\r\ncol\r\n\t{mso-width-source:auto;\r\n\tmso-ruby-visibility:none;}\r\nbr\r\n\t{mso-data-placement:same-cell;}\r\ntd\r\n\t{padding-top:1px;\r\n\tpadding-right:1px;\r\n\tpadding-left:1px;\r\n\tmso-ignore:padding;\r\n\tcolor:black;\r\n\tfont-size:12.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;\r\n\tmso-number-format:General;\r\n\ttext-align:general;\r\n\tvertical-align:middle;\r\n\tborder:none;\r\n\tmso-background-source:auto;\r\n\tmso-pattern:auto;\r\n\tmso-protection:locked visible;\r\n\twhite-space:nowrap;\r\n\tmso-rotate:0;}\r\n.xl65\r\n\t{font-weight:700;\r\n\tfont-style:italic;}\r\n.xl66\r\n\t{text-align:center;\r\n\tborder-top:.5pt solid windowtext;\r\n\tborder-right:none;\r\n\tborder-bottom:.5pt solid windowtext;\r\n\tborder-left:.5pt solid windowtext;}\r\n.xl67\r\n\t{text-align:center;\r\n\tborder-top:.5pt solid windowtext;\r\n\tborder-right:.5pt solid windowtext;\r\n\tborder-bottom:.5pt solid windowtext;\r\n\tborder-left:none;}\r\n.xl68\r\n\t{text-align:center;\r\n\tborder-top:.5pt solid windowtext;\r\n\tborder-right:none;\r\n\tborder-bottom:none;\r\n\tborder-left:.5pt solid windowtext;}\r\n.xl69\r\n\t{text-align:center;\r\n\tborder-top:.5pt solid windowtext;\r\n\tborder-right:.5pt solid windowtext;\r\n\tborder-bottom:none;\r\n\tborder-left:none;}\r\n.xl70\r\n\t{text-align:center;\r\n\tborder-top:none;\r\n\tborder-right:none;\r\n\tborder-bottom:.5pt solid windowtext;\r\n\tborder-left:.5pt solid windowtext;}\r\n.xl71\r\n\t{text-align:center;\r\n\tborder-top:none;\r\n\tborder-right:.5pt solid windowtext;\r\n\tborder-bottom:.5pt solid windowtext;\r\n\tborder-left:none;}\r\n.xl72\r\n\t{mso-number-format:"Short Date";}\r\n.xl73\r\n\t{background:#0F9ED5;\r\n\tmso-pattern:black none;}\r\n.xl74\r\n\t{text-align:center;\r\n\tborder-top:.5pt solid windowtext;\r\n\tborder-right:.5pt solid windowtext;\r\n\tborder-bottom:none;\r\n\tborder-left:.5pt solid windowtext;\r\n\tbackground:#0F9ED5;\r\n\tmso-pattern:black none;}\r\n.xl75\r\n\t{text-align:center;\r\n\tborder-top:none;\r\n\tborder-right:.5pt solid windowtext;\r\n\tborder-bottom:none;\r\n\tborder-left:.5pt solid windowtext;\r\n\tbackground:#0F9ED5;\r\n\tmso-pattern:black none;}\r\n.xl76\r\n\t{text-align:center;\r\n\tborder-top:none;\r\n\tborder-right:.5pt solid windowtext;\r\n\tborder-bottom:.5pt solid windowtext;\r\n\tborder-left:.5pt solid windowtext;\r\n\tbackground:#0F9ED5;\r\n\tmso-pattern:black none;}\r\nruby\r\n\t{ruby-align:left;}\r\nrt\r\n\t{color:windowtext;\r\n\tfont-size:9.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;\r\n\tmso-char-type:none;\r\n\tdisplay:none;}\r\n-->\r\n</style>\r\n</head>\r\n\r\n<div style=\'max-height:42px\'></div>\r\n\r\n<body link="#467886" vlink="#96607D">\r\n\r\n<table border=0 cellpadding=0 cellspacing=0 width=354 style=\'border-collapse:\r\n collapse;width:265pt\'>\r\n\x3C!--StartFragment-->\r\n <col width=87 style=\'width:65pt\'>\r\n <col width=93 style=\'mso-width-source:userset;mso-width-alt:2986;width:70pt\'>\r\n <col width=87 span=2 style=\'width:65pt\'>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 width=87 style=\'height:16.0pt;width:65pt\'></td>\r\n <td width=93 style=\'width:70pt\'></td>\r\n <td width=87 style=\'width:65pt\'></td>\r\n <td width=87 style=\'width:65pt\'></td>\r\n </tr>\r\n <div style=\'max-height:84px\'></div>\r\n <tr height=47 style=\'height:35.0pt\'>\r\n <td height=47 style=\'height:35.0pt\'></td>\r\n <td class=xl65>Univer</td>\r\n <td class=xl73>U<font class="font6">niv</font><font class="font0">er</font></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td colspan=2 class=xl66 style=\'border-right:.5pt solid black\'>Univer</td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td colspan=2 rowspan=2 class=xl68 style=\'border-right:.5pt solid black;\r\n border-bottom:.5pt solid black\'>Univer</td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\' data-sheets-value="{&quot;1&quot;:3,&quot;3&quot;:45607}"\r\n data-sheets-numberformat="{&quot;1&quot;:5,&quot;2&quot;:&quot;yyyy/m/d&quot;,&quot;3&quot;:1}"></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=35 style=\'height:26.0pt\'>\r\n <td height=35 style=\'height:26.0pt\'></td>\r\n <td rowspan=5 class=xl74 style=\'border-bottom:.5pt solid black\'>Univer</td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=31 style=\'height:23.0pt\'>\r\n <td height=31 style=\'height:23.0pt\' data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;univer&quot;}"\r\n data-sheets-textstyleruns="{&quot;1&quot;:0}{&quot;1&quot;:1,&quot;2&quot;:{&quot;2&quot;:{&quot;1&quot;:2,&quot;2&quot;:14275305},&quot;4&quot;:18,&quot;5&quot;:1,&quot;6&quot;:1}}{&quot;1&quot;:4}"></td>\r\n <td class=xl72 align=right>2024/11/11</td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n\x3C!--EndFragment-->\r\n</table>\r\n\r\n</body>\r\n\r\n</html>\r\n';
+
+export const googleSample = '<google-sheets-html-origin><style type="text/css">\x3C!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--></style><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none" data-sheets-root="1"><colgroup><col width="100"/><col width="100"/><col width="100"/><col width="100"/></colgroup><tbody><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-weight:bold;font-style:italic;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;Univer&quot;}">Univer</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;background-color:#ff0000;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;univer&quot;}" data-sheets-textstyleruns="{&quot;1&quot;:0}{&quot;1&quot;:1,&quot;2&quot;:{&quot;2&quot;:{&quot;1&quot;:2,&quot;2&quot;:14275305},&quot;4&quot;:18,&quot;5&quot;:1,&quot;6&quot;:1}}{&quot;1&quot;:4}"><span style="font-size:10pt;font-family:Arial;font-style:normal;">u</span><span style="font-size:18pt;font-family:Arial;font-weight:bold;font-style:italic;color:#d9d2e9;">niv</span><span style="font-size:10pt;font-family:Arial;font-style:normal;">er</span></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:center;" rowspan="1" colspan="2" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;univer&quot;}">univer</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:center;" rowspan="2" colspan="2" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;univer&quot;}"><span><div style="max-height:42px">univer</div></span></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:middle;background-color:#ff0000;text-align:center;" rowspan="4" colspan="1" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;univer&quot;}"><span><div style="max-height:84px">univer</div></span></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{&quot;1&quot;:3,&quot;3&quot;:45607}" data-sheets-numberformat="{&quot;1&quot;:5,&quot;2&quot;:&quot;yyyy/m/d&quot;,&quot;3&quot;:1}">2024/11/11</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr></tbody></table>';
+
+// font
+export const fontSampleByExcel = '<html xmlns:v="urn:schemas-microsoft-com:vml"\r\nxmlns:o="urn:schemas-microsoft-com:office:office"\r\nxmlns:x="urn:schemas-microsoft-com:office:excel"\r\nxmlns="http://www.w3.org/TR/REC-html40">\r\n\r\n<head>\r\n<meta http-equiv=Content-Type content="text/html; charset=utf-8">\r\n<meta name=ProgId content=Excel.Sheet>\r\n<meta name=Generator content="Microsoft Excel 15">\r\n<link id=Main-File rel=Main-File\r\nhref="file:////Users/yuanbin/Library/Group%20Containers/UBF8T346G9.Office/TemporaryItems/msohtmlclip/clip.htm">\r\n<link rel=File-List\r\nhref="file:////Users/yuanbin/Library/Group%20Containers/UBF8T346G9.Office/TemporaryItems/msohtmlclip/clip_filelist.xml">\r\n<style>\r\n\x3C!--table\r\n\t{mso-displayed-decimal-separator:"\\.";\r\n\tmso-displayed-thousand-separator:"\\,";}\r\n@page\r\n\t{margin:.75in .7in .75in .7in;\r\n\tmso-header-margin:.3in;\r\n\tmso-footer-margin:.3in;}\r\n.font5\r\n\t{color:windowtext;\r\n\tfont-size:9.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;}\r\ntr\r\n\t{mso-height-source:auto;\r\n\tmso-ruby-visibility:none;}\r\ncol\r\n\t{mso-width-source:auto;\r\n\tmso-ruby-visibility:none;}\r\nbr\r\n\t{mso-data-placement:same-cell;}\r\ntd\r\n\t{padding-top:1px;\r\n\tpadding-right:1px;\r\n\tpadding-left:1px;\r\n\tmso-ignore:padding;\r\n\tcolor:black;\r\n\tfont-size:12.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;\r\n\tmso-number-format:General;\r\n\ttext-align:general;\r\n\tvertical-align:middle;\r\n\tborder:none;\r\n\tmso-background-source:auto;\r\n\tmso-pattern:auto;\r\n\tmso-protection:locked visible;\r\n\twhite-space:nowrap;\r\n\tmso-rotate:0;}\r\n.xl65\r\n\t{font-size:18.0pt;}\r\n.xl66\r\n\t{text-decoration:underline;\r\n\ttext-underline-style:single;}\r\n.xl67\r\n\t{font-weight:700;}\r\n.xl68\r\n\t{font-style:italic;}\r\n.xl70\r\n\t{font-weight:700;\r\n\tfont-style:italic;\r\n\ttext-decoration:underline;\r\n\ttext-underline-style:single;}\r\n.xl71\r\n\t{color:yellow;}\r\n.xl72\r\n\t{font-family:仿宋;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;}\r\n.xl73\r\n\t{background:yellow;\r\n\tmso-pattern:black none;}\r\nruby\r\n\t{ruby-align:left;}\r\nrt\r\n\t{color:windowtext;\r\n\tfont-size:9.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;\r\n\tmso-char-type:none;\r\n\tdisplay:none;}\r\n-->\r\n</style>\r\n</head>\r\n\r\n<body link="#0563C1" vlink="#954F72">\r\n\r\n<table border=0 cellpadding=0 cellspacing=0 width=129 style=\'border-collapse:\r\n collapse;width:97pt\'>\r\n\x3C!--StartFragment-->\r\n <col width=129 style=\'mso-width-source:userset;mso-width-alt:4138;width:97pt\'>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 class=xl67 width=129 style=\'height:16.0pt;width:97pt\'>B</td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 class=xl68 style=\'height:16.0pt\'>I</td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 class=xl66 style=\'height:16.0pt\'>U</td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 class=xl69 style=\'height:16.0pt\'><s>S</s></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 class=xl70 style=\'height:16.0pt\'><s>BOTH</s></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'>font-size:12</td>\r\n </tr>\r\n <tr height=31 style=\'height:23.0pt\'>\r\n <td height=31 class=xl65 style=\'height:23.0pt\'>font-size:18</td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 class=xl71 style=\'height:16.0pt\'>color</td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 class=xl73 style=\'height:16.0pt\'>background</td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 class=xl72 style=\'height:16.0pt\'>font-family</td>\r\n </tr>\r\n\x3C!--EndFragment-->\r\n</table>\r\n\r\n</body>\r\n\r\n</html>\r\n';
+export const fontSampleByGoogle = '<google-sheets-html-origin><style type="text/css">\x3C!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--></style><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none" data-sheets-root="1"><colgroup><col width="100"/></colgroup><tbody><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-weight:bold;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;B&quot;}">B</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-style:italic;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;I&quot;}">I</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-family:Arial;font-weight:normal;text-decoration:underline;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;U&quot;}">U</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-decoration:line-through;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;S&quot;}">S</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-size:12pt;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;font-size:12&quot;}">font-size:12</td></tr><tr style="height:21px;"><td style="border-right:1px solid transparent;overflow:visible;padding:2px 0px 2px 0px;vertical-align:bottom;font-size:18pt;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;font-size:18&quot;}"><div style="white-space:nowrap;overflow:hidden;position:relative;width:196px;left:3px;"><div style="float:left;">font-size:18</div></div></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;color:#ffff00;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;color&quot;}">color</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;background-color:#ffff00;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;background&quot;}">background</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-family:Hei;font-weight:normal;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;font-family&quot;}">font-family</td></tr></tbody></table>';
+export const fontSampleByUniver = '<html><head></head><body><google data-copy-id="ZLzDRp" -sheets-html-origin=""><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none"><colgroup><col width="73"></colgroup>\n<tbody><tr style="height: 19px;"><td style="font-weight: bold; ">B</td></tr><tr style="height: 19px;"><td style="font-style: italic; ">I</td></tr><tr style="height: 19px;"><td style="text-decoration-line: underline; ">U</td></tr><tr style="height: 19px;"><td style="text-decoration-line: line-through; ">S</td></tr><tr style="height: 19px;"><td style="font-size: 12pt; ">font-size:12</td></tr><tr style="height: 29px;"><td style="font-size: 18pt; ">font-size:18</td></tr><tr style="height: 19px;"><td style="color: #ffff00; ">color</td></tr><tr style="height: 19px;"><td style="background: #ffff00; ">background</td></tr><tr style="height: 19px;"><td style="font-family: SimSun; ">font-family</td></tr></tbody></table></google></body></html>';
+
+// border
+export const borderSampleByExcel = '<html xmlns:v="urn:schemas-microsoft-com:vml"\r\nxmlns:o="urn:schemas-microsoft-com:office:office"\r\nxmlns:x="urn:schemas-microsoft-com:office:excel"\r\nxmlns="http://www.w3.org/TR/REC-html40">\r\n\r\n<head>\r\n<meta http-equiv=Content-Type content="text/html; charset=utf-8">\r\n<meta name=ProgId content=Excel.Sheet>\r\n<meta name=Generator content="Microsoft Excel 15">\r\n<link id=Main-File rel=Main-File\r\nhref="file:////Users/yuanbin/Library/Group%20Containers/UBF8T346G9.Office/TemporaryItems/msohtmlclip/clip.htm">\r\n<link rel=File-List\r\nhref="file:////Users/yuanbin/Library/Group%20Containers/UBF8T346G9.Office/TemporaryItems/msohtmlclip/clip_filelist.xml">\r\n<style>\r\n\x3C!--table\r\n\t{mso-displayed-decimal-separator:"\\.";\r\n\tmso-displayed-thousand-separator:"\\,";}\r\n@page\r\n\t{margin:.75in .7in .75in .7in;\r\n\tmso-header-margin:.3in;\r\n\tmso-footer-margin:.3in;}\r\ntr\r\n\t{mso-height-source:auto;\r\n\tmso-ruby-visibility:none;}\r\ncol\r\n\t{mso-width-source:auto;\r\n\tmso-ruby-visibility:none;}\r\nbr\r\n\t{mso-data-placement:same-cell;}\r\ntd\r\n\t{padding-top:1px;\r\n\tpadding-right:1px;\r\n\tpadding-left:1px;\r\n\tmso-ignore:padding;\r\n\tcolor:black;\r\n\tfont-size:12.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;\r\n\tmso-number-format:General;\r\n\ttext-align:general;\r\n\tvertical-align:middle;\r\n\tborder:none;\r\n\tmso-background-source:auto;\r\n\tmso-pattern:auto;\r\n\tmso-protection:locked visible;\r\n\twhite-space:nowrap;\r\n\tmso-rotate:0;}\r\n.xl65\r\n\t{border:.5pt solid black;}\r\n.xl66\r\n\t{text-align:center;\r\n\tborder:.5pt solid black;}\r\nruby\r\n\t{ruby-align:left;}\r\nrt\r\n\t{color:windowtext;\r\n\tfont-size:9.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;\r\n\tmso-char-type:none;\r\n\tdisplay:none;}\r\n-->\r\n</style>\r\n</head>\r\n\r\n<body link="#0563C1" vlink="#954F72">\r\n\r\n<table border=0 cellpadding=0 cellspacing=0 width=348 style=\'border-collapse:\r\n collapse;width:260pt\'>\r\n\x3C!--StartFragment-->\r\n <col width=87 span=4 style=\'width:65pt\'>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 width=87 style=\'height:16.0pt;width:65pt\'></td>\r\n <td width=87 style=\'width:65pt\'></td>\r\n <td width=87 style=\'width:65pt\'></td>\r\n <td width=87 style=\'width:65pt\'></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td class=xl65> </td>\r\n <td class=xl65 style=\'border-left:none\'> </td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td class=xl65 style=\'border-top:none\'> </td>\r\n <td class=xl65 style=\'border-top:none;border-left:none\'> </td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td class=xl65 style=\'border-top:none\'> </td>\r\n <td class=xl65 style=\'border-top:none;border-left:none\'> </td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td class=xl65 style=\'border-top:none\'> </td>\r\n <td class=xl65 style=\'border-top:none;border-left:none\'> </td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td class=xl65 style=\'border-top:none\'> </td>\r\n <td class=xl65 style=\'border-top:none;border-left:none\'> </td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td colspan=2 rowspan=5 class=xl66> </td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n </tr>\r\n <tr height=21 style=\'height:16.0pt\'>\r\n <td height=21 style=\'height:16.0pt\'></td>\r\n <td></td>\r\n <td></td>\r\n <td></td>\r\n </tr>\r\n\x3C!--EndFragment-->\r\n</table>\r\n\r\n</body>\r\n\r\n</html>\r\n';
+export const borderSampleByGoogle = '<google-sheets-html-origin><style type="text/css">\x3C!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--></style><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none" data-sheets-root="1"><colgroup><col width="100"/><col width="100"/><col width="100"/><col width="100"/></colgroup><tbody><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="border-right:1px solid #000000;border-bottom:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" rowspan="5" colspan="2"><span><div style="max-height:105px"></div></span></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="border-right:1px solid #000000;overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;"></td></tr></tbody></table>';
+export const borderSampleByUniver = '<html><head></head><body><google data-copy-id="PgwMK9" -sheets-html-origin=""><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none"><colgroup><col width="73"><col width="73"><col width="73"><col width="73"></colgroup>\n<tbody><tr style="height: 19px;"><td></td><td></td><td></td><td></td></tr><tr style="height: 19px;"><td></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td></td></tr><tr style="height: 19px;"><td></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td></td></tr><tr style="height: 19px;"><td></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td></td></tr><tr style="height: 19px;"><td></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td></td></tr><tr style="height: 19px;"><td></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td style="border-bottom: 0.5pt solid #000000; border-top: 0.5pt solid #000000; border-right: 0.5pt solid #000000; border-left: 0.5pt solid #000000; "></td><td></td></tr><tr style="height: 19px;"><td></td><td></td><td></td><td></td></tr><tr style="height: 19px;"><td></td><td></td><td></td><td></td></tr><tr style="height: 19px;"><td></td><td rowspan="5" colspan="2" style="border-top: 0.5pt solid #000000; border-left: 0.5pt solid #000000; ;border-bottom: 0.5pt solid #000000; border-right: 0.5pt solid #000000; "></td><td></td></tr><tr style="height: 19px;"><td></td><td></td></tr><tr style="height: 19px;"><td></td><td></td></tr><tr style="height: 19px;"><td></td><td></td></tr><tr style="height: 19px;"><td></td><td></td></tr><tr style="height: 19px;"><td></td><td></td><td></td><td></td></tr></tbody></table></google></body></html>';
+
+// rotate
+export const rotateSampleByUniver = '<html><head></head><body><google data-copy-id="1rz7ZZ" -sheets-html-origin=""><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none"><colgroup><col width="73"></colgroup>\n<tbody><tr style="height: 19px;"><td>univer</td></tr><tr style="height: 46.67004020088826px;"><td style="data-rotate: (-45deg);">univer</td></tr><tr style="height: 46.67004020088826px;"><td style="data-rotate: (45deg);">univer</td></tr><tr style="height: 48.00140380859375px;"><td style="data-rotate: (0deg ,1);">univer</td></tr><tr style="height: 48.00140380859375px;"><td style="data-rotate: (-90deg);">univer</td></tr><tr style="height: 48.00140380859375px;"><td style="data-rotate: (90deg);">univer</td></tr></tbody></table></google></body></html>';
+
+// alignment
+export const alignmentSampleByExcel = '<html xmlns:v="urn:schemas-microsoft-com:vml"\r\nxmlns:o="urn:schemas-microsoft-com:office:office"\r\nxmlns:x="urn:schemas-microsoft-com:office:excel"\r\nxmlns="http://www.w3.org/TR/REC-html40">\r\n\r\n<head>\r\n<meta http-equiv=Content-Type content="text/html; charset=utf-8">\r\n<meta name=ProgId content=Excel.Sheet>\r\n<meta name=Generator content="Microsoft Excel 15">\r\n<link id=Main-File rel=Main-File\r\nhref="file:////Users/yuanbin/Library/Group%20Containers/UBF8T346G9.Office/TemporaryItems/msohtmlclip/clip.htm">\r\n<link rel=File-List\r\nhref="file:////Users/yuanbin/Library/Group%20Containers/UBF8T346G9.Office/TemporaryItems/msohtmlclip/clip_filelist.xml">\r\n<style>\r\n\x3C!--table\r\n\t{mso-displayed-decimal-separator:"\\.";\r\n\tmso-displayed-thousand-separator:"\\,";}\r\n@page\r\n\t{margin:.75in .7in .75in .7in;\r\n\tmso-header-margin:.3in;\r\n\tmso-footer-margin:.3in;}\r\ntr\r\n\t{mso-height-source:auto;\r\n\tmso-ruby-visibility:none;}\r\ncol\r\n\t{mso-width-source:auto;\r\n\tmso-ruby-visibility:none;}\r\nbr\r\n\t{mso-data-placement:same-cell;}\r\ntd\r\n\t{padding-top:1px;\r\n\tpadding-right:1px;\r\n\tpadding-left:1px;\r\n\tmso-ignore:padding;\r\n\tcolor:black;\r\n\tfont-size:12.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;\r\n\tmso-number-format:General;\r\n\ttext-align:general;\r\n\tvertical-align:middle;\r\n\tborder:none;\r\n\tmso-background-source:auto;\r\n\tmso-pattern:auto;\r\n\tmso-protection:locked visible;\r\n\twhite-space:nowrap;\r\n\tmso-rotate:0;}\r\n.xl65\r\n\t{text-align:left;\r\n\tvertical-align:bottom;}\r\n.xl66\r\n\t{text-align:right;\r\n\tvertical-align:bottom;}\r\n.xl67\r\n\t{text-align:center;\r\n\tvertical-align:bottom;}\r\n.xl68\r\n\t{vertical-align:top;}\r\n.xl69\r\n\t{color:#44546A;\r\n\tfont-size:11.0pt;\r\n\tfont-weight:700;}\r\n.xl70\r\n\t{vertical-align:bottom;}\r\nruby\r\n\t{ruby-align:left;}\r\nrt\r\n\t{color:windowtext;\r\n\tfont-size:9.0pt;\r\n\tfont-weight:400;\r\n\tfont-style:normal;\r\n\ttext-decoration:none;\r\n\tfont-family:等线;\r\n\tmso-generic-font-family:auto;\r\n\tmso-font-charset:134;\r\n\tmso-char-type:none;\r\n\tdisplay:none;}\r\n-->\r\n</style>\r\n</head>\r\n\r\n<body link="#0563C1" vlink="#954F72">\r\n\r\n<table border=0 cellpadding=0 cellspacing=0 width=522 style=\'border-collapse:\r\n collapse;width:390pt\'>\r\n <col width=87 span=6 style=\'width:65pt\'>\r\n <tr height=88 style=\'mso-height-source:userset;height:66.0pt\'>\r\n\x3C!--StartFragment-->\r\n <td height=88 class=xl65 width=87 style=\'height:66.0pt;width:65pt\'>左对齐</td>\r\n <td class=xl66 width=87 style=\'width:65pt\'>右对齐</td>\r\n <td class=xl67 width=87 style=\'width:65pt\'>中间对齐</td>\r\n <td class=xl68 width=87 style=\'width:65pt\'>顶部</td>\r\n <td class=xl70 width=87 style=\'width:65pt\'>底部对齐</td>\r\n <td class=xl69 width=87 style=\'width:65pt\'>居中对齐</td>\r\n\x3C!--EndFragment-->\r\n </tr>\r\n</table>\r\n\r\n</body>\r\n\r\n</html>\r\n';
+export const alignmentSampleByGoogle = '<google-sheets-html-origin><style type="text/css">\x3C!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--></style><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none" data-sheets-root="1"><colgroup><col width="100"/><col width="100"/><col width="100"/><col width="100"/><col width="100"/><col width="100"/></colgroup><tbody><tr style="height:65px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-family:Arial;font-size:12pt;font-weight:normal;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;左对齐&quot;}">左对齐</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-family:Arial;font-size:12pt;font-weight:normal;text-align:right;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;右对齐&quot;}">右对齐</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-family:Arial;font-size:12pt;font-weight:normal;text-align:center;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;中间对齐&quot;}">中间对齐</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:top;font-family:Arial;font-size:12pt;font-weight:normal;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;顶部&quot;}">顶部</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;font-family:Arial;font-size:12pt;font-weight:normal;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;底部对齐&quot;}">底部对齐</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:middle;font-family:Arial;font-size:11pt;font-weight:bold;color:#44546a;" data-sheets-value="{&quot;1&quot;:2,&quot;2&quot;:&quot;居中对齐&quot;}">居中对齐</td></tr></tbody></table>';
+export const alignmentSampleByUniver = '<html><head></head><body><google data-copy-id="rJhHMI" -sheets-html-origin=""><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none"><colgroup><col width="73"><col width="73"><col width="73"><col width="73"><col width="73"><col width="73"></colgroup>\n<tbody><tr style="height: 66px;"><td style="color: rgb(0, 0, 0); font-size: 12pt; text-align: left; vertical-align: bottom; font-family: 等线; ">左对齐</td><td style="color: rgb(0, 0, 0); font-size: 12pt; text-align: right; vertical-align: bottom; font-family: 等线; ">右对齐</td><td style="color: rgb(0, 0, 0); font-size: 12pt; text-align: center; vertical-align: bottom; font-family: 等线; ">中间对齐</td><td style="color: rgb(0, 0, 0); font-size: 12pt; vertical-align: top; font-family: 等线; ">顶部</td><td style="color: rgb(0, 0, 0); font-size: 12pt; vertical-align: bottom; font-family: 等线; ">底部对齐</td><td style="color: rgb(68, 84, 106); font-size: 11pt; vertical-align: middle; font-weight: bold; font-family: 等线; ">居中对齐</td></tr></tbody></table></google></body></html>';
diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
index e39a1d470c..7f3b63726b 100644
--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
@@ -17,6 +17,7 @@
import type { ICellData, IMutationInfo, IRange, Worksheet } from '@univerjs/core';
import {
Disposable,
+ ErrorService,
extractPureTextFromCell,
ICommandService,
ILogService,
@@ -109,7 +110,8 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
@Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,
@INotificationService private readonly _notificationService: INotificationService,
@IPlatformService private readonly _platformService: IPlatformService,
- @Inject(LocaleService) private readonly _localeService: LocaleService
+ @Inject(LocaleService) private readonly _localeService: LocaleService,
+ @Inject(ErrorService) private readonly _errorService: ErrorService
) {
super();
this._htmlToUSM = new HtmlToUSMService({
@@ -221,7 +223,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
addClipboardHook(hook: ISheetClipboardHook): IDisposable {
if (this._clipboardHooks.findIndex((h) => h.id === hook.id) !== -1) {
this._logService.error('[SheetClipboardService]', 'hook already exists', hook.id);
- return { dispose: () => {} };
+ return { dispose: () => { } };
}
// hook added should be ordered at meaning while
const insertIndex = this._clipboardHooks.findIndex((existingHook) => {
@@ -374,12 +376,19 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
// cell properties and cell contents.
const { rowProperties, colProperties, cellMatrix } = this._htmlToUSM.convert(html);
const { startColumn, endColumn, startRow, endRow } = cellMatrix.getDataRange();
- const rowCount = endRow - startRow + 1;
- const colCount = endColumn - startColumn + 1;
if (!cellMatrix || endColumn < startColumn || endRow < startRow) {
return false;
}
+ const worksheet = this._univerInstanceService
+ .getUniverSheetInstance(unitId)
+ ?.getSheetBySheetId(subUnitId);
+ if (!worksheet) {
+ return false;
+ }
+
+ const mergeData = worksheet?.getMergeData();
+
// 2. get filtered rows in the target pasting area and get the final pasting matrix
// we also handle transpose pasting at this step
// note: handle transpose before filtering
@@ -388,7 +397,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
// 3. call hooks with cell position and properties and get mutations (both do mutations and undo mutations)
// we also handle 'copy value only' or 'copy style only' as this step
- const pastedRange = this._transformPastedData(rowCount, colCount, cellMatrix, selection.range);
+ const pastedRange = this._getPastedRange(cellMatrix, selection.range, mergeData);
// pastedRange.endColumn = pastedRange.startColumn + colCount;
// pastedRange.endRow = pastedRange.startRow + rowCount;
@@ -398,6 +407,14 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
return false;
}
+ if (mergeData) {
+ const pastedRangeLapWithMergedCell = mergeData.some((merge) => Rectangle.intersects(pastedRange, merge) && !Rectangle.contains(pastedRange, merge));
+ if (pastedRangeLapWithMergedCell) {
+ this._errorService.emit('The paste area overlaps with merged cells.');
+ return false;
+ }
+ }
+
// 4. execute these mutations by the one method
return this._pasteUSM(
{
@@ -436,24 +453,34 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
}
});
+ const worksheet = this._univerInstanceService
+ .getUniverSheetInstance(copyUnitId)
+ ?.getSheetBySheetId(copySubUnitId);
+ if (!worksheet) {
+ return false;
+ }
+
+ const mergeData = worksheet?.getMergeData();
+
const { startColumn, endColumn, startRow, endRow } = range;
- const pastedRange = this._transformPastedData(
- endRow - startRow + 1,
- endColumn - startColumn + 1,
+ const pastedRange = this._getPastedRange(
cellMatrix,
- selection.range
+ selection.range,
+ mergeData
);
if (!pastedRange) {
return false;
}
- const worksheet = this._univerInstanceService
- .getUniverSheetInstance(copyUnitId)
- ?.getSheetBySheetId(copySubUnitId);
- if (!worksheet) {
- return false;
+ if (mergeData) {
+ const pastedRangeLapWithMergedCell = mergeData.some((merge) => Rectangle.intersects(pastedRange, merge) && !Rectangle.contains(pastedRange, merge));
+ if (pastedRangeLapWithMergedCell) {
+ this._errorService.emit('The paste area overlaps with merged cells.');
+ return false;
+ }
}
+
const colManager = worksheet.getColumnManager();
const rowManager = worksheet.getRowManager();
const defaultColumnWidth = worksheet.getConfig().defaultColumnWidth;
@@ -469,7 +496,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
for (let j = startRow; j <= endRow; j++) {
const row = rowManager.getRowOrCreate(j);
- rowProperties.push({ height: `${row.h || defaultRowHeight}` });
+ rowProperties.push({ height: `${row.ah || row.h || defaultRowHeight}` });
}
const pasteRes = this._pasteUSM(
@@ -818,6 +845,39 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
return range;
}
+ private _getPastedRange(cellMatrix: ObjectMatrix<ICellDataWithSpanInfo>, pasteRange: IRange, mergedCell: IRange[]) {
+ const { startColumn, endColumn, startRow, endRow } = cellMatrix.getDataRange();
+ const rowCount = endRow - startRow + 1;
+ const colCount = endColumn - startColumn + 1;
+
+ const pasteStartRow = pasteRange.startRow;
+ const pasteStartColumn = pasteRange.startColumn;
+
+ const pasteSelectionRangeRowLen = pasteRange.endRow - pasteRange.startRow + 1;
+ const pasteSelectionRangeColLen = pasteRange.endColumn - pasteRange.startColumn + 1;
+
+ if (pasteSelectionRangeRowLen % rowCount === 0 && pasteSelectionRangeColLen % colCount === 0) {
+ const hasLapWithMerge = mergedCell?.some((merge) => Rectangle.intersects(pasteRange, merge));
+ if (!hasLapWithMerge) {
+ for (let r = 0; r < pasteSelectionRangeRowLen; r++) {
+ for (let c = 0; c < pasteSelectionRangeColLen; c++) {
+ const cell = cellMatrix.getValue(r % rowCount, c % colCount);
+ cell && cellMatrix.setValue(r, c, cell);
+ }
+ }
+ return pasteRange;
+ }
+ }
+
+ return {
+ ...pasteRange,
+ startRow: pasteStartRow,
+ startColumn: pasteStartColumn,
+ endRow: pasteStartRow + rowCount - 1,
+ endColumn: pasteStartColumn + colCount - 1,
+ };
+ }
+
/**
* Determine whether the cells starting from the upper left corner of the range (merged or non-merged or combined) are consistent with the size of the original data
* @param cellMatrix
@@ -849,6 +909,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
function getMatrixPlainText(matrix: ObjectMatrix<ICellDataWithSpanInfo>) {
let plain = '';
+ const matrixLength = matrix.getLength();
matrix.forRow((row, cols) => {
const arr: string[] = [];
cols.forEach((col) => {
@@ -859,7 +920,7 @@ function getMatrixPlainText(matrix: ObjectMatrix<ICellDataWithSpanInfo>) {
}
});
plain += arr.join('\t');
- if (row !== matrix.getLength() - 1) {
+ if (row !== matrixLength - 1) {
plain += '\n';
}
});
diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts
index 5684708e72..f1dcb04f5c 100644
--- a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts
+++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts
@@ -19,13 +19,12 @@ import { ObjectMatrix } from '@univerjs/core';
import { handleStringToStyle } from '@univerjs/ui';
import type { IPastePlugin } from '@univerjs/docs-ui';
-import { pixelToPt } from '@univerjs/engine-render';
-import { generateBody } from '../../../controllers/clipboard/utils';
+import type { SpreadsheetSkeleton } from '@univerjs/engine-render';
import type { ISheetSkeletonManagerParam } from '../../sheet-skeleton-manager.service';
import type {
ICellDataWithSpanInfo,
IClipboardPropertyItem,
- IParsedCellValue,
+ IParsedCellValueByClipboard,
IUniverSheetCopyDataModel,
} from '../type';
import { extractNodeStyle } from './parse-node-style';
@@ -41,6 +40,27 @@ export interface IParsedTablesInfo {
index: number;
}
+const sheetStyleRules: string[] =
+ [
+ 'color_color',
+ 'background_background',
+ 'font-size_fontSize',
+ 'text-align_textAlign',
+ 'vertical-align_verticalAlign',
+ 'font-weight_fontWeight',
+ 'font-style_fontStyle',
+ 'font-family_fontFamily',
+ 'text-decoration_textDecoration',
+ ];
+
+const borderRules: string[] =
+ [
+ 'border-left_borderLeft',
+ 'border-right_borderRight',
+ 'border-top_borderTop',
+ 'border-bottom_borderBottom',
+ ];
+
function matchFilter(node: HTMLElement, filter: IStyleRule['filter']) {
const tagName = node.tagName.toLowerCase();
@@ -159,29 +179,6 @@ export class HtmlToUSMService {
p,
});
rowProperties.push({}); // TODO@yuhongz
-
- if (tableStrings) {
- tables.forEach((t) => {
- const curRow = valueMatrix.getDataRange().endRow + 1;
- if (t.index === i) {
- const tableString = tableStrings.shift();
- const {
- cellMatrix,
- colProperties: tableColProp,
- rowProperties: tableRowProp,
- } = this._parseTable(tableString!);
-
- cellMatrix &&
- cellMatrix.forValue((row, col, value) => {
- valueMatrix.setValue(curRow + row, col, value);
- });
- if (tableColProp) {
- colProperties.push(...tableColProp);
- }
- rowProperties.push(...tableRowProp);
- }
- });
- }
}
} else {
if (dataStream) {
@@ -200,30 +197,21 @@ export class HtmlToUSMService {
});
rowProperties.push({}); // TODO@yuhongz
}
-
- if (tableStrings) {
- tableStrings.forEach((t) => {
- const curRow = valueMatrix.getDataRange().endRow + 1;
- const { cellMatrix, rowProperties: tableRowProp, colProperties: tableColProp } = this._parseTable(t!);
- if (cellMatrix) {
- cellMatrix.forValue((row, col, value) => {
- const { rowSpan = 1, colSpan = 1 } = value;
- for (let i = 0; i < rowSpan; i++) {
- for (let j = 0; j < colSpan; j++) {
- valueMatrix.setValue(curRow + row + i, col + j, {
- v: '',
- });
- }
- }
- valueMatrix.setValue(curRow + row, col, value);
- });
- }
- if (tableColProp) {
- colProperties.push(...tableColProp);
- }
- rowProperties.push(...tableRowProp);
- });
- }
+ }
+ if (tableStrings) {
+ tableStrings.forEach((t) => {
+ const curRow = valueMatrix.getDataRange().endRow + 1;
+ const { cellMatrix, rowProperties: tableRowProp, colProperties: tableColProp } = this._parseTable(t!);
+ if (cellMatrix) {
+ cellMatrix.forValue((row, col, value) => {
+ valueMatrix.setValue(curRow + row, col, value);
+ });
+ }
+ if (tableColProp) {
+ colProperties.push(...tableColProp);
+ }
+ rowProperties.push(...tableRowProp);
+ });
}
return {
rowProperties,
@@ -234,68 +222,27 @@ export class HtmlToUSMService {
private _parseTable(html: string) {
const valueMatrix = new ObjectMatrix<ICellDataWithSpanInfo>();
- const colProperties = parseColGroup(html);
- const { rowProperties, rowCount, cellMatrix: parsedCellMatrix } = parseTableRows(html);
+ const colProperties = parseColGroup(html) ?? [];
+ const { rowProperties = [] } = parseTableRows(html);
+ const parsedCellMatrix = parseTableByHtml(this.htmlElement, this.getCurrentSkeleton()?.skeleton);
parsedCellMatrix &&
parsedCellMatrix.forValue((row, col, value) => {
- let styleString = value.properties?.style;
- // TODO@Dushusir Temporarily use handleStringToStyle. After all replication and paste function is completed, fix the handleStringToStyle method
-
- const className = value.properties?.class;
- if (className) {
- const dom = this.htmlElement.contentDocument?.getElementsByClassName(className)?.[0];
- if (dom) {
- const computedStyle = window.getComputedStyle(dom!, null);
-
- const { fontSize, fontFamily, border, borderLeft, borderRight, borderTop, borderBottom, verticalAlign } = computedStyle;
- if (fontSize) {
- styleString += `;font-size: ${pixelToPt(Number.parseInt(fontSize))}pt`;
- }
- if (fontFamily) {
- styleString += `;font-family: ${fontFamily}`;
- }
- if (border) {
- styleString += `;border: ${border}`;
- }
- if (borderLeft) {
- styleString += `;border-left: ${borderLeft}`;
- }
- if (borderRight) {
- styleString += `;border-right: ${borderRight}`;
- }
- if (borderTop) {
- styleString += `;border-top: ${borderTop}`;
- }
- if (borderBottom) {
- styleString += `;border-bottom: ${borderBottom}`;
- }
- if (verticalAlign) {
- styleString += `;vertical-align: ${verticalAlign}`;
- }
- }
- }
- const style = handleStringToStyle(undefined, styleString);
-
- if (/\r|\n/.test(value.content)) {
- const body = generateBody(value.content);
- const p = this._generateDocumentDataModelSnapshot({
- body,
- });
- valueMatrix.setValue(row, col, {
- v: value.content,
- p,
+ const style = handleStringToStyle(undefined, value.style);
+ const cellValue = value?.richTextParma?.p
+ ? {
+ v: value.richTextParma.v,
+ p: value.richTextParma.p,
s: style,
rowSpan: value.rowSpan,
colSpan: value.colSpan,
- });
- } else {
- valueMatrix.setValue(row, col, {
+ }
+ : {
v: value.content,
s: style,
rowSpan: value.rowSpan,
colSpan: value.colSpan,
- });
- }
+ };
+ valueMatrix.setValue(row, col, cellValue);
});
return {
rowProperties,
@@ -356,6 +303,9 @@ export class HtmlToUSMService {
});
}
} else if (node.nodeType === Node.ELEMENT_NODE) {
+ if (node.nodeName === 'STYLE') {
+ continue;
+ }
const parentStyles = parent ? this.styleCache.get(parent) : {};
const styleRule = this.styleRules.find(({ filter }) => matchFilter(node as HTMLElement, filter));
const nodeStyles = styleRule
@@ -392,8 +342,6 @@ export class HtmlToUSMService {
function parseTableRows(html: string): {
rowProperties: IClipboardPropertyItem[];
rowCount: number;
- colCount: number;
- cellMatrix: ObjectMatrix<IParsedCellValue> | null;
} {
const ROWS_REGEX = /<tr([\s\S]*?)>([\s\S]*?)<\/tr>/gi;
const rowMatches = html.matchAll(ROWS_REGEX);
@@ -401,89 +349,15 @@ function parseTableRows(html: string): {
return {
rowProperties: [],
rowCount: 0,
- colCount: 0,
- cellMatrix: null,
};
}
const rowMatchesAsArray = Array.from(rowMatches);
const rowProperties = rowMatchesAsArray.map((rowMatch) => parseProperties(rowMatch[1]));
- const { colCount, cellMatrix } = parseTableCells(rowMatchesAsArray.map((rowMatch) => rowMatch[2]));
-
return {
rowProperties,
rowCount: rowProperties.length,
- colCount,
- cellMatrix,
- };
-}
-
-/**
- *
- * @param tdStrings
- */
-function parseTableCells(tdStrings: string[]) {
- const cellMatrix = new ObjectMatrix<IParsedCellValue>();
- const maxRowOfCol = new Map<number, number>();
- const TDS_REGEX = /<td([\s\S]*?)>([\s\S]*?)<\/td>/gi;
-
- let colCount = 0;
- let colIndex = 0;
- let rowIndex = 0;
-
- tdStrings.forEach((trStr, r) => {
- const isFirstRow = r === 0;
- const cellMatches = trStr.matchAll(TDS_REGEX);
-
- colIndex = 0;
-
- Array.from(cellMatches).forEach((cellMatch) => {
- const cellProperties = parseProperties(cellMatch[1]);
- const content = decodeHTMLEntities(cellMatch[2].replace('<br>', '\r').replace(/<\/?[^>]*>/g, '')); // paste from excel
- const rowSpan = cellProperties.rowspan ? +cellProperties.rowspan : 1;
- const colSpan = cellProperties.colspan ? +cellProperties.colspan : 1;
-
- if (!isFirstRow) {
- for (let i = colIndex; i < colCount; i++) {
- const thisPosOccupied = maxRowOfCol.get(i)! >= rowIndex;
- if (!thisPosOccupied) {
- colIndex = i;
- break;
- }
- }
- }
-
- const value: IParsedCellValue = {
- content,
- properties: cellProperties,
- };
- if (colSpan > 1) value.colSpan = +colSpan;
- if (rowSpan > 1) value.rowSpan = +rowSpan;
-
- // when iterating the first row, we should calc colCount as well
- if (isFirstRow) {
- colCount += colSpan;
- }
-
- // update maxRowOfCol
- for (let i = colIndex; i < colIndex + colSpan; i++) {
- maxRowOfCol.set(i, rowIndex + rowSpan - 1);
- }
-
- // set value to matrix
- cellMatrix.setValue(rowIndex, colIndex, value);
-
- // point to next colIndex
- colIndex += colSpan;
- });
-
- rowIndex += 1;
- });
-
- return {
- colCount,
- cellMatrix,
};
}
@@ -513,14 +387,8 @@ function parseProperties(propertyStr: string): IClipboardPropertyItem {
* @returns cols and their properties
*/
function parseColGroup(raw: string): IClipboardPropertyItem[] | null {
- const COLGROUP_TAG_REGEX = /<colgroup([\s\S]*?)>(.*?)<\/colgroup>/;
- const colgroupMatch = raw.match(COLGROUP_TAG_REGEX);
- if (!colgroupMatch || !colgroupMatch[2]) {
- return null;
- }
-
const COL_TAG_REGEX = /<col([\s\S]*?)>/g;
- const colMatches = colgroupMatch[2].matchAll(COL_TAG_REGEX);
+ const colMatches = raw.matchAll(COL_TAG_REGEX);
if (!colMatches) {
return null;
}
@@ -546,3 +414,234 @@ function decodeHTMLEntities(input: string): string {
return input.replace(/&lt;|&gt;|&amp;|&quot;|&#39;|&nbsp;|<br>/g, (match) => entities[match]);
}
+
+function extractBordersAndKeepOthers(styleString: string, bordersToKeep: string[]) {
+ if (!styleString) return '';
+ const borderRegex = /border(-top|-right|-bottom|-left)?\s*:\s*([^;]+);/g;
+
+ const extractedBorders: Record<string, string> = {};
+
+ const withoutBorders = styleString.replace(borderRegex, (match, p1, p2) => {
+ const borderType = `border${p1 || ''}`;
+ extractedBorders[borderType] = p2.trim();
+ return '';
+ });
+
+ let newStyleString = bordersToKeep
+ .map((border) => {
+ if (border === 'border' && extractedBorders[border]) {
+ return `border: ${extractedBorders[border]};`;
+ } else if (extractedBorders[border]) {
+ return `${border}: ${extractedBorders[border]};`;
+ }
+ return '';
+ })
+ .filter((style) => style)
+ .join(' ');
+
+ newStyleString += ` ${withoutBorders.trim()}`;
+
+ return newStyleString.trim();
+}
+
+function parseTableByHtml(htmlElement: HTMLIFrameElement, skeleton?: SpreadsheetSkeleton) {
+ const cellMatrix = new ObjectMatrix<IParsedCellValueByClipboard>();
+ const tableEle = htmlElement.contentDocument?.querySelector('table');
+ if (!tableEle) {
+ return cellMatrix;
+ }
+ const rows = tableEle?.querySelectorAll('tr');
+
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
+ const row = rows[rowIndex];
+ const cells = row.querySelectorAll('td, th');
+ let colSetValueIndex = 0;
+ for (let colIndex = 0; colIndex < cells.length;) {
+ const cell = cells[colIndex];
+ let cellStyle = '';
+ let cellText;
+ let cellRichStyle;
+ const rowSpan = Number(cell.getAttribute('rowSpan')) || 1;
+ const colSpan = Number(cell.getAttribute('colSpan')) || 1;
+
+ // If there is a class attribute, use getComputedStyle
+ const hasClass = cell.getAttribute('class');
+ const computedStyle = getComputedStyle(cell);
+ if (hasClass) {
+ sheetStyleRules.forEach((rule) => {
+ const [originName, camelName] = rule.split('_');
+ const ruleValue = computedStyle.getPropertyValue(originName) || computedStyle[camelName as keyof typeof computedStyle];
+ if (ruleValue) {
+ cellStyle += `${originName}:${ruleValue};`;
+ }
+ });
+ } else {
+ const regex = /<\w+\s+[^>]*?style="([^"]*)"/gi;
+ const match = regex.exec(cell.outerHTML);
+ if (match?.[1]) {
+ cellStyle = match[1];
+ }
+ }
+
+ borderRules.forEach((rule) => {
+ const [originName, camelName] = rule.split('_');
+ const ruleValue = computedStyle.getPropertyValue(originName) || computedStyle[camelName as keyof typeof computedStyle];
+ if (ruleValue) {
+ cellStyle += `${originName}:${ruleValue};`;
+ }
+ });
+
+ if (rowSpan > 1 && colSpan > 1) {
+ // compatible google sheet;The border style of merged cells in Google is set on the right and bottom sides of the merged cells
+ if (!cellStyle.includes('border-top') && !cellStyle.includes('border-left')) {
+ const topStyle = extractStyleProperty(cellMatrix.getValue(rowIndex - 1, colIndex)?.style, 'border-bottom');
+ const leftStyle = extractStyleProperty(cellMatrix.getValue(rowIndex, colIndex - 1)?.style, 'border-right');
+ if (topStyle) {
+ cellStyle += `border-top:${topStyle};`;
+ }
+ if (leftStyle) {
+ cellStyle += `border-left:${leftStyle};`;
+ }
+ }
+ }
+
+ // Determine whether it is rich text based on whether there are html tags
+ const isRichText = /<[^>]+>/.test(cell.innerHTML);
+ if (isRichText && skeleton) {
+ const newDocBody: IDocumentBody = {
+ dataStream: '',
+ textRuns: [],
+ };
+ // Rich text parsing method, refer to the doc
+ parseCellHtml(null, cell.childNodes, newDocBody);
+ const documentModel = skeleton.getBlankCellDocumentModel()?.documentModel;
+ const p = documentModel?.getSnapshot();
+ const singleDataStream = `${newDocBody.dataStream}\r\n`;
+ const documentData = {
+ ...p, ...{
+ body: {
+ dataStream: singleDataStream,
+ textRuns: newDocBody.textRuns,
+ paragraphs: generateParagraphs(singleDataStream),
+ },
+ },
+ };
+ documentModel?.reset(documentData);
+ cellRichStyle = documentModel?.getSnapshot();
+ cellText = newDocBody.dataStream;
+ } else {
+ cellText = cell.innerHTML.replace(/[\r\n]/g, '');
+ }
+
+ const cellValue = (rowSpan > 1 || colSpan > 1)
+ ? {
+ rowSpan,
+ colSpan,
+ content: cellText,
+ style: cellStyle,
+ richTextParma: {
+ p: cellRichStyle,
+ v: cellText,
+ },
+ }
+ : {
+ content: cellText,
+ style: cellStyle,
+ richTextParma: {
+ p: cellRichStyle,
+ v: cellText,
+ },
+ };
+
+ if (cellMatrix.getValue(rowIndex, colSetValueIndex)) {
+ colSetValueIndex += 1;
+ continue;
+ } else {
+ // Clone the style of merged cells to each individual cell; switch to cloning only border styles if there are issues later.
+ if ((rowSpan > 1 || colSpan > 1)) {
+ if (rowSpan === 1) {
+ for (let i = colSetValueIndex; i < colSetValueIndex + colSpan; i++) {
+ cellMatrix.setValue(rowIndex, i, { style: extractBordersAndKeepOthers(cellStyle, ['border-top', 'border-bottom']) });
+ }
+ cellMatrix.setValue(rowIndex, colSetValueIndex + colSpan - 1, { style: extractBordersAndKeepOthers(cellStyle, ['border-top', 'border-bottom', 'border-right']) });
+ cellMatrix.setValue(rowIndex, colSetValueIndex, { ...cellValue, style: extractBordersAndKeepOthers(cellStyle, ['border-top', 'border-bottom', 'border-left']) });
+ } else if (colSpan === 1) {
+ for (let i = rowIndex; i < rowIndex + rowSpan; i++) {
+ cellMatrix.setValue(i, colSetValueIndex, { style: extractBordersAndKeepOthers(cellStyle, ['border-left', 'border-right']) });
+ }
+ cellMatrix.setValue(rowIndex + rowSpan - 1, colSetValueIndex, { style: extractBordersAndKeepOthers(cellStyle, ['border-left', 'border-right', 'border-bottom']) });
+ cellMatrix.setValue(rowIndex, colSetValueIndex, { ...cellValue, style: extractBordersAndKeepOthers(cellStyle, ['border-left', 'border-right', 'border-top']) });
+ } else {
+ for (let i = colSetValueIndex; i < colSetValueIndex + colSpan; i++) {
+ cellMatrix.setValue(rowIndex, i, { style: extractBordersAndKeepOthers(cellStyle, ['border-top']) });
+ cellMatrix.setValue(rowIndex + rowSpan - 1, i, { style: extractBordersAndKeepOthers(cellStyle, ['border-bottom']) });
+ }
+ for (let i = rowIndex; i < rowIndex + rowSpan; i++) {
+ cellMatrix.setValue(i, colSetValueIndex, { style: extractBordersAndKeepOthers(cellStyle, ['border-left']) });
+ cellMatrix.setValue(i, colSetValueIndex + colSpan - 1, { style: extractBordersAndKeepOthers(cellStyle, ['border-right']) });
+ }
+ cellMatrix.setValue(rowIndex + rowSpan - 1, colSetValueIndex, { style: extractBordersAndKeepOthers(cellStyle, ['border-left', 'border-bottom']) });
+ cellMatrix.setValue(rowIndex, colSetValueIndex + colSpan - 1, { style: extractBordersAndKeepOthers(cellStyle, ['border-right', 'border-top']) });
+ cellMatrix.setValue(rowIndex + rowSpan - 1, colSetValueIndex + colSpan - 1, { style: extractBordersAndKeepOthers(cellStyle, ['border-right', 'border-bottom']) });
+ cellMatrix.setValue(rowIndex, colSetValueIndex, { ...cellValue, style: extractBordersAndKeepOthers(cellStyle, ['border-top', 'border-left']) });
+ for (let i = rowIndex; i < rowIndex + rowSpan; i++) {
+ for (let j = colSetValueIndex; j < colSetValueIndex + colSpan; j++) {
+ if (!cellMatrix.getValue(i, j)) {
+ cellMatrix.setValue(i, j, { style: extractBordersAndKeepOthers(cellStyle, []) });
+ }
+ }
+ }
+ }
+ } else {
+ cellMatrix.setValue(rowIndex, colSetValueIndex, cellValue);
+ }
+ colSetValueIndex += colSpan;
+ colIndex++;
+ }
+ }
+ }
+ return cellMatrix;
+}
+
+function parseCellHtml(parent: Nullable<ChildNode>, nodes: NodeListOf<ChildNode>, doc: IDocumentBody, styleCache: Map<ChildNode, ITextStyle> = new Map()) {
+ for (const node of nodes) {
+ if (node.nodeType === Node.TEXT_NODE) {
+ const text = node.nodeValue?.replace(/[\r\n]/g, '');
+ let style;
+
+ if (parent && styleCache.has(parent)) {
+ style = styleCache.get(parent);
+ }
+
+ doc.dataStream += text;
+
+ if (style && Object.getOwnPropertyNames(style).length) {
+ doc.textRuns!.push({
+ st: doc.dataStream.length - text!.length,
+ ed: doc.dataStream.length,
+ ts: style,
+ });
+ }
+ } else if (node.nodeType === Node.COMMENT_NODE || node.nodeName === 'STYLE') {
+ continue;
+ } else if (node.nodeType === Node.ELEMENT_NODE) {
+ const parentStyles = parent ? styleCache.get(parent) : {};
+ const predefinedStyles = getComputedStyle(node as HTMLElement);
+ const nodeStyles = extractNodeStyle(node as HTMLElement, predefinedStyles);
+
+ styleCache.set(node, { ...parentStyles, ...nodeStyles });
+ const { childNodes } = node;
+ parseCellHtml(node, childNodes, doc, styleCache);
+ }
+ }
+}
+
+function extractStyleProperty(styleString?: string, propertyName?: string) {
+ if (!styleString || !propertyName) return null;
+ const regex = new RegExp(`(${propertyName}\\s*:\\s*[^;]+);`, 'i');
+ const match = styleString.match(regex);
+ if (match) {
+ return match[1];
+ }
+ return null;
+}
diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/parse-node-style.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/parse-node-style.ts
index 279122a569..60e2c34dc7 100644
--- a/packages/sheets-ui/src/services/clipboard/html-to-usm/parse-node-style.ts
+++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/parse-node-style.ts
@@ -16,10 +16,9 @@
import type { ITextStyle } from '@univerjs/core';
import { BaselineOffset, BooleanNumber, ColorKit } from '@univerjs/core';
-import { pixelToPt } from '@univerjs/engine-render';
-export function extractNodeStyle(node: HTMLElement): ITextStyle {
- const styles = node.style;
+export function extractNodeStyle(node: HTMLElement, predefinedStyles?: CSSStyleDeclaration): ITextStyle {
+ const styles = predefinedStyles ?? node.style;
const docStyles: ITextStyle = {};
const tagName = node.tagName.toLowerCase();
@@ -72,11 +71,12 @@ export function extractNodeStyle(node: HTMLElement): ITextStyle {
const fontSize = Number.parseInt(cssValue);
if (!Number.isNaN(fontSize)) {
- // TODO: @JOCS, hand other CSS value unit, rem, em, pt, %
+ // TODO: @ybzky need other font size unit support
if (cssValue.endsWith('pt')) {
docStyles.fs = fontSize;
} else if (cssValue.endsWith('px')) {
- docStyles.fs = pixelToPt(fontSize);
+ const transformedFontSize = fontSize * 0.75;
+ docStyles.fs = transformedFontSize;
}
}
diff --git a/packages/sheets-ui/src/services/clipboard/type.ts b/packages/sheets-ui/src/services/clipboard/type.ts
index faf5200568..0ae87ff9ee 100644
--- a/packages/sheets-ui/src/services/clipboard/type.ts
+++ b/packages/sheets-ui/src/services/clipboard/type.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { ICellData, IMutationInfo, IRange, ObjectMatrix } from '@univerjs/core';
+import type { ICellData, IDocumentData, IMutationInfo, IRange, ObjectMatrix } from '@univerjs/core';
export enum COPY_TYPE {
COPY = 'COPY',
@@ -34,6 +34,18 @@ export interface IParsedCellValue {
content: string;
}
+export interface IParsedCellValueByClipboard {
+ rowSpan?: number;
+ colSpan?: number;
+ style?: string;
+ content?: string;
+ richTextParma?: {
+ p?: IDocumentData;
+ v?: string;
+ };
+
+}
+
export interface IUniverSheetCopyDataModel {
rowProperties?: IClipboardPropertyItem[];
colProperties?: IClipboardPropertyItem[] | null;
diff --git a/packages/sheets-ui/src/services/clipboard/usm-to-html/convertor.ts b/packages/sheets-ui/src/services/clipboard/usm-to-html/convertor.ts
index 3202a75caa..e37bcc4919 100644
--- a/packages/sheets-ui/src/services/clipboard/usm-to-html/convertor.ts
+++ b/packages/sheets-ui/src/services/clipboard/usm-to-html/convertor.ts
@@ -29,13 +29,27 @@ function getRowContent(
row: number,
cols: number[],
hooks: ISheetClipboardHook[],
- matrix: ObjectMatrix<ICellDataWithSpanInfo>
+ matrix: ObjectMatrix<ICellDataWithSpanInfo>,
+ mergeSet: Set<string>
) {
const properties = hooks.map((hook) => hook.onCopyRow?.(row)).filter((v) => !!v) as IClipboardPropertyItem[];
const mergedProperties = mergeProperties(properties);
const str = zipClipboardPropertyItemToString(mergedProperties);
const tds = cols
- .map((col) => getTDContent(row, col, hooks, matrix))
+ .map((col) => {
+ if (!mergeSet.has(`${row}-${col}`)) {
+ const v = matrix.getValue(row, col);
+ if (v?.rowSpan && v?.colSpan) {
+ for (let i = row; i < row + v.rowSpan; i++) {
+ for (let j = col; j < col + v.colSpan; j++) {
+ mergeSet.add(`${i}-${j}`);
+ }
+ }
+ }
+ return getTDContent(row, col, hooks, matrix);
+ }
+ return null;
+ })
.filter((v) => !!v)
.join('');
@@ -124,6 +138,7 @@ export class USMToHtmlService {
const colStyles = getColStyle(getArrayFromTo(startColumn, endColumn), hooks);
// row styles and table contents
const rowContents: string[] = [];
+ const mergeSet = new Set<string>();
const {
startRow: dataStartRow,
@@ -136,10 +151,10 @@ export class USMToHtmlService {
{ length: dataEndColumn - dataStartColumn + 1 },
(_, index) => dataStartColumn + index
);
- rowContents.push(getRowContent(row, cols, hooks, matrix));
+ rowContents.push(getRowContent(row, cols, hooks, matrix, mergeSet));
}
- const html = `<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${colStyles}
+ const html = `<google-sheets-html-origin><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none">${colStyles}
<tbody>${rowContents.join('')}</tbody></table>`;
return html;
}
diff --git a/packages/ui/src/utils/cell.ts b/packages/ui/src/utils/cell.ts
index b9a43cefdc..6b2c4d6292 100644
--- a/packages/ui/src/utils/cell.ts
+++ b/packages/ui/src/utils/cell.ts
@@ -24,11 +24,15 @@ import type {
ITextDecoration,
ITextRun,
} from '@univerjs/core';
-import { BaselineOffset, getBorderStyleType, Tools } from '@univerjs/core';
-import { ptToPx, pxToPt } from '@univerjs/engine-render';
+import { BaselineOffset, BorderStyleTypes, ColorKit, getBorderStyleType, Tools } from '@univerjs/core';
+import { ptToPx } from '@univerjs/engine-render';
import { textTrim } from './util';
+const PX_TO_PT_RATIO = 0.75;
+const MAX_FONT_SIZE = 78;
+const MIN_FONT_SIZE = 9;
+
// TODO: move to Utils
/**
* The entire list of DOM spans is parsed into a rich-text JSON style sheet
@@ -135,11 +139,12 @@ export function handleDomToJson($dom: HTMLElement): IDocumentData | string {
export function handleStringToStyle($dom?: HTMLElement, cssStyle: string = '') {
let cssText = $dom?.style?.cssText ?? '';
cssText += cssStyle;
+ cssText = cssText.replace(/[\r\n]+/g, '');
if (cssText.length === 0) {
return {};
}
const cssTextArray = cssText.split(';');
- const styleList: IStyleData = {};
+ const styleList: IStyleData & Record<string, unknown> = {};
const borderInfo = {
t: '',
@@ -149,13 +154,14 @@ export function handleStringToStyle($dom?: HTMLElement, cssStyle: string = '') {
};
cssTextArray.forEach((s) => {
+ const originStr = s;
s = s.toLowerCase();
const key = textTrim(s.substr(0, s.indexOf(':')));
const value = textTrim(s.substr(s.indexOf(':') + 1));
// bold
if (key === 'font-weight') {
- if (value === 'bold') {
+ if (value === 'bold' || value === '700') {
styleList.bl = 1;
} else {
styleList.bl = 0;
@@ -171,6 +177,7 @@ export function handleStringToStyle($dom?: HTMLElement, cssStyle: string = '') {
}
// font family
else if (key === 'font-family') {
+ const value = textTrim(originStr.substr(originStr.indexOf(':') + 1));
styleList.ff = value;
}
// font size
@@ -187,7 +194,7 @@ export function handleStringToStyle($dom?: HTMLElement, cssStyle: string = '') {
// px to pt TODO@Dushusir: px or pt?
if (value.indexOf('px') !== -1) {
- fs = pxToPt(Number.parseInt(value));
+ fs = getPtFontSizeByPx(Number.parseInt(value, 10));
}
styleList.fs = fs;
@@ -200,9 +207,12 @@ export function handleStringToStyle($dom?: HTMLElement, cssStyle: string = '') {
}
// fill color / background
else if (key === 'background' || key === 'background-color') {
- styleList.bg = {
- rgb: value,
- };
+ const backgroundColor = new ColorKit(value);
+ if (backgroundColor) {
+ styleList.bg = {
+ rgb: backgroundColor.toRgbString(),
+ };
+ }
}
// text line type
@@ -283,10 +293,27 @@ export function handleStringToStyle($dom?: HTMLElement, cssStyle: string = '') {
// line through
else if (key === 'text-decoration' || key === 'univer-strike') {
- if (value !== 'none') {
- styleList.st = {
- s: 1,
- };
+ const lineValue = value.split(' ')?.[0];
+ if (lineValue === 'underline') {
+ if (!styleList.ul) {
+ styleList.ul = { s: 1 };
+ }
+ styleList.ul.s = 1;
+ }
+
+ // line through
+ else if (lineValue === 'line-through') {
+ if (!styleList.st) {
+ styleList.st = { s: 1 };
+ }
+ styleList.st.s = 1;
+ }
+ // overline
+ else if (lineValue === 'overline') {
+ if (!styleList.ol) {
+ styleList.ol = { s: 1 };
+ }
+ styleList.ol.s = 1;
}
}
// underline
@@ -455,27 +482,39 @@ export function handleStringToStyle($dom?: HTMLElement, cssStyle: string = '') {
const type = `${arr[0]} ${arr[1]}`;
arr.splice(0, 2);
const color = arr.join('');
- const obj = {
- cl: {
- rgb: color,
- },
- s: getBorderStyleType(type),
- };
- if (key === 'border-bottom') {
- styleList.bd.b = value === 'none' ? null : obj;
- } else if (key === 'border-top') {
- styleList.bd.t = value === 'none' ? null : obj;
- } else if (key === 'border-left') {
- styleList.bd.l = value === 'none' ? null : obj;
- } else if (key === 'border-right') {
- styleList.bd.r = value === 'none' ? null : obj;
- } else if (key === 'border') {
- styleList.bd = {
- r: value === 'none' ? null : obj,
- t: value === 'none' ? null : obj,
- b: value === 'none' ? null : obj,
- l: value === 'none' ? null : obj,
+ const lineType = getBorderStyleType(type);
+ if (lineType !== BorderStyleTypes.NONE) {
+ const obj = {
+ cl: {
+ rgb: color,
+ },
+ s: getBorderStyleType(type),
};
+ if (key === 'border-bottom') {
+ styleList.bd.b = value === 'none' ? null : obj;
+ } else if (key === 'border-top') {
+ styleList.bd.t = value === 'none' ? null : obj;
+ } else if (key === 'border-left') {
+ styleList.bd.l = value === 'none' ? null : obj;
+ } else if (key === 'border-right') {
+ styleList.bd.r = value === 'none' ? null : obj;
+ } else if (key === 'border') {
+ styleList.bd = {
+ r: value === 'none' ? null : obj,
+ t: value === 'none' ? null : obj,
+ b: value === 'none' ? null : obj,
+ l: value === 'none' ? null : obj,
+ };
+ }
+ }
+ } else if (key === 'data-rotate') {
+ const regex = /[+-]?\d+/;
+ const match = value.match(regex);
+
+ if (value === '(0deg ,1)') {
+ styleList.tr = { a: 0, v: 1 };
+ } else if (match) {
+ styleList.tr = { a: Number(match[0]) };
}
}
@@ -488,6 +527,12 @@ export function handleStringToStyle($dom?: HTMLElement, cssStyle: string = '') {
// }
});
+ Object.keys(styleList).forEach((key) => {
+ if (typeof styleList[key] === 'object' && !Object.keys(styleList[key] as object).length) {
+ delete styleList[key];
+ }
+ });
+
return styleList;
}
@@ -863,3 +908,17 @@ function getStyles(styleText: string): IKeyValue {
return output;
}
+
+function extractColorFromString(str: string) {
+ const regex = /#([0-9a-f]{3,6})\b|rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)/gi;
+ const matches = str.match(regex);
+ return matches ? matches[0] : null;
+}
+
+function getPtFontSizeByPx(size: number) {
+ const ptSize = Math.round(size * PX_TO_PT_RATIO);
+
+ if (ptSize < MIN_FONT_SIZE) return MIN_FONT_SIZE;
+ if (ptSize > MAX_FONT_SIZE) return MAX_FONT_SIZE;
+ return ptSize;
+}