forked from exceljs/exceljs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-table.js
71 lines (64 loc) · 1.35 KB
/
test-table.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const Excel = require('../lib/exceljs.nodejs.js');
const HrStopwatch = require('./utils/hr-stopwatch');
const [, , filename] = process.argv;
const wb = new Excel.Workbook();
const ws = wb.addWorksheet('Foo');
const now = new Date();
const today = Date.UTC(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDay()
);
ws.columns = [{key: 'date', width: 32}, {key: 'number'}, {key: 'word'}];
const words = [
'Twas',
'brillig',
'and',
'the',
'slithy',
'toves',
'did',
'gyre',
'and',
'gimble',
'in',
'the',
'wabe',
];
ws.addTable({
name: 'TestTable',
ref: 'A1',
headerRow: true,
totalsRow: true,
style: {
theme: 'TableStyleDark3',
showRowStripes: true,
},
columns: [
{name: 'Date', totalsRowLabel: 'Totally', filterButton: true},
{
name: 'Id',
totalsRowFunction: 'max',
filterButton: true,
totalsRowResult: 8,
},
{
name: 'Word',
filterButton: false,
style: {font: {bold: true, name: 'Comic Sans MS'}},
},
],
rows: words.map((word, i) => [new Date(+today + (86400 * i)), i, word]),
});
const stopwatch = new HrStopwatch();
stopwatch.start();
wb.xlsx
.writeFile(filename)
.then(() => {
const micros = stopwatch.microseconds;
console.log('Done.');
console.log('Time taken:', micros);
})
.catch(error => {
console.log(error.message);
});