Commit 14af61cd authored by Administrator's avatar Administrator

support multi sheet selected

parent a3d79e61
......@@ -2,7 +2,8 @@ var am_xlsx2json = require('../')
am_xlsx2json({
input: __dirname + '/place-sample.xls',
output: __dirname + '/output.json'
output: __dirname + '/output.json',
sheet:['Worksheet','Sheet1']
}, function(err, result) {
if(err) {
console.error(err);
......
This diff is collapsed.
No preview for this file type
......@@ -23,7 +23,7 @@ function XLSX_json(config, callback) {
function CV(config, callback) {
var wb = this.load_xlsx(config.input)
var json = this.to_json(wb);
var json = this.to_json(wb,config);
var output = config.output;
if (config.output !== null) {
var stream = fs.createWriteStream(output, {
......@@ -39,13 +39,24 @@ function CV(config, callback) {
CV.prototype.load_xlsx = function(input) {
return xlsx.readFile(input);
}
CV.prototype.to_json = function(workbook) {
CV.prototype.to_json = function(workbook,config) {
var result = {};
workbook.SheetNames.forEach(function(sheetName) {
var roa = xlsx.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
if(roa.length > 0){
result[sheetName] = roa;
}
});
var target_sheet = config.sheet;
if (target_sheet == null){
workbook.SheetNames.forEach(function(sheetName) {
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;
}
\ 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