当前位置: 代码迷 >> 综合 >> antd导入excel
  详细解决方案

antd导入excel

热度:32   发布时间:2023-09-06 11:42:48.0
<a-upload accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
:beforeUpload="beforeUpload" @change="handleFileChange"><a-button type="primary">导入Excel</a-button>
</a-upload>methods:
//导入excel
beforeUpload(file){let _this = thisreturn new Promise(function(resolve, reject){// readExcel方法也使用了Promise异步转同步,此处使用then对返回值进行处理_this.readExcel(file).then(result => {// 此时标识校验成功,为resolve返回if (result) resolve(result)})})
},
//解析Excel
readExcel(file) {let _this = thisreturn new Promise(function (resolve, reject) {// 返回Promise对象const reader = new FileReader()reader.onload = (e) => {// 异步执行try {// 以二进制流方式读取得到整份excel表格对象let data = e.target.result, workbook = XLSX.read(data, {type: 'binary'})const exlname = workbook.SheetNames[0] // 取第一张表const exl = XLSX.utils.sheet_to_json(workbook.Sheets[exlname]) // 生成json表格内容console.log(exl)let arr = []exl.map((v, i) => {let obj = {}//对获取的Excel数据进行操作arr.push(obj)})_this.dataSource = arrresolve()} catch (e) {reject(e.message)}}reader.readAsBinaryString(file)})
},

vue实现Excel导入
https://blog.csdn.net/sinat_35538827/article/details/101444051
https://blog.csdn.net/qq_41348029/article/details/84584276
文件类型:
https://blog.csdn.net/usuallyuser/article/details/83060341
Excel限制文本长度
http://www.veryhuo.com/a/view/80048.html
Excel设置下拉选项
https://baijiahao.baidu.com/s?id=1599864933052928528&wfr=spider&for=pc

  相关解决方案