vue3,读取excel文件

html内容  

            点击上传
          



先下载并且引入插件
import * as XLSX from 'xlsx'


change方法内容


if (e.status !== 'ready') return   // 防止触发两次
        if (e.length <= 0) {
          ElMessage.warning('请选择文件')
        } else if (e.name.split('.')[1] !== 'xlsx') {
          ElMessage.warning('上传格式不正确,请上传xlsx格式')
        } else {
          const file = e.raw
          let v = new FormData()
          v.append('file', 9999999999)
          console.log(v)
          // const file = e.target.files[0]
          const reader = new FileReader()
          reader.readAsArrayBuffer(file)
          reader.onload = async ev => {
            let data = ev.target.result
            console.log(data, '这里是文件流')
            const workbook = XLSX.read(data, { type: 'binary', cellDates: true })
            const wsname = workbook.SheetNames[0]
            const getData = XLSX.utils.sheet_to_json(workbook.Sheets[wsname])
            // console.log(getData, '899')
          }
        }

你可能感兴趣的:(excel,javascript,前端)