-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
62 lines (60 loc) · 1.06 KB
/
utils.js
File metadata and controls
62 lines (60 loc) · 1.06 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Created by 18468 on 2017/8/7.
*/
var fs = require('fs');
var xlsx = require('node-xlsx');
var data = [{
name: 'sheet1',
data: [
[
'ID',
'Name',
'Score'
],
[
'1',
'Michael',
'99'
],
[
'2',
'Jordan',
'98'
]
]
},
{
name: 'sheet2',
data: [
[
'AA',
'BB'
],
[
'23',
'24'
]
]
}
]
function creatXls(name, data) {
fs.unlink('./' + name + '.xlsx', function (params) {
var buffer = xlsx.build(data);
fs.writeFile('./' + name + '.xlsx', buffer, function (err) {
if (err){
creatXls(name+'(1)',data)
throw err;
}
console.log('Write to xls has finished');
// 读xlsx
// var obj = xlsx.parse("./" + "resut.xls");
// console.log(JSON.stringify(obj));
});
})
}
// creatXls('result', [{
// name: '数据',
// data: _data
// }])
// 写xlsx
exports.creatXls = creatXls