@sswroom/sswr 1.6.13 → 1.6.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/spreadsheet.js ADDED
@@ -0,0 +1,2227 @@
1
+ import * as data from "./data.js";
2
+ import * as text from "./text.js";
3
+ import * as unit from "./unit.js";
4
+
5
+ export const FontFamily = {
6
+ NA: 0,
7
+ Roman: 1,
8
+ Swiss: 2,
9
+ Modern: 3,
10
+ Script: 4,
11
+ Decorative: 5
12
+ }
13
+
14
+ export const BorderType = {
15
+ None: 0,
16
+ Thin: 1,
17
+ Medium: 2,
18
+ Dashed: 3,
19
+ Dotted: 4,
20
+ Thick: 5,
21
+ DOUBLE: 6,
22
+ Hair: 7,
23
+ MediumDashed: 8,
24
+ DashDot: 9,
25
+ MediumDashDot: 10,
26
+ DashDotDot: 11,
27
+ MediumDashDotDot: 12,
28
+ SlantedDashDot: 13
29
+ }
30
+
31
+ export const FillPattern = {
32
+ NoFill: 0,
33
+ SolidForeground: 1,
34
+ FineDot: 2,
35
+ AltBars: 3,
36
+ SparseDots: 4,
37
+ ThickHorzBands: 5,
38
+ ThickVertBands: 6,
39
+ ThickBackwardDiag: 7,
40
+ ThickForwardDiag: 8,
41
+ BigSpots: 9,
42
+ Bricks: 10,
43
+ ThinHorzBands: 11,
44
+ ThinVertBands: 12,
45
+ ThinBackwardDiag: 13,
46
+ ThinForwardDiag: 14,
47
+ Squares: 15,
48
+ Diamonds: 16,
49
+ LessDots: 17,
50
+ LeastDots: 18
51
+ }
52
+
53
+ export const CellDataType = {
54
+ String: 0,
55
+ Number: 1,
56
+ DateTime: 2,
57
+ MergedLeft: 3,
58
+ MergedUp: 4
59
+ }
60
+
61
+ export const AnchorType = {
62
+ Absolute: 0,
63
+ OneCell: 1,
64
+ TwoCell: 2
65
+ }
66
+
67
+ export const LegendPos = {
68
+ Bottom: 0
69
+ }
70
+
71
+ export const BlankAs = {
72
+ Default: 0,
73
+ Gap: 1,
74
+ Zero: 2
75
+ }
76
+
77
+ export const ChartType = {
78
+ Unknown: 0,
79
+ LineChart: 1
80
+ }
81
+
82
+ export const AxisType = {
83
+ Date: 0,
84
+ Category: 1,
85
+ Numeric: 2,
86
+ Series: 3
87
+ }
88
+
89
+ export const AxisPosition = {
90
+ Left: 0,
91
+ Top: 1,
92
+ Right: 2,
93
+ Bottom: 3
94
+ }
95
+
96
+ export const TickLabelPosition = {
97
+ High: 0,
98
+ Low: 1,
99
+ NextTo: 2,
100
+ None: 3
101
+ }
102
+
103
+ export const AxisCrosses = {
104
+ AutoZero: 0,
105
+ Max: 1,
106
+ Min: 2
107
+ }
108
+
109
+ export const ColorType = {
110
+ Preset: 0,
111
+ Argb: 1
112
+ }
113
+
114
+ export const PresetColor = {
115
+ AliceBlue: 0,
116
+ AntiqueWhite: 1,
117
+ Aqua: 2,
118
+ Aquamarine: 3,
119
+ Azure: 4,
120
+ Beige: 5,
121
+ Bisque: 6,
122
+ Black: 7,
123
+ BlanchedAlmond: 8,
124
+ Blue: 9,
125
+ BlueViolet: 10,
126
+ Brown: 11,
127
+ BurlyWood: 12,
128
+ CadetBlue: 13,
129
+ Chartreuse: 14,
130
+ Chocolate: 15,
131
+ Coral: 16,
132
+ CornflowerBlue: 17,
133
+ Cornsilk: 18,
134
+ Crimson: 19,
135
+ Cyan: 20,
136
+ DeepPink: 21,
137
+ DeepSkyBlue: 22,
138
+ DimGray: 23,
139
+ DarkBlue: 24,
140
+ DarkCyan: 25,
141
+ DarkGoldenrod: 26,
142
+ DarkGray: 27,
143
+ DarkGreen: 28,
144
+ DarkKhaki: 29,
145
+ DarkMagenta: 30,
146
+ DarkOliveGreen: 31,
147
+ DarkOrange: 32,
148
+ DarkOrchid: 33,
149
+ DarkRed: 34,
150
+ DarkSalmon: 35,
151
+ DarkSeaGreen: 36,
152
+ DarkSlateBlue: 37,
153
+ DarkSlateGray: 38,
154
+ DarkTurquoise: 39,
155
+ DarkViolet: 40,
156
+ DodgerBlue: 41,
157
+ Firebrick: 42,
158
+ FloralWhite: 43,
159
+ ForestGreen: 44,
160
+ Fuchsia: 45,
161
+ Gainsboro: 46,
162
+ GhostWhite: 47,
163
+ Gold: 48,
164
+ Goldenrod: 49,
165
+ Gray: 50,
166
+ Green: 51,
167
+ GreenYellow: 52,
168
+ Honeydew: 53,
169
+ HotPink: 54,
170
+ IndianRed: 55,
171
+ Indigo: 56,
172
+ Ivory: 57,
173
+ Khaki: 58,
174
+ Lavender: 59,
175
+ LavenderBlush: 60,
176
+ LawnGreen: 61,
177
+ LemonChiffon: 62,
178
+ Lime: 63,
179
+ LimeGreen: 64,
180
+ Linen: 65,
181
+ LightBlue: 66,
182
+ LightCoral: 67,
183
+ LightCyan: 68,
184
+ LightGoldenrodYellow: 69,
185
+ LightGray: 70,
186
+ LightGreen: 71,
187
+ LightPink: 72,
188
+ LightSalmon: 73,
189
+ LightSeaGreen: 74,
190
+ LightSkyBlue: 75,
191
+ LightSlateGray: 76,
192
+ LightSteelBlue: 77,
193
+ LightYellow: 78,
194
+ Magenta: 79,
195
+ Maroon: 80,
196
+ MediumAquamarine: 81,
197
+ MediumBlue: 82,
198
+ MediumOrchid: 83,
199
+ MediumPurple: 84,
200
+ MediumSeaGreen: 85,
201
+ MediumSlateBlue: 86,
202
+ MediumSpringGreen: 87,
203
+ MediumTurquoise: 88,
204
+ MediumVioletRed: 89,
205
+ MidnightBlue: 90,
206
+ MintCream: 91,
207
+ MistyRose: 92,
208
+ Moccasin: 93,
209
+ NavajoWhite: 94,
210
+ Navy: 95,
211
+ OldLace: 96,
212
+ Olive: 97,
213
+ OliveDrab: 98,
214
+ Orange: 99,
215
+ OrangeRed: 100,
216
+ Orchid: 101,
217
+ PaleGoldenrod: 102,
218
+ PaleGreen: 103,
219
+ PaleTurquoise: 104,
220
+ PaleVioletRed: 105,
221
+ PapayaWhip: 106,
222
+ PeachPuff: 107,
223
+ Peru: 108,
224
+ Pink: 109,
225
+ Plum: 110,
226
+ PowderBlue: 111,
227
+ Purple: 112,
228
+ Red: 113,
229
+ RosyBrown: 114,
230
+ RoyalBlue: 115,
231
+ SaddleBrown: 116,
232
+ Salmon: 117,
233
+ SandyBrown: 118,
234
+ SeaGreen: 119,
235
+ SeaShell: 120,
236
+ Sienna: 121,
237
+ Silver: 122,
238
+ SkyBlue: 123,
239
+ SlateBlue: 124,
240
+ SlateGray: 125,
241
+ Snow: 126,
242
+ SpringGreen: 127,
243
+ SteelBlue: 128,
244
+ Tan: 129,
245
+ Teal: 130,
246
+ Thistle: 131,
247
+ Tomato: 132,
248
+ Turquoise: 133,
249
+ Violet: 134,
250
+ Wheat: 135,
251
+ White: 136,
252
+ WhiteSmoke: 137,
253
+ Yellow: 138,
254
+ YellowGreen: 139
255
+ }
256
+
257
+ export class WorkbookFont
258
+ {
259
+ constructor()
260
+ {
261
+ /** @type {string|null} */
262
+ this.name = null;
263
+ this.size = 0;
264
+ this.bold = false;
265
+ this.italic = false;
266
+ this.underline = false;
267
+ this.color = 0;
268
+ this.family = FontFamily.NA;
269
+ }
270
+
271
+ /**
272
+ * @param {string | null} name
273
+ */
274
+ setName(name)
275
+ {
276
+ this.name = name;
277
+ return this;
278
+ }
279
+
280
+ /**
281
+ * @param {number} size
282
+ */
283
+ setSize(size)
284
+ {
285
+ this.size = size;
286
+ return this;
287
+ }
288
+
289
+ /**
290
+ * @param {boolean} bold
291
+ */
292
+ setBold(bold)
293
+ {
294
+ this.bold = bold;
295
+ }
296
+
297
+ /**
298
+ * @param {boolean} italic
299
+ */
300
+ setItalic(italic)
301
+ {
302
+ this.italic = italic;
303
+ }
304
+
305
+ /**
306
+ * @param {boolean} underline
307
+ */
308
+ setUnderline(underline)
309
+ {
310
+ this.underline = underline;
311
+ }
312
+
313
+ /**
314
+ * @param {number} color
315
+ */
316
+ setColor(color)
317
+ {
318
+ this.color = color;
319
+ }
320
+
321
+ /**
322
+ * @param {number} family
323
+ */
324
+ setFamily(family)
325
+ {
326
+ this.family = family;
327
+ }
328
+
329
+ getName()
330
+ {
331
+ return this.name;
332
+ }
333
+
334
+ getSize()
335
+ {
336
+ return this.size;
337
+ }
338
+
339
+ isBold()
340
+ {
341
+ return this.bold;
342
+ }
343
+
344
+ isItalic()
345
+ {
346
+ return this.italic;
347
+ }
348
+
349
+ isUnderline()
350
+ {
351
+ return this.underline;
352
+ }
353
+
354
+ getColor()
355
+ {
356
+ return this.color;
357
+ }
358
+
359
+ getFamily()
360
+ {
361
+ return this.family;
362
+ }
363
+
364
+ clone()
365
+ {
366
+ let font = new WorkbookFont();
367
+ font.name = this.name;
368
+ font.size = this.size;
369
+ font.bold = this.bold;
370
+ font.italic = this.italic;
371
+ font.underline = this.underline;
372
+ font.color = this.color;
373
+ font.family = this.family;
374
+ return font;
375
+ }
376
+
377
+ /**
378
+ * @param {WorkbookFont} font
379
+ */
380
+ equals(font)
381
+ {
382
+ return this.name == font.name &&
383
+ this.size == font.size &&
384
+ this.bold == font.bold &&
385
+ this.italic == font.italic &&
386
+ this.underline == font.underline &&
387
+ this.color == font.color;
388
+ }
389
+ }
390
+
391
+ export class BorderStyle
392
+ {
393
+ /**
394
+ * @param {number} borderColor
395
+ * @param {number} borderType
396
+ */
397
+ constructor(borderColor, borderType)
398
+ {
399
+ this.borderColor = borderColor;
400
+ this.borderType = borderType;
401
+ }
402
+
403
+ /**
404
+ * @param {BorderStyle} style
405
+ */
406
+ set(style)
407
+ {
408
+ this.borderColor = style.borderColor;
409
+ this.borderType = style.borderType;
410
+ }
411
+
412
+ clone()
413
+ {
414
+ return new BorderStyle(this.borderColor, this.borderType);
415
+ }
416
+
417
+ /**
418
+ * @param {BorderStyle} style
419
+ */
420
+ equals(style)
421
+ {
422
+ if (style.borderType == BorderType.None && this.borderType == BorderType.None)
423
+ return true;
424
+ else if (style.borderType != this.borderType)
425
+ return false;
426
+ else if (style.borderColor != this.borderColor)
427
+ return false;
428
+ else
429
+ return true;
430
+ }
431
+ }
432
+
433
+ export class CellStyle
434
+ {
435
+ /**
436
+ * @param {number} index
437
+ */
438
+ constructor(index)
439
+ {
440
+ this.index = index;
441
+ /** @type {string|null} */
442
+ this.id = null;
443
+ this.halign = text.HAlignment.Unknown;
444
+ this.valign = text.VAlignment.Unknown;
445
+ this.wordWrap = false;
446
+ this.borderBottom = new BorderStyle(0, BorderType.None);
447
+ this.borderLeft = new BorderStyle(0, BorderType.None);
448
+ this.borderRight = new BorderStyle(0, BorderType.None);
449
+ this.borderTop = new BorderStyle(0, BorderType.None);
450
+ /** @type {WorkbookFont|null} */
451
+ this.font = null;
452
+ this.fillColor = 0xffffff;
453
+ this.fillPattern = FillPattern.NoFill;
454
+ /** @type {string|null} */
455
+ this.dataFormat = null;
456
+ this.protection = false;
457
+ };
458
+
459
+ clone()
460
+ {
461
+ let style = new CellStyle(this.index);
462
+ style.id = this.id;
463
+ style.halign = this.halign;
464
+ style.valign = this.valign;
465
+ style.wordWrap = this.wordWrap;
466
+ style.borderBottom = this.borderBottom.clone();
467
+ style.borderLeft = this.borderLeft.clone();
468
+ style.borderRight = this.borderRight.clone();
469
+ style.borderTop = this.borderTop.clone();
470
+ style.font = this.font;
471
+ style.fillColor = this.fillColor;
472
+ style.fillPattern = this.fillPattern;
473
+ style.dataFormat = this.dataFormat;
474
+ style.protection = this.protection;
475
+ return style;
476
+ }
477
+
478
+ /**
479
+ * @param {CellStyle} style
480
+ */
481
+ copyFrom(style)
482
+ {
483
+ this.index = style.index;
484
+ this.id = style.id;
485
+ this.halign = style.halign;
486
+ this.valign = style.valign;
487
+ this.wordWrap = style.wordWrap;
488
+ this.borderBottom = style.borderBottom.clone();
489
+ this.borderLeft = style.borderLeft.clone();
490
+ this.borderRight = style.borderRight.clone();
491
+ this.borderTop = style.borderTop.clone();
492
+ this.font = style.font;
493
+ this.fillColor = style.fillColor;
494
+ this.fillPattern = style.fillPattern;
495
+ this.dataFormat = style.dataFormat;
496
+ this.protection = style.protection;
497
+ }
498
+
499
+ /**
500
+ * @param {CellStyle} style
501
+ */
502
+ equals(style)
503
+ {
504
+ if (style.halign != this.halign)
505
+ return false;
506
+ if (style.valign != this.valign)
507
+ return false;
508
+ if (style.wordWrap != this.wordWrap)
509
+ return false;
510
+
511
+ if (style.borderBottom != this.borderBottom)
512
+ return false;
513
+ if (style.borderLeft != this.borderLeft)
514
+ return false;
515
+ if (style.borderRight != this.borderRight)
516
+ return false;
517
+ if (style.borderTop != this.borderTop)
518
+ return false;
519
+
520
+ if (this.font == null)
521
+ {
522
+ if (style.font != null)
523
+ return false;
524
+ }
525
+ else if (style.font == null)
526
+ {
527
+ return false;
528
+ }
529
+ else
530
+ {
531
+ if (style.font.equals(this.font))
532
+ return false;
533
+ }
534
+ if (style.fillColor != this.fillColor)
535
+ return false;
536
+ if (style.fillPattern != this.fillPattern)
537
+ return false;
538
+ if (this.dataFormat != style.dataFormat)
539
+ return false;
540
+ if (style.protection != this.protection)
541
+ return false;
542
+ return true;
543
+ }
544
+
545
+ /**
546
+ * @param {number} index
547
+ */
548
+ setIndex(index)
549
+ {
550
+ this.index = index;
551
+ }
552
+
553
+ /**
554
+ * @param {string | null} id
555
+ */
556
+ setID(id)
557
+ {
558
+ if (id == null)
559
+ return;
560
+ this.id = id;
561
+ }
562
+
563
+ /**
564
+ * @param {text.HAlignment} halign
565
+ */
566
+ setHAlign(halign)
567
+ {
568
+ this.halign = halign;
569
+ }
570
+
571
+ /**
572
+ * @param {text.VAlignment} valign
573
+ */
574
+ setVAlign(valign)
575
+ {
576
+ this.valign = valign;
577
+ }
578
+
579
+ /**
580
+ * @param {boolean} wordWrap
581
+ */
582
+ setWordWrap(wordWrap)
583
+ {
584
+ this.wordWrap = wordWrap;
585
+ }
586
+
587
+ /**
588
+ * @param {number} color
589
+ * @param {number} pattern
590
+ */
591
+ setFillColor(color, pattern)
592
+ {
593
+ this.fillColor = color;
594
+ this.fillPattern = pattern;
595
+ }
596
+
597
+ /**
598
+ * @param {WorkbookFont | null} font
599
+ */
600
+ setFont(font)
601
+ {
602
+ this.font = font;
603
+ }
604
+
605
+ /**
606
+ * @param {BorderStyle} border
607
+ */
608
+ setBorderLeft(border)
609
+ {
610
+ this.borderLeft.set(border);
611
+ }
612
+
613
+ /**
614
+ * @param {BorderStyle} border
615
+ */
616
+ setBorderRight(border)
617
+ {
618
+ this.borderRight.set(border);
619
+ }
620
+
621
+ /**
622
+ * @param {BorderStyle} border
623
+ */
624
+ setBorderTop(border)
625
+ {
626
+ this.borderTop = border;
627
+ }
628
+
629
+ /**
630
+ * @param {BorderStyle} border
631
+ */
632
+ setBorderBottom(border)
633
+ {
634
+ this.borderBottom.set(border);
635
+ }
636
+
637
+ /**
638
+ * @param {string | null} dataFormat
639
+ */
640
+ setDataFormat(dataFormat)
641
+ {
642
+ this.dataFormat = dataFormat;
643
+ }
644
+
645
+ getIndex()
646
+ {
647
+ return this.index;
648
+ }
649
+
650
+ getID()
651
+ {
652
+ return this.id;
653
+ }
654
+
655
+ getHAlign()
656
+ {
657
+ return this.halign;
658
+ }
659
+
660
+ getVAlign()
661
+ {
662
+ return this.valign;
663
+ }
664
+
665
+ getWordWrap()
666
+ {
667
+ return this.wordWrap;
668
+ }
669
+
670
+ getFillColor()
671
+ {
672
+ return this.fillColor;
673
+ }
674
+
675
+ getFillPattern()
676
+ {
677
+ return this.fillPattern;
678
+ }
679
+
680
+ getFont()
681
+ {
682
+ return this.font;
683
+ }
684
+
685
+ getBorderLeft()
686
+ {
687
+ return this.borderLeft;
688
+ }
689
+
690
+ getBorderRight()
691
+ {
692
+ return this.borderRight;
693
+ }
694
+
695
+ getBorderTop()
696
+ {
697
+ return this.borderTop;
698
+ }
699
+
700
+ getBorderBottom()
701
+ {
702
+ return this.borderBottom;
703
+ }
704
+
705
+ getDataFormat()
706
+ {
707
+ return this.dataFormat;
708
+ }
709
+ }
710
+
711
+ export class Worksheet
712
+ {
713
+ /**
714
+ * @param {number} row
715
+ */
716
+ createRow(row)
717
+ {
718
+ if (row >= 1048576)
719
+ return null;
720
+ while (row >= this.rows.length)
721
+ {
722
+ this.rows.push(null);
723
+ }
724
+ let rowData = this.rows[row];
725
+ if (rowData == null)
726
+ {
727
+ rowData = {style: null, height: -1, cells: []};
728
+ this.rows[row] = rowData;
729
+ }
730
+ return rowData;
731
+ }
732
+
733
+ /**
734
+ * @param {number} row
735
+ * @param {number} col
736
+ * @param {boolean} keepMerge
737
+ */
738
+ getCellData(row, col, keepMerge)
739
+ {
740
+ let rowData;
741
+ let cell;
742
+ if (row >= this.rows.length + 65536)
743
+ return null;
744
+ if (col >= 65536)
745
+ return null;
746
+ if (col > this.maxCol)
747
+ {
748
+ this.maxCol = col;
749
+ }
750
+ while (true)
751
+ {
752
+ if ((rowData = this.createRow(row)) == null)
753
+ return null;
754
+ while (col >= rowData.cells.length)
755
+ {
756
+ rowData.cells.push(null);
757
+ }
758
+ if ((cell = rowData.cells[col]) == null)
759
+ {
760
+ cell = {cdt: CellDataType.String, cellValue: null, style: null, mergeHori: 0, mergeVert: 0, hidden: false, cellURL: null};
761
+ rowData.cells[col] = cell;
762
+ }
763
+
764
+ if (keepMerge)
765
+ break;
766
+ if (cell.cdt == CellDataType.MergedLeft)
767
+ {
768
+ col--;
769
+ }
770
+ else if (cell.cdt == CellDataType.MergedUp)
771
+ {
772
+ row--;
773
+ }
774
+ else
775
+ {
776
+ break;
777
+ }
778
+ }
779
+ return cell;
780
+ }
781
+
782
+ /**
783
+ * @param {{style: CellStyle|null,cells: ({cdt: number,cellValue: string|null,style: CellStyle|null,mergeHori: number,mergeVert: number,hidden: boolean,cellURL: string|null}|null)[],height: number}} row
784
+ * @param {Workbook} srcCtrl
785
+ * @param {Workbook} newCtrl
786
+ */
787
+ cloneRow(row, srcCtrl, newCtrl)
788
+ {
789
+ let newRow;
790
+ let cell;
791
+ let i;
792
+ let j;
793
+ let style;
794
+ if (row.style)
795
+ style = newCtrl.getStyle(srcCtrl.getStyleIndex(row.style));
796
+ else
797
+ style = null;
798
+ newRow = {style: style, cells: new Array(), height: -1};
799
+ newRow.height = row.height;
800
+ i = 0;
801
+ j = row.cells.length;
802
+ while (i < j)
803
+ {
804
+ if ((cell = row.cells[i]) == null)
805
+ {
806
+ newRow.cells.push(null);
807
+ }
808
+ else
809
+ {
810
+ newRow.cells.push(this.cloneCell(cell, srcCtrl, newCtrl));
811
+ }
812
+ i++;
813
+ }
814
+ return newRow;
815
+ }
816
+
817
+ /**
818
+ * @param {{cdt: number,cellValue: string|null,style: CellStyle|null,mergeHori: number,mergeVert: number,hidden: boolean,cellURL: string|null}} cell
819
+ * @param {Workbook} srcCtrl
820
+ * @param {Workbook} newCtrl
821
+ */
822
+ cloneCell(cell, srcCtrl, newCtrl)
823
+ {
824
+ let newCell = {};
825
+ newCell.cdt = cell.cdt;
826
+ newCell.cellValue = cell.cellValue;
827
+ if (cell.style)
828
+ newCell.style = newCtrl.getStyle(srcCtrl.getStyleIndex(cell.style));
829
+ else
830
+ newCell.style = null;
831
+ newCell.mergeHori = cell.mergeHori;
832
+ newCell.mergeVert = cell.mergeVert;
833
+ newCell.hidden = cell.hidden;
834
+ newCell.cellURL = cell.cellURL;
835
+ return newCell;
836
+ }
837
+
838
+ /**
839
+ * @param {string} name
840
+ */
841
+ constructor(name)
842
+ {
843
+ this.name = name;
844
+ /** @type {({style: CellStyle|null,cells: ({cdt: number,cellValue: string|null,style: CellStyle|null,mergeHori: number,mergeVert: number,hidden: boolean,cellURL: string|null}|null)[],height: number}|null)[]} */
845
+ this.rows = [];
846
+ /** @type {number[]} */
847
+ this.colWidthsPt = [];
848
+ // @type {WorksheetDrawing[]}
849
+ this.drawings = [];
850
+ this.freezeHori = 0;
851
+ this.freezeVert = 0;
852
+ this.marginLeft = 2.0;
853
+ this.marginRight = 2.0;
854
+ this.marginTop = 2.5;
855
+ this.marginBottom = 2.5;
856
+ this.marginHeader = 1.3;
857
+ this.marginFooter = 1.3;
858
+ this.zoom = 100;
859
+ this.options = 0x4b6;
860
+ this.maxCol = 0;
861
+ this.defColWidthPt = 48.0;
862
+ this.defRowHeightPt = 13.5;
863
+ }
864
+
865
+ /**
866
+ * @param {Workbook} srcCtrl
867
+ * @param {Workbook} newCtrl
868
+ */
869
+ clone(srcCtrl, newCtrl)
870
+ {
871
+ let i;
872
+ let j;
873
+ let row;
874
+ let newWS = new Worksheet(this.name);
875
+ newWS.freezeHori = this.freezeHori;
876
+ newWS.freezeVert = this.freezeVert;
877
+ newWS.marginLeft = this.marginLeft;
878
+ newWS.marginRight = this.marginRight;
879
+ newWS.marginTop = this.marginTop;
880
+ newWS.marginBottom = this.marginBottom;
881
+ newWS.marginHeader = this.marginHeader;
882
+ newWS.marginFooter = this.marginFooter;
883
+ newWS.options = this.options;
884
+ newWS.zoom = this.zoom;
885
+ i = 0;
886
+ j = this.colWidthsPt.length;
887
+ while (i < j)
888
+ {
889
+ newWS.colWidthsPt.push(this.colWidthsPt[i]);
890
+ i++;
891
+ }
892
+ i = 0;
893
+ j = this.rows.length;
894
+ while (i < j)
895
+ {
896
+ if ((row = this.rows[i]) == null)
897
+ {
898
+ newWS.rows.push(null);
899
+ }
900
+ else
901
+ {
902
+ newWS.rows.push(this.cloneRow(row, srcCtrl, newCtrl));
903
+ }
904
+ i++;
905
+ }
906
+ return newWS;
907
+ }
908
+
909
+ /**
910
+ * @param {number} options
911
+ */
912
+ setOptions(options)
913
+ {
914
+ this.options = options;
915
+ }
916
+
917
+ getOptions()
918
+ {
919
+ return this.options;
920
+ }
921
+
922
+ /**
923
+ * @param {number} freezeHori
924
+ */
925
+ setFreezeHori(freezeHori)
926
+ {
927
+ this.freezeHori = freezeHori;
928
+ this.options |= 0x108;
929
+ }
930
+
931
+ getFreezeHori()
932
+ {
933
+ return this.freezeHori;
934
+ }
935
+
936
+ /**
937
+ * @param {number} freezeVert
938
+ */
939
+ setFreezeVert(freezeVert)
940
+ {
941
+ this.freezeVert = freezeVert;
942
+ this.options |= 0x108;
943
+ }
944
+
945
+ getFreezeVert()
946
+ {
947
+ return this.freezeVert;
948
+ }
949
+
950
+ /**
951
+ * @param {number} marginLeft
952
+ */
953
+ setMarginLeft(marginLeft)
954
+ {
955
+ this.marginLeft = marginLeft;
956
+ }
957
+
958
+ getMarginLeft()
959
+ {
960
+ return this.marginLeft;
961
+ }
962
+
963
+ /**
964
+ * @param {number} marginRight
965
+ */
966
+ setMarginRight(marginRight)
967
+ {
968
+ this.marginRight = marginRight;
969
+ }
970
+
971
+ getMarginRight()
972
+ {
973
+ return this.marginRight;
974
+ }
975
+
976
+ /**
977
+ * @param {number} marginTop
978
+ */
979
+ setMarginTop(marginTop)
980
+ {
981
+ this.marginTop = marginTop;
982
+ }
983
+
984
+ getMarginTop()
985
+ {
986
+ return this.marginTop;
987
+ }
988
+
989
+ /**
990
+ * @param {number} marginBottom
991
+ */
992
+ setMarginBottom(marginBottom)
993
+ {
994
+ this.marginBottom = marginBottom;
995
+ }
996
+
997
+ getMarginBottom()
998
+ {
999
+ return this.marginBottom;
1000
+ }
1001
+
1002
+ /**
1003
+ * @param {number} marginHeader
1004
+ */
1005
+ setMarginHeader(marginHeader)
1006
+ {
1007
+ this.marginHeader = marginHeader;
1008
+ }
1009
+
1010
+ getMarginHeader()
1011
+ {
1012
+ return this.marginHeader;
1013
+ }
1014
+
1015
+ /**
1016
+ * @param {number} marginFooter
1017
+ */
1018
+ setMarginFooter(marginFooter)
1019
+ {
1020
+ this.marginFooter = marginFooter;
1021
+ }
1022
+
1023
+ getMarginFooter()
1024
+ {
1025
+ return this.marginFooter;
1026
+ }
1027
+
1028
+ /**
1029
+ * @param {number} zoom
1030
+ */
1031
+ setZoom(zoom)
1032
+ {
1033
+ this.zoom = zoom;
1034
+ }
1035
+
1036
+ getZoom()
1037
+ {
1038
+ return this.zoom;
1039
+ }
1040
+
1041
+ isDefaultPageSetup()
1042
+ {
1043
+ return this.marginHeader == 1.3 && this.marginFooter == 1.3 && this.marginLeft == 2.0 && this.marginRight == 2.0 && this.marginTop == 2.5 && this.marginBottom == 2.5;
1044
+ }
1045
+
1046
+ /**
1047
+ * @param {number} defColWidthPt
1048
+ */
1049
+ setDefColWidthPt(defColWidthPt)
1050
+ {
1051
+ this.defColWidthPt = defColWidthPt;
1052
+ }
1053
+
1054
+ getDefColWidthPt()
1055
+ {
1056
+ return this.defColWidthPt;
1057
+ }
1058
+
1059
+ /**
1060
+ * @param {number} defRowHeightPt
1061
+ */
1062
+ setDefRowHeightPt(defRowHeightPt)
1063
+ {
1064
+ this.defRowHeightPt = defRowHeightPt;
1065
+ }
1066
+
1067
+ getDefRowHeightPt()
1068
+ {
1069
+ return this.defRowHeightPt;
1070
+ }
1071
+
1072
+ getName()
1073
+ {
1074
+ return this.name;
1075
+ }
1076
+
1077
+ /**
1078
+ * @param {number} row
1079
+ * @param {number} col
1080
+ * @param {CellStyle|null} style
1081
+ */
1082
+ setCellStyle(row, col, style)
1083
+ {
1084
+ let cell;
1085
+ if ((cell = this.getCellData(row, col, false)) == null)
1086
+ return false;
1087
+ cell.style = style;
1088
+ return true;
1089
+ }
1090
+
1091
+ /**
1092
+ * @param {number} row
1093
+ * @param {number} col
1094
+ * @param {Workbook} wb
1095
+ * @param {text.HAlignment} hAlign
1096
+ */
1097
+ setCellStyleHAlign(row, col, wb, hAlign)
1098
+ {
1099
+ let cell;
1100
+ if ((cell = this.getCellData(row, col, false)) == null)
1101
+ return false;
1102
+ let tmpStyle;
1103
+ if (cell.style == null)
1104
+ {
1105
+ if (hAlign == text.HAlignment.Unknown)
1106
+ return true;
1107
+ tmpStyle = new CellStyle(0);
1108
+ tmpStyle.setHAlign(hAlign);
1109
+ cell.style = wb.findOrCreateStyle(tmpStyle);
1110
+ }
1111
+ else
1112
+ {
1113
+ if (cell.style.getHAlign() == hAlign)
1114
+ return true;
1115
+ tmpStyle = cell.style.clone();
1116
+ tmpStyle.setHAlign(hAlign);
1117
+ cell.style = wb.findOrCreateStyle(tmpStyle);
1118
+ }
1119
+ return true;
1120
+ }
1121
+
1122
+ /**
1123
+ * @param {number} row
1124
+ * @param {number} col
1125
+ * @param {Workbook} wb
1126
+ * @param {number} color
1127
+ * @param {number} borderType
1128
+ */
1129
+ setCellStyleBorderBottom(row, col, wb, color, borderType)
1130
+ {
1131
+ let cell;
1132
+ if ((cell = this.getCellData(row, col, true)) == null)
1133
+ return false;
1134
+ let tmpStyle;
1135
+ if (cell.style == null)
1136
+ {
1137
+ if (borderType == BorderType.None)
1138
+ return true;
1139
+ tmpStyle = new CellStyle(0);
1140
+ tmpStyle.setBorderBottom(new BorderStyle(color, borderType));
1141
+ cell.style = wb.findOrCreateStyle(tmpStyle);
1142
+ }
1143
+ else
1144
+ {
1145
+
1146
+ if (cell.style.getBorderBottom().equals(new BorderStyle(color, borderType)))
1147
+ return true;
1148
+ tmpStyle = cell.style.clone();
1149
+ tmpStyle.setBorderBottom(new BorderStyle(color, borderType));
1150
+ cell.style = wb.findOrCreateStyle(tmpStyle);
1151
+ }
1152
+ return true;
1153
+ }
1154
+
1155
+ /**
1156
+ * @param {number} row
1157
+ * @param {number} col
1158
+ * @param {string | null} url
1159
+ */
1160
+ setCellURL(row, col, url)
1161
+ {
1162
+ let cell;
1163
+ if ((cell = this.getCellData(row, col, false)) == null)
1164
+ return false;
1165
+ cell.cellURL = url;
1166
+ return true;
1167
+ }
1168
+
1169
+ /**
1170
+ * @param {number} row
1171
+ * @param {number} col
1172
+ * @param {string | null} val
1173
+ * @param {CellStyle | null} style
1174
+ */
1175
+ setCellString(row, col, val, style)
1176
+ {
1177
+ let cell;
1178
+ if ((cell = this.getCellData(row, col, false)) == null)
1179
+ return false;
1180
+ cell.cdt = CellDataType.String;
1181
+ cell.cellValue = val;
1182
+ if (style) cell.style = style;
1183
+ return true;
1184
+ }
1185
+
1186
+ /**
1187
+ * @param {number} row
1188
+ * @param {number} col
1189
+ * @param {data.Timestamp} val
1190
+ * @param {CellStyle | null} style
1191
+ */
1192
+ setCellTS(row, col, val, style)
1193
+ {
1194
+ let cell;
1195
+ if ((cell = this.getCellData(row, col, false)) == null)
1196
+ return false;
1197
+ cell.cdt = CellDataType.DateTime;
1198
+ cell.cellValue = val.toString("yyyy-MM-ddTHH:mm:ss.fffffffff");
1199
+ if (style) cell.style = style;
1200
+ return true;
1201
+ }
1202
+
1203
+ /**
1204
+ * @param {number} row
1205
+ * @param {number} col
1206
+ * @param {number} val
1207
+ * @param {CellStyle | null} style
1208
+ */
1209
+ setCellDouble(row, col, val, style)
1210
+ {
1211
+ let cell;
1212
+ if ((cell = this.getCellData(row, col, false)) == null)
1213
+ return false;
1214
+ cell.cdt = CellDataType.Number;
1215
+ cell.cellValue = ""+val;
1216
+ if (style) cell.style = style;
1217
+ return true;
1218
+ }
1219
+
1220
+ /**
1221
+ * @param {number} row
1222
+ * @param {number} col
1223
+ * @param {number} val
1224
+ * @param {CellStyle | null} style
1225
+ */
1226
+ setCellInt32(row, col, val, style)
1227
+ {
1228
+ let cell;
1229
+ if ((cell = this.getCellData(row, col, false)) == null)
1230
+ return false;
1231
+ cell.cdt = CellDataType.Number;
1232
+ cell.cellValue = ""+val;
1233
+ if (style) cell.style = style;
1234
+ return true;
1235
+ }
1236
+
1237
+ /**
1238
+ * @param {number} row
1239
+ * @param {number} col
1240
+ * @param {number} val
1241
+ * @param {CellStyle | null} style
1242
+ */
1243
+ setCellInt64(row, col, val, style)
1244
+ {
1245
+ let cell;
1246
+ if ((cell = this.getCellData(row, col, false)) == null)
1247
+ return false;
1248
+ cell.cdt = CellDataType.Number;
1249
+ cell.cellValue = ""+val;
1250
+ if (style) cell.style = style;
1251
+ return true;
1252
+ }
1253
+
1254
+ /**
1255
+ * @param {number} row
1256
+ * @param {number} col
1257
+ * @param {CellStyle | null} style
1258
+ */
1259
+ setCellEmpty(row, col, style)
1260
+ {
1261
+ let cell;
1262
+ if ((cell = this.getCellData(row, col, false)) == null)
1263
+ return false;
1264
+ cell.cdt = CellDataType.Number;
1265
+ cell.cellValue = null;
1266
+ if (style) cell.style = style;
1267
+ return true;
1268
+ }
1269
+
1270
+ /**
1271
+ * @param {number} row
1272
+ * @param {number} col
1273
+ * @param {number} height
1274
+ * @param {number} width
1275
+ */
1276
+ mergeCells(row, col, height, width)
1277
+ {
1278
+ if (width == 0)
1279
+ return false;
1280
+ if (height == 0)
1281
+ return false;
1282
+ if (width == 0 && height == 0)
1283
+ return false;
1284
+
1285
+ let cell;
1286
+ let i;
1287
+ let j;
1288
+ i = 0;
1289
+ while (i < height)
1290
+ {
1291
+ j = 0;
1292
+ while (j < width)
1293
+ {
1294
+ if ((cell = this.getCellData(row + i, col + j, true)) != null && (cell.cdt == CellDataType.MergedLeft || cell.cdt == CellDataType.MergedUp))
1295
+ return false;
1296
+ j++;
1297
+ }
1298
+ i++;
1299
+ }
1300
+
1301
+ i = 0;
1302
+ while (i < height)
1303
+ {
1304
+ j = 0;
1305
+ while (j < width)
1306
+ {
1307
+ if ((cell = this.getCellData(row + i, col + j, true)) != null)
1308
+ {
1309
+ if (i == 0)
1310
+ {
1311
+ if (j == 0)
1312
+ {
1313
+ cell.mergeHori = width;
1314
+ cell.mergeVert = height;
1315
+ }
1316
+ else
1317
+ {
1318
+ cell.cdt = CellDataType.MergedLeft;
1319
+ }
1320
+ }
1321
+ else
1322
+ {
1323
+ cell.cdt = CellDataType.MergedUp;
1324
+ }
1325
+ }
1326
+ j++;
1327
+ }
1328
+ i++;
1329
+ }
1330
+ return true;
1331
+ }
1332
+
1333
+ /**
1334
+ * @param {number} row
1335
+ * @param {number} col
1336
+ */
1337
+ setCellMergeLeft(row, col)
1338
+ {
1339
+ if (col == 0)
1340
+ return false;
1341
+
1342
+ let cell;
1343
+ let width = 1;
1344
+ let height = 1;
1345
+ if ((cell = this.getCellData(row, col, true)) != null)
1346
+ cell.cdt = CellDataType.MergedLeft;
1347
+ col--;
1348
+ width++;
1349
+ while (true)
1350
+ {
1351
+ if ((cell = this.getCellData(row, col, true)) == null)
1352
+ {
1353
+ return false;
1354
+ }
1355
+ else if (cell.cdt == CellDataType.MergedUp)
1356
+ {
1357
+ row--;
1358
+ height++;
1359
+ }
1360
+ else if (cell.cdt == CellDataType.MergedLeft)
1361
+ {
1362
+ col--;
1363
+ width++;
1364
+ }
1365
+ else
1366
+ {
1367
+ if (cell.mergeHori < width)
1368
+ {
1369
+ cell.mergeHori = width;
1370
+ }
1371
+ if (cell.mergeVert < height)
1372
+ {
1373
+ cell.mergeVert = height;
1374
+ }
1375
+ break;
1376
+ }
1377
+ }
1378
+ return true;
1379
+ }
1380
+
1381
+ /**
1382
+ * @param {number} row
1383
+ * @param {number} col
1384
+ */
1385
+ setCellMergeUp(row, col)
1386
+ {
1387
+ if (row == 0)
1388
+ return false;
1389
+
1390
+ let cell;
1391
+ let width = 1;
1392
+ let height = 1;
1393
+ if ((cell = this.getCellData(row, col, true)) != null)
1394
+ cell.cdt = CellDataType.MergedUp;
1395
+ row--;
1396
+ height++;
1397
+ while (true)
1398
+ {
1399
+ if ((cell = this.getCellData(row, col, true)) == null)
1400
+ {
1401
+ return false;
1402
+ }
1403
+ else if (cell.cdt == CellDataType.MergedUp)
1404
+ {
1405
+ row--;
1406
+ height++;
1407
+ }
1408
+ else if (cell.cdt == CellDataType.MergedLeft)
1409
+ {
1410
+ col--;
1411
+ width++;
1412
+ }
1413
+ else
1414
+ {
1415
+ if (cell.mergeHori < width)
1416
+ {
1417
+ cell.mergeHori = width;
1418
+ }
1419
+ if (cell.mergeVert < height)
1420
+ {
1421
+ cell.mergeVert = height;
1422
+ }
1423
+ break;
1424
+ }
1425
+ }
1426
+ return true;
1427
+ }
1428
+
1429
+ /**
1430
+ * @param {number} row
1431
+ * @param {boolean} hidden
1432
+ */
1433
+ setRowHidden(row, hidden)
1434
+ {
1435
+ let cell;
1436
+ if (row >= 65536 || (cell = this.getCellData(row, 0, true)) == null)
1437
+ return false;
1438
+ cell.hidden = hidden;
1439
+ return true;
1440
+ }
1441
+
1442
+ /**
1443
+ * @param {number} row
1444
+ * @param {number} height
1445
+ */
1446
+ setRowHeight(row, height)
1447
+ {
1448
+ let rowData;
1449
+ if ((rowData = this.createRow(row)) != null)
1450
+ {
1451
+ rowData.height = height;
1452
+ return true;
1453
+ }
1454
+ else
1455
+ {
1456
+ return false;
1457
+ }
1458
+ }
1459
+
1460
+ getCount()
1461
+ {
1462
+ return this.rows.length;
1463
+ }
1464
+
1465
+ /**
1466
+ * @param {number} row
1467
+ */
1468
+ getItem(row)
1469
+ {
1470
+ return this.rows[row];
1471
+ }
1472
+
1473
+ /**
1474
+ * @param {number} col
1475
+ */
1476
+ removeCol(col)
1477
+ {
1478
+ let i;
1479
+ let row;
1480
+
1481
+ this.colWidthsPt.splice(col, 1);
1482
+ i = this.rows.length;
1483
+ while (i-- > 0)
1484
+ {
1485
+ if ((row = this.rows[i]) != null)
1486
+ {
1487
+ row.cells.splice(col, 1);
1488
+ }
1489
+ }
1490
+ }
1491
+
1492
+ /**
1493
+ * @param {number} col
1494
+ */
1495
+ insertCol(col)
1496
+ {
1497
+ let i;
1498
+ let row;
1499
+
1500
+ if (this.colWidthsPt.length > col)
1501
+ {
1502
+ this.colWidthsPt.splice(col, 0, 0);
1503
+ }
1504
+ i = this.rows.length;
1505
+ while (i-- > 0)
1506
+ {
1507
+ if ((row = this.rows[i]) != null)
1508
+ {
1509
+ if (row.cells.length > col)
1510
+ {
1511
+ row.cells.splice(col, 0, null);
1512
+ }
1513
+ }
1514
+ }
1515
+ }
1516
+
1517
+ getMaxCol()
1518
+ {
1519
+ this.maxCol;
1520
+ }
1521
+
1522
+ /**
1523
+ * @param {number} col
1524
+ * @param {number} width
1525
+ * @param {unit.Distance.Unit} du
1526
+ */
1527
+ setColWidth(col, width, du)
1528
+ {
1529
+ while (col >= this.colWidthsPt.length)
1530
+ {
1531
+ this.colWidthsPt.push(-1);
1532
+ }
1533
+ if (du == unit.Distance.Unit.POINT)
1534
+ {
1535
+ this.colWidthsPt[col] = width;
1536
+ }
1537
+ else
1538
+ {
1539
+ this.colWidthsPt[col] = unit.Distance.convert(du, unit.Distance.Unit.POINT, width);
1540
+ }
1541
+ }
1542
+
1543
+ getColWidthCount()
1544
+ {
1545
+ return this.colWidthsPt.length;
1546
+ }
1547
+
1548
+ /**
1549
+ * @param {number} col
1550
+ */
1551
+ getColWidthPt(col)
1552
+ {
1553
+ if (col >= this.colWidthsPt.length)
1554
+ return -1;
1555
+ return this.colWidthsPt[col];
1556
+ }
1557
+
1558
+ /**
1559
+ * @param {number} col
1560
+ * @param {unit.Distance.Unit} du
1561
+ */
1562
+ getColWidth(col, du)
1563
+ {
1564
+ if (col >= this.colWidthsPt.length)
1565
+ return -1;
1566
+ if (du == unit.Distance.Unit.POINT)
1567
+ return this.colWidthsPt[col];
1568
+ return unit.Distance.convert(unit.Distance.Unit.POINT, du, this.colWidthsPt[col]);
1569
+ }
1570
+
1571
+ /**
1572
+ * @param {number} row
1573
+ * @param {number} col
1574
+ */
1575
+ getCellDataRead(row, col)
1576
+ {
1577
+ let rowData;
1578
+ let cell;
1579
+ if (row >= this.rows.length + 65536)
1580
+ return null;
1581
+ if (col >= 65536)
1582
+ return null;
1583
+ if (col > this.maxCol)
1584
+ {
1585
+ return null;
1586
+ }
1587
+ while (true)
1588
+ {
1589
+ if ((rowData = this.rows[row]) == null)
1590
+ return null;
1591
+ if ((cell = rowData.cells[col]) == null)
1592
+ {
1593
+ return null;
1594
+ }
1595
+ if (cell.cdt == CellDataType.MergedLeft)
1596
+ {
1597
+ col--;
1598
+ }
1599
+ else if (cell.cdt == CellDataType.MergedUp)
1600
+ {
1601
+ row--;
1602
+ }
1603
+ else
1604
+ {
1605
+ break;
1606
+ }
1607
+ }
1608
+ return cell;
1609
+ }
1610
+
1611
+ /**
1612
+ * @param {{cdt: number,cellValue: string|null,style: CellStyle|null,mergeHori: number,mergeVert: number,hidden: boolean,cellURL: string|null} | null} cell
1613
+ */
1614
+ getCellString(cell)
1615
+ {
1616
+ let cellValue;
1617
+ if (cell == null || (cellValue = cell.cellValue) == null)
1618
+ {
1619
+ return false;
1620
+ }
1621
+ if (cell.cdt == CellDataType.Number)
1622
+ {
1623
+ let v = Number(cellValue);
1624
+ let iv;
1625
+ if (Number.isNaN(v))
1626
+ {
1627
+ return cellValue;
1628
+ }
1629
+ else
1630
+ {
1631
+ return ""+v;
1632
+ /* if (iv == v)
1633
+ {
1634
+ sb.AppendI32(iv);
1635
+ }
1636
+ else
1637
+ {
1638
+ sb.AppendDouble(v);
1639
+ }*/
1640
+ /* Text::String *fmt;
1641
+ if (cell.style && (fmt = cell.style.GetDataFormat()) != 0)
1642
+ {
1643
+ printf("Style: %s\r\n", fmt.v);
1644
+ }
1645
+ else
1646
+ {
1647
+ printf("Style: null\r\n");
1648
+ }*/
1649
+ }
1650
+ }
1651
+ else
1652
+ {
1653
+ return cellValue;
1654
+ }
1655
+ }
1656
+
1657
+ getDrawingCount()
1658
+ {
1659
+ return this.drawings.length;
1660
+ }
1661
+ // getDrawing(index: number): WorksheetDrawing|null;
1662
+ // getDrawingNoCheck(index: number): WorksheetDrawing;
1663
+ // createDrawing(du: unit.Distance.Unit, x: number, y: number, w: number, h: number): WorksheetDrawing;
1664
+ // createChart(du: unit.Distance.Unit, x: number, y: number, w: number, h: number, title: string|null): OfficeChart;
1665
+ }
1666
+
1667
+
1668
+ export class Workbook extends data.ParsedObject
1669
+ {
1670
+ static defPalette = [
1671
+ 0xff000000, 0xffffffff, 0xffff0000, 0xff00ff00, 0xff0000ff, 0xffffff00, 0xffff00ff, 0xff00ffff,
1672
+ 0xff800000, 0xff008000, 0xff000080, 0xff808000, 0xff800080, 0xff008080, 0xffc0c0c0, 0xff808080,
1673
+ 0xff9999ff, 0xff993366, 0xffffffcc, 0xffccffff, 0xff660066, 0xffff8080, 0xff0066cc, 0xffccccff,
1674
+ 0xff000080, 0xffff00ff, 0xffffff00, 0xff00ffff, 0xff800080, 0xff800000, 0xff008080, 0xff0000ff,
1675
+ 0xff00ccff, 0xffccffff, 0xffccffcc, 0xffffff99, 0xff99ccff, 0xffff99cc, 0xffcc99ff, 0xffffcc99,
1676
+ 0xff3366ff, 0xff33cccc, 0xff99cc00, 0xffffcc00, 0xffff9900, 0xffff6600, 0xff666699, 0xff969696,
1677
+ 0xff003366, 0xff339966, 0xff003300, 0xff333300, 0xff993300, 0xff993366, 0xff333399, 0xff333333
1678
+ ];
1679
+
1680
+ constructor()
1681
+ {
1682
+ super("Untitled", "Workbook");
1683
+ /**
1684
+ * @type {string|null}
1685
+ */
1686
+ this.author = null;
1687
+ /**
1688
+ * @type {string|null}
1689
+ */
1690
+ this.lastAuthor = null;
1691
+ /**
1692
+ * @type {string|null}
1693
+ */
1694
+ this.company = null;
1695
+ /**
1696
+ * @type {data.Timestamp|null}
1697
+ */
1698
+ this.createTime = null;
1699
+ /**
1700
+ * @type {data.Timestamp|null}
1701
+ */
1702
+ this.modifyTime = null;
1703
+ this.version = 0;
1704
+ this.windowTopX = 0;
1705
+ this.windowTopY = 0;
1706
+ this.windowWidth = 0;
1707
+ this.windowHeight = 0;
1708
+ this.activeSheet = 0;
1709
+ /** @type {number[]} */
1710
+ this.palette = new Array(56);
1711
+ /** @type {Worksheet[]} */
1712
+ this.sheets = [];
1713
+ /** @type {CellStyle[]} */
1714
+ this.styles = [];
1715
+ /** @type {WorkbookFont[]} */
1716
+ this.fonts = [];
1717
+
1718
+ let i;
1719
+ for (i in Workbook.defPalette)
1720
+ {
1721
+ this.palette[i] = Workbook.defPalette[i];
1722
+ }
1723
+
1724
+ this.newCellStyle(null, text.HAlignment.Unknown, text.VAlignment.Bottom, "general");
1725
+ this.newFont("Arial", 10.0, false).setFamily(FontFamily.Swiss);
1726
+ this.newFont("Arial", 10.0, false);
1727
+ this.newFont("Arial", 10.0, false);
1728
+ this.newFont("Arial", 10.0, false);
1729
+
1730
+ }
1731
+
1732
+ clone()
1733
+ {
1734
+ let i;
1735
+ let j;
1736
+ let newWB = new Workbook();
1737
+ newWB.author = this.author;
1738
+ newWB.lastAuthor = this.lastAuthor;
1739
+ newWB.company = this.company;
1740
+ newWB.createTime = this.createTime;
1741
+ newWB.modifyTime = this.modifyTime;
1742
+ newWB.version = this.version;
1743
+ newWB.windowTopX = this.windowTopX;
1744
+ newWB.windowTopY = this.windowTopY;
1745
+ newWB.windowWidth = this.windowWidth;
1746
+ newWB.windowHeight = this.windowHeight;
1747
+ newWB.activeSheet = this.activeSheet;
1748
+ for (i in this.palette)
1749
+ {
1750
+ newWB.palette[i] = this.palette[i];
1751
+ }
1752
+
1753
+ for (i in this.styles)
1754
+ {
1755
+ newWB.styles.push(this.styles[i].clone());
1756
+ }
1757
+ for (i in this.sheets)
1758
+ {
1759
+ newWB.sheets.push(this.sheets[i].clone(this, newWB));
1760
+ }
1761
+ i = 0;
1762
+ j = this.fonts.length;
1763
+ while (i < j)
1764
+ {
1765
+ newWB.fonts.push(this.fonts[i].clone());
1766
+ i++;
1767
+ }
1768
+ return newWB;
1769
+ }
1770
+
1771
+ addDefaultStyles()
1772
+ {
1773
+ let style;
1774
+ while (this.styles.length < 21)
1775
+ {
1776
+ style = new CellStyle(this.styles.length);
1777
+ this.styles.push(style);
1778
+ }
1779
+ }
1780
+
1781
+ /**
1782
+ * @param {string | null} author
1783
+ */
1784
+ setAuthor(author)
1785
+ {
1786
+ this.author = author;
1787
+ }
1788
+
1789
+ /**
1790
+ * @param {string | null} lastAuthor
1791
+ */
1792
+ setLastAuthor(lastAuthor)
1793
+ {
1794
+ this.lastAuthor = lastAuthor;
1795
+ }
1796
+
1797
+ /**
1798
+ * @param {string | null} company
1799
+ */
1800
+ setCompany(company)
1801
+ {
1802
+ this.company = company;
1803
+ }
1804
+
1805
+ /**
1806
+ * @param {data.Timestamp | null} createTime
1807
+ */
1808
+ setCreateTime(createTime)
1809
+ {
1810
+ this.createTime = createTime;
1811
+ }
1812
+
1813
+ /**
1814
+ * @param {data.Timestamp | null} modifyTime
1815
+ */
1816
+ setModifyTime(modifyTime)
1817
+ {
1818
+ this.modifyTime = modifyTime;
1819
+ }
1820
+
1821
+ /**
1822
+ * @param {number} version
1823
+ */
1824
+ setVersion(version)
1825
+ {
1826
+ this.version = version;
1827
+ }
1828
+
1829
+ getAuthor()
1830
+ {
1831
+ return this.author;
1832
+ }
1833
+
1834
+ getLastAuthor()
1835
+ {
1836
+ return this.lastAuthor;
1837
+ }
1838
+
1839
+ getCompany()
1840
+ {
1841
+ return this.company;
1842
+ }
1843
+
1844
+ getCreateTime()
1845
+ {
1846
+ return this.createTime;
1847
+ }
1848
+
1849
+ getModifyTime()
1850
+ {
1851
+ return this.modifyTime;
1852
+ }
1853
+
1854
+ getVersion()
1855
+ {
1856
+ return this.version;
1857
+ }
1858
+
1859
+ hasInfo()
1860
+ {
1861
+ if (this.author != null)
1862
+ return true;
1863
+ if (this.lastAuthor != null)
1864
+ return true;
1865
+ if (this.company != null)
1866
+ return true;
1867
+ if (this.createTime != null)
1868
+ return true;
1869
+ if (this.version != 0)
1870
+ return true;
1871
+ return false;
1872
+ }
1873
+
1874
+ /**
1875
+ * @param {number} windowTopX
1876
+ */
1877
+ setWindowTopX(windowTopX)
1878
+ {
1879
+ this.windowTopX = windowTopX;
1880
+ }
1881
+
1882
+ /**
1883
+ * @param {number} windowTopY
1884
+ */
1885
+ setWindowTopY(windowTopY)
1886
+ {
1887
+ this.windowTopY = windowTopY;
1888
+ }
1889
+
1890
+ /**
1891
+ * @param {number} windowWidth
1892
+ */
1893
+ setWindowWidth(windowWidth)
1894
+ {
1895
+ this.windowWidth = windowWidth;
1896
+ }
1897
+
1898
+ /**
1899
+ * @param {number} windowHeight
1900
+ */
1901
+ setWindowHeight(windowHeight)
1902
+ {
1903
+ this.windowHeight = windowHeight;
1904
+ }
1905
+
1906
+ /**
1907
+ * @param {number} index
1908
+ */
1909
+ setActiveSheet(index)
1910
+ {
1911
+ this.activeSheet = index;
1912
+ }
1913
+
1914
+ getWindowTopX()
1915
+ {
1916
+ return this.windowTopX;
1917
+ }
1918
+
1919
+ getWindowTopY()
1920
+ {
1921
+ return this.windowTopY;
1922
+ }
1923
+
1924
+ getWindowWidth()
1925
+ {
1926
+ return this.windowWidth;
1927
+ }
1928
+
1929
+ getWindowHeight()
1930
+ {
1931
+ return this.windowHeight;
1932
+ }
1933
+
1934
+ getActiveSheet()
1935
+ {
1936
+ return this.activeSheet;
1937
+ }
1938
+
1939
+ hasWindowInfo()
1940
+ {
1941
+ if (this.windowTopX != 0 || this.windowTopY != 0 || this.windowWidth != 0 || this.windowHeight != 0 || this.activeSheet != 0)
1942
+ return true;
1943
+ return false;
1944
+ }
1945
+
1946
+ hasCellStyle()
1947
+ {
1948
+ if (this.styles.length > 0)
1949
+ return true;
1950
+ return false;
1951
+ }
1952
+
1953
+ newCellStyleDef()
1954
+ {
1955
+ let style = new CellStyle(this.styles.length);
1956
+ this.styles.push(style);
1957
+ return style;
1958
+ }
1959
+
1960
+ /**
1961
+ * @param {WorkbookFont | null} font
1962
+ * @param {text.HAlignment} halign
1963
+ * @param {text.VAlignment} valign
1964
+ * @param {string | null} dataFormat
1965
+ */
1966
+ newCellStyle(font, halign, valign, dataFormat)
1967
+ {
1968
+ let style = new CellStyle(this.styles.length);
1969
+ style.setFont(font);
1970
+ style.setHAlign(halign);
1971
+ style.setVAlign(valign);
1972
+ style.setDataFormat(dataFormat);
1973
+ this.styles.push(style);
1974
+ return style;
1975
+ }
1976
+
1977
+ getStyleCount()
1978
+ {
1979
+ return this.styles.length;
1980
+ }
1981
+
1982
+ /**
1983
+ * @param {CellStyle} style
1984
+ */
1985
+ getStyleIndex(style)
1986
+ {
1987
+ let i = this.styles.length;
1988
+ while (i-- > 0)
1989
+ {
1990
+ if (this.styles[i] == style)
1991
+ return i;
1992
+ }
1993
+ return -1;
1994
+ }
1995
+
1996
+ /**
1997
+ * @param {number} index
1998
+ */
1999
+ getStyle(index)
2000
+ {
2001
+ return this.styles[index];
2002
+ }
2003
+
2004
+ /**
2005
+ * @param {CellStyle} tmpStyle
2006
+ */
2007
+ findOrCreateStyle(tmpStyle)
2008
+ {
2009
+ let style;
2010
+ let i = this.styles.length;
2011
+ while (i-- > 0)
2012
+ {
2013
+ if ((style = this.styles[i]) != null)
2014
+ {
2015
+ if (style.equals(tmpStyle))
2016
+ {
2017
+ return style;
2018
+ }
2019
+ }
2020
+ }
2021
+ style = tmpStyle.clone();
2022
+ style.setIndex(this.styles.length);
2023
+ this.styles.push(style);
2024
+ return style;
2025
+ }
2026
+
2027
+ getDefaultStyle()
2028
+ {
2029
+ return this.styles[0];
2030
+ }
2031
+
2032
+ getPalette()
2033
+ {
2034
+ return this.palette;
2035
+ }
2036
+
2037
+ /**
2038
+ * @param {number[]} palette
2039
+ */
2040
+ setPalette(palette)
2041
+ {
2042
+ let i;
2043
+ for (i in palette)
2044
+ {
2045
+ this.palette[i] = palette[i];
2046
+ }
2047
+ }
2048
+
2049
+ /**
2050
+ * @param {string | null} name
2051
+ */
2052
+ addWorksheet(name)
2053
+ {
2054
+ if (name == null)
2055
+ name = "Sheet"+ this.sheets.length;
2056
+ let ws = new Worksheet(name);
2057
+ this.sheets.push(ws);
2058
+ return ws;
2059
+ }
2060
+
2061
+ /**
2062
+ * @param {number} index
2063
+ * @param {string} name
2064
+ */
2065
+ insertWorksheet(index, name)
2066
+ {
2067
+ let ws = new Worksheet(name);
2068
+ this.sheets.splice(index, 0, ws);
2069
+ return ws;
2070
+ }
2071
+
2072
+ getCount()
2073
+ {
2074
+ return this.sheets.length;
2075
+ }
2076
+
2077
+ /**
2078
+ * @param {number} index
2079
+ */
2080
+ getItem(index)
2081
+ {
2082
+ return this.sheets[index];
2083
+ }
2084
+
2085
+ removeAt(index)
2086
+ {
2087
+ return this.sheets.splice(index, 1);
2088
+ }
2089
+
2090
+ /**
2091
+ * @param {string} name
2092
+ */
2093
+ getWorksheetByName(name)
2094
+ {
2095
+ let i;
2096
+ for (i in this.sheets)
2097
+ {
2098
+ if (this.sheets[i].getName() == name)
2099
+ return this.sheets[i];
2100
+ }
2101
+ return null;
2102
+ }
2103
+
2104
+ getFontCount()
2105
+ {
2106
+ return this.fonts.length;
2107
+ }
2108
+
2109
+ /**
2110
+ * @param {number} index
2111
+ */
2112
+ getFontNoCheck(index)
2113
+ {
2114
+ let fnt = this.fonts[index];
2115
+ if (fnt == null)
2116
+ throw new Error("Font is null");
2117
+ return fnt;
2118
+ }
2119
+
2120
+ /**
2121
+ * @param {number} index
2122
+ */
2123
+ getFont(index)
2124
+ {
2125
+ return this.fonts[index];
2126
+ }
2127
+
2128
+ /**
2129
+ * @param {WorkbookFont} font
2130
+ */
2131
+ getFontIndex(font)
2132
+ {
2133
+ let i;
2134
+ for (i in this.fonts)
2135
+ {
2136
+ if (this.fonts[i] == font)
2137
+ {
2138
+ return i;
2139
+ }
2140
+ }
2141
+ return -1;
2142
+ }
2143
+
2144
+ newFont(name, size, bold)
2145
+ {
2146
+ let font = new WorkbookFont();
2147
+ this.fonts.push(font);
2148
+ font.setName(name);
2149
+ font.setSize(size);
2150
+ font.setBold(bold);
2151
+ return font;
2152
+ }
2153
+
2154
+ static getDefPalette()
2155
+ {
2156
+ return Workbook.defPalette;
2157
+ }
2158
+
2159
+ /**
2160
+ * @param {number} col
2161
+ */
2162
+ static colCode(col)
2163
+ {
2164
+ if (col < 26)
2165
+ {
2166
+ return String.fromCharCode(65 + col);
2167
+ }
2168
+ col -= 26;
2169
+ if (col < 26 * 26)
2170
+ {
2171
+ return String.fromCharCode(65 + (col / 26), 65 + (col % 26));
2172
+ }
2173
+ let sbuff = new Array(3);
2174
+ col -= 26 * 26;
2175
+ sbuff[2] = (65 + (col % 26));
2176
+ col = col / 26;
2177
+ sbuff[1] = (65 + (col % 26));
2178
+ sbuff[0] = (65 + (col / 26));
2179
+ return String.fromCharCode(sbuff[0], sbuff[1], sbuff[2]);
2180
+ }
2181
+ }
2182
+
2183
+ export class XLSUtil
2184
+ {
2185
+ /**
2186
+ * @param {data.Timestamp} ts
2187
+ */
2188
+ static date2Number(ts)
2189
+ {
2190
+ ts = ts.setTimeZoneQHR(0);
2191
+ let secs = ts.inst.sec;
2192
+ let days = Number(secs / 86400n) + 25569;
2193
+ secs -= BigInt(days - 25569) * 86400n;
2194
+ while (secs < 0)
2195
+ {
2196
+ secs += 86400n;
2197
+ days -= 1;
2198
+ }
2199
+ return days + Number(secs) / 86400.0 + (ts.inst.nanosec + 50000) / 86400000000000.0;
2200
+ }
2201
+
2202
+ /**
2203
+ * @param {number} v
2204
+ */
2205
+ static number2Timestamp(v)
2206
+ {
2207
+ let days = Math.floor(v);
2208
+ let tz = data.DateTimeUtil.getLocalTzQhr();
2209
+ let ds = (v - days);
2210
+ let s = Math.floor(ds * 86400);
2211
+ return new data.Timestamp(new data.TimeInstant(BigInt(days - 25569) * 86400n + BigInt(s), Math.round((ds * 86400 - s) * 1000000000)), tz);
2212
+ }
2213
+
2214
+ static getCellID(col, row)
2215
+ {
2216
+ let s;
2217
+ if (col >= 26)
2218
+ {
2219
+ s = String.fromCharCode(0x41 + Math.floor(col / 26) - 1, 0x41 + (col % 26));
2220
+ }
2221
+ else
2222
+ {
2223
+ s = String.fromCharCode(0x41 + col);
2224
+ }
2225
+ return s + (row + 1);
2226
+ }
2227
+ }