npm install xlsx --s
handlePreview(file)?{
????????//?console.log(file);
????????this.importfile(file.raw)
????????this.fileList?=?[]
??????},
importfile?(obj)?{
????????const?_this?=?this
????????const?reader?=?new?FileReader()
????????reader.readAsArrayBuffer(obj)//需要傳blob類型
????????reader.onload?=?function?()?{
??????????const?buffer?=?reader.result
??????????const?bytes?=?new?Uint8Array(buffer)
??????????const?length?=?bytes.byteLength
??????????let?binary?=?''
??????????for?(let?i?=?0;?i?<?length;?i++)?{
????????????binary?+=?String.fromCharCode(bytes[i])
??????????}
??????????const?XLSX?=?require('xlsx')//引用
??????????const?wb?=?XLSX.read(binary,?{
????????????type:?'binary'
??????????})
??????????let?tableList?=?['業(yè)務(wù)類型','用戶訂單號(hào)','快遞單號(hào)']
??????????for(?let?i?=?0;?i<tableList.length;?i++?)?{
????????????if?(?wb.Strings[i].t?!=?tableList[i]?)?{
??????????????_this.$message.error('格式錯(cuò)誤院刁,請(qǐng)重新上傳');
??????????????return?false
????????????}
??????????}
??????????const?outdata?=?XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]])
??????????//?console.log(outdata)?//?此為取到的excel中內(nèi)容名船,然后就可以自己改數(shù)據(jù),畫頁(yè)面啦~
??????????_this.allVisible?=?true
??????????let?dataStr?=?[]
??????????for?(?let?i?=?0;?i<outdata.length;?i++?)?{
????????????dataStr.push({
??????????????expressName:?outdata[i].業(yè)務(wù)類型?==?undefined???'':outdata[i].業(yè)務(wù)類型,
??????????????expressNumber:?outdata[i].用戶訂單號(hào)?==?undefined???'':outdata[i].用戶訂單號(hào),
??????????????orderId:?outdata[i].快遞單號(hào)?==?undefined???'':outdata[i].快遞單號(hào).toString(),
????????????});
??????????}
??????????_this.allTableData?=?dataStr
????????}
??????},