const xlsx = require('node-xlsx');
const fs = require('fs');

const data = [{
  name : 'sheet1',
  data : [
    [
      '1',
      '2',
      '3'
    ]
  ]
}]

// 读xlsx
const obj = xlsx.parse("./test.xls");
const arr = obj[0].data;
let tmpName = ''

arr.forEach(function (item, index) {
  if (item[0]) {
    tmpName = item[0]
  }
  if (item[1] === '合计') {
    data[0].data.push([tmpName, (item[3] || 0) + (item[4] || 0) + (item[5] || 0), item[8]])
  }
})

// 写xlsx
const buffer = xlsx.build(data);
fs.writeFile('./result.xls', buffer, function (err){
  if (err)
    throw err;
  console.log('写入成功');
});