🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### 解析excel表格 ***** * 安装依赖:`npm install -save vue-xlsx ` * 引入依赖:`import xlsx from 'xlsx'` * 基本使用 * 视图: ``` <el-upload action="" :auto-upload="false" :on-change="onChange" :limit="1" > <el-button type="primary">选择文件</el-button> </el-upload> ``` ``` /* 读取文件 */ readFile(file) { return new Promise((resolve) => { const reader = new FileReader() reader.readAsBinaryString(file) reader.onload = (ev) => { resolve(ev.target.result) } }) }, async onChange(file) { this.$set(this.ruleForm, 'file', file.name) const dataBinary = await this.readFile(file.raw) const workBook = xlsx.read(dataBinary, { type: 'binary', cellDates: true }) const workSheet = workBook.Sheets[workBook.SheetNames[0]] const data = xlsx.utils.sheet_to_json(workSheet) console.log(data) }, ```