@cj-tech-master/excelts 1.4.5 → 1.5.0
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 +454 -159
- package/dist/browser/excelts.iife.js.map +1 -1
- package/dist/browser/excelts.iife.min.js +28 -28
- package/dist/cjs/doc/anchor.js +25 -11
- package/dist/cjs/doc/cell.js +75 -43
- package/dist/cjs/doc/column.js +74 -22
- package/dist/cjs/doc/defined-names.js +53 -7
- package/dist/cjs/doc/image.js +11 -8
- package/dist/cjs/doc/range.js +64 -28
- package/dist/cjs/doc/row.js +72 -31
- package/dist/cjs/doc/table.js +3 -5
- package/dist/cjs/doc/workbook.js +30 -6
- package/dist/cjs/doc/worksheet.js +165 -41
- package/dist/cjs/utils/sheet-utils.js +3 -1
- package/dist/cjs/utils/unzip/extract.js +30 -82
- package/dist/cjs/utils/unzip/index.js +18 -2
- package/dist/cjs/utils/unzip/zip-parser.js +458 -0
- package/dist/esm/doc/anchor.js +25 -11
- package/dist/esm/doc/cell.js +75 -43
- package/dist/esm/doc/column.js +74 -22
- package/dist/esm/doc/defined-names.js +53 -7
- package/dist/esm/doc/image.js +11 -8
- package/dist/esm/doc/range.js +64 -28
- package/dist/esm/doc/row.js +72 -31
- package/dist/esm/doc/table.js +3 -5
- package/dist/esm/doc/workbook.js +30 -6
- package/dist/esm/doc/worksheet.js +165 -41
- package/dist/esm/utils/sheet-utils.js +3 -1
- package/dist/esm/utils/unzip/extract.js +28 -82
- package/dist/esm/utils/unzip/index.js +17 -2
- package/dist/esm/utils/unzip/zip-parser.js +451 -0
- package/dist/types/doc/anchor.d.ts +14 -7
- package/dist/types/doc/cell.d.ts +78 -37
- package/dist/types/doc/column.d.ts +72 -36
- package/dist/types/doc/defined-names.d.ts +11 -8
- package/dist/types/doc/image.d.ts +29 -12
- package/dist/types/doc/pivot-table.d.ts +1 -1
- package/dist/types/doc/range.d.ts +15 -4
- package/dist/types/doc/row.d.ts +78 -40
- package/dist/types/doc/table.d.ts +21 -36
- package/dist/types/doc/workbook.d.ts +54 -34
- package/dist/types/doc/worksheet.d.ts +255 -83
- package/dist/types/stream/xlsx/worksheet-reader.d.ts +3 -5
- package/dist/types/types.d.ts +86 -26
- package/dist/types/utils/col-cache.d.ts +11 -8
- package/dist/types/utils/unzip/extract.d.ts +16 -14
- package/dist/types/utils/unzip/index.d.ts +15 -1
- package/dist/types/utils/unzip/zip-parser.d.ts +92 -0
- package/package.json +1 -1
package/dist/cjs/doc/range.js
CHANGED
|
@@ -5,11 +5,17 @@ const col_cache_js_1 = require("../utils/col-cache");
|
|
|
5
5
|
// used by worksheet to calculate sheet dimensions
|
|
6
6
|
class Range {
|
|
7
7
|
constructor(...args) {
|
|
8
|
+
this.model = {
|
|
9
|
+
top: 0,
|
|
10
|
+
left: 0,
|
|
11
|
+
bottom: 0,
|
|
12
|
+
right: 0
|
|
13
|
+
};
|
|
8
14
|
this.decode(args);
|
|
9
15
|
}
|
|
10
16
|
setTLBR(t, l, b, r, s) {
|
|
11
|
-
if (
|
|
12
|
-
// setTLBR(tl, br, s)
|
|
17
|
+
if (typeof t === "string" && typeof l === "string") {
|
|
18
|
+
// setTLBR(tl, br, s) - t and l are address strings
|
|
13
19
|
const tl = col_cache_js_1.colCache.decodeAddress(t);
|
|
14
20
|
const br = col_cache_js_1.colCache.decodeAddress(l);
|
|
15
21
|
this.model = {
|
|
@@ -17,12 +23,14 @@ class Range {
|
|
|
17
23
|
left: Math.min(tl.col, br.col),
|
|
18
24
|
bottom: Math.max(tl.row, br.row),
|
|
19
25
|
right: Math.max(tl.col, br.col),
|
|
20
|
-
sheetName: b
|
|
26
|
+
sheetName: typeof b === "string" ? b : undefined
|
|
21
27
|
};
|
|
22
|
-
this.setTLBR(tl.row, tl.col, br.row, br.col, s);
|
|
23
28
|
}
|
|
24
|
-
else
|
|
25
|
-
|
|
29
|
+
else if (typeof t === "number" &&
|
|
30
|
+
typeof l === "number" &&
|
|
31
|
+
typeof b === "number" &&
|
|
32
|
+
typeof r === "number") {
|
|
33
|
+
// setTLBR(t, l, b, r, s) - all numbers
|
|
26
34
|
this.model = {
|
|
27
35
|
top: Math.min(t, b),
|
|
28
36
|
left: Math.min(l, r),
|
|
@@ -35,16 +43,33 @@ class Range {
|
|
|
35
43
|
decode(argv) {
|
|
36
44
|
switch (argv.length) {
|
|
37
45
|
case 5: // [t,l,b,r,s]
|
|
38
|
-
|
|
46
|
+
if (typeof argv[0] === "number" &&
|
|
47
|
+
typeof argv[1] === "number" &&
|
|
48
|
+
typeof argv[2] === "number" &&
|
|
49
|
+
typeof argv[3] === "number" &&
|
|
50
|
+
typeof argv[4] === "string") {
|
|
51
|
+
this.setTLBR(argv[0], argv[1], argv[2], argv[3], argv[4]);
|
|
52
|
+
}
|
|
39
53
|
break;
|
|
40
54
|
case 4: // [t,l,b,r]
|
|
41
|
-
|
|
55
|
+
if (typeof argv[0] === "number" &&
|
|
56
|
+
typeof argv[1] === "number" &&
|
|
57
|
+
typeof argv[2] === "number" &&
|
|
58
|
+
typeof argv[3] === "number") {
|
|
59
|
+
this.setTLBR(argv[0], argv[1], argv[2], argv[3]);
|
|
60
|
+
}
|
|
42
61
|
break;
|
|
43
62
|
case 3: // [tl,br,s]
|
|
44
|
-
|
|
63
|
+
if (typeof argv[0] === "string" &&
|
|
64
|
+
typeof argv[1] === "string" &&
|
|
65
|
+
typeof argv[2] === "string") {
|
|
66
|
+
this.setTLBR(argv[0], argv[1], argv[2]);
|
|
67
|
+
}
|
|
45
68
|
break;
|
|
46
69
|
case 2: // [tl,br]
|
|
47
|
-
|
|
70
|
+
if (typeof argv[0] === "string" && typeof argv[1] === "string") {
|
|
71
|
+
this.setTLBR(argv[0], argv[1]);
|
|
72
|
+
}
|
|
48
73
|
break;
|
|
49
74
|
case 1: {
|
|
50
75
|
const value = argv[0];
|
|
@@ -58,11 +83,15 @@ class Range {
|
|
|
58
83
|
sheetName: value.sheetName
|
|
59
84
|
};
|
|
60
85
|
}
|
|
61
|
-
else if (value
|
|
86
|
+
else if (Array.isArray(value)) {
|
|
62
87
|
// an arguments array
|
|
63
88
|
this.decode(value);
|
|
64
89
|
}
|
|
65
|
-
else if (
|
|
90
|
+
else if (typeof value === "object" &&
|
|
91
|
+
"top" in value &&
|
|
92
|
+
"left" in value &&
|
|
93
|
+
"bottom" in value &&
|
|
94
|
+
"right" in value) {
|
|
66
95
|
// a model
|
|
67
96
|
this.model = {
|
|
68
97
|
top: value.top,
|
|
@@ -72,25 +101,27 @@ class Range {
|
|
|
72
101
|
sheetName: value.sheetName
|
|
73
102
|
};
|
|
74
103
|
}
|
|
75
|
-
else {
|
|
104
|
+
else if (typeof value === "string") {
|
|
76
105
|
// [sheetName!]tl:br
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
106
|
+
const decoded = col_cache_js_1.colCache.decodeEx(value);
|
|
107
|
+
if ("top" in decoded) {
|
|
108
|
+
// It's a DecodedRange
|
|
79
109
|
this.model = {
|
|
80
|
-
top:
|
|
81
|
-
left:
|
|
82
|
-
bottom:
|
|
83
|
-
right:
|
|
84
|
-
sheetName:
|
|
110
|
+
top: decoded.top,
|
|
111
|
+
left: decoded.left,
|
|
112
|
+
bottom: decoded.bottom,
|
|
113
|
+
right: decoded.right,
|
|
114
|
+
sheetName: decoded.sheetName
|
|
85
115
|
};
|
|
86
116
|
}
|
|
87
|
-
else {
|
|
117
|
+
else if ("row" in decoded) {
|
|
118
|
+
// It's an Address
|
|
88
119
|
this.model = {
|
|
89
|
-
top:
|
|
90
|
-
left:
|
|
91
|
-
bottom:
|
|
92
|
-
right:
|
|
93
|
-
sheetName:
|
|
120
|
+
top: decoded.row,
|
|
121
|
+
left: decoded.col,
|
|
122
|
+
bottom: decoded.row,
|
|
123
|
+
right: decoded.col,
|
|
124
|
+
sheetName: decoded.sheetName
|
|
94
125
|
};
|
|
95
126
|
}
|
|
96
127
|
}
|
|
@@ -172,7 +203,9 @@ class Range {
|
|
|
172
203
|
}
|
|
173
204
|
expandToAddress(addressStr) {
|
|
174
205
|
const address = col_cache_js_1.colCache.decodeEx(addressStr);
|
|
175
|
-
|
|
206
|
+
if ("row" in address && "col" in address) {
|
|
207
|
+
this.expand(address.row, address.col, address.row, address.col);
|
|
208
|
+
}
|
|
176
209
|
}
|
|
177
210
|
get tl() {
|
|
178
211
|
return col_cache_js_1.colCache.n2l(this.left) + this.top;
|
|
@@ -224,7 +257,10 @@ class Range {
|
|
|
224
257
|
}
|
|
225
258
|
contains(addressStr) {
|
|
226
259
|
const address = col_cache_js_1.colCache.decodeEx(addressStr);
|
|
227
|
-
|
|
260
|
+
if ("row" in address && "col" in address) {
|
|
261
|
+
return this.containsEx(address);
|
|
262
|
+
}
|
|
263
|
+
return false;
|
|
228
264
|
}
|
|
229
265
|
containsEx(address) {
|
|
230
266
|
if (address.sheetName && this.sheetName && address.sheetName !== this.sheetName) {
|
package/dist/cjs/doc/row.js
CHANGED
|
@@ -12,19 +12,29 @@ class Row {
|
|
|
12
12
|
this.style = {};
|
|
13
13
|
this.outlineLevel = 0;
|
|
14
14
|
}
|
|
15
|
-
|
|
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
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -83,12 +99,12 @@ class Row {
|
|
|
83
99
|
cDst = this.getCell(i);
|
|
84
100
|
cDst.value = cSrc.value;
|
|
85
101
|
cDst.style = cSrc.style;
|
|
86
|
-
cDst.
|
|
102
|
+
cDst.comment = cSrc.comment;
|
|
87
103
|
}
|
|
88
104
|
else if (cDst) {
|
|
89
105
|
cDst.value = null;
|
|
90
106
|
cDst.style = {};
|
|
91
|
-
cDst.
|
|
107
|
+
cDst.comment = undefined;
|
|
92
108
|
}
|
|
93
109
|
}
|
|
94
110
|
}
|
|
@@ -100,7 +116,7 @@ class Row {
|
|
|
100
116
|
cDst = this.getCell(i + nExpand);
|
|
101
117
|
cDst.value = cSrc.value;
|
|
102
118
|
cDst.style = cSrc.style;
|
|
103
|
-
cDst.
|
|
119
|
+
cDst.comment = cSrc.comment;
|
|
104
120
|
}
|
|
105
121
|
else {
|
|
106
122
|
this._cells[i + nExpand - 1] = undefined;
|
|
@@ -112,29 +128,29 @@ class Row {
|
|
|
112
128
|
cDst = this.getCell(start + i);
|
|
113
129
|
cDst.value = inserts[i];
|
|
114
130
|
cDst.style = {};
|
|
115
|
-
cDst.
|
|
131
|
+
cDst.comment = undefined;
|
|
116
132
|
}
|
|
117
133
|
}
|
|
118
|
-
eachCell(
|
|
134
|
+
eachCell(optOrCallback, maybeCallback) {
|
|
119
135
|
let options = null;
|
|
120
|
-
let
|
|
121
|
-
if (typeof
|
|
122
|
-
|
|
136
|
+
let callback;
|
|
137
|
+
if (typeof optOrCallback === "function") {
|
|
138
|
+
callback = optOrCallback;
|
|
123
139
|
}
|
|
124
140
|
else {
|
|
125
|
-
options =
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Returns true if the row includes at least one cell with a value
|
|
226
|
+
*/
|
|
205
227
|
get hasValues() {
|
|
206
|
-
return this._cells.some(
|
|
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
|
-
|
|
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;
|
|
@@ -242,46 +272,57 @@ class Row {
|
|
|
242
272
|
this.style[name] = value;
|
|
243
273
|
this._cells.forEach(cell => {
|
|
244
274
|
if (cell) {
|
|
245
|
-
cell[name] = value;
|
|
275
|
+
cell.style[name] = value;
|
|
246
276
|
}
|
|
247
277
|
});
|
|
248
|
-
return value;
|
|
249
278
|
}
|
|
250
279
|
get numFmt() {
|
|
251
280
|
return this.style.numFmt;
|
|
252
281
|
}
|
|
253
282
|
set numFmt(value) {
|
|
254
|
-
|
|
283
|
+
if (value !== undefined) {
|
|
284
|
+
this._applyStyle("numFmt", value);
|
|
285
|
+
}
|
|
255
286
|
}
|
|
256
287
|
get font() {
|
|
257
288
|
return this.style.font;
|
|
258
289
|
}
|
|
259
290
|
set font(value) {
|
|
260
|
-
|
|
291
|
+
if (value !== undefined) {
|
|
292
|
+
this._applyStyle("font", value);
|
|
293
|
+
}
|
|
261
294
|
}
|
|
262
295
|
get alignment() {
|
|
263
296
|
return this.style.alignment;
|
|
264
297
|
}
|
|
265
298
|
set alignment(value) {
|
|
266
|
-
|
|
299
|
+
if (value !== undefined) {
|
|
300
|
+
this._applyStyle("alignment", value);
|
|
301
|
+
}
|
|
267
302
|
}
|
|
268
303
|
get protection() {
|
|
269
304
|
return this.style.protection;
|
|
270
305
|
}
|
|
271
306
|
set protection(value) {
|
|
272
|
-
|
|
307
|
+
if (value !== undefined) {
|
|
308
|
+
this._applyStyle("protection", value);
|
|
309
|
+
}
|
|
273
310
|
}
|
|
274
311
|
get border() {
|
|
275
312
|
return this.style.border;
|
|
276
313
|
}
|
|
277
314
|
set border(value) {
|
|
278
|
-
|
|
315
|
+
if (value !== undefined) {
|
|
316
|
+
this._applyStyle("border", value);
|
|
317
|
+
}
|
|
279
318
|
}
|
|
280
319
|
get fill() {
|
|
281
320
|
return this.style.fill;
|
|
282
321
|
}
|
|
283
322
|
set fill(value) {
|
|
284
|
-
|
|
323
|
+
if (value !== undefined) {
|
|
324
|
+
this._applyStyle("fill", value);
|
|
325
|
+
}
|
|
285
326
|
}
|
|
286
327
|
get hidden() {
|
|
287
328
|
return !!this._hidden;
|
package/dist/cjs/doc/table.js
CHANGED
|
@@ -157,9 +157,7 @@ class Table {
|
|
|
157
157
|
// the sheet...
|
|
158
158
|
const assignStyle = (cell, style) => {
|
|
159
159
|
if (style) {
|
|
160
|
-
Object.
|
|
161
|
-
cell.style[key] = style[key];
|
|
162
|
-
});
|
|
160
|
+
Object.assign(cell.style, style);
|
|
163
161
|
}
|
|
164
162
|
};
|
|
165
163
|
const { worksheet, table } = this;
|
|
@@ -377,10 +375,10 @@ class Table {
|
|
|
377
375
|
this._assign(this.table, "totalsRow", value);
|
|
378
376
|
}
|
|
379
377
|
get theme() {
|
|
380
|
-
return this.table.style.
|
|
378
|
+
return this.table.style.theme;
|
|
381
379
|
}
|
|
382
380
|
set theme(value) {
|
|
383
|
-
this.table.style.
|
|
381
|
+
this.table.style.theme = value;
|
|
384
382
|
}
|
|
385
383
|
get showFirstColumn() {
|
|
386
384
|
return this.table.style.showFirstColumn;
|
package/dist/cjs/doc/workbook.js
CHANGED
|
@@ -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,15 +56,19 @@ 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);
|
|
56
|
-
const worksheetOptions =
|
|
65
|
+
const worksheetOptions = {
|
|
66
|
+
...options,
|
|
57
67
|
id,
|
|
58
68
|
name,
|
|
59
69
|
orderNo: lastOrderNo + 1,
|
|
60
70
|
workbook: this
|
|
61
|
-
}
|
|
71
|
+
};
|
|
62
72
|
const worksheet = new worksheet_js_1.Worksheet(worksheetOptions);
|
|
63
73
|
this._worksheets[id] = worksheet;
|
|
64
74
|
return worksheet;
|
|
@@ -72,6 +82,9 @@ class Workbook {
|
|
|
72
82
|
worksheet.destroy();
|
|
73
83
|
}
|
|
74
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Fetch sheet by name or id
|
|
87
|
+
*/
|
|
75
88
|
getWorksheet(id) {
|
|
76
89
|
if (id === undefined) {
|
|
77
90
|
return this._worksheets.find(Boolean);
|
|
@@ -84,6 +97,9 @@ class Workbook {
|
|
|
84
97
|
}
|
|
85
98
|
return undefined;
|
|
86
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Return a clone of worksheets in order
|
|
102
|
+
*/
|
|
87
103
|
get worksheets() {
|
|
88
104
|
// return a clone of _worksheets
|
|
89
105
|
return this._worksheets
|
|
@@ -91,9 +107,14 @@ class Workbook {
|
|
|
91
107
|
.sort((a, b) => a.orderNo - b.orderNo)
|
|
92
108
|
.filter(Boolean);
|
|
93
109
|
}
|
|
94
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Iterate over all sheets.
|
|
112
|
+
*
|
|
113
|
+
* Note: `workbook.worksheets.forEach` will still work but this is better.
|
|
114
|
+
*/
|
|
115
|
+
eachSheet(callback) {
|
|
95
116
|
this.worksheets.forEach(sheet => {
|
|
96
|
-
|
|
117
|
+
callback(sheet, sheet.id);
|
|
97
118
|
});
|
|
98
119
|
}
|
|
99
120
|
get definedNames() {
|
|
@@ -103,14 +124,17 @@ class Workbook {
|
|
|
103
124
|
// Note: themes are not an exposed feature, meddle at your peril!
|
|
104
125
|
this._themes = undefined;
|
|
105
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Add Image to Workbook and return the id
|
|
129
|
+
*/
|
|
106
130
|
addImage(image) {
|
|
107
131
|
// TODO: validation?
|
|
108
132
|
const id = this.media.length;
|
|
109
|
-
this.media.push(
|
|
133
|
+
this.media.push({ ...image, type: "image" });
|
|
110
134
|
return id;
|
|
111
135
|
}
|
|
112
136
|
getImage(id) {
|
|
113
|
-
return this.media[id];
|
|
137
|
+
return this.media[Number(id)];
|
|
114
138
|
}
|
|
115
139
|
get model() {
|
|
116
140
|
return {
|