-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtestSheet.js
59 lines (45 loc) · 1.53 KB
/
testSheet.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
const fs = require('fs');
const Worksheet = require('../lib/doc/worksheet');
const sheetname = process.argv[2];
const stringname = process.argv[3];
const relname = process.argv[4];
const ws = new Worksheet();
ws.columns = [
{header: 'Col 1', key: 'key', width: 25},
{header: 'Col 2', key: 'name', width: 25},
{header: 'Col 3', key: 'age'},
{header: 'Col 4', key: 'addr1', width: 8},
{header: 'Col 5', key: 'addr2', width: 10},
];
ws.getCell('A2').value = 'Hello, World!';
ws.getCell('B1').value = 'Hello, World!';
ws.getCell('C1').value = 5;
ws.getCell('D1').value = 3.14;
ws.getCell('C3').value = 'Boo!';
ws.getCell('A4').value = 'merge 3x1';
ws.getCell('B4').value = 'Won\'t see this';
ws.mergeCells('A4:C4');
ws.getCell('B5').value = 'merge 3x3';
ws.mergeCells('B5', 'D7');
ws.getCell('C8').value = 'merge 1x2';
ws.mergeCells(8, 3, 9, 3);
ws.getCell('A10').value = {
text: 'www.google.com',
hyperlink: 'http://www.google.com',
};
const promises = [];
console.log(`Writing sheet to ${sheetname}`);
const sheetstream = fs.createWriteStream(sheetname);
promises.push(ws.write(sheetstream));
console.log(`Writing string table to ${stringname}`);
const stringstream = fs.createWriteStream(stringname);
promises.push(ws.sharedStrings.write(stringstream));
console.log(`Writing relationship table to ${relname}`);
const relstream = fs.createWriteStream(relname);
promises.push(ws.relationships.write(relstream));
Promise.all(promises).then(() => {
sheetstream.close();
stringstream.close();
relstream.close();
console.log('Done.');
});