xls-to-json
Advanced tools
Comparing version 0.0.0 to 0.0.1
@@ -11,3 +11,3 @@ var fs = require('fs'); | ||
function XLS_json (config) { | ||
function XLS_json (config, callback) { | ||
console.log(config) | ||
@@ -19,17 +19,11 @@ if(!config.input) { | ||
if(!config.output) { | ||
console.error("You miss a output file"); | ||
process.exit(2); | ||
} | ||
var cv = new CV(config); | ||
var cv = new CV(config, callback); | ||
} | ||
function CV(config) { | ||
function CV(config, callback) { | ||
var wb = this.load_xls(config.input) | ||
var ws = this.ws(wb); | ||
var csv = this.csv(ws) | ||
this.cvjson(csv, config.output) | ||
this.cvjson(csv, config.output, callback) | ||
} | ||
@@ -54,3 +48,3 @@ | ||
CV.prototype.cvjson = function(csv, output) { | ||
CV.prototype.cvjson = function(csv, output, callback) { | ||
cvcsv() | ||
@@ -79,4 +73,9 @@ .from.string(csv) | ||
console.log('Number of lines: '+count); | ||
var stream = fs.createWriteStream(output, { flags : 'w' }); | ||
stream.write(JSON.stringify(record)); | ||
if(output !== null) { | ||
var stream = fs.createWriteStream(output, { flags : 'w' }); | ||
stream.write(JSON.stringify(record)); | ||
callback(null, record); | ||
} else { | ||
callback(null, record); | ||
} | ||
@@ -87,2 +86,2 @@ }) | ||
}); | ||
} | ||
} |
{ | ||
"name": "xls-to-json", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Converting xls file to json files using nodejs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,3 +8,3 @@ # node-xls-json | ||
``` | ||
npm install node-xls-to-json | ||
npm install xls-to-json | ||
``` | ||
@@ -15,9 +15,17 @@ | ||
``` | ||
node_xj = require("node-xls-to-json"); | ||
node_xj = require("xls-to-json"); | ||
node_xj({ | ||
input: "sample.xls", | ||
output: "output.json" | ||
}, function(err, result) { | ||
if(err) { | ||
console.error(err); | ||
} else { | ||
console.log(result); | ||
} | ||
}); | ||
``` | ||
In config object, you have to enter an input path. But If you don't want to output any file you can set to `null`. | ||
## License | ||
@@ -24,0 +32,0 @@ |
@@ -6,2 +6,10 @@ var xls_json = require('../') | ||
output: __dirname + '/test.json' | ||
}, function(err, result) { | ||
if(err) { | ||
console.error(err); | ||
} else { | ||
console.log(result); | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
99864
82
33