I am trying to import data in excel file to mysql just like row colon using nodejs are there any references i can learn or any module in nodejs that does my work or any sample code
Asked
Active
Viewed 1,723 times
0
-
1Does this help: https://stackoverflow.com/questions/31651931/how-to-import-excel-file-xlsx-to-mysql-using-nodejs?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa? – GE ownt Apr 13 '18 at 05:01
-
Possible duplicate of [how to import excel file (XLSX) to mysql using nodejs](https://stackoverflow.com/questions/31651931/how-to-import-excel-file-xlsx-to-mysql-using-nodejs) – RobC Apr 13 '18 at 16:08
-
I did excel sheet json convert format using npm "xls-to-json-lc" and imported it to mysql... It's working... Thanks guys... – ganesan s May 29 '18 at 04:53
1 Answers
0
I used Npm packages "xlsx-to-json-lc" and "xls-to-json-lc" to import excel file to json directly without converting to csv. Hope this helps...
var storage = multer.diskStorage({ //multers disk storage settings
destination: function (req, file, cb) {
cb(null, './uploads/')
},
filename: function (req, file, cb) {
var datetimestamp = dateFormat(new Date(), "yyyy~mm~dd h~MM~ss");
cb(null, '`enter code here`templete' + '-' + datetimestamp + '.' +
`enter code here`file.originalname.split('.')[file.originalname.split('.').length - 1])
filename = file.fieldname;
}
});
var upload = multer({ //multer settings
storage: storage,
fileFilter: function (req, file, callback) { //file filter
if (['xls', 'xlsx'].indexOf(file.originalname.split('.')[file.originalname.split('.').length - 1]) === -1) {
return callback(new Error('Wrong extension type'));
}
callback(null, true);
}
}).single('file');
var exceltojson;
upload(req, res, function (err) {
if (err) {
res.json({ error_code: 1, err_desc: err });
return;
}
if (!req.file) {
//res.json({ error_code: 1, err_desc: err });
return;
}
if (req.file.originalname.split('.')[req.file.originalname.split('.').length - 1] === 'xlsx') {
exceltojson = xlsxtojson;
} else {
exceltojson = xlstojson;
}
try {
exceltojson({
input: req.file.path,
output: null, //since we don't need output.json
//lowerCaseHeaders: true
}, function (err, result) {
if (err) {
return res.json({ error_code: 1, err_desc: err, data: null });
}
else {
console.log(result);
}
});
})

ganesan s
- 33
- 14