Browse Source
Feat/modify input excel (#2587)
* feat: optimize parameter
* Revert "feat: optimize parameter"
This reverts commit 957dfc95dd.
* feat: can input irregulate excel
pull/2589/head
jsong
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
36 additions and
2 deletions
-
src/components/Excel/src/ImportExcel.vue
|
|
|
@ -42,6 +42,40 @@ |
|
|
|
const inputRef = ref<HTMLInputElement | null>(null); |
|
|
|
const loadingRef = ref<Boolean>(false); |
|
|
|
|
|
|
|
function shapeWorkSheel(sheet: XLSX.WorkSheet, range: XLSX.Range) { |
|
|
|
let str = ' ', |
|
|
|
char = 65, |
|
|
|
customWorkSheet = { |
|
|
|
t: 's', |
|
|
|
v: str, |
|
|
|
r: '<t> </t><phoneticPr fontId="1" type="noConversion"/>', |
|
|
|
h: str, |
|
|
|
w: str, |
|
|
|
}; |
|
|
|
if (!sheet || !sheet['!ref']) return []; |
|
|
|
let c = 0, |
|
|
|
r = 1; |
|
|
|
while (c < range.e.c + 1) { |
|
|
|
while (r < range.e.r + 1) { |
|
|
|
if (!sheet[String.fromCharCode(char) + r]) { |
|
|
|
sheet[String.fromCharCode(char) + r] = customWorkSheet; |
|
|
|
} |
|
|
|
r++; |
|
|
|
} |
|
|
|
r = 1; |
|
|
|
str += ' '; |
|
|
|
customWorkSheet = { |
|
|
|
t: 's', |
|
|
|
v: str, |
|
|
|
r: '<t> </t><phoneticPr fontId="1" type="noConversion"/>', |
|
|
|
h: str, |
|
|
|
w: str, |
|
|
|
}; |
|
|
|
c++; |
|
|
|
char++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description: 第一行作为头部 |
|
|
|
*/ |
|
|
|
@ -49,8 +83,8 @@ |
|
|
|
if (!sheet || !sheet['!ref']) return []; |
|
|
|
const headers: string[] = []; |
|
|
|
// A3:B7=>{s:{c:0, r:2}, e:{c:1, r:6}} |
|
|
|
const range = XLSX.utils.decode_range(sheet['!ref']); |
|
|
|
|
|
|
|
const range: XLSX.Range = XLSX.utils.decode_range(sheet['!ref']); |
|
|
|
shapeWorkSheel(sheet, range); |
|
|
|
const R = range.s.r; |
|
|
|
/* start in the first row */ |
|
|
|
for (let C = range.s.c; C <= range.e.c; ++C) { |
|
|
|
|