前端导入Excel

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_42265852/article/details/97169433

1 html 

<Button @click="imFile.click()" type="primary" :loading="excelLoading"  style="margin-right: 5px;" v-if="importClassIsShow">导入Excel</Button>
<input type="file" @change="importFile(this)" id="imFile" style="display: none"
    accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"/>

2 script

const XLSX = require('xlsx');

imFile: '',

mounted() {
  this.imFile = document.getElementById('imFile');
},


importFile() {// 导入excel
    let obj = this.imFile;
    if (!obj.files) return;
    this.excelLoading = true;
    let f = obj.files[0], reader = new FileReader(), _this = this;
    reader.onload = async function (e) {
        let data = e.target.result;
        if (_this.rABS) {
            _this.wb = XLSX.read(btoa(this.fixdata(data)

没有更多推荐了,返回首页