-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (29 loc) · 970 Bytes
/
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
import fs from 'fs';
import * as XLSX from 'xlsx/xlsx.mjs';
import employees from './data-sources/employee.js';
class IndexSvc {
setFsToXlsx() {
XLSX.set_fs(fs);
}
async exportArrayToExcel(items, output) {
console.log('Exporting to Excel...🚀');
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(items);
XLSX.utils.book_append_sheet(wb, ws, 'Employees');
XLSX.writeFile(wb, output);
console.log('Exported to Excel successfully! ✅');
}
static run() {
const items = employees;
const OUTPUT = './output'
const FILENAME = 'employees.xls';
const output = `${OUTPUT}/${FILENAME}`;
// check if output directory exists
if (!fs.existsSync(OUTPUT)) {
fs.mkdirSync(OUTPUT);
}
this.prototype.setFsToXlsx();
this.prototype.exportArrayToExcel(items, output);
}
}
export default IndexSvc;