-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (38 loc) · 1.1 KB
/
Copy pathindex.js
File metadata and controls
45 lines (38 loc) · 1.1 KB
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
const xlsx = require("xlsx");
const excellParser = (model) => {
let { file, body } = model;
// Read the Excel file from the buffer
let workbook = xlsx.read(
file,
{ type: "buffer" },
{ cellDates: true },
{ cellNF: false },
{ cellText: false }
);
let main = [];
const worksheet = workbook.Sheets[body.sheetName];
for (let i = 1; i <= 1000; i++) {
if (worksheet[`B${i}`] !== undefined) {
if (worksheet[`B${i}`].v >= 1) {
if (
(worksheet[`E${i}`].v === 0 || worksheet[`E${i}`] === undefined) &&
(worksheet[`G${i}`].v === 0 || worksheet[`G${i}`] === undefined)
) {
break;
}
let info = {
SL: worksheet[`B${i}`].v,
issueDate: new Date(1899, 12, worksheet[`C${i}`].v + 1),
productName: worksheet[`D${i}`].v,
productAmount: worksheet[`E${i}`].v,
salePrice: worksheet[`F${i}`].v,
organizationName: worksheet[`G${i}`].v,
address: worksheet[`H${i}`].v,
};
main.push(info);
}
}
}
return main;
};
module.exports = excellParser;