@cj-tech-master/excelts 1.4.5-canary.20251212053535.13d32d8 → 1.4.5-canary.20251212143538.45665af

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.
@@ -130,14 +130,21 @@ class Worksheet {
130
130
  }
131
131
  this._name = name;
132
132
  }
133
+ /**
134
+ * The workbook that contains this worksheet
135
+ */
133
136
  get workbook() {
134
137
  return this._workbook;
135
138
  }
136
- // when you're done with this worksheet, call this to remove from workbook
139
+ /**
140
+ * When you're done with this worksheet, call this to remove from workbook
141
+ */
137
142
  destroy() {
138
143
  this._workbook.removeWorksheetEx(this);
139
144
  }
140
- // Get the bounding range of the cells in this worksheet
145
+ /**
146
+ * Get the bounding range of the cells in this worksheet
147
+ */
141
148
  get dimensions() {
142
149
  const dimensions = new Range();
143
150
  this._rows.forEach(row => {
@@ -152,12 +159,18 @@ class Worksheet {
152
159
  }
153
160
  // =========================================================================
154
161
  // Columns
155
- // get the current columns array.
162
+ /**
163
+ * Get the current columns array
164
+ */
156
165
  get columns() {
157
166
  return this._columns;
158
167
  }
159
- // set the columns from an array of column definitions.
160
- // Note: any headers defined will overwrite existing values.
168
+ /**
169
+ * Add column headers and define column keys and widths.
170
+ *
171
+ * Note: these column structures are a workbook-building convenience only,
172
+ * apart from the column width, they will not be fully persisted.
173
+ */
161
174
  set columns(value) {
162
175
  // calculate max header row count
163
176
  this._headerRowCount = value.reduce((pv, cv) => {
@@ -185,7 +198,9 @@ class Worksheet {
185
198
  eachColumnKey(f) {
186
199
  Object.keys(this._keys).forEach(key => f(this._keys[key], key));
187
200
  }
188
- // get a single column by col number. If it doesn't exist, create it and any gaps before it
201
+ /**
202
+ * Access an individual column by key, letter and 1-based column number
203
+ */
189
204
  getColumn(c) {
190
205
  let colNum;
191
206
  if (typeof c === "string") {
@@ -211,6 +226,17 @@ class Worksheet {
211
226
  }
212
227
  return this._columns[colNum - 1];
213
228
  }
229
+ /**
230
+ * Cut one or more columns (columns to the right are shifted left)
231
+ * and optionally insert more
232
+ *
233
+ * If column properties have been defined, they will be cut or moved accordingly
234
+ *
235
+ * Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
236
+ *
237
+ * Also: If the worksheet has more rows than values in the column inserts,
238
+ * the rows will still be shifted as if the values existed
239
+ */
214
240
  spliceColumns(start, count, ...inserts) {
215
241
  const rows = this._rows;
216
242
  const nRows = rows.length;
@@ -250,9 +276,15 @@ class Worksheet {
250
276
  // account for defined names
251
277
  this.workbook.definedNames.spliceColumns(this.name, start, count, inserts.length);
252
278
  }
279
+ /**
280
+ * Get the last column in a worksheet
281
+ */
253
282
  get lastColumn() {
254
283
  return this.getColumn(this.columnCount);
255
284
  }
285
+ /**
286
+ * The total column size of the document. Equal to the maximum cell count from all of the rows
287
+ */
256
288
  get columnCount() {
257
289
  let maxCount = 0;
258
290
  this.eachRow(row => {
@@ -260,6 +292,9 @@ class Worksheet {
260
292
  });
261
293
  return maxCount;
262
294
  }
295
+ /**
296
+ * A count of the number of columns that have values
297
+ */
263
298
  get actualColumnCount() {
264
299
  // performance nightmare - for each row, counts all the columns used
265
300
  const counts = [];
@@ -291,23 +326,41 @@ class Worksheet {
291
326
  get _nextRow() {
292
327
  return this._lastRowNumber + 1;
293
328
  }
329
+ /**
330
+ * Get the last editable row in a worksheet (or undefined if there are none)
331
+ */
294
332
  get lastRow() {
295
333
  if (this._rows.length) {
296
334
  return this._rows[this._rows.length - 1];
297
335
  }
298
336
  return undefined;
299
337
  }
300
- // find a row (if exists) by row number
338
+ /**
339
+ * Tries to find and return row for row number, else undefined
340
+ *
341
+ * @param r - The 1-indexed row number
342
+ */
301
343
  findRow(r) {
302
344
  return this._rows[r - 1];
303
345
  }
304
- // find multiple rows (if exists) by row number
346
+ /**
347
+ * Tries to find and return rows for row number start and length, else undefined
348
+ *
349
+ * @param start - The 1-indexed starting row number
350
+ * @param length - The length of the expected array
351
+ */
305
352
  findRows(start, length) {
306
353
  return this._rows.slice(start - 1, start - 1 + length);
307
354
  }
355
+ /**
356
+ * The total row size of the document. Equal to the row number of the last row that has values.
357
+ */
308
358
  get rowCount() {
309
359
  return this._lastRowNumber;
310
360
  }
361
+ /**
362
+ * A count of the number of rows that have values. If a mid-document row is empty, it will not be included in the count.
363
+ */
311
364
  get actualRowCount() {
312
365
  // counts actual rows that have actual data
313
366
  let count = 0;
@@ -316,7 +369,9 @@ class Worksheet {
316
369
  });
317
370
  return count;
318
371
  }
319
- // get a row by row number.
372
+ /**
373
+ * Get or create row by 1-based index
374
+ */
320
375
  getRow(r) {
321
376
  let row = this._rows[r - 1];
322
377
  if (!row) {
@@ -324,7 +379,9 @@ class Worksheet {
324
379
  }
325
380
  return row;
326
381
  }
327
- // get multiple rows by row number.
382
+ /**
383
+ * Get or create rows by 1-based index
384
+ */
328
385
  getRows(start, length) {
329
386
  if (length < 1) {
330
387
  return undefined;
@@ -335,6 +392,10 @@ class Worksheet {
335
392
  }
336
393
  return rows;
337
394
  }
395
+ /**
396
+ * Add a couple of Rows by key-value, after the last current row, using the column keys,
397
+ * or add a row by contiguous Array (assign to columns A, B & C)
398
+ */
338
399
  addRow(value, style = "n") {
339
400
  const rowNo = this._nextRow;
340
401
  const row = this.getRow(rowNo);
@@ -342,6 +403,9 @@ class Worksheet {
342
403
  this._setStyleOption(rowNo, style[0] === "i" ? style : "n");
343
404
  return row;
344
405
  }
406
+ /**
407
+ * Add multiple rows by providing an array of arrays or key-value pairs
408
+ */
345
409
  addRows(value, style = "n") {
346
410
  const rows = [];
347
411
  value.forEach(row => {
@@ -349,11 +413,19 @@ class Worksheet {
349
413
  });
350
414
  return rows;
351
415
  }
416
+ /**
417
+ * Insert a Row by key-value, at the position (shifting down all rows from position),
418
+ * using the column keys, or add a row by contiguous Array (assign to columns A, B & C)
419
+ */
352
420
  insertRow(pos, value, style = "n") {
353
421
  this.spliceRows(pos, 0, value);
354
422
  this._setStyleOption(pos, style);
355
423
  return this.getRow(pos);
356
424
  }
425
+ /**
426
+ * Insert multiple rows at position (shifting down all rows from position)
427
+ * by providing an array of arrays or key-value pairs
428
+ */
357
429
  insertRows(pos, values, style = "n") {
358
430
  this.spliceRows(pos, 0, ...values);
359
431
  if (style !== "n") {
@@ -387,6 +459,9 @@ class Worksheet {
387
459
  });
388
460
  rDst.height = rSrc.height;
389
461
  }
462
+ /**
463
+ * Duplicate rows and insert new rows
464
+ */
390
465
  duplicateRow(rowNum, count, insert = false) {
391
466
  // create count duplicates of rowNum
392
467
  // either inserting new or overwriting existing rows
@@ -403,6 +478,12 @@ class Worksheet {
403
478
  });
404
479
  }
405
480
  }
481
+ /**
482
+ * Cut one or more rows (rows below are shifted up)
483
+ * and optionally insert more
484
+ *
485
+ * Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
486
+ */
406
487
  spliceRows(start, count, ...inserts) {
407
488
  // same problem as row.splice, except worse.
408
489
  const nKeep = start + count;
@@ -467,31 +548,33 @@ class Worksheet {
467
548
  // account for defined names
468
549
  this.workbook.definedNames.spliceRows(this.name, start, count, nInserts);
469
550
  }
470
- eachRow(optionsOrIteratee, maybeIteratee) {
551
+ eachRow(optOrCallback, maybeCallback) {
471
552
  let options;
472
- let iteratee;
473
- if (typeof optionsOrIteratee === "function") {
474
- iteratee = optionsOrIteratee;
553
+ let callback;
554
+ if (typeof optOrCallback === "function") {
555
+ callback = optOrCallback;
475
556
  }
476
557
  else {
477
- options = optionsOrIteratee;
478
- iteratee = maybeIteratee;
558
+ options = optOrCallback;
559
+ callback = maybeCallback;
479
560
  }
480
561
  if (options && options.includeEmpty) {
481
562
  const n = this._rows.length;
482
563
  for (let i = 1; i <= n; i++) {
483
- iteratee(this.getRow(i), i);
564
+ callback(this.getRow(i), i);
484
565
  }
485
566
  }
486
567
  else {
487
568
  this._rows.forEach(row => {
488
569
  if (row && row.hasValues) {
489
- iteratee(row, row.number);
570
+ callback(row, row.number);
490
571
  }
491
572
  });
492
573
  }
493
574
  }
494
- // return all rows as sparse array
575
+ /**
576
+ * Return all rows as sparse array
577
+ */
495
578
  getSheetValues() {
496
579
  const rows = [];
497
580
  this._rows.forEach(row => {
@@ -503,13 +586,17 @@ class Worksheet {
503
586
  }
504
587
  // =========================================================================
505
588
  // Cells
506
- // returns the cell at [r,c] or address given by r. If not found, return undefined
589
+ /**
590
+ * Returns the cell at [r,c] or address given by r. If not found, return undefined
591
+ */
507
592
  findCell(r, c) {
508
593
  const address = colCache.getAddress(r, c);
509
594
  const row = this._rows[address.row - 1];
510
595
  return row ? row.findCell(address.col) : undefined;
511
596
  }
512
- // return the cell at [r,c] or address given by r. If not found, create a new one.
597
+ /**
598
+ * Get or create cell at [r,c] or address given by r
599
+ */
513
600
  getCell(r, c) {
514
601
  const address = colCache.getAddress(r, c);
515
602
  const row = this.getRow(address.row);
@@ -517,7 +604,15 @@ class Worksheet {
517
604
  }
518
605
  // =========================================================================
519
606
  // Merge
520
- // convert the range defined by ['tl:br'], [tl,br] or [t,l,b,r] into a single 'merged' cell
607
+ /**
608
+ * Merge cells, either:
609
+ *
610
+ * tlbr string, e.g. `'A4:B5'`
611
+ *
612
+ * tl string, br string, e.g. `'G10', 'H11'`
613
+ *
614
+ * t, l, b, r numbers, e.g. `10,11,12,13`
615
+ */
521
616
  mergeCells(...cells) {
522
617
  const dimensions = new Range(cells);
523
618
  this._mergeCellsInternal(dimensions);
@@ -562,9 +657,11 @@ class Worksheet {
562
657
  // return true if this._merges has a merge object
563
658
  return Object.values(this._merges).some(Boolean);
564
659
  }
565
- // scan the range defined by ['tl:br'], [tl,br] or [t,l,b,r] and if any cell is part of a merge,
566
- // un-merge the group. Note this function can affect multiple merges and merge-blocks are
567
- // atomic - either they're all merged or all un-merged.
660
+ /**
661
+ * Scan the range and if any cell is part of a merge, un-merge the group.
662
+ * Note this function can affect multiple merges and merge-blocks are
663
+ * atomic - either they're all merged or all un-merged.
664
+ */
568
665
  unMergeCells(...cells) {
569
666
  const dimensions = new Range(cells);
570
667
  // find any cells in that range and unmerge them
@@ -636,6 +733,10 @@ class Worksheet {
636
733
  }
637
734
  // =========================================================================
638
735
  // Images
736
+ /**
737
+ * Using the image id from `Workbook.addImage`,
738
+ * embed an image within the worksheet to cover a range
739
+ */
639
740
  addImage(imageId, range) {
640
741
  const model = {
641
742
  type: "image",
@@ -647,6 +748,9 @@ class Worksheet {
647
748
  getImages() {
648
749
  return this._media.filter(m => m.type === "image");
649
750
  }
751
+ /**
752
+ * Using the image id from `Workbook.addImage`, set the background to the worksheet
753
+ */
650
754
  addBackgroundImage(imageId) {
651
755
  const model = {
652
756
  type: "background",
@@ -660,6 +764,9 @@ class Worksheet {
660
764
  }
661
765
  // =========================================================================
662
766
  // Worksheet Protection
767
+ /**
768
+ * Protect the worksheet with optional password and options
769
+ */
663
770
  protect(password, options) {
664
771
  // TODO: make this function truly async
665
772
  // perhaps marshal to worker thread or something
@@ -694,17 +801,29 @@ class Worksheet {
694
801
  }
695
802
  // =========================================================================
696
803
  // Tables
804
+ /**
805
+ * Add a new table and return a reference to it
806
+ */
697
807
  addTable(model) {
698
808
  const table = new Table(this, model);
699
809
  this.tables[model.name] = table;
700
810
  return table;
701
811
  }
812
+ /**
813
+ * Fetch table by name
814
+ */
702
815
  getTable(name) {
703
816
  return this.tables[name];
704
817
  }
818
+ /**
819
+ * Delete table by name
820
+ */
705
821
  removeTable(name) {
706
822
  delete this.tables[name];
707
823
  }
824
+ /**
825
+ * Fetch all tables in the worksheet
826
+ */
708
827
  getTables() {
709
828
  return Object.values(this.tables);
710
829
  }
@@ -720,9 +839,15 @@ Please leave feedback at https://github.com/excelts/excelts/discussions/2575`);
720
839
  }
721
840
  // ===========================================================================
722
841
  // Conditional Formatting
842
+ /**
843
+ * Add conditional formatting rules
844
+ */
723
845
  addConditionalFormatting(cf) {
724
846
  this.conditionalFormattings.push(cf);
725
847
  }
848
+ /**
849
+ * Delete conditional formatting rules
850
+ */
726
851
  removeConditionalFormatting(filter) {
727
852
  if (typeof filter === "number") {
728
853
  this.conditionalFormattings.splice(filter, 1);
@@ -19,40 +19,75 @@ export interface ColumnModel {
19
19
  outlineLevel?: number;
20
20
  collapsed?: boolean;
21
21
  }
22
+ /**
23
+ * Column defines the column properties for 1 column.
24
+ * This includes header rows, widths, key, (style), etc.
25
+ * Worksheet will condense the columns as appropriate during serialization
26
+ */
22
27
  declare class Column {
23
28
  private _worksheet;
24
29
  private _number;
25
30
  private _header;
26
31
  private _key;
32
+ /** The width of the column */
27
33
  width?: number;
28
34
  private _hidden;
29
35
  private _outlineLevel;
36
+ /** Styles applied to the column */
30
37
  style: Partial<Style>;
31
38
  constructor(worksheet: Worksheet, number: number, defn?: ColumnDefn | false);
32
39
  get number(): number;
33
40
  get worksheet(): Worksheet;
41
+ /**
42
+ * Column letter key
43
+ */
34
44
  get letter(): string;
35
45
  get isCustomWidth(): boolean;
36
46
  get defn(): ColumnDefn;
37
47
  set defn(value: ColumnDefn | undefined);
38
48
  get headers(): string[];
49
+ /**
50
+ * Can be a string to set one row high header or an array to set multi-row high header
51
+ */
39
52
  get header(): string | string[] | undefined;
40
53
  set header(value: string | string[] | undefined);
54
+ /**
55
+ * The name of the properties associated with this column in each row
56
+ */
41
57
  get key(): string | undefined;
42
58
  set key(value: string | undefined);
59
+ /**
60
+ * Hides the column
61
+ */
43
62
  get hidden(): boolean;
44
63
  set hidden(value: boolean);
64
+ /**
65
+ * Set an outline level for columns
66
+ */
45
67
  get outlineLevel(): number;
46
68
  set outlineLevel(value: number | undefined);
69
+ /**
70
+ * Indicate the collapsed state based on outlineLevel
71
+ */
47
72
  get collapsed(): boolean;
48
73
  toString(): string;
49
74
  equivalentTo(other: Column): boolean;
50
75
  equivalentToModel(model: ColumnModel): boolean;
51
76
  get isDefault(): boolean;
52
77
  get headerCount(): number;
53
- eachCell(options: {
78
+ /**
79
+ * Iterate over all current cells in this column
80
+ */
81
+ eachCell(callback: (cell: Cell, rowNumber: number) => void): void;
82
+ /**
83
+ * Iterate over all current cells in this column including empty cells
84
+ */
85
+ eachCell(opt: {
54
86
  includeEmpty?: boolean;
55
- } | ((cell: Cell, rowNumber: number) => void), iteratee?: (cell: Cell, rowNumber: number) => void): void;
87
+ }, callback: (cell: Cell, rowNumber: number) => void): void;
88
+ /**
89
+ * The cell values in the column
90
+ */
56
91
  get values(): CellValueType[];
57
92
  set values(v: CellValueType[]);
58
93
  get numFmt(): string | NumFmt | undefined;
@@ -16,9 +16,6 @@ export interface RowModel {
16
16
  outlineLevel: number;
17
17
  collapsed: boolean;
18
18
  }
19
- interface EachCellOptions {
20
- includeEmpty?: boolean;
21
- }
22
19
  declare class Row {
23
20
  private _worksheet;
24
21
  private _number;
@@ -28,22 +25,70 @@ declare class Row {
28
25
  private _outlineLevel?;
29
26
  height?: number;
30
27
  constructor(worksheet: Worksheet, number: number);
28
+ /**
29
+ * The row number
30
+ */
31
31
  get number(): number;
32
+ /**
33
+ * The worksheet that contains this row
34
+ */
32
35
  get worksheet(): Worksheet;
36
+ /**
37
+ * Commit a completed row to stream.
38
+ * Inform Streaming Writer that this row (and all rows before it) are complete
39
+ * and ready to write. Has no effect on Worksheet document.
40
+ */
33
41
  commit(): void;
42
+ /**
43
+ * Helps GC by breaking cyclic references
44
+ */
34
45
  destroy(): void;
35
46
  findCell(colNumber: number): Cell | undefined;
36
47
  getCellEx(address: CellAddress): Cell;
48
+ /**
49
+ * Get cell by number, column letter or column key
50
+ */
37
51
  getCell(col: string | number): Cell;
52
+ /**
53
+ * Cut one or more cells (cells to the right are shifted left)
54
+ *
55
+ * Note: this operation will not affect other rows
56
+ */
38
57
  splice(start: number, count: number, ...inserts: CellValue[]): void;
39
- eachCell(iteratee: (cell: Cell, colNumber: number) => void): void;
40
- eachCell(options: EachCellOptions, iteratee: (cell: Cell, colNumber: number) => void): void;
58
+ /**
59
+ * Iterate over all non-null cells in a row
60
+ */
61
+ eachCell(callback: (cell: Cell, colNumber: number) => void): void;
62
+ /**
63
+ * Iterate over all cells in a row (including empty cells)
64
+ */
65
+ eachCell(opt: {
66
+ includeEmpty?: boolean;
67
+ }, callback: (cell: Cell, colNumber: number) => void): void;
41
68
  addPageBreak(lft?: number, rght?: number): void;
69
+ /**
70
+ * Get a row as a sparse array
71
+ */
42
72
  get values(): CellValue[];
73
+ /**
74
+ * Set the values by contiguous or sparse array, or by key'd object literal
75
+ */
43
76
  set values(value: RowValues);
77
+ /**
78
+ * Returns true if the row includes at least one cell with a value
79
+ */
44
80
  get hasValues(): boolean;
81
+ /**
82
+ * Number of cells including empty ones
83
+ */
45
84
  get cellCount(): number;
85
+ /**
86
+ * Number of non-empty cells
87
+ */
46
88
  get actualCellCount(): number;
89
+ /**
90
+ * Get the min and max column number for the non-null cells in this row or null
91
+ */
47
92
  get dimensions(): RowDimensions | null;
48
93
  private _applyStyle;
49
94
  get numFmt(): string | NumFmt | undefined;
@@ -65,17 +65,40 @@ declare class Workbook {
65
65
  private _xlsx?;
66
66
  private _csv?;
67
67
  constructor();
68
+ /**
69
+ * xlsx file format operations
70
+ */
68
71
  get xlsx(): XLSX;
72
+ /**
73
+ * csv file format operations
74
+ */
69
75
  get csv(): CSV;
70
76
  get nextId(): number;
77
+ /**
78
+ * Add a new worksheet and return a reference to it
79
+ */
71
80
  addWorksheet(name?: string, options?: AddWorksheetOptions): Worksheet;
72
81
  removeWorksheetEx(worksheet: Worksheet): void;
73
82
  removeWorksheet(id: number | string): void;
83
+ /**
84
+ * Fetch sheet by name or id
85
+ */
74
86
  getWorksheet(id?: number | string): Worksheet | undefined;
87
+ /**
88
+ * Return a clone of worksheets in order
89
+ */
75
90
  get worksheets(): Worksheet[];
76
- eachSheet(iteratee: (sheet: Worksheet, id: number) => void): void;
91
+ /**
92
+ * Iterate over all sheets.
93
+ *
94
+ * Note: `workbook.worksheets.forEach` will still work but this is better.
95
+ */
96
+ eachSheet(callback: (sheet: Worksheet, id: number) => void): void;
77
97
  get definedNames(): DefinedNames;
78
98
  clearThemes(): void;
99
+ /**
100
+ * Add Image to Workbook and return the id
101
+ */
79
102
  addImage(image: Image): number;
80
103
  getImage(id: number | string): WorkbookMedia | undefined;
81
104
  get model(): WorkbookModel;