@cj-tech-master/excelts 1.4.5-canary.20251212064440.3eb099f → 1.4.5-canary.20251212160853.7621827

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.
@@ -5,9 +5,11 @@ const col_cache_js_1 = require("../utils/col-cache");
5
5
  const under_dash_js_1 = require("../utils/under-dash");
6
6
  const enums_js_1 = require("./enums");
7
7
  const DEFAULT_COLUMN_WIDTH = 9;
8
- // Column defines the column properties for 1 column.
9
- // This includes header rows, widths, key, (style), etc.
10
- // Worksheet will condense the columns as appropriate during serialization
8
+ /**
9
+ * Column defines the column properties for 1 column.
10
+ * This includes header rows, widths, key, (style), etc.
11
+ * Worksheet will condense the columns as appropriate during serialization
12
+ */
11
13
  class Column {
12
14
  constructor(worksheet, number, defn) {
13
15
  this._worksheet = worksheet;
@@ -23,6 +25,9 @@ class Column {
23
25
  get worksheet() {
24
26
  return this._worksheet;
25
27
  }
28
+ /**
29
+ * Column letter key
30
+ */
26
31
  get letter() {
27
32
  return col_cache_js_1.colCache.n2l(this._number);
28
33
  }
@@ -71,6 +76,9 @@ class Column {
71
76
  }
72
77
  return [];
73
78
  }
79
+ /**
80
+ * Can be a string to set one row high header or an array to set multi-row high header
81
+ */
74
82
  get header() {
75
83
  return this._header;
76
84
  }
@@ -85,6 +93,9 @@ class Column {
85
93
  this._header = undefined;
86
94
  }
87
95
  }
96
+ /**
97
+ * The name of the properties associated with this column in each row
98
+ */
88
99
  get key() {
89
100
  return this._key;
90
101
  }
@@ -98,18 +109,27 @@ class Column {
98
109
  this._worksheet.setColumnKey(this._key, this);
99
110
  }
100
111
  }
112
+ /**
113
+ * Hides the column
114
+ */
101
115
  get hidden() {
102
116
  return !!this._hidden;
103
117
  }
104
118
  set hidden(value) {
105
119
  this._hidden = value;
106
120
  }
121
+ /**
122
+ * Set an outline level for columns
123
+ */
107
124
  get outlineLevel() {
108
125
  return this._outlineLevel || 0;
109
126
  }
110
127
  set outlineLevel(value) {
111
128
  this._outlineLevel = value;
112
129
  }
130
+ /**
131
+ * Indicate the collapsed state based on outlineLevel
132
+ */
113
133
  get collapsed() {
114
134
  return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelCol);
115
135
  }
@@ -151,16 +171,25 @@ class Column {
151
171
  get headerCount() {
152
172
  return this.headers.length;
153
173
  }
154
- eachCell(options, iteratee) {
174
+ eachCell(optionsOrCallback, maybeCallback) {
155
175
  const colNumber = this.number;
156
- if (!iteratee) {
157
- iteratee = options;
176
+ let options;
177
+ let callback;
178
+ if (typeof optionsOrCallback === "function") {
158
179
  options = {};
180
+ callback = optionsOrCallback;
181
+ }
182
+ else {
183
+ options = optionsOrCallback;
184
+ callback = maybeCallback;
159
185
  }
160
186
  this._worksheet.eachRow(options, (row, rowNumber) => {
161
- iteratee(row.getCell(colNumber), rowNumber);
187
+ callback(row.getCell(colNumber), rowNumber);
162
188
  });
163
189
  }
190
+ /**
191
+ * The cell values in the column
192
+ */
164
193
  get values() {
165
194
  const v = [];
166
195
  this.eachCell((cell, rowNumber) => {
@@ -12,19 +12,29 @@ class Row {
12
12
  this.style = {};
13
13
  this.outlineLevel = 0;
14
14
  }
15
- // return the row number
15
+ /**
16
+ * The row number
17
+ */
16
18
  get number() {
17
19
  return this._number;
18
20
  }
21
+ /**
22
+ * The worksheet that contains this row
23
+ */
19
24
  get worksheet() {
20
25
  return this._worksheet;
21
26
  }
22
- // Inform Streaming Writer that this row (and all rows before it) are complete
23
- // and ready to write. Has no effect on Worksheet document
27
+ /**
28
+ * Commit a completed row to stream.
29
+ * Inform Streaming Writer that this row (and all rows before it) are complete
30
+ * and ready to write. Has no effect on Worksheet document.
31
+ */
24
32
  commit() {
25
33
  this._worksheet._commitRow(this);
26
34
  }
27
- // helps GC by breaking cyclic references
35
+ /**
36
+ * Helps GC by breaking cyclic references
37
+ */
28
38
  destroy() {
29
39
  delete this._worksheet;
30
40
  delete this._cells;
@@ -43,7 +53,9 @@ class Row {
43
53
  }
44
54
  return cell;
45
55
  }
46
- // get cell by key, letter or column number
56
+ /**
57
+ * Get cell by number, column letter or column key
58
+ */
47
59
  getCell(col) {
48
60
  let colNum;
49
61
  if (typeof col === "string") {
@@ -66,7 +78,11 @@ class Row {
66
78
  col: colNum
67
79
  }));
68
80
  }
69
- // remove cell(s) and shift all higher cells down by count
81
+ /**
82
+ * Cut one or more cells (cells to the right are shifted left)
83
+ *
84
+ * Note: this operation will not affect other rows
85
+ */
70
86
  splice(start, count, ...inserts) {
71
87
  const nKeep = start + count;
72
88
  const nExpand = inserts.length - count;
@@ -115,26 +131,26 @@ class Row {
115
131
  cDst.comment = undefined;
116
132
  }
117
133
  }
118
- eachCell(optionsOrIteratee, maybeIteratee) {
134
+ eachCell(optOrCallback, maybeCallback) {
119
135
  let options = null;
120
- let iteratee;
121
- if (typeof optionsOrIteratee === "function") {
122
- iteratee = optionsOrIteratee;
136
+ let callback;
137
+ if (typeof optOrCallback === "function") {
138
+ callback = optOrCallback;
123
139
  }
124
140
  else {
125
- options = optionsOrIteratee;
126
- iteratee = maybeIteratee;
141
+ options = optOrCallback;
142
+ callback = maybeCallback;
127
143
  }
128
144
  if (options && options.includeEmpty) {
129
145
  const n = this._cells.length;
130
146
  for (let i = 1; i <= n; i++) {
131
- iteratee(this.getCell(i), i);
147
+ callback(this.getCell(i), i);
132
148
  }
133
149
  }
134
150
  else {
135
151
  this._cells.forEach((cell, index) => {
136
152
  if (cell && cell.type !== enums_js_1.Enums.ValueType.Null) {
137
- iteratee(cell, index + 1);
153
+ callback(cell, index + 1);
138
154
  }
139
155
  });
140
156
  }
@@ -155,7 +171,9 @@ class Row {
155
171
  }
156
172
  ws.rowBreaks.push(pb);
157
173
  }
158
- // return a sparse array of cell values
174
+ /**
175
+ * Get a row as a sparse array
176
+ */
159
177
  get values() {
160
178
  const values = [];
161
179
  this._cells.forEach(cell => {
@@ -165,7 +183,9 @@ class Row {
165
183
  });
166
184
  return values;
167
185
  }
168
- // set the values by contiguous or sparse array, or by key'd object literal
186
+ /**
187
+ * Set the values by contiguous or sparse array, or by key'd object literal
188
+ */
169
189
  set values(value) {
170
190
  // this operation is not additive - any prior cells are removed
171
191
  this._cells = [];
@@ -201,13 +221,21 @@ class Row {
201
221
  });
202
222
  }
203
223
  }
204
- // returns true if the row includes at least one cell with a value
224
+ /**
225
+ * Returns true if the row includes at least one cell with a value
226
+ */
205
227
  get hasValues() {
206
228
  return this._cells.some(cell => cell && cell.type !== enums_js_1.Enums.ValueType.Null);
207
229
  }
230
+ /**
231
+ * Number of cells including empty ones
232
+ */
208
233
  get cellCount() {
209
234
  return this._cells.length;
210
235
  }
236
+ /**
237
+ * Number of non-empty cells
238
+ */
211
239
  get actualCellCount() {
212
240
  let count = 0;
213
241
  this.eachCell(() => {
@@ -215,7 +243,9 @@ class Row {
215
243
  });
216
244
  return count;
217
245
  }
218
- // get the min and max column number for the non-null cells in this row or null
246
+ /**
247
+ * Get the min and max column number for the non-null cells in this row or null
248
+ */
219
249
  get dimensions() {
220
250
  let min = 0;
221
251
  let max = 0;
@@ -29,12 +29,18 @@ class Workbook {
29
29
  this.pivotTables = [];
30
30
  this._definedNames = new defined_names_js_1.DefinedNames();
31
31
  }
32
+ /**
33
+ * xlsx file format operations
34
+ */
32
35
  get xlsx() {
33
36
  if (!this._xlsx) {
34
37
  this._xlsx = new xlsx_js_1.XLSX(this);
35
38
  }
36
39
  return this._xlsx;
37
40
  }
41
+ /**
42
+ * csv file format operations
43
+ */
38
44
  get csv() {
39
45
  if (!this._csv) {
40
46
  this._csv = new csv_js_1.CSV(this);
@@ -50,6 +56,9 @@ class Workbook {
50
56
  }
51
57
  return this._worksheets.length || 1;
52
58
  }
59
+ /**
60
+ * Add a new worksheet and return a reference to it
61
+ */
53
62
  addWorksheet(name, options) {
54
63
  const id = this.nextId;
55
64
  const lastOrderNo = this._worksheets.reduce((acc, ws) => ((ws && ws.orderNo) > acc ? ws.orderNo : acc), 0);
@@ -73,6 +82,9 @@ class Workbook {
73
82
  worksheet.destroy();
74
83
  }
75
84
  }
85
+ /**
86
+ * Fetch sheet by name or id
87
+ */
76
88
  getWorksheet(id) {
77
89
  if (id === undefined) {
78
90
  return this._worksheets.find(Boolean);
@@ -85,6 +97,9 @@ class Workbook {
85
97
  }
86
98
  return undefined;
87
99
  }
100
+ /**
101
+ * Return a clone of worksheets in order
102
+ */
88
103
  get worksheets() {
89
104
  // return a clone of _worksheets
90
105
  return this._worksheets
@@ -92,9 +107,14 @@ class Workbook {
92
107
  .sort((a, b) => a.orderNo - b.orderNo)
93
108
  .filter(Boolean);
94
109
  }
95
- eachSheet(iteratee) {
110
+ /**
111
+ * Iterate over all sheets.
112
+ *
113
+ * Note: `workbook.worksheets.forEach` will still work but this is better.
114
+ */
115
+ eachSheet(callback) {
96
116
  this.worksheets.forEach(sheet => {
97
- iteratee(sheet, sheet.id);
117
+ callback(sheet, sheet.id);
98
118
  });
99
119
  }
100
120
  get definedNames() {
@@ -104,6 +124,9 @@ class Workbook {
104
124
  // Note: themes are not an exposed feature, meddle at your peril!
105
125
  this._themes = undefined;
106
126
  }
127
+ /**
128
+ * Add Image to Workbook and return the id
129
+ */
107
130
  addImage(image) {
108
131
  // TODO: validation?
109
132
  const id = this.media.length;