-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperateExcel.js
37 lines (35 loc) · 1.25 KB
/
operateExcel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Created by junping on 14-12-18.
*/
var xlsx = require("node-xlsx");
var fs = require("fs");
module.exports = OperateExcel;
function OperateExcel(){};
OperateExcel.readyExcel = function(excelName, sheetNameArray, callback){
var path = __dirname + "/excel/" + excelName;
fs.exists(path, function(flag){
if(!flag){
return callback(new Error(path + " not exist"));
}
//read all sheet
var sheetArray = xlsx.parse("./excel/" + excelName);
var returnObj = {};
for(var i=0; i<sheetArray.length; i++){
var sheetDB = sheetArray[i];//one sheet data
var sheetName = sheetDB.name;//sheet name
//each
if(sheetNameArray instanceof Array && sheetNameArray.length > 0){
for(var j=0; j<sheetNameArray.length; j++){
if(sheetName === sheetNameArray[j]){
sheetDB["data"].shift();//delete first row filed
returnObj[sheetName] = sheetDB["data"];
}
}
}else{
sheetDB["data"].shift();//delete first row filed
returnObj[sheetName] = sheetDB["data"];
}
}
callback(null, returnObj);
});
};