Commit 14af61cd authored by Administrator's avatar Administrator

support multi sheet selected

parent a3d79e61
...@@ -2,7 +2,8 @@ var am_xlsx2json = require('../') ...@@ -2,7 +2,8 @@ var am_xlsx2json = require('../')
am_xlsx2json({ am_xlsx2json({
input: __dirname + '/place-sample.xls', input: __dirname + '/place-sample.xls',
output: __dirname + '/output.json' output: __dirname + '/output.json',
sheet:['Worksheet','Sheet1']
}, function(err, result) { }, function(err, result) {
if(err) { if(err) {
console.error(err); console.error(err);
......
This diff is collapsed.
No preview for this file type
...@@ -23,7 +23,7 @@ function XLSX_json(config, callback) { ...@@ -23,7 +23,7 @@ function XLSX_json(config, callback) {
function CV(config, callback) { function CV(config, callback) {
var wb = this.load_xlsx(config.input) var wb = this.load_xlsx(config.input)
var json = this.to_json(wb); var json = this.to_json(wb,config);
var output = config.output; var output = config.output;
if (config.output !== null) { if (config.output !== null) {
var stream = fs.createWriteStream(output, { var stream = fs.createWriteStream(output, {
...@@ -39,13 +39,24 @@ function CV(config, callback) { ...@@ -39,13 +39,24 @@ function CV(config, callback) {
CV.prototype.load_xlsx = function(input) { CV.prototype.load_xlsx = function(input) {
return xlsx.readFile(input); return xlsx.readFile(input);
} }
CV.prototype.to_json = function(workbook) { CV.prototype.to_json = function(workbook,config) {
var result = {}; var result = {};
workbook.SheetNames.forEach(function(sheetName) { var target_sheet = config.sheet;
var roa = xlsx.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]); if (target_sheet == null){
if(roa.length > 0){ workbook.SheetNames.forEach(function(sheetName) {
result[sheetName] = roa; var roa = xlsx.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
} if(roa.length > 0){
}); result[sheetName] = roa;
}
});
} else {
target_sheet.forEach(function(sheetName) {
var roa = xlsx.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
if(roa.length > 0){
result[sheetName] = roa;
}
})
}
return result; return result;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment