Skip to content

Instantly share code, notes, and snippets.

@debasreedash
Created February 2, 2015 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debasreedash/33efd4473ba8b344a5ac to your computer and use it in GitHub Desktop.
Save debasreedash/33efd4473ba8b344a5ac to your computer and use it in GitHub Desktop.
conversion from excel to json
var convertJson = require('convert-json');
exports.convertXLSXToJson = function(req, res) {
var path = fileServerPath + req.body.name;
console.log("in method req.body: " + path);
try
{
console.log("Going to convert...");
convertJson.xlsx(path, {header:true}, function(err, result) {
console.log("In convert callback");
try
{
console.log("Testing 'err'");
if(err)
{
console.log(err);
res.send(err);
console.log("Sent 'err' in response");
}
else
{
console.log("No 'err'");
res.send(result);
console.log("Sent 'result' in response");
}
}
catch (ex)
{
console.log("Inner try");
res.send(ex);
console.log("Sent 'ex' from inner try");
}
// result should be a json object or array.
});
console.log("Doing convert...");
}
catch (ex)
{
console.log("Error in outer try");
res.send(ex);
console.log("Sent 'ex' from outer try");
}
console.log("Leaving function");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment