-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjunk
101 lines (82 loc) · 2.86 KB
/
junk
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// const result = excelToJson({
// source: fs.readFileSync('Product.xlsx') // fs.readFileSync return a Buffer
// });
// console.log(result)
// fs.createReadStream('grades.csv')
// .pipe(csv())
// .on('data', (row) => {
// csvjson.push(row);
// console.log(row)
// })
// .on('end', () => {
// console.log('CSV file successfully processed');
// });
//connect2()
// xlsxFile('Product.xlsx').then((rows) => {
// console.log(rows)
// xljson.push(row);
// })
// console.log(process.env.URI)
// mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true }, (connect) => {
// console.log('Mongoose connected');
// })
// app.get("/csvtopdf", upload.single('file'), async(req, res) => {
// const rows = await CSVToJSON().fromFile('uploads/grades.csv');
// let data = JSON.stringify(rows);
// ejs.render('template', { result: rows, route: "csv" });
// fs.writeFile('./temp.html', data, function(error, data) {
// if (error) {
// res.writeHead(404);
// res.write('Whoops! File not found!');
// } else {
// res.redirect('/pdfFromHtml')
// }
// })
// app.get('/pdfFromHTML', function(req, res) {
// res.pdfFromHTML({
// filename: 'generated.pdf',
// html: 'views/template.ejs',
// });
// });
app.get("/xltopdf", upload.single('file'), (req, res) => {
console.log(req.body.file)
if (fs.existsSync('./product.json')) {
let rawdata = fs.readFileSync('product.json');
let data = JSON.parse(rawdata);
data = JSON.stringify(data);
fs.writeFile('./temp.html', data, function(error, data) {
if (error) {
res.writeHead(404);
res.write('Whoops! File not found!');
} else {
res.redirect('/pdfFromHtml')
}
});
// console.log(data);
} else {
node_xj({
input: "./uploads/Product.xlsx", // input xls
output: "product.json", // output json
allowEmptyKey: false,
lowerCaseHeaders: true
},
function(err, result) {
if (err) {
console.error(err);
} else {
let rawdata = fs.readFileSync('product.json');
let data = JSON.parse(rawdata);
data = JSON.stringify(data);
fs.writeFile('./temp.html', data, function(error, data) {
if (error) {
res.writeHead(404);
res.write('Whoops! File not found!');
} else {
res.redirect('/pdfFromHtml')
}
});
}
}
);
}
})