1.安装
npm install node-xlsx --save2.
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
该文章介绍了一个Node.js类,用于读取和处理Excel文件。通过npm安装node-xlsx库,然后创建一个ParseXls类,接收文件路径和工作表编号,读取指定工作表的数据,删除空行和空列,最后返回处理后的数据。
2497

被折叠的 条评论
为什么被折叠?



