-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (45 loc) · 1.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const xlsx = require('xlsx');
const fs = require('fs');
const file = xlsx.readFile(`input/${process.argv[2]}`);
const sheets = file.Sheets
const sheet = sheets[Object.keys(sheets)[0]];
const data = xlsx.utils.sheet_to_json(sheet);
let fileIndex = 1;
const fileName = process.argv[2].split('.')[0]
function saveIntoFile(arr){
// console.log(arr.length)
let newWB = xlsx.utils.book_new();
let newWS = xlsx.utils.json_to_sheet(arr);
xlsx.utils.book_append_sheet(newWB, newWS, 'Worksheet');
xlsx.writeFile(newWB, `output/${fileName}-${fileIndex}.xls`);
fileIndex++
}
const sortedByGroup = data.sort((a,b) => {
const fa = a['Группа'].toLowerCase();
const fb = b['Группа'].toLowerCase();
if(fa < fb){
return -1;
} else if(fa > fb){
return 1;
} else {
return 0;
}
})
let container = []
let count = 1;
for(let i = 0; i<=sortedByGroup.length-1; i++){
container.push(sortedByGroup[i]);
if(!sortedByGroup[i-1]){
continue
} else if(sortedByGroup[i]['Группа'].toLowerCase() !== sortedByGroup[i-1]['Группа'].toLowerCase()){
count++;
}
if(count === 345){
saveIntoFile(container);
container = [];
count = 0
};;
}
if(container.length>0){
saveIntoFile(container);
}