首页 > 其他分享 >vue中读取本地Excel文件

vue中读取本地Excel文件

时间:2022-12-22 18:56:41浏览次数:59  
标签:vue const 读取 Excel content let path fileData

readExcelFile

const XLSX = require('xlsx')
const path = "./file/file.xlsx" //放在public目录下的文件可以直接访问
axios.get(path, { responseType: 'arraybuffer' }).then((res) => {
  let data = new Uint8Array(res);
  let workbook = XLSX.read(data, { type: "array" });
  let sheets = workbook.Sheets;
  let content = [];
  for (let key in sheets){
  //读出来的workbook数据,转换为json格式
    content.push(XLSX.utils.sheet_to_json(sheets[key]));
  }
  const fileName = path.substr(path.lastIndexOf('/') + 1);
  let fileData = [];
  fileData.push(content[0][0]);
  for (let i in this.tableList) {
    fileData.push(this.tableList[i]);
  }
  //下载Excel文件
  ctx.downloadExcel(fileName,fileData);
}).catch(err => {
  ctx.err = err;
})

 

参考:https://www.yisu.com/zixun/164546.html

标签:vue,const,读取,Excel,content,let,path,fileData
From: https://www.cnblogs.com/ZhaoHS/p/16722505.html

相关文章