forked from Ziv-Barber/officegen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_xlsx.js
45 lines (34 loc) · 993 Bytes
/
make_xlsx.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
38
39
40
41
42
43
44
var fs = require('fs');
var officegen = require('../lib/index.js');
var xlsx = officegen ( 'xlsx' );
xlsx.on ( 'finalize', function ( written ) {
console.log ( 'Finish to create an Excel file.\nTotal bytes created: ' + written + '\n' );
});
xlsx.on ( 'error', function ( err ) {
console.log ( err );
});
sheet = xlsx.makeNewSheet ();
sheet.name = 'Excel Test';
// The direct option - two-dimensional array:
sheet.data[0] = [];
sheet.data[0][0] = 1;
sheet.data[1] = [];
sheet.data[1][3] = 'abc';
sheet.data[1][4] = 'More';
sheet.data[1][5] = 'Text';
sheet.data[1][6] = 'Here';
sheet.data[2] = [];
sheet.data[2][5] = 'abc';
sheet.data[2][6] = 900;
sheet.data[6] = [];
sheet.data[6][2] = 1972;
// Using setCell:
sheet.setCell ( 'E7', 340 );
sheet.setCell ( 'I1', -3 );
sheet.setCell ( 'I2', 31.12 );
sheet.setCell ( 'G102', 'Hello World!' );
var out = fs.createWriteStream ( 'out.xlsx' );
out.on ( 'error', function ( err ) {
console.log ( err );
});
xlsx.generate ( out );