-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (35 loc) · 973 Bytes
/
app.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
const http = require("http");
const fs = require("fs");
const ExcelJS = require("exceljs");
const hostname = "127.0.0.1";
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello World");
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
const func = () => {
console.time("write");
const options = {
worksheets: "emit",
};
const path = "path/to/file";
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader(path, options);
workbookReader.read();
workbookReader.on("worksheet", (worksheet) => {
worksheet.on("row", (row) => {
fs.appendFileSync("result.json", JSON.stringify(row.values));
});
});
workbookReader.on("end", () => {
console.timeEnd("write");
server.close();
});
workbookReader.on("error", (err) => {
console.log(err);
});
};
func();