import xlsx from "xlsx"//安装并导入插件
async readExcelFile (url) {
await this.$http.get(url, { responseType: 'arraybuffer' })
.then((res) => {
const data = new Uint8Array(res.data)
const wb = xlsx.read(data, { type: 'array' })
const sheets = wb.Sheets // 获取文档数据
this.content = this.transformSheets(sheets)//Excel转JSON
}).catch(err => {
this.err = err
})
},
transformSheets (sheets) {
const content1 = []
const tmplist = []
for (const key in sheets) {
tmplist.push(xlsx.utils.sheet_to_json(sheets[key]).length)//xlsx插件自带方法
content1.push(xlsx.utils.sheet_to_json(sheets[key]))
}
console.log(tmplist)
console.log(content1)
},
通过 aixos 直接读取本地excel文件,并以json 格式解析 excel 文件内容
于 2024-04-16 15:18:25 首次发布