-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtestBookOut.js
363 lines (330 loc) · 9.51 KB
/
testBookOut.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
const _ = require('../lib/utils/under-dash.js');
const HrStopwatch = require('./utils/hr-stopwatch');
const ExcelJS = require('../excel');
const {Workbook} = ExcelJS;
const [, , filename] = process.argv;
const wb = new Workbook();
const ws = wb.addWorksheet('blort');
const fonts = {
arialBlackUI14: {
name: 'Arial Black',
family: 2,
size: 14,
underline: true,
italic: true,
},
comicSansUdB16: {
name: 'Comic Sans MS',
family: 4,
size: 16,
underline: 'double',
bold: true,
},
whiteText: {
name: 'Arial Black',
family: 2,
size: 14,
color: {argb: 'FFFFFFFF'},
},
};
const alignments = [
{text: 'Top Left', alignment: {horizontal: 'left', vertical: 'top'}},
{
text: 'Middle Centre',
alignment: {horizontal: 'center', vertical: 'middle'},
},
{
text: 'Bottom Right',
alignment: {horizontal: 'right', vertical: 'bottom'},
},
{
text: 'Wrap Text - Wrapping Wrapping Wrappity Wrap Wrap Wrap',
alignment: {wrapText: true},
},
{text: 'Indent 1', alignment: {indent: 1}},
{text: 'Indent 2', alignment: {indent: 2}},
{
text: 'Rotate 15',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: 15},
},
{
text: 'Rotate 30',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: 30},
},
{
text: 'Rotate 45',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: 45},
},
{
text: 'Rotate 60',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: 60},
},
{
text: 'Rotate 75',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: 75},
},
{
text: 'Rotate 90',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: 90},
},
{
text: 'Rotate -15',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: -55},
},
{
text: 'Rotate -30',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: -30},
},
{
text: 'Rotate -45',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: -45},
},
{
text: 'Rotate -60',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: -60},
},
{
text: 'Rotate -75',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: -75},
},
{
text: 'Rotate -90',
alignment: {horizontal: 'right', vertical: 'bottom', textRotation: -90},
},
{
text: 'Vertical Text',
alignment: {
horizontal: 'right',
vertical: 'bottom',
textRotation: 'vertical',
},
},
];
// const badAlignments = [
// { text: 'Rotate -91', alignment: { textRotation: -91 } },
// { text: 'Rotate 91', alignment: { textRotation: 91 } },
// { text: 'Indent -1', alignment: { indent: -1 } },
// { text: 'Blank', alignment: { } }
// ];
const borders = {
thin: {
top: {style: 'thin'},
left: {style: 'thin'},
bottom: {style: 'thin'},
right: {style: 'thin'},
},
doubleRed: {
color: {argb: 'FFFF0000'},
top: {style: 'double'},
left: {style: 'double'},
bottom: {style: 'double'},
right: {style: 'double'},
},
thickRainbow: {
top: {style: 'double', color: {argb: 'FFFF00FF'}},
left: {style: 'double', color: {argb: 'FF00FFFF'}},
bottom: {style: 'double', color: {argb: 'FF00FF00'}},
right: {style: 'double', color: {argb: 'FFFF00FF'}},
diagonal: {
style: 'double',
color: {argb: 'FFFFFF00'},
up: true,
down: true,
},
},
thinWhite: {
top: {style: 'thin'},
left: {style: 'thin'},
bottom: {style: 'thin'},
right: {style: 'thin'},
color: {argb: 'FFFFFFFF'},
},
};
const fills = {
solidGreen: {
type: 'pattern',
pattern: 'solid',
fgColor: {argb: 'FF00FF00'},
},
redDarkVertical: {
type: 'pattern',
pattern: 'darkVertical',
fgColor: {argb: 'FFFF0000'},
},
redGreenDarkTrellis: {
type: 'pattern',
pattern: 'darkTrellis',
fgColor: {argb: 'FFFF0000'},
bgColor: {argb: 'FF00FF00'},
},
blueWhiteHGrad: {
type: 'gradient',
gradient: 'angle',
degree: 0,
stops: [
{position: 0, color: {argb: 'FF0000FF'}},
{position: 1, color: {argb: 'FFFFFFFF'}},
],
},
rgbPathGrad: {
type: 'gradient',
gradient: 'path',
center: {left: 0.5, top: 0.5},
stops: [
{position: 0, color: {argb: 'FFFF0000'}},
{position: 0.5, color: {argb: 'FF00FF00'}},
{position: 1, color: {argb: 'FF0000FF'}},
],
},
};
ws.columns = [
{header: 'Col 1', key: 'key', width: 25},
{header: 'Col 2', key: 'name', width: 32},
{header: 'Col 3', key: 'age', width: 21},
{header: 'Col 4', key: 'addr1', width: 18},
{header: 'Col 5', key: 'addr2', width: 8},
{header: 'Col 6', width: 8},
{header: 'Col 7', width: 8},
{
header: 'Col 8',
width: 8,
style: {font: fonts.comicSansUdB16, alignment: alignments[1].alignment},
},
{header: 'Col 9', width: 8, hidden: true},
];
ws.getCell('A2').value = 7;
ws.getCell('B2').value = 'Hello, World!';
ws.getCell('B2').font = fonts.comicSansUdB16;
ws.getCell('B2').border = borders.thin;
ws.getCell('C2').value = -5.55;
ws.getCell('C2').numFmt = '"£"#,##0.00;[Red]-"£"#,##0.00';
ws.getCell('C2').font = fonts.arialBlackUI14;
ws.getCell('D2').value = 3.14;
ws.getCell('D2').value = new Date();
ws.getCell('D2').numFmt = 'd-mmm-yyyy';
ws.getCell('D2').font = fonts.comicSansUdB16;
ws.getCell('D2').border = borders.doubleRed;
// eslint-disable-next-line prefer-template
ws.getCell('E2').value = ['Hello', 'World'].join(', ') + '!';
ws.getCell('F2').value = true;
ws.getCell('G2').value = {error: '#N/A'};
ws.getCell('H2').value = {error: '#VALUE!'};
ws.getCell('A3').value = {
text: 'www.google.com',
hyperlink: 'http://www.google.com',
tooltip: 'Google!',
};
ws.getCell('A4').value = 'Boo!';
ws.getCell('C4').value = 'Hoo!';
ws.mergeCells('A4', 'C4');
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('C6').border = borders.thickRainbow;
ws.getCell('A7').value = 1;
ws.getCell('B7').value = 2;
ws.getCell('C7').value = {formula: 'A7+B7'};
const now = new Date();
ws.getCell('A8').value = now;
ws.getCell('B8').value = 0;
ws.getCell('C8').value = {formula: 'A8+B8', result: now};
ws.getCell('A9').value = 1.6;
ws.getCell('A9').numFmt = '# ?/?';
ws.getCell('B9').value = 1.6;
ws.getCell('B9').numFmt = 'h:mm:ss';
ws.getCell('C9').value = 0.016;
ws.getCell('C9').numFmt = '0.00%';
ws.getCell('D9').value = 1.6;
ws.getCell('D9').numFmt = '[Green]#,##0 ;[Red](#,##0)';
ws.getCell('E9').value = 1.6;
ws.getCell('E9').numFmt = '#0.000';
ws.getCell('F9').value = 0.016;
ws.getCell('F9').numFmt = '# ?/?%';
ws.getCell('A10').value = '<';
ws.getCell('B10').value = '>';
ws.getCell('C10').value = '<a>';
ws.getCell('D10').value = '><';
ws.getRow(11).height = 40;
_.each(alignments, (alignment, index) => {
const rowNumber = 11;
const colNumber = index + 1;
const cell = ws.getCell(rowNumber, colNumber);
cell.value = alignment.text;
cell.alignment = alignment.alignment;
});
const row12 = ws.getRow(12);
row12.height = 40;
row12.getCell(1).value = 'Blue White Horizontal Gradient';
row12.getCell(1).fill = fills.blueWhiteHGrad;
row12.getCell(2).value = 'Red Dark Vertical';
row12.getCell(2).fill = fills.redDarkVertical;
row12.getCell(3).value = 'Red Green Dark Trellis';
row12.getCell(3).fill = fills.redGreenDarkTrellis;
row12.getCell(4).value = 'RGB Path Gradient';
row12.getCell(4).fill = fills.rgbPathGrad;
row12.getCell(5).value = 'Solid Green';
row12.getCell(5).fill = fills.solidGreen;
// testing background and color trickery
ws.getCell('F5').value = 'white';
ws.getCell('F5').fill = fills.solidGreen;
ws.getCell('F5').border = borders.thinWhite;
ws.getCell('F5').font = fonts.whiteText;
ws.getCell('E4').fill = fills.solidGreen;
ws.getCell('E5').fill = fills.solidGreen;
ws.getCell('E6').fill = fills.solidGreen;
ws.getCell('F4').fill = fills.solidGreen;
ws.getCell('F6').fill = fills.solidGreen;
ws.getCell('G4').fill = fills.solidGreen;
ws.getCell('G5').fill = fills.solidGreen;
ws.getCell('G6').fill = fills.solidGreen;
// row and column styles
ws.getRow(13).font = fonts.arialBlackUI14;
ws.getCell('H12').value = 'Foo';
ws.getCell('G13').value = 'Foo';
ws.getCell('H13').value = 'Bar';
ws.getCell('I13').value = 'Baz';
ws.getCell('H14').value = 'Baz';
// hidden stuff
ws.getRow(16).hidden = true;
ws.getCell('I15').value = 'You Can\'t See Me!';
ws.getCell('A16').value = 'You Can\'t See Me!';
const A18 = ws.getCell('A18');
A18.value = 'Wrap Text - Wrapping Wrapping Wrappity Wrap Wrap Wrap';
A18.alignment = {wrapText: true};
const A20 = ws.getCell('A20');
A20.value = 'Wrap Text - Wrapping Wrappity Wrap';
A20.alignment = {shrinkToFit: true};
ws.getCell('A2').name = 'Passe';
ws.getCell('B2').name = 'Passe';
ws.getCell('E2').name = 'Greet';
ws.getCell('A22').value = {formula: 'E2'};
ws.getCell('A24').value = 'Choose';
ws.getCell('D24').value = 'Hewie';
ws.getCell('D24').name = 'Nephews';
ws.getCell('E24').value = 'Dewie';
ws.getCell('E24').name = 'Nephews';
ws.getCell('F24').value = 'Louie';
ws.getCell('F24').name = 'Nephews';
ws.getCell('B24').dataValidation = {
type: 'list',
allowBlank: true,
formulae: ['Nephews'],
};
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);
});