@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.
- package/dist/browser/excelts.iife.js +259 -20
- package/dist/browser/excelts.iife.js.map +1 -1
- package/dist/browser/excelts.iife.min.js +3 -3
- 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 +153 -23
- 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/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 +153 -23
- 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/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 +158 -11
- 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
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure Uint8Array-based ZIP parser
|
|
3
|
+
* Works in both Node.js and browser environments
|
|
4
|
+
* No dependency on Node.js stream module
|
|
5
|
+
*/
|
|
6
|
+
import { decompress, decompressSync } from "../zip/compress.js";
|
|
7
|
+
// ZIP file signatures
|
|
8
|
+
const LOCAL_FILE_HEADER_SIG = 0x04034b50;
|
|
9
|
+
const CENTRAL_DIR_HEADER_SIG = 0x02014b50;
|
|
10
|
+
const END_OF_CENTRAL_DIR_SIG = 0x06054b50;
|
|
11
|
+
const ZIP64_END_OF_CENTRAL_DIR_SIG = 0x06064b50;
|
|
12
|
+
const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG = 0x07064b50;
|
|
13
|
+
// Compression methods
|
|
14
|
+
const COMPRESSION_STORED = 0;
|
|
15
|
+
const COMPRESSION_DEFLATE = 8;
|
|
16
|
+
/**
|
|
17
|
+
* Parse DOS date/time format to JavaScript Date
|
|
18
|
+
* Dates in zip file entries are stored as DosDateTime
|
|
19
|
+
* Spec: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-dosdatetimetofiletime
|
|
20
|
+
*/
|
|
21
|
+
function parseDateTime(date, time) {
|
|
22
|
+
const day = date & 0x1f;
|
|
23
|
+
const month = (date >> 5) & 0x0f;
|
|
24
|
+
const year = ((date >> 9) & 0x7f) + 1980;
|
|
25
|
+
const seconds = time ? (time & 0x1f) * 2 : 0;
|
|
26
|
+
const minutes = time ? (time >> 5) & 0x3f : 0;
|
|
27
|
+
const hours = time ? time >> 11 : 0;
|
|
28
|
+
return new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse ZIP64 extra field
|
|
32
|
+
*/
|
|
33
|
+
function parseZip64ExtraField(extraField, compressedSize, uncompressedSize, localHeaderOffset) {
|
|
34
|
+
const view = new DataView(extraField.buffer, extraField.byteOffset, extraField.byteLength);
|
|
35
|
+
let offset = 0;
|
|
36
|
+
while (offset + 4 <= extraField.length) {
|
|
37
|
+
const signature = view.getUint16(offset, true);
|
|
38
|
+
const partSize = view.getUint16(offset + 2, true);
|
|
39
|
+
if (signature === 0x0001) {
|
|
40
|
+
// ZIP64 extended information
|
|
41
|
+
let fieldOffset = offset + 4;
|
|
42
|
+
if (uncompressedSize === 0xffffffff && fieldOffset + 8 <= offset + 4 + partSize) {
|
|
43
|
+
uncompressedSize = Number(view.getBigUint64(fieldOffset, true));
|
|
44
|
+
fieldOffset += 8;
|
|
45
|
+
}
|
|
46
|
+
if (compressedSize === 0xffffffff && fieldOffset + 8 <= offset + 4 + partSize) {
|
|
47
|
+
compressedSize = Number(view.getBigUint64(fieldOffset, true));
|
|
48
|
+
fieldOffset += 8;
|
|
49
|
+
}
|
|
50
|
+
if (localHeaderOffset === 0xffffffff && fieldOffset + 8 <= offset + 4 + partSize) {
|
|
51
|
+
localHeaderOffset = Number(view.getBigUint64(fieldOffset, true));
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
offset += 4 + partSize;
|
|
56
|
+
}
|
|
57
|
+
return { compressedSize, uncompressedSize, localHeaderOffset };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* DataView helper for reading little-endian values
|
|
61
|
+
*/
|
|
62
|
+
class BinaryReader {
|
|
63
|
+
constructor(data, offset = 0) {
|
|
64
|
+
this.data = data;
|
|
65
|
+
this.view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
66
|
+
this.offset = offset;
|
|
67
|
+
}
|
|
68
|
+
get position() {
|
|
69
|
+
return this.offset;
|
|
70
|
+
}
|
|
71
|
+
set position(value) {
|
|
72
|
+
this.offset = value;
|
|
73
|
+
}
|
|
74
|
+
get remaining() {
|
|
75
|
+
return this.data.length - this.offset;
|
|
76
|
+
}
|
|
77
|
+
readUint8() {
|
|
78
|
+
const value = this.view.getUint8(this.offset);
|
|
79
|
+
this.offset += 1;
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
readUint16() {
|
|
83
|
+
const value = this.view.getUint16(this.offset, true);
|
|
84
|
+
this.offset += 2;
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
readUint32() {
|
|
88
|
+
const value = this.view.getUint32(this.offset, true);
|
|
89
|
+
this.offset += 4;
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
readBigUint64() {
|
|
93
|
+
const value = this.view.getBigUint64(this.offset, true);
|
|
94
|
+
this.offset += 8;
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
readBytes(length) {
|
|
98
|
+
const bytes = this.data.subarray(this.offset, this.offset + length);
|
|
99
|
+
this.offset += length;
|
|
100
|
+
return bytes;
|
|
101
|
+
}
|
|
102
|
+
readString(length, utf8 = true) {
|
|
103
|
+
const bytes = this.readBytes(length);
|
|
104
|
+
if (utf8) {
|
|
105
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
106
|
+
}
|
|
107
|
+
// Fallback to ASCII/Latin-1
|
|
108
|
+
return String.fromCharCode(...bytes);
|
|
109
|
+
}
|
|
110
|
+
skip(length) {
|
|
111
|
+
this.offset += length;
|
|
112
|
+
}
|
|
113
|
+
slice(start, end) {
|
|
114
|
+
return this.data.subarray(start, end);
|
|
115
|
+
}
|
|
116
|
+
peekUint32(offset) {
|
|
117
|
+
return this.view.getUint32(offset, true);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Find the End of Central Directory record
|
|
122
|
+
* Searches backwards from the end of the file
|
|
123
|
+
*/
|
|
124
|
+
function findEndOfCentralDir(data) {
|
|
125
|
+
// EOCD is at least 22 bytes, search backwards
|
|
126
|
+
// Comment can be up to 65535 bytes
|
|
127
|
+
const minOffset = Math.max(0, data.length - 65557);
|
|
128
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
129
|
+
for (let i = data.length - 22; i >= minOffset; i--) {
|
|
130
|
+
if (view.getUint32(i, true) === END_OF_CENTRAL_DIR_SIG) {
|
|
131
|
+
return i;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return -1;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Find ZIP64 End of Central Directory Locator
|
|
138
|
+
*/
|
|
139
|
+
function findZip64EOCDLocator(data, eocdOffset) {
|
|
140
|
+
// ZIP64 EOCD Locator is 20 bytes and appears right before EOCD
|
|
141
|
+
const locatorOffset = eocdOffset - 20;
|
|
142
|
+
if (locatorOffset < 0) {
|
|
143
|
+
return -1;
|
|
144
|
+
}
|
|
145
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
146
|
+
if (view.getUint32(locatorOffset, true) === ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG) {
|
|
147
|
+
return locatorOffset;
|
|
148
|
+
}
|
|
149
|
+
return -1;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Parse ZIP file entries from Central Directory
|
|
153
|
+
*/
|
|
154
|
+
export function parseZipEntries(data, options = {}) {
|
|
155
|
+
const { decodeStrings = true } = options;
|
|
156
|
+
const entries = [];
|
|
157
|
+
// Find End of Central Directory
|
|
158
|
+
const eocdOffset = findEndOfCentralDir(data);
|
|
159
|
+
if (eocdOffset === -1) {
|
|
160
|
+
throw new Error("Invalid ZIP file: End of Central Directory not found");
|
|
161
|
+
}
|
|
162
|
+
const reader = new BinaryReader(data, eocdOffset);
|
|
163
|
+
// Read EOCD
|
|
164
|
+
// Offset Size Description
|
|
165
|
+
// 0 4 EOCD signature (0x06054b50)
|
|
166
|
+
// 4 2 Number of this disk
|
|
167
|
+
// 6 2 Disk where central directory starts
|
|
168
|
+
// 8 2 Number of central directory records on this disk
|
|
169
|
+
// 10 2 Total number of central directory records
|
|
170
|
+
// 12 4 Size of central directory (bytes)
|
|
171
|
+
// 16 4 Offset of start of central directory
|
|
172
|
+
// 20 2 Comment length
|
|
173
|
+
reader.skip(4); // signature
|
|
174
|
+
reader.skip(2); // disk number
|
|
175
|
+
reader.skip(2); // disk where central dir starts
|
|
176
|
+
reader.skip(2); // entries on this disk
|
|
177
|
+
let totalEntries = reader.readUint16(); // total entries
|
|
178
|
+
let centralDirSize = reader.readUint32();
|
|
179
|
+
let centralDirOffset = reader.readUint32();
|
|
180
|
+
// Check for ZIP64
|
|
181
|
+
const zip64LocatorOffset = findZip64EOCDLocator(data, eocdOffset);
|
|
182
|
+
if (zip64LocatorOffset !== -1) {
|
|
183
|
+
const locatorReader = new BinaryReader(data, zip64LocatorOffset);
|
|
184
|
+
locatorReader.skip(4); // signature
|
|
185
|
+
locatorReader.skip(4); // disk number with ZIP64 EOCD
|
|
186
|
+
const zip64EOCDOffset = Number(locatorReader.readBigUint64());
|
|
187
|
+
// Read ZIP64 EOCD
|
|
188
|
+
const zip64Reader = new BinaryReader(data, zip64EOCDOffset);
|
|
189
|
+
const zip64Sig = zip64Reader.readUint32();
|
|
190
|
+
if (zip64Sig === ZIP64_END_OF_CENTRAL_DIR_SIG) {
|
|
191
|
+
zip64Reader.skip(8); // size of ZIP64 EOCD
|
|
192
|
+
zip64Reader.skip(2); // version made by
|
|
193
|
+
zip64Reader.skip(2); // version needed
|
|
194
|
+
zip64Reader.skip(4); // disk number
|
|
195
|
+
zip64Reader.skip(4); // disk with central dir
|
|
196
|
+
const zip64TotalEntries = Number(zip64Reader.readBigUint64());
|
|
197
|
+
const zip64CentralDirSize = Number(zip64Reader.readBigUint64());
|
|
198
|
+
const zip64CentralDirOffset = Number(zip64Reader.readBigUint64());
|
|
199
|
+
// Use ZIP64 values if standard values are maxed out
|
|
200
|
+
if (totalEntries === 0xffff) {
|
|
201
|
+
totalEntries = zip64TotalEntries;
|
|
202
|
+
}
|
|
203
|
+
if (centralDirSize === 0xffffffff) {
|
|
204
|
+
centralDirSize = zip64CentralDirSize;
|
|
205
|
+
}
|
|
206
|
+
if (centralDirOffset === 0xffffffff) {
|
|
207
|
+
centralDirOffset = zip64CentralDirOffset;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Read Central Directory entries
|
|
212
|
+
const centralReader = new BinaryReader(data, centralDirOffset);
|
|
213
|
+
for (let i = 0; i < totalEntries; i++) {
|
|
214
|
+
const sig = centralReader.readUint32();
|
|
215
|
+
if (sig !== CENTRAL_DIR_HEADER_SIG) {
|
|
216
|
+
throw new Error(`Invalid Central Directory header signature at entry ${i}`);
|
|
217
|
+
}
|
|
218
|
+
// Central Directory File Header format:
|
|
219
|
+
// Offset Size Description
|
|
220
|
+
// 0 4 Central directory file header signature (0x02014b50)
|
|
221
|
+
// 4 2 Version made by
|
|
222
|
+
// 6 2 Version needed to extract
|
|
223
|
+
// 8 2 General purpose bit flag
|
|
224
|
+
// 10 2 Compression method
|
|
225
|
+
// 12 2 File last modification time
|
|
226
|
+
// 14 2 File last modification date
|
|
227
|
+
// 16 4 CRC-32
|
|
228
|
+
// 20 4 Compressed size
|
|
229
|
+
// 24 4 Uncompressed size
|
|
230
|
+
// 28 2 File name length
|
|
231
|
+
// 30 2 Extra field length
|
|
232
|
+
// 32 2 File comment length
|
|
233
|
+
// 34 2 Disk number where file starts
|
|
234
|
+
// 36 2 Internal file attributes
|
|
235
|
+
// 38 4 External file attributes
|
|
236
|
+
// 42 4 Relative offset of local file header
|
|
237
|
+
// 46 n File name
|
|
238
|
+
// 46+n m Extra field
|
|
239
|
+
// 46+n+m k File comment
|
|
240
|
+
centralReader.skip(2); // version made by
|
|
241
|
+
centralReader.skip(2); // version needed
|
|
242
|
+
const flags = centralReader.readUint16();
|
|
243
|
+
const compressionMethod = centralReader.readUint16();
|
|
244
|
+
const lastModTime = centralReader.readUint16();
|
|
245
|
+
const lastModDate = centralReader.readUint16();
|
|
246
|
+
const crc32 = centralReader.readUint32();
|
|
247
|
+
let compressedSize = centralReader.readUint32();
|
|
248
|
+
let uncompressedSize = centralReader.readUint32();
|
|
249
|
+
const fileNameLength = centralReader.readUint16();
|
|
250
|
+
const extraFieldLength = centralReader.readUint16();
|
|
251
|
+
const commentLength = centralReader.readUint16();
|
|
252
|
+
centralReader.skip(2); // disk number start
|
|
253
|
+
centralReader.skip(2); // internal attributes
|
|
254
|
+
const externalAttributes = centralReader.readUint32();
|
|
255
|
+
let localHeaderOffset = centralReader.readUint32();
|
|
256
|
+
// Check for UTF-8 flag (bit 11)
|
|
257
|
+
const isUtf8 = (flags & 0x800) !== 0;
|
|
258
|
+
const useUtf8 = decodeStrings && isUtf8;
|
|
259
|
+
const fileName = centralReader.readString(fileNameLength, useUtf8);
|
|
260
|
+
const extraField = centralReader.readBytes(extraFieldLength);
|
|
261
|
+
const comment = centralReader.readString(commentLength, useUtf8);
|
|
262
|
+
// Parse extra field for ZIP64 values
|
|
263
|
+
if (extraFieldLength > 0) {
|
|
264
|
+
const parsed = parseZip64ExtraField(extraField, compressedSize, uncompressedSize, localHeaderOffset);
|
|
265
|
+
compressedSize = parsed.compressedSize;
|
|
266
|
+
uncompressedSize = parsed.uncompressedSize;
|
|
267
|
+
localHeaderOffset = parsed.localHeaderOffset;
|
|
268
|
+
}
|
|
269
|
+
const isDirectory = fileName.endsWith("/") || (externalAttributes & 0x10) !== 0;
|
|
270
|
+
const isEncrypted = (flags & 0x01) !== 0;
|
|
271
|
+
entries.push({
|
|
272
|
+
path: fileName,
|
|
273
|
+
isDirectory,
|
|
274
|
+
compressedSize,
|
|
275
|
+
uncompressedSize,
|
|
276
|
+
compressionMethod,
|
|
277
|
+
crc32,
|
|
278
|
+
lastModified: parseDateTime(lastModDate, lastModTime),
|
|
279
|
+
localHeaderOffset,
|
|
280
|
+
comment,
|
|
281
|
+
externalAttributes,
|
|
282
|
+
isEncrypted
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
return entries;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Extract file data for a specific entry
|
|
289
|
+
*/
|
|
290
|
+
export async function extractEntryData(data, entry) {
|
|
291
|
+
if (entry.isDirectory) {
|
|
292
|
+
return new Uint8Array(0);
|
|
293
|
+
}
|
|
294
|
+
if (entry.isEncrypted) {
|
|
295
|
+
throw new Error(`File "${entry.path}" is encrypted and cannot be extracted`);
|
|
296
|
+
}
|
|
297
|
+
const reader = new BinaryReader(data, entry.localHeaderOffset);
|
|
298
|
+
// Read local file header
|
|
299
|
+
const sig = reader.readUint32();
|
|
300
|
+
if (sig !== LOCAL_FILE_HEADER_SIG) {
|
|
301
|
+
throw new Error(`Invalid local file header signature for "${entry.path}"`);
|
|
302
|
+
}
|
|
303
|
+
reader.skip(2); // version needed
|
|
304
|
+
reader.skip(2); // flags
|
|
305
|
+
reader.skip(2); // compression method
|
|
306
|
+
reader.skip(2); // last mod time
|
|
307
|
+
reader.skip(2); // last mod date
|
|
308
|
+
reader.skip(4); // crc32
|
|
309
|
+
reader.skip(4); // compressed size
|
|
310
|
+
reader.skip(4); // uncompressed size
|
|
311
|
+
const fileNameLength = reader.readUint16();
|
|
312
|
+
const extraFieldLength = reader.readUint16();
|
|
313
|
+
reader.skip(fileNameLength);
|
|
314
|
+
reader.skip(extraFieldLength);
|
|
315
|
+
// Extract compressed data
|
|
316
|
+
const compressedData = reader.readBytes(entry.compressedSize);
|
|
317
|
+
// Decompress if needed
|
|
318
|
+
if (entry.compressionMethod === COMPRESSION_STORED) {
|
|
319
|
+
return compressedData;
|
|
320
|
+
}
|
|
321
|
+
else if (entry.compressionMethod === COMPRESSION_DEFLATE) {
|
|
322
|
+
return decompress(compressedData);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
throw new Error(`Unsupported compression method: ${entry.compressionMethod}`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Extract file data synchronously (Node.js only)
|
|
330
|
+
*/
|
|
331
|
+
export function extractEntryDataSync(data, entry) {
|
|
332
|
+
if (entry.isDirectory) {
|
|
333
|
+
return new Uint8Array(0);
|
|
334
|
+
}
|
|
335
|
+
if (entry.isEncrypted) {
|
|
336
|
+
throw new Error(`File "${entry.path}" is encrypted and cannot be extracted`);
|
|
337
|
+
}
|
|
338
|
+
const reader = new BinaryReader(data, entry.localHeaderOffset);
|
|
339
|
+
// Read local file header
|
|
340
|
+
const sig = reader.readUint32();
|
|
341
|
+
if (sig !== LOCAL_FILE_HEADER_SIG) {
|
|
342
|
+
throw new Error(`Invalid local file header signature for "${entry.path}"`);
|
|
343
|
+
}
|
|
344
|
+
reader.skip(2); // version needed
|
|
345
|
+
reader.skip(2); // flags
|
|
346
|
+
reader.skip(2); // compression method
|
|
347
|
+
reader.skip(2); // last mod time
|
|
348
|
+
reader.skip(2); // last mod date
|
|
349
|
+
reader.skip(4); // crc32
|
|
350
|
+
reader.skip(4); // compressed size
|
|
351
|
+
reader.skip(4); // uncompressed size
|
|
352
|
+
const fileNameLength = reader.readUint16();
|
|
353
|
+
const extraFieldLength = reader.readUint16();
|
|
354
|
+
reader.skip(fileNameLength);
|
|
355
|
+
reader.skip(extraFieldLength);
|
|
356
|
+
// Extract compressed data
|
|
357
|
+
const compressedData = reader.readBytes(entry.compressedSize);
|
|
358
|
+
// Decompress if needed
|
|
359
|
+
if (entry.compressionMethod === COMPRESSION_STORED) {
|
|
360
|
+
return compressedData;
|
|
361
|
+
}
|
|
362
|
+
else if (entry.compressionMethod === COMPRESSION_DEFLATE) {
|
|
363
|
+
return decompressSync(compressedData);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
throw new Error(`Unsupported compression method: ${entry.compressionMethod}`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* High-level ZIP parser class
|
|
371
|
+
*/
|
|
372
|
+
export class ZipParser {
|
|
373
|
+
constructor(data, options = {}) {
|
|
374
|
+
this.data = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
|
|
375
|
+
this.entries = parseZipEntries(this.data, options);
|
|
376
|
+
this.entryMap = new Map(this.entries.map(e => [e.path, e]));
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Get all entries in the ZIP file
|
|
380
|
+
*/
|
|
381
|
+
getEntries() {
|
|
382
|
+
return this.entries;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Get entry by path
|
|
386
|
+
*/
|
|
387
|
+
getEntry(path) {
|
|
388
|
+
return this.entryMap.get(path);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Check if entry exists
|
|
392
|
+
*/
|
|
393
|
+
hasEntry(path) {
|
|
394
|
+
return this.entryMap.has(path);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* List all file paths
|
|
398
|
+
*/
|
|
399
|
+
listFiles() {
|
|
400
|
+
return this.entries.map(e => e.path);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Extract a single file (async)
|
|
404
|
+
*/
|
|
405
|
+
async extract(path) {
|
|
406
|
+
const entry = this.entryMap.get(path);
|
|
407
|
+
if (!entry) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
return extractEntryData(this.data, entry);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Extract a single file (sync, Node.js only)
|
|
414
|
+
*/
|
|
415
|
+
extractSync(path) {
|
|
416
|
+
const entry = this.entryMap.get(path);
|
|
417
|
+
if (!entry) {
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
return extractEntryDataSync(this.data, entry);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Extract all files (async)
|
|
424
|
+
*/
|
|
425
|
+
async extractAll() {
|
|
426
|
+
const result = new Map();
|
|
427
|
+
for (const entry of this.entries) {
|
|
428
|
+
const data = await extractEntryData(this.data, entry);
|
|
429
|
+
result.set(entry.path, data);
|
|
430
|
+
}
|
|
431
|
+
return result;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Iterate over entries with async callback
|
|
435
|
+
*/
|
|
436
|
+
async forEach(callback) {
|
|
437
|
+
for (const entry of this.entries) {
|
|
438
|
+
let dataPromise = null;
|
|
439
|
+
const getData = () => {
|
|
440
|
+
if (!dataPromise) {
|
|
441
|
+
dataPromise = extractEntryData(this.data, entry);
|
|
442
|
+
}
|
|
443
|
+
return dataPromise;
|
|
444
|
+
};
|
|
445
|
+
const shouldContinue = await callback(entry, getData);
|
|
446
|
+
if (shouldContinue === false) {
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
@@ -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
|
-
|
|
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
|
-
}
|
|
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;
|
package/dist/types/doc/row.d.ts
CHANGED
|
@@ -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
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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;
|