convert excel file to json using node js

Solutions on MaxInterview for convert excel file to json using node js by the best coders in the world

showing results for - "convert excel file to json using node js"
Liam
13 Feb 2017
1let express = require('express'),
2    app = express(),
3    bodyParser = require('body-parser'),
4    multer = require('multer'),
5    crypto = require('crypto'),
6    xlsxtojson = require('xlsx-to-json'),
7    xlstojson = require("xls-to-json");
8
9let fileExtension = require('file-extension');
10
11    app.use(bodyParser.json());  
12
13    let storage = multer.diskStorage({ //multers disk storage settings
14        destination: function (req, file, cb) {
15            cb(null, './input/')
16        },
17        filename: function (req, file, cb) {
18            crypto.pseudoRandomBytes(16, function (err, raw) {
19                cb(null, raw.toString('hex') + Date.now() + '.' + fileExtension(file.mimetype));
20                });
21        }
22    });
23
24    let upload = multer({storage: storage}).single('file');
25
26    /** Method to handle the form submit */
27    app.post('/sendFile', function(req, res) {
28        let excel2json;
29        upload(req,res,function(err){
30            if(err){
31                 res.json({error_code:401,err_desc:err});
32                 return;
33            }
34            if(!req.file){
35                res.json({error_code:404,err_desc:"File not found!"});
36                return;
37            }
38
39            if(req.file.originalname.split('.')[req.file.originalname.split('.').length-1] === 'xlsx'){
40                excel2json = xlsxtojson;
41            } else {
42                excel2json = xlstojson;
43            }
44
45           //  code to convert excel data to json  format
46            excel2json({
47                input: req.file.path,  
48                output: "output/"+Date.now()+".json", // output json 
49                lowerCaseHeaders:true
50            }, function(err, result) {
51                if(err) {
52                  res.json(err);
53                } else {
54                  res.json(result);
55                }
56            });
57
58        })
59
60    });
61    // load index file to upload file on http://localhost:3000/
62    app.get('/',function(req,res){
63        res.sendFile(__dirname + "/index.html");
64    });
65
66    app.listen('3000', function(){
67        console.log('Server running on port 3000');
68    });
69
queries leading to this page
extract excel sheet data to json in nodejsexcel buffer convert into json object in node jsconvert excel file to json using node jsnode js json to excel node excel to jsonconvert excel to json in node jsnode js read excel file from location and send to jsonhow to write to json data into excel file in node jshow to convert excel file into json in node js using module xlsxnode command convert json to excelexcel to json converter nodejsexceljs to json npmjson to excel data in node jshow to convert json into excel file in nodejsnode js excel to json exampleshow to convert excel to json file in node jsnpmjs excel to jsonconvert excel file into json in javascrip 5btexcel to json in node javascriptnode convert excel to jsonhow to convert a json data in excel in node jsconvert json to excel in node jsread excel file as json node jsconvert excel data to json node jsexcel to json nodejswrite json data to excel in node jsconvert json to excel nodejsconvert xls to json nodehow to convert excel to json in node jsjs read excel to jsonnode js export json to excelhow to convert excel to json in nodejshow to convert excel file into json in javascriptexcel file buffer convert to json in node jsnode json to excelconvert excel to json in node js using node xlsxconvert excel to json nodejsnode app excel to jsonexcel to json javascript nodeexcel file to json javascriptconverting excel sheet to json jsnode js excel to jsonextract data from excel sheet in nodejs and store as a jsonprint excel file to json javascripthow to convert json into excel file using javascriptjson to excel using nodeconvert excel file to json in javascriptextract data from excel sheet to json in nodejsjson file to excel using nodecreate excel from json node js json to excel in node jsnodejs export json to exceljson to excel convert in node jsjs convert excel to jsoncreate excel from json in nodejshow to parse excel to json node js using exeljsnodejs json to excelexceljs json to excel node js node js excel from jsonjson to excel nodecreate excel from json in node jsjson to excel nodejsjson to excel in node jsexpressjs json to excelread excel file and convert to json in javascriptconvert json to excel node jsconvert json file to excelsheet in nodejshow to convert excel file to json in node jsnodejs convert excel to json filecreate json from excel nodejsexcel to json javascriptconvert excel to json in nodejsconvert excel to json node jshow to convert from excel to json file in node js for beginners node js json to excelnode js read excel file to json typescriptexport json to excel nodejs nodejs create excel file with json objectconverting json into excel jsexcel to json nodehow to convert excel file into jason in node js using module xlsxcreate excel file from json nodejshow to parse excel to json node jsjson to excel in nodejsjson to excel node jsnodejs convert excel to jsonnodejs create excel file from jsonhow to create json to excel in node jshow to write json data to excel sheet in node jsconvert excel to json using javascripthow to get excel sheet data in json using nodejsconvert excel file to json javascriptwrite json data in excel using nodejsnodejs xls to jsonhow to convert json data to excel in nodejshow to convert json to excel file in node jsconvert excel online to json node jsconvert json file into excell using jsnodejs read excel file to jsonhow to convert excel file to json using javascriptusing sheet js to convert excel file to jsonexcel to json in node jsexcel file to json using jsnodejs data to json to exceltransfer json to excel using node ksnodejs excel to jsonhow to put json data in excel using nodejsexcel buffer to json in node jshow to convert from excel to json file for beginners in node jsnode js read excel file to jsonhow to write json data in excel file sheet in node jsconvert excel to json 7c json to excel node jsconvert excel file to json using node js