1.安装
npm install node-xlsx --save
2.
const nodeXlsx = require('node-xlsx')
class ParseXls {
constructor(path, number) {
this.path = path
this.number = number
}
readXls() {
const exl = nodeXlsx.parse(this.path)
let array = exl[this.number].data //number为0,表示第一个sheet
for (let i in array) {
if (array[i].length === 0) {
array.splice(0, 1)//删除空行
}
else{
for (let j in array[i]){
if (array[i][j] === underfind){
array[i][j].splice(j,1)//删除空列
}
}
}
}
return array
}
}
module.exports = ParseXls