Skip to content

Commit 0f6946a

Browse files
committed
perf[UploadExcel]: optimized code (#1552)
1 parent 22cdfc2 commit 0f6946a

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

src/components/UploadExcel/index.vue

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ export default {
8282
const reader = new FileReader()
8383
reader.onload = e => {
8484
const data = e.target.result
85-
const fixedData = this.fixData(data)
86-
const workbook = XLSX.read(btoa(fixedData), { type: 'base64' })
85+
const workbook = XLSX.read(data, { type: 'array' })
8786
const firstSheetName = workbook.SheetNames[0]
8887
const worksheet = workbook.Sheets[firstSheetName]
8988
const header = this.getHeaderRow(worksheet)
@@ -95,14 +94,6 @@ export default {
9594
reader.readAsArrayBuffer(rawFile)
9695
})
9796
},
98-
fixData(data) {
99-
let o = ''
100-
let l = 0
101-
const w = 10240
102-
for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)))
103-
o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)))
104-
return o
105-
},
10697
getHeaderRow(sheet) {
10798
const headers = []
10899
const range = XLSX.utils.decode_range(sheet['!ref'])

0 commit comments

Comments
 (0)