- Get the scores of all classes and send them to each teacher according to the class generated table
- After having everyone’s salary, it is distributed to individuals according to the salary scale of each person’s life
- Get the summary data from the data center and distribute it to the units
const XLSXWriter = require('xlsx-writestream');
const powXLSX = require('xlsx-extract').XLSX;
const fs = require('fs');
const fileName = './test.xlsx';
const groupName = "Class";
const generateTable = (json, name) = > {
const newFile = `./result/${name}.xlsx`
console.log(`${name}. XLSX have${json.length}The data `)
const writer = new XLSXWriter(newFile, {} /* options */);
writer.getReadStream().pipe(fs.createWriteStream(newFile));
json.forEach(item= > {
writer.addRow(item)
})
writer.finalize();
}
let title = []
let groupIndex = 0;
const data = []
let groupArr = [];
new powXLSX().extract(fileName, { sheet_all: true }) By default, only the first sheet is read. The parameters are set as follows
.on('sheet'.function (sheet) {
console.log('sheet', sheet); // sheet is array [sheetname, sheetid, sheetnr]
})
.on('row'.function (row) {
if(! title.length) { title = row groupIndex = row.findIndex(e= > e === groupName)
} else {
console.log(data.length + 1)
const value = {}
title.forEach((item, index) = > value[item] = row[index])
data.push(value);
groupArr = [...new Set([...groupArr, row[groupIndex]])]
}
})
.on('cell'.function (cell) {
// console.log('cell', cell); //cell is a value or null
})
.on('error'.function (err) {
console.error('error', err);
})
.on('end'.function (err) {
console.log(` altogether${data.length}The data `)
console.log(` should be generated${groupArr.length}A table `)
groupArr.forEach(name= > {
generateTable(data.filter(item= > item[groupName] === name), name)
})
});
Copy the code