From 2391f56f207621f896fa0e51d93290b1d7d04065 Mon Sep 17 00:00:00 2001 From: pipipi-pikachu Date: Tue, 20 Jul 2021 22:18:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=B2=98=E8=B4=B4excel=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=B6=85=E8=BF=87=E8=A1=A8=E6=A0=BC=E6=9C=AC=E8=BA=AB?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - src/utils/clipboard.ts | 39 +- .../element/TableElement/CustomTextarea.vue | 16 +- .../element/TableElement/EditableTable.vue | 20 +- yarn.lock | 12572 ---------------- 5 files changed, 36 insertions(+), 12612 deletions(-) delete mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore index 47d255b6..11f5d714 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .DS_Store node_modules /dist -*.lock # local env files .env.local diff --git a/src/utils/clipboard.ts b/src/utils/clipboard.ts index 03ea1546..e8127181 100644 --- a/src/utils/clipboard.ts +++ b/src/utils/clipboard.ts @@ -53,29 +53,20 @@ export const pasteCustomClipboardString = (text: string) => { return clipboardData } -/** - * 检查粘贴元素是否为外部exlc表格类型 - * @param text - * @returns - */ -export const exlcTesting = (text: string): string[][] | boolean => { - // 判定一下是不是exl格式 - const lineList: string[] = text.split('\r\n') - // 按照\n拆分表格 最后会多出一个空字串 - if (lineList[lineList.length - 1] === '') { - lineList.splice(length - 1, 1) +// 尝试解析剪贴板内容是否为Excel表格(或类似的)数据格式 +export const pasteExcelClipboardString = (text: string): string[][] | boolean => { + const lines: string[] = text.split('\r\n') + + if (lines[lines.length - 1] === '') lines.pop() + + let colCount = -1 + const data: string[][] = [] + for (const index in lines) { + data[index] = lines[index].split('\t') + + if (data[index].length === 1) return false + if (colCount === -1) colCount = data[index].length + else if (colCount !== data[index].length) return false } - let tNum = -1 - const exlc: string[][] = [] - for (const index in lineList) { - exlc[index] = lineList[index].split('\t') - if (exlc[index].length === 1) return false - if (tNum === -1) { - tNum = exlc[index].length - } - else if (tNum !== exlc[index].length) { - return false - } - } - return exlc + return data } \ No newline at end of file diff --git a/src/views/components/element/TableElement/CustomTextarea.vue b/src/views/components/element/TableElement/CustomTextarea.vue index 03549501..081e21d2 100644 --- a/src/views/components/element/TableElement/CustomTextarea.vue +++ b/src/views/components/element/TableElement/CustomTextarea.vue @@ -12,7 +12,7 @@