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