ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 解析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) }, ```