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(paste): fix extra spaces after pasting text copied from Excel (#6538)

wpxp123456245358136d21
diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.ts
index e85917ee67..0291046909 100644
--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts
@@ -369,7 +369,7 @@ export function getSetCellValueMutations(
if (isTextFormat(style?.n?.pattern)) {
cellValue.t = CellValueType.STRING;
} else {
- const content = String(value.v);
+ const content = String(value.v).trim();
const numfmtValue = getNumfmtParseValueFilter(content);
if (numfmtValue?.v !== undefined && typeof numfmtValue.v === 'number') {
// If the numeric string will lose precision when converted to a number, set the cell type to force string
@@ -479,7 +479,7 @@ export function getSetCellStyleMutations(
}
(newValue.s as IStyleData).n = style?.n;
} else {
- const content = String(value.v);
+ const content = String(value.v).trim();
const numfmtValue = getNumfmtParseValueFilter(content);
if (numfmtValue?.z) {
if (!newValue.s) {
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/__snapshots__/sheet-paste.spec.ts.snap b/packages/sheets-ui/src/services/clipboard/__tests__/__snapshots__/sheet-paste.spec.ts.snap
index faae8d8f4b..d2ba98caa9 100644
--- a/packages/sheets-ui/src/services/clipboard/__tests__/__snapshots__/sheet-paste.spec.ts.snap
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/__snapshots__/sheet-paste.spec.ts.snap
@@ -24,17 +24,17 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
"colSpan": 1,
"p": {
"body": {
- "dataStream": " background color
+ "dataStream": " background color
",
"paragraphs": [
{
- "startIndex": 53,
+ "startIndex": 19,
},
],
"textRuns": [
{
- "ed": 37,
- "st": 36,
+ "ed": 18,
+ "st": 17,
"ts": {
"cl": {
"rgb": "rgb(0,0,0)",
@@ -83,7 +83,7 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
"tb": 1,
"vt": 2,
},
- "v": " background color ",
+ "v": " background color ",
},
"2": {
"colSpan": 1,
@@ -532,17 +532,17 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
"colSpan": 1,
"p": {
"body": {
- "dataStream": " U N I V ER UP UP UP
+ "dataStream": " U N I V ER UP UP UP
",
"paragraphs": [
{
- "startIndex": 272,
+ "startIndex": 29,
},
],
"textRuns": [
{
- "ed": 21,
- "st": 20,
+ "ed": 2,
+ "st": 1,
"ts": {
"cl": {
"rgb": "rgb(166,201,236)",
@@ -552,8 +552,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 42,
- "st": 41,
+ "ed": 4,
+ "st": 3,
"ts": {
"cl": {
"rgb": "rgb(64,64,64)",
@@ -563,8 +563,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 63,
- "st": 62,
+ "ed": 6,
+ "st": 5,
"ts": {
"cl": {
"rgb": "rgb(166,166,166)",
@@ -574,8 +574,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 84,
- "st": 83,
+ "ed": 8,
+ "st": 7,
"ts": {
"cl": {
"rgb": "rgb(131,226,142)",
@@ -585,8 +585,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 106,
- "st": 104,
+ "ed": 11,
+ "st": 9,
"ts": {
"cl": {
"rgb": "rgb(0,0,0)",
@@ -596,8 +596,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 127,
- "st": 126,
+ "ed": 13,
+ "st": 12,
"ts": {
"cl": {
"rgb": "rgb(0,0,0)",
@@ -607,8 +607,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 149,
- "st": 147,
+ "ed": 16,
+ "st": 14,
"ts": {
"bl": 1,
"cl": {
@@ -619,8 +619,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 170,
- "st": 169,
+ "ed": 18,
+ "st": 17,
"ts": {
"cl": {
"rgb": "rgb(0,0,0)",
@@ -630,8 +630,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 192,
- "st": 190,
+ "ed": 21,
+ "st": 19,
"ts": {
"cl": {
"rgb": "rgb(0,0,0)",
@@ -642,8 +642,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 213,
- "st": 212,
+ "ed": 23,
+ "st": 22,
"ts": {
"cl": {
"rgb": "rgb(0,0,0)",
@@ -653,8 +653,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 235,
- "st": 233,
+ "ed": 26,
+ "st": 24,
"ts": {
"cl": {
"rgb": "rgb(0,0,0)",
@@ -667,8 +667,8 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
},
},
{
- "ed": 256,
- "st": 255,
+ "ed": 28,
+ "st": 27,
"ts": {
"cl": {
"rgb": "rgb(0,0,0)",
@@ -714,7 +714,7 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
"tb": 1,
"vt": 2,
},
- "v": " U N I V ER UP UP UP ",
+ "v": " U N I V ER UP UP UP ",
},
"1": {
"colSpan": 1,
@@ -886,7 +886,7 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
"tb": 3,
"vt": 2,
},
- "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
+ "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
},
"2": {
"colSpan": 1,
@@ -1041,7 +1041,7 @@ exports[`Test clipboard > Test paste > test convert util func from excel 1`] = `
"tb": 1,
"vt": 2,
},
- "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
+ "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
},
"2": {
"colSpan": undefined,
@@ -2941,7 +2941,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"bl": 1,
"vt": 3,
},
- "v": " bold ",
+ "v": " bold ",
},
"1": {
"colSpan": 1,
@@ -2952,7 +2952,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
"vt": 3,
},
- "v": " background color ",
+ "v": " background color ",
},
"2": {
"colSpan": 1,
@@ -2992,7 +2992,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"s": {
"vt": 3,
},
- "v": " merge cell with border & style ",
+ "v": " merge cell with border & style ",
},
"7": {
"colSpan": 1,
@@ -3027,7 +3027,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"it": 1,
"vt": 3,
},
- "v": " italic ",
+ "v": " italic ",
},
"1": {
"colSpan": 1,
@@ -3142,7 +3142,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"ht": 3,
"vt": 3,
},
- "v": " horizontal Aligment ",
+ "v": " horizontal Aligment ",
},
"2": {
"colSpan": 1,
@@ -3269,7 +3269,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"ht": 3,
"vt": 3,
},
- "v": " 1.11E+09 ",
+ "v": " 1.11E+09 ",
},
},
"11": {
@@ -3277,17 +3277,17 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"colSpan": 1,
"p": {
"body": {
- "dataStream": " UNIVER UP UP UP
+ "dataStream": " UNIVER UP UP UP
",
"paragraphs": [
{
- "startIndex": 51,
+ "startIndex": 17,
},
],
"textRuns": [
{
- "ed": 21,
- "st": 20,
+ "ed": 2,
+ "st": 1,
"ts": {
"bl": 1,
"ff": "Arial",
@@ -3295,16 +3295,16 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
},
{
- "ed": 22,
- "st": 21,
+ "ed": 3,
+ "st": 2,
"ts": {
"ff": "Arial",
"fs": 17,
},
},
{
- "ed": 24,
- "st": 22,
+ "ed": 5,
+ "st": 3,
"ts": {
"ff": "Arial",
"fs": 17,
@@ -3312,16 +3312,16 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
},
{
- "ed": 25,
- "st": 24,
+ "ed": 6,
+ "st": 5,
"ts": {
"ff": "Arial",
"fs": 17,
},
},
{
- "ed": 26,
- "st": 25,
+ "ed": 7,
+ "st": 6,
"ts": {
"cl": {
"rgb": "rgb(74,134,232)",
@@ -3331,24 +3331,24 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
},
{
- "ed": 27,
- "st": 26,
+ "ed": 8,
+ "st": 7,
"ts": {
"ff": "Arial",
"fs": 17,
},
},
{
- "ed": 30,
- "st": 27,
+ "ed": 11,
+ "st": 8,
"ts": {
"ff": "Arial",
"fs": 10,
},
},
{
- "ed": 32,
- "st": 30,
+ "ed": 13,
+ "st": 11,
"ts": {
"ff": "Arial",
"fs": 10,
@@ -3358,8 +3358,8 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
},
{
- "ed": 35,
- "st": 32,
+ "ed": 16,
+ "st": 13,
"ts": {
"ff": "Arial",
"fs": 10,
@@ -3393,7 +3393,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"s": {
"vt": 3,
},
- "v": " UNIVER UP UP UP ",
+ "v": " UNIVER UP UP UP ",
},
"1": {
"colSpan": 1,
@@ -3484,7 +3484,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"tb": 3,
"vt": 3,
},
- "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
+ "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
},
"2": {
"colSpan": 1,
@@ -3564,11 +3564,11 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"colSpan": 1,
"p": {
"body": {
- "dataStream": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap
+ "dataStream": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap
",
"paragraphs": [
{
- "startIndex": 129,
+ "startIndex": 53,
},
],
"textRuns": [],
@@ -3607,7 +3607,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
"vt": 3,
},
- "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
+ "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
},
"2": {
"colSpan": 1,
@@ -3690,7 +3690,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"tb": 2,
"vt": 3,
},
- "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
+ "v": " text wrap wrap wrap wrap wrap wrap wrap wrap wrap ",
},
"2": {
"colSpan": 1,
@@ -3857,7 +3857,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
"vt": 3,
},
- "v": " underline ",
+ "v": " underline ",
},
"1": {
"colSpan": 1,
@@ -3879,7 +3879,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
"vt": 3,
},
- "v": " border line ",
+ "v": " border line ",
},
"2": {
"colSpan": 1,
@@ -3950,7 +3950,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"it": 1,
"vt": 2,
},
- "v": " univer ",
+ "v": " univer ",
},
"7": {
"colSpan": undefined,
@@ -3998,7 +3998,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"ht": 3,
"vt": 3,
},
- "v": " 2024/1/1 ",
+ "v": " 2024/1/1 ",
},
},
"3": {
@@ -4011,7 +4011,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
"vt": 3,
},
- "v": " strike through ",
+ "v": " strike through ",
},
"1": {
"colSpan": 1,
@@ -4102,7 +4102,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"fs": 17,
"vt": 3,
},
- "v": " font size ",
+ "v": " font size ",
},
"1": {
"colSpan": 1,
@@ -4124,11 +4124,11 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"colSpan": 1,
"p": {
"body": {
- "dataStream": "
+ "dataStream": "
",
"paragraphs": [
{
- "startIndex": 80,
+ "startIndex": 4,
},
],
"textRuns": [],
@@ -4159,7 +4159,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"s": {
"vt": 3,
},
- "v": " ",
+ "v": " ",
},
"4": {
"colSpan": 1,
@@ -4189,17 +4189,17 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"colSpan": 1,
"p": {
"body": {
- "dataStream": " univer
+ "dataStream": " univer
",
"paragraphs": [
{
- "startIndex": 86,
+ "startIndex": 10,
},
],
"textRuns": [
{
- "ed": 44,
- "st": 20,
+ "ed": 2,
+ "st": 1,
"ts": {
"bl": 1,
"cl": {
@@ -4209,8 +4209,8 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
},
{
- "ed": 50,
- "st": 44,
+ "ed": 8,
+ "st": 2,
"ts": {
"bl": 1,
"cl": {
@@ -4220,8 +4220,8 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
},
{
- "ed": 70,
- "st": 50,
+ "ed": 9,
+ "st": 8,
"ts": {
"bl": 1,
"cl": {
@@ -4281,7 +4281,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"it": 1,
"vt": 2,
},
- "v": " univer ",
+ "v": " univer ",
},
"7": {
"colSpan": 1,
@@ -4306,7 +4306,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"ht": 3,
"vt": 3,
},
- "v": " $1.00 ",
+ "v": " $1.00 ",
},
},
"5": {
@@ -4319,7 +4319,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
"vt": 3,
},
- "v": " font color ",
+ "v": " font color ",
},
"1": {
"colSpan": 1,
@@ -4434,7 +4434,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"ff": "Impact",
"vt": 3,
},
- "v": " font family ",
+ "v": " font family ",
},
"1": {
"colSpan": 1,
@@ -4538,7 +4538,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"ht": 3,
"vt": 3,
},
- "v": " 5% ",
+ "v": " 5% ",
},
},
"7": {
@@ -4668,11 +4668,11 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"colSpan": 2,
"p": {
"body": {
- "dataStream": "
+ "dataStream": "
",
"paragraphs": [
{
- "startIndex": 80,
+ "startIndex": 4,
},
],
"textRuns": [],
@@ -4703,7 +4703,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"s": {
"vt": 3,
},
- "v": " ",
+ "v": " ",
},
"4": {
"colSpan": undefined,
@@ -4733,17 +4733,17 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"colSpan": 2,
"p": {
"body": {
- "dataStream": " univer
+ "dataStream": " univer
",
"paragraphs": [
{
- "startIndex": 86,
+ "startIndex": 10,
},
],
"textRuns": [
{
- "ed": 44,
- "st": 20,
+ "ed": 2,
+ "st": 1,
"ts": {
"bl": 1,
"cl": {
@@ -4754,8 +4754,8 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
},
{
- "ed": 50,
- "st": 44,
+ "ed": 8,
+ "st": 2,
"ts": {
"bl": 1,
"cl": {
@@ -4766,8 +4766,8 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
},
{
- "ed": 70,
- "st": 50,
+ "ed": 9,
+ "st": 8,
"ts": {
"bl": 1,
"cl": {
@@ -4832,7 +4832,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
},
"vt": 2,
},
- "v": " univer ",
+ "v": " univer ",
},
"7": {
"colSpan": undefined,
@@ -4884,7 +4884,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"ht": 3,
"vt": 3,
},
- "v": " 32.32 ",
+ "v": " 32.32 ",
},
},
"9": {
@@ -4903,7 +4903,7 @@ exports[`Test clipboard > Test paste > test convert util func from google 1`] =
"ht": 2,
"vt": 3,
},
- "v": " horizontal Aligment ",
+ "v": " horizontal Aligment ",
},
"2": {
"colSpan": 1,
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
index 0ae813f688..08f034d7bb 100644
--- 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
@@ -31,7 +31,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { SheetSkeletonManagerService } from '../../sheet-skeleton-manager.service';
import { ISheetClipboardService } from '../clipboard.service';
import { clipboardTestBed } from './clipboard-test-bed';
-import { excelSample, excelSample2, excelSample3, excelSample4, excelSample5 } from './constant';
+import { excelSample, excelSample2, excelSample3, excelSample4, excelSample5, excelSample6 } from './constant';
describe('Test clipboard', () => {
let univer: Univer;
@@ -421,5 +421,36 @@ describe('Test clipboard', () => {
expect(cellValue?.v).toBe(23123);
expect(cellValue?.t).toBe(CellValueType.NUMBER);
});
+
+ it('copy value is ` 1 3 `, no specific format', async () => {
+ const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');
+ if (!worksheet) return false;
+
+ // set selection to K1:L1
+ const selectionManager = get(SheetsSelectionsService);
+ selectionManager.addSelections([
+ {
+ range: {
+ startRow: 0,
+ startColumn: 0,
+ endRow: 0,
+ endColumn: 0,
+ rangeType: RANGE_TYPE.NORMAL,
+ },
+ primary: null,
+ style: null,
+ },
+ ]);
+
+ // paste data, excelSample2 value is 000123456
+ const res = await sheetClipboardService.legacyPaste(excelSample6);
+ expect(res).toBeTruthy();
+
+ // check the values
+ const cellValue = getValues(0, 0, 0, 0)?.[0]?.[0];
+ // space char code is 32(' '), no-break space char code is 160(\u00A0)
+ expect(cellValue?.v).toMatch(/[ \u00A0]{2}1[ \u00A0]{3}3[ \u00A0]{3}/);
+ expect(cellValue?.t).toBe(CellValueType.STRING);
+ });
});
});
diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/constant.ts b/packages/sheets-ui/src/services/clipboard/__tests__/constant.ts
index 5e84d96e55..c68f2cfbbf 100644
--- a/packages/sheets-ui/src/services/clipboard/__tests__/constant.ts
+++ b/packages/sheets-ui/src/services/clipboard/__tests__/constant.ts
@@ -28,6 +28,9 @@ export const excelSample4 = '<html xmlns:o="urn:schemas-microsoft-com:office:off
// copy value is $ 23,123.00, the format "$#,##0.00", the origin value 23123
export const excelSample5 = '<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:///C:/Users/26775/AppData/Local/Temp/msohtmlclip1/01/clip.htm">\r\n<link rel=File-List\r\nhref="file:///C:/Users/26775/AppData/Local/Temp/msohtmlclip1/01/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:11.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:bottom;\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{mso-number-format:"_-\\\\$* \\#\\,\\#\\#0\\.00_ \\;_-\\\\$* \\\\-\\#\\,\\#\\#0\\.00\\\\ \\;_-\\\\$* \\0022-\\0022??_ \\;_-\\@_ ";}\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=95 style=\'border-collapse:\r\n collapse;width:71pt\'>\r\n <col width=95 style=\'mso-width-source:userset;mso-width-alt:3040;width:71pt\'>\r\n <tr height=19 style=\'height:14.25pt\'>\r\n\x3C!--StartFragment-->\r\n <td height=19 class=xl65 width=95 style=\'height:14.25pt;width:71pt\'><span\r\n style=\'mso-spacerun:yes\'> </span>$<span style=\'mso-spacerun:yes\'>  \r\n </span>23,123.00 </td>\r\n\x3C!--EndFragment-->\r\n </tr>\r\n</table>\r\n\r\n</body>\r\n\r\n</html>\r\n';
+// copy value is ' 1 3 ', no specific format
+export const excelSample6 = '<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:///C:/Users/26775/AppData/Local/Temp/msohtmlclip1/01/clip.htm">\r\n<link rel=File-List\r\nhref="file:///C:/Users/26775/AppData/Local/Temp/msohtmlclip1/01/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:11.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:bottom;\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\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="#467886" vlink="#96607D">\r\n\r\n<table border=0 cellpadding=0 cellspacing=0 width=69 style=\'border-collapse:\r\n collapse;width:52pt\'>\r\n <col width=69 style=\'width:52pt\'>\r\n <tr height=19 style=\'height:14.0pt\'>\r\n\x3C!--StartFragment-->\r\n <td height=19 width=69 style=\'height:14.0pt;width:52pt\'><span\r\n style=\'mso-spacerun:yes\'>  </span>1<span style=\'mso-spacerun:yes\'>  \r\n </span>3<span style=\'mso-spacerun:yes\'>   </span></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 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
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 65a1cd09db..459cbf1b08 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
@@ -26,7 +26,7 @@ import type {
IUniverSheetCopyDataModel,
} from '../type';
import type { IAfterProcessRule, IPastePlugin } from './paste-plugins/type';
-import { CustomRangeType, DEFAULT_WORKSHEET_ROW_HEIGHT, generateRandomId, getNumfmtParseValueFilter, ObjectMatrix, skipParseTagNames } from '@univerjs/core';
+import { CustomRangeType, DEFAULT_WORKSHEET_ROW_HEIGHT, generateRandomId, getNumfmtParseValueFilter, isRealNum, ObjectMatrix, skipParseTagNames } from '@univerjs/core';
import { handleStringToStyle, textTrim } from '@univerjs/ui';
import { extractNodeStyle } from './parse-node-style';
import parseToDom, { convertToCellStyle, generateParagraphs } from './utils';
@@ -476,7 +476,7 @@ export class HtmlToUSMService {
const cellText = cell.innerHTML.replace(/<span[^>]*mso-spacerun:yes[^>]*>[\s\S]*?<\/span>/gi, '').replace(/\s/g, '');
const parseInfo = getNumfmtParseValueFilter(cellText);
- if (parseInfo && parseInfo.v !== undefined && parseInfo.v !== null) {
+ if (parseInfo && parseInfo.z && isRealNum(parseInfo.v)) {
return {
cellText,
cellRichStyle: undefined,
diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/utils.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/utils.ts
index 319ed0e7bc..9ddbc9a9b8 100644
--- a/packages/sheets-ui/src/services/clipboard/html-to-usm/utils.ts
+++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/utils.ts
@@ -19,9 +19,27 @@ import type { ICellDataWithSpanInfo } from '../type';
import { DataStreamTreeTokenType, Tools } from '@univerjs/core';
import { ptToPixel } from '@univerjs/engine-render';
+function cleanTextNodes(node: Node) {
+ if (node.nodeType === Node.TEXT_NODE) {
+ /**
+ * Clean excel copied text nodes:
+ * \r => carriage return
+ * \n => new line
+ * \t => tab
+ * multiple spaces => indentation
+ * These will be treated as a single space in excel cell. '\r\n ' = ' '
+ */
+ node.textContent = (node.textContent || '').replace(/\r?\n[\t ]*/g, ' ');
+ return;
+ }
+
+ node.childNodes.forEach(cleanTextNodes);
+}
+
export default function parseToDom(rawHtml: string) {
const template = document.createElement('body');
template.innerHTML = rawHtml;
+ cleanTextNodes(template);
return template;
}