上传Excel前打印数据结构

2022-05-06 18:34:53 浏览数 (2)

代码语言:javascript复制
    <el-upload action="http://192.168.1.78:8079/weeg-common-base/commonFile/upload"  :show-file-list="false"
      :before-upload="beforeUpload" accept=".xls,.xlsx">
      <el-button size="small">
        上传文件
        <i class="el-icon-upload el-icon--right"></i>
      </el-button>
    </el-upload>

import XLSX from "xlsx" 

代码语言:javascript复制
    beforeUpload(file){
      let fr = new FileReader()
      fr.onloadend = (e)=>{
        let data = e.target.result
        let workbook = XLSX.read(data,{
          type:'binary'
        })
        let xlsName = workbook.SheetNames[0]  //sheet1
        let jsonData = XLSX.utils.sheet_to_json(workbook.Sheets[xlsName])
        console.log(jsonData)
      }
      fr.onerror = (err)=>{
        console.log(err)
      }
      fr.readAsBinaryString(file)     
    },

0 人点赞