forked from exceljs/exceljs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testCsvOut.js
64 lines (50 loc) · 1.47 KB
/
testCsvOut.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
const Workbook = require('../lib/doc/workbook');
const filename = process.argv[2];
const wb = new Workbook();
const ws = wb.addWorksheet('blort');
ws.columns = [
{header: 'Col 1', key: 'key', width: 25},
{header: 'Col 2', key: 'name', width: 25},
{header: 'Col 3', key: 'age', width: 21},
{header: 'Col 4', key: 'addr1', width: 18},
{header: 'Col 5', key: 'addr2', width: 8},
];
ws.getCell('A2').value = 7;
ws.getCell('B2').value = 'Hello, World!';
ws.getCell('C2').value = -5.55;
ws.getCell('D2').value = 3.14;
ws.getCell('D2').value = new Date(2015, 2, 10, 7, 8, 9);
ws.getCell('E2').value = `${['Hello', 'World'].join(', ')}!`;
ws.getCell('A3').value = {
text: 'www.google.com',
hyperlink: 'http://www.google.com',
};
ws.getCell('A4').value = 'Boo!';
ws.getCell('C4').value = 'Hoo!';
ws.getCell('A5').value = 1;
ws.getCell('B5').value = 2;
ws.getCell('C5').value = {formula: 'A5+B5', result: 3};
ws.getCell('A6').value = 'Hello';
ws.getCell('B6').value = 'World';
ws.getCell('C6').value = {
formula: 'CONCATENATE(A6,", ",B6,"!")',
result: 'Hello, World!',
};
ws.getCell('A7').value = 1;
ws.getCell('B7').value = 2;
ws.getCell('D7').value = 4;
ws.getCell('A10').value = '<';
ws.getCell('B10').value = '>';
ws.getCell('C10').value = '<a>';
ws.getCell('D10').value = '><';
const options = {
dateFormat: 'DD/MM/YYYY HH:mm:ss',
};
wb.csv
.writeFile(filename, options)
.then(() => {
console.log('Done.');
})
.catch(error => {
console.log(error.message);
});