nodejs操作execl表の内容
node-xlsxモジュールを導入する
var xlsx = require('node-xlsx');
var sheets = xlsx.parse('./excle/2.xlsx');// sheets
var sheet2 = xlsx.parse("./excle/3.xls")
var exe1 =[]
var exe2 =[]
execle
sheets.forEach(function(sheet){
for(var rowId in sheet['data']){
var row=sheet['data'][rowId];
var json ={
name:row[1],
idnumber:row[4]
}
exe1.push(json)
}
});
sheet2.forEach(function(sheet){
for(var rowId in sheet['data']){
var row=sheet['data'][rowId];
var jsons ={
name:row[0],
idnumber:row[1]
}
exe2.push(jsons)
}
});
elxelにデータを書き込みます.var data = [{
name: 'sheet1',
data: [
[
'ID',
'Name',
'Score'
],
[
'1',
'Michael',
'99'
],
[
'2',
'Jordan',
'98'
]
]
},
{
name: 'sheet2',
data: [
[
'AA',
'BB'
],
[
'23',
'24'
]
]
}
]
var buffer = xlsx.build(data);
//
fs.writeFile('a.xlsx', buffer, function(err) {
if (err) {
console.log("Write failed: " + err);
return;
}
console.log("Write completed.");
});