// vue
<input
type="file"
@change="importExcel($event)"
ref="importExcel"
id="importExcel"
style="display:none;"
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" >
<a id="exportExcel" ref="exportExcel"></a>
<a-button type="primary" class="button" @click="btnImportClick">导入Excel</a-button>
<a-button type="primary" class="button" @click="btnExportClick(excelData)" style="margin-left:20px;">导出Excel</a-button>`
export const importExcelMethods = function(event) {
if (!event.target.files) {
return
}
var suffix = event.target.files[0].name.split('.')[1]
if (suffix != 'xls' && suffix != 'xlsx') {
alert('导入的文件格式不正确!')
return
}
var f = event.target.files[0]
var reader = new FileReader()
reader.onload = function (e) {
var data = e.target.result
if (rABS) {
wb = XLSX.read(btoa(fixdata(data)), {
//手动转化
type: 'base64',
})
} else {
wb = XLSX.read(data, {
type: 'binary',
})
}
const wsname = wb.SheetNames[0]
const ws = wb.Sheets[wsname]
const zdata = utils.sheet_to_json(ws, { header: 1 })
const newData = JSON.stringify(
XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]])
)
console.log('===',newData)
}
if (rABS) {
reader.readAsArrayBuffer(f)
} else {
reader.readAsBinaryString(f)
}
}
//调用
importExcel(event){
const myevent = event
importExcelMethods(myevent)
},
现在的问题是:我封装渲染后想返回zdata,但是就是显示undefined
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…