@justybase/spreadsheet-tasks 1.3.3 → 2.0.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +25 -16
  3. package/browser/browser-spreadsheet.js +3037 -0
  4. package/browser/justybase-spreadsheet.min.js +36 -0
  5. package/dist/cjs/index.d.ts +399 -0
  6. package/dist/cjs/index.js +3944 -0
  7. package/dist/cjs/index.js.map +1 -0
  8. package/dist/esm/index.js +3889 -0
  9. package/dist/esm/index.js.map +1 -0
  10. package/dist/esm/package.json +1 -0
  11. package/docs/API.md +8 -9
  12. package/docs/PACKAGING.md +32 -0
  13. package/docs/PUBLISHING.md +8 -1
  14. package/examples/basic-read.ts +1 -1
  15. package/examples/formats-verify.ts +1 -2
  16. package/examples/large-dataset.ts +1 -1
  17. package/package.json +28 -13
  18. package/dist/BiffReaderWriter.d.ts +0 -44
  19. package/dist/BiffReaderWriter.d.ts.map +0 -1
  20. package/dist/BiffReaderWriter.js +0 -282
  21. package/dist/BiffReaderWriter.js.map +0 -1
  22. package/dist/BigBuffer.d.ts +0 -24
  23. package/dist/BigBuffer.d.ts.map +0 -1
  24. package/dist/BigBuffer.js +0 -120
  25. package/dist/BigBuffer.js.map +0 -1
  26. package/dist/ExcelReaderAbstract.d.ts +0 -17
  27. package/dist/ExcelReaderAbstract.d.ts.map +0 -1
  28. package/dist/ExcelReaderAbstract.js +0 -25
  29. package/dist/ExcelReaderAbstract.js.map +0 -1
  30. package/dist/Formats.d.ts +0 -34
  31. package/dist/Formats.d.ts.map +0 -1
  32. package/dist/Formats.js +0 -48
  33. package/dist/Formats.js.map +0 -1
  34. package/dist/ReaderFactory.d.ts +0 -6
  35. package/dist/ReaderFactory.d.ts.map +0 -1
  36. package/dist/ReaderFactory.js +0 -56
  37. package/dist/ReaderFactory.js.map +0 -1
  38. package/dist/XlsbReader.d.ts +0 -24
  39. package/dist/XlsbReader.d.ts.map +0 -1
  40. package/dist/XlsbReader.js +0 -186
  41. package/dist/XlsbReader.js.map +0 -1
  42. package/dist/XlsbWriter.d.ts +0 -80
  43. package/dist/XlsbWriter.d.ts.map +0 -1
  44. package/dist/XlsbWriter.js +0 -964
  45. package/dist/XlsbWriter.js.map +0 -1
  46. package/dist/XlsxReader.d.ts +0 -30
  47. package/dist/XlsxReader.d.ts.map +0 -1
  48. package/dist/XlsxReader.js +0 -341
  49. package/dist/XlsxReader.js.map +0 -1
  50. package/dist/XlsxWriter.d.ts +0 -51
  51. package/dist/XlsxWriter.d.ts.map +0 -1
  52. package/dist/XlsxWriter.js +0 -632
  53. package/dist/XlsxWriter.js.map +0 -1
  54. package/dist/index.d.ts +0 -10
  55. package/dist/index.d.ts.map +0 -1
  56. package/dist/index.js +0 -29
  57. package/dist/index.js.map +0 -1
@@ -0,0 +1,3944 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ BiffReaderWriter: () => BiffReaderWriter,
34
+ BigBuffer: () => BigBuffer,
35
+ ExcelReaderAbstract: () => ExcelReaderAbstract,
36
+ F: () => F,
37
+ INVALID_SHEET_NAME_CHARS: () => INVALID_SHEET_NAME_CHARS,
38
+ ReaderFactory: () => ReaderFactory,
39
+ StreamingSheetState: () => StreamingSheetState,
40
+ XlsbReader: () => XlsbReader,
41
+ XlsbWriter: () => XlsbWriter,
42
+ XlsxReader: () => XlsxReader,
43
+ XlsxWriter: () => XlsxWriter,
44
+ applyHeaderWidths: () => applyHeaderWidths,
45
+ defaultColWidth: () => defaultColWidth,
46
+ getFormat: () => getFormat,
47
+ initColWidths: () => initColWidths,
48
+ isFormattedCell: () => isFormattedCell,
49
+ sanitizeSheetName: () => sanitizeSheetName,
50
+ unwrapCell: () => unwrapCell,
51
+ updateColWidthsFromRows: () => updateColWidthsFromRows
52
+ });
53
+ module.exports = __toCommonJS(index_exports);
54
+
55
+ // src/BigBuffer.ts
56
+ var import_buffer = require("buffer");
57
+ var BigBuffer = class {
58
+ constructor(chunkSize = 65536) {
59
+ this.chunkSize = chunkSize;
60
+ this.chunks = [];
61
+ this.currentBuffer = import_buffer.Buffer.alloc(chunkSize);
62
+ this.cursor = 0;
63
+ }
64
+ ensureCapacity(size) {
65
+ if (this.cursor + size > this.chunkSize) {
66
+ this._flush();
67
+ }
68
+ }
69
+ _ensureCapacity(size) {
70
+ this.ensureCapacity(size);
71
+ }
72
+ _flush() {
73
+ if (this.cursor > 0) {
74
+ this.chunks.push(this.currentBuffer.subarray(0, this.cursor));
75
+ this.currentBuffer = import_buffer.Buffer.alloc(this.chunkSize);
76
+ this.cursor = 0;
77
+ }
78
+ }
79
+ write(buffer) {
80
+ let len = buffer.length;
81
+ let offset = 0;
82
+ while (len > 0) {
83
+ let available = this.chunkSize - this.cursor;
84
+ if (available === 0) {
85
+ this._flush();
86
+ available = this.chunkSize;
87
+ }
88
+ const toWrite = Math.min(len, available);
89
+ buffer.copy(this.currentBuffer, this.cursor, offset, offset + toWrite);
90
+ this.cursor += toWrite;
91
+ offset += toWrite;
92
+ len -= toWrite;
93
+ }
94
+ }
95
+ writeByte(val) {
96
+ this._ensureCapacity(1);
97
+ this.currentBuffer[this.cursor] = val;
98
+ this.cursor++;
99
+ }
100
+ writeUnsafeByte(val) {
101
+ this.currentBuffer[this.cursor++] = val;
102
+ }
103
+ writeInt32LE(val) {
104
+ this._ensureCapacity(4);
105
+ this.currentBuffer.writeInt32LE(val, this.cursor);
106
+ this.cursor += 4;
107
+ }
108
+ writeUnsafeInt32LE(val) {
109
+ this.currentBuffer.writeInt32LE(val, this.cursor);
110
+ this.cursor += 4;
111
+ }
112
+ writeDoubleLE(val) {
113
+ this._ensureCapacity(8);
114
+ this.currentBuffer.writeDoubleLE(val, this.cursor);
115
+ this.cursor += 8;
116
+ }
117
+ writeUnsafeDoubleLE(val) {
118
+ this.currentBuffer.writeDoubleLE(val, this.cursor);
119
+ this.cursor += 8;
120
+ }
121
+ writeString(str) {
122
+ const byteLength = import_buffer.Buffer.byteLength(str, "utf8");
123
+ if (this.cursor + byteLength <= this.chunkSize) {
124
+ this.cursor += this.currentBuffer.write(str, this.cursor, "utf8");
125
+ return;
126
+ }
127
+ this._flush();
128
+ if (byteLength > this.chunkSize) {
129
+ this.chunks.push(import_buffer.Buffer.from(str, "utf8"));
130
+ } else {
131
+ this.cursor += this.currentBuffer.write(str, this.cursor, "utf8");
132
+ }
133
+ }
134
+ writeUtf16LE(str) {
135
+ const byteLength = str.length * 2;
136
+ if (this.cursor + byteLength <= this.chunkSize) {
137
+ for (let i = 0; i < str.length; i++) {
138
+ const code = str.charCodeAt(i);
139
+ this.currentBuffer[this.cursor++] = code & 255;
140
+ this.currentBuffer[this.cursor++] = code >> 8 & 255;
141
+ }
142
+ return;
143
+ }
144
+ this._flush();
145
+ if (byteLength > this.chunkSize) {
146
+ this.chunks.push(import_buffer.Buffer.from(str, "utf16le"));
147
+ } else {
148
+ for (let i = 0; i < str.length; i++) {
149
+ const code = str.charCodeAt(i);
150
+ this.currentBuffer[this.cursor++] = code & 255;
151
+ this.currentBuffer[this.cursor++] = code >> 8 & 255;
152
+ }
153
+ }
154
+ }
155
+ getChunks() {
156
+ if (this.cursor > 0) {
157
+ this.chunks.push(this.currentBuffer.subarray(0, this.cursor));
158
+ this.currentBuffer = import_buffer.Buffer.alloc(this.chunkSize);
159
+ this.cursor = 0;
160
+ }
161
+ return this.chunks;
162
+ }
163
+ reset() {
164
+ this.chunks = [];
165
+ this.cursor = 0;
166
+ }
167
+ };
168
+
169
+ // src/ExcelReaderAbstract.ts
170
+ var ExcelReaderAbstract = class {
171
+ constructor() {
172
+ this.fieldCount = 0;
173
+ this.rowCount = 0;
174
+ this.actualSheetName = "";
175
+ this.resultsCount = 0;
176
+ this._oaEpoch = Date.UTC(1899, 11, 30);
177
+ }
178
+ async close() {
179
+ }
180
+ dispose() {
181
+ }
182
+ getDateTimeFromOaDate(oaDate) {
183
+ const ms = oaDate * 864e5 + this._oaEpoch;
184
+ return new Date(ms);
185
+ }
186
+ };
187
+
188
+ // src/BiffReaderWriter.ts
189
+ var BiffReaderWriter = class {
190
+ constructor(buffer) {
191
+ this._isSheet = false;
192
+ this._workbookId = 0;
193
+ this._recId = null;
194
+ this._workbookName = null;
195
+ this._inCellXf = false;
196
+ this._inNumberFormat = false;
197
+ this._numberFormatIndex = 0;
198
+ this._format = 0;
199
+ this._formatString = null;
200
+ this._sharedStringValue = null;
201
+ this._sharedStringUniqueCount = 0;
202
+ this._cellType = 0;
203
+ this._intValue = 0;
204
+ this._doubleVal = 0;
205
+ this._boolValue = false;
206
+ this._stringValue = null;
207
+ this._columnNum = -1;
208
+ this._xfIndex = 0;
209
+ this._readCell = false;
210
+ this._rowIndex = -1;
211
+ // Start of the current record data (excluding ID and Length)
212
+ this._recordStart = 0;
213
+ this._xfIndexToNumFmtId = [];
214
+ this._customNumFmts = /* @__PURE__ */ new Set();
215
+ if (!Buffer.isBuffer(buffer)) {
216
+ throw new Error("BiffReaderWriter expects a Buffer");
217
+ }
218
+ this.buffer = buffer;
219
+ this.pos = 0;
220
+ this.length = buffer.length;
221
+ }
222
+ _tryReadVariableValue() {
223
+ if (this.pos >= this.length) return null;
224
+ const b1 = this.buffer[this.pos++];
225
+ let value = (b1 & 127) >>> 0;
226
+ if ((b1 & 128) === 0) return value;
227
+ if (this.pos >= this.length) return null;
228
+ const b2 = this.buffer[this.pos++];
229
+ value = ((b2 & 127) << 7 | value) >>> 0;
230
+ if ((b2 & 128) === 0) return value;
231
+ if (this.pos >= this.length) return null;
232
+ const b3 = this.buffer[this.pos++];
233
+ value = ((b3 & 127) << 14 | value) >>> 0;
234
+ if ((b3 & 128) === 0) return value;
235
+ if (this.pos >= this.length) return null;
236
+ const b4 = this.buffer[this.pos++];
237
+ value = ((b4 & 127) << 21 | value) >>> 0;
238
+ return value;
239
+ }
240
+ _getDWord(offset) {
241
+ return this.buffer.readUInt32LE(this._recordStart + offset);
242
+ }
243
+ _getInt32(offset) {
244
+ return this.buffer.readInt32LE(this._recordStart + offset);
245
+ }
246
+ _getWord(offset) {
247
+ return this.buffer.readUInt16LE(this._recordStart + offset);
248
+ }
249
+ _getByte(offset) {
250
+ return this.buffer[this._recordStart + offset];
251
+ }
252
+ _getDouble(offset) {
253
+ return this.buffer.readDoubleLE(this._recordStart + offset);
254
+ }
255
+ _getString(offset, length) {
256
+ const start = this._recordStart + offset;
257
+ const end = start + length * 2;
258
+ if (end > this.buffer.length) return "";
259
+ return this.buffer.toString("utf16le", start, end);
260
+ }
261
+ _getNullableString(offsetRef) {
262
+ const length = this._getDWord(offsetRef.val);
263
+ offsetRef.val += 4;
264
+ if (length === 4294967295) return null;
265
+ const str = this._getString(offsetRef.val, length);
266
+ offsetRef.val += length * 2;
267
+ return str;
268
+ }
269
+ readWorkbook() {
270
+ const recordId = this._tryReadVariableValue();
271
+ const recordLength = this._tryReadVariableValue();
272
+ if (recordId === null || recordLength === null) return false;
273
+ const startPos = this.pos;
274
+ if (startPos + recordLength > this.length) return false;
275
+ this._recordStart = startPos;
276
+ this.pos += recordLength;
277
+ this._isSheet = false;
278
+ if (recordId === 156) {
279
+ this._workbookId = this._getDWord(4);
280
+ const offsetRef = { val: 8 };
281
+ this._recId = this._getNullableString(offsetRef);
282
+ const nameLength = this._getDWord(offsetRef.val);
283
+ this._workbookName = this._getString(offsetRef.val + 4, nameLength);
284
+ this._isSheet = true;
285
+ }
286
+ return true;
287
+ }
288
+ readSharedStrings() {
289
+ const recordId = this._tryReadVariableValue();
290
+ const recordLength = this._tryReadVariableValue();
291
+ if (recordId === null || recordLength === null) return false;
292
+ const startPos = this.pos;
293
+ if (startPos + recordLength > this.length) return false;
294
+ this._recordStart = startPos;
295
+ this.pos += recordLength;
296
+ this._sharedStringValue = null;
297
+ if (recordId === 19) {
298
+ const length = this._getDWord(1);
299
+ this._sharedStringValue = this._getString(5, length);
300
+ } else if (recordId === 159) {
301
+ this._sharedStringUniqueCount = this._getDWord(4);
302
+ }
303
+ return true;
304
+ }
305
+ readStyles() {
306
+ const recordId = this._tryReadVariableValue();
307
+ const recordLength = this._tryReadVariableValue();
308
+ if (recordId === null || recordLength === null) return false;
309
+ const startPos = this.pos;
310
+ if (startPos + recordLength > this.length) return false;
311
+ this._recordStart = startPos;
312
+ this.pos += recordLength;
313
+ const _cellXfStart = 617;
314
+ const _cellXfEnd = 618;
315
+ const _numberFormatStart = 615;
316
+ const _numberFormatEnd = 616;
317
+ const _xf = 47;
318
+ const _numberFormat = 44;
319
+ switch (recordId) {
320
+ case _cellXfStart:
321
+ this._inCellXf = true;
322
+ break;
323
+ case _cellXfEnd:
324
+ this._inCellXf = false;
325
+ break;
326
+ case _numberFormatStart:
327
+ this._inNumberFormat = true;
328
+ break;
329
+ case _numberFormatEnd:
330
+ this._inNumberFormat = false;
331
+ break;
332
+ case _xf:
333
+ if (this._inCellXf) {
334
+ this._numberFormatIndex = this._getWord(2);
335
+ this._xfIndexToNumFmtId.push(this._numberFormatIndex);
336
+ }
337
+ break;
338
+ case _numberFormat:
339
+ if (this._inNumberFormat) {
340
+ this._format = this._getWord(0);
341
+ const length = this._getDWord(2);
342
+ this._formatString = this._getString(6, length);
343
+ const code = this._formatString.toLowerCase();
344
+ if (code.includes("yy") || code.includes("mm") || code.includes("dd") || code.includes("h:mm")) {
345
+ this._customNumFmts.add(this._format);
346
+ }
347
+ }
348
+ break;
349
+ }
350
+ return true;
351
+ }
352
+ _getRkNumber(offset) {
353
+ const flags = this._getByte(offset);
354
+ let result = 0;
355
+ if ((flags & 2) !== 0) {
356
+ const intVal = this._getInt32(offset);
357
+ result = intVal >> 2;
358
+ } else {
359
+ const raw = this._getInt32(offset);
360
+ const highBits = raw & 4294967292;
361
+ const dBuf = Buffer.allocUnsafe(8);
362
+ dBuf.writeInt32LE(0, 0);
363
+ dBuf.writeInt32LE(highBits, 4);
364
+ result = dBuf.readDoubleLE(0);
365
+ }
366
+ if ((flags & 1) !== 0) {
367
+ result /= 100;
368
+ }
369
+ return result;
370
+ }
371
+ readWorksheet() {
372
+ const recordId = this._tryReadVariableValue();
373
+ const recordLength = this._tryReadVariableValue();
374
+ if (recordId === null || recordLength === null) return false;
375
+ const startPos = this.pos;
376
+ if (startPos + recordLength > this.length) return false;
377
+ this._recordStart = startPos;
378
+ this.pos += recordLength;
379
+ this._readCell = false;
380
+ this._columnNum = -1;
381
+ const _row = 0;
382
+ const _blank = 1;
383
+ const _number = 2;
384
+ const _boolError = 3;
385
+ const _bool = 4;
386
+ const _float = 5;
387
+ const _string = 6;
388
+ const _sharedString = 7;
389
+ const _formulaString = 8;
390
+ const _formulaNumber = 9;
391
+ const _formulaBool = 10;
392
+ const _formulaError = 11;
393
+ switch (recordId) {
394
+ case _row:
395
+ this._rowIndex = this._getInt32(0);
396
+ break;
397
+ case _blank:
398
+ case _boolError:
399
+ case _formulaError:
400
+ this._readCell = true;
401
+ this._cellType = 0;
402
+ break;
403
+ case _number:
404
+ this._doubleVal = this._getRkNumber(8);
405
+ this._readCell = true;
406
+ this._cellType = 3;
407
+ break;
408
+ case _bool:
409
+ case _formulaBool:
410
+ this._boolValue = this._getByte(8) === 1;
411
+ this._readCell = true;
412
+ this._cellType = 4;
413
+ break;
414
+ case _formulaNumber:
415
+ case _float:
416
+ this._doubleVal = this._getDouble(8);
417
+ this._readCell = true;
418
+ this._cellType = 3;
419
+ break;
420
+ case _string:
421
+ case _formulaString: {
422
+ const length = this._getDWord(8);
423
+ this._stringValue = this._getString(12, length);
424
+ this._readCell = true;
425
+ this._cellType = 5;
426
+ break;
427
+ }
428
+ case _sharedString:
429
+ this._intValue = this._getDWord(8);
430
+ this._readCell = true;
431
+ this._cellType = 2;
432
+ break;
433
+ }
434
+ if (this._readCell) {
435
+ this._columnNum = this._getDWord(0);
436
+ this._xfIndex = this._getDWord(4) & 16777215;
437
+ }
438
+ return true;
439
+ }
440
+ };
441
+
442
+ // src/XlsbReader.ts
443
+ var import_adm_zip = __toESM(require("adm-zip"));
444
+ var XlsbReader = class extends ExcelReaderAbstract {
445
+ constructor() {
446
+ super();
447
+ this.zip = null;
448
+ this.sharedStrings = [];
449
+ this.sheetNames = [];
450
+ this.sheets = [];
451
+ this._currentSheetIndex = -1;
452
+ this._reader = null;
453
+ this._currentRow = [];
454
+ this._pendingRowIndex = -1;
455
+ this._eof = false;
456
+ this.xfIdToNumFmtId = [];
457
+ this.customDateFormats = null;
458
+ }
459
+ async open(path2, readSharedStrings = true) {
460
+ this.zip = new import_adm_zip.default(path2);
461
+ const wbEntry = this.zip.getEntry("xl/workbook.bin");
462
+ if (wbEntry) {
463
+ const buf = wbEntry.getData();
464
+ const reader = new BiffReaderWriter(buf);
465
+ while (reader.readWorkbook()) {
466
+ if (reader._isSheet) {
467
+ const name = reader._workbookName;
468
+ const rId = reader._recId;
469
+ this.sheetNames.push(name);
470
+ this.sheets.push({ name, rId, path: null });
471
+ }
472
+ }
473
+ }
474
+ const relsEntry = this.zip.getEntry("xl/_rels/workbook.bin.rels");
475
+ if (relsEntry) {
476
+ const xml = relsEntry.getData().toString("utf8");
477
+ const relRegex = /<Relationship[^>]*Id="([^"]*)"[^>]*Target="([^"]*)"/g;
478
+ let match;
479
+ const rIdToTarget = {};
480
+ while ((match = relRegex.exec(xml)) !== null) {
481
+ rIdToTarget[match[1]] = match[2];
482
+ }
483
+ for (const sheet of this.sheets) {
484
+ let target = rIdToTarget[sheet.rId];
485
+ if (target) {
486
+ if (target.startsWith("/")) target = target.substring(1);
487
+ if (!target.startsWith("xl/")) target = "xl/" + target;
488
+ sheet.path = target;
489
+ }
490
+ }
491
+ }
492
+ if (readSharedStrings) {
493
+ const ssPath = "xl/sharedStrings.bin";
494
+ if (this.zip.getEntry(ssPath)) {
495
+ this._readSharedStrings(ssPath);
496
+ }
497
+ }
498
+ const stylesPath = "xl/styles.bin";
499
+ if (this.zip.getEntry(stylesPath)) {
500
+ this._readStyles(stylesPath);
501
+ }
502
+ this.resultsCount = this.sheets.length;
503
+ this._currentSheetIndex = -1;
504
+ }
505
+ _readSharedStrings(path2) {
506
+ const entry = this.zip.getEntry(path2);
507
+ if (!entry) return;
508
+ const reader = new BiffReaderWriter(entry.getData());
509
+ while (reader.readSharedStrings()) {
510
+ if (reader._sharedStringValue !== null) {
511
+ this.sharedStrings.push(reader._sharedStringValue);
512
+ }
513
+ }
514
+ }
515
+ _readStyles(path2) {
516
+ const entry = this.zip.getEntry(path2);
517
+ if (!entry) return;
518
+ const reader = new BiffReaderWriter(entry.getData());
519
+ while (reader.readStyles()) {
520
+ }
521
+ this.xfIdToNumFmtId = reader._xfIndexToNumFmtId;
522
+ this.customDateFormats = reader._customNumFmts;
523
+ }
524
+ getSheetNames() {
525
+ return this.sheetNames;
526
+ }
527
+ async read() {
528
+ if (this._currentSheetIndex === -1) {
529
+ this._currentSheetIndex = 0;
530
+ if (!this._initSheet(0)) return false;
531
+ }
532
+ if (this._eof) return false;
533
+ this._currentRow = [];
534
+ while (true) {
535
+ const hasRecord = this._reader.readWorksheet();
536
+ if (!hasRecord) {
537
+ this._eof = true;
538
+ return true;
539
+ }
540
+ if (this._reader._rowIndex !== -1 && this._reader._rowIndex !== this._pendingRowIndex) {
541
+ this._pendingRowIndex = this._reader._rowIndex;
542
+ return true;
543
+ }
544
+ if (this._reader._readCell) {
545
+ const col = this._reader._columnNum;
546
+ let val = null;
547
+ switch (this._reader._cellType) {
548
+ case 2:
549
+ val = this.sharedStrings[this._reader._intValue];
550
+ break;
551
+ case 3: {
552
+ val = this._reader._doubleVal;
553
+ const xfIndex = this._reader._xfIndex;
554
+ let numFmtId = 0;
555
+ if (this.xfIdToNumFmtId && xfIndex < this.xfIdToNumFmtId.length) {
556
+ numFmtId = this.xfIdToNumFmtId[xfIndex];
557
+ }
558
+ const isDate = numFmtId >= 14 && numFmtId <= 22 || numFmtId >= 45 && numFmtId <= 47 || this.customDateFormats && this.customDateFormats.has(numFmtId);
559
+ if (isDate) {
560
+ try {
561
+ val = this.getDateTimeFromOaDate(val);
562
+ } catch {
563
+ }
564
+ }
565
+ break;
566
+ }
567
+ case 4:
568
+ val = this._reader._boolValue;
569
+ break;
570
+ case 5:
571
+ val = this._reader._stringValue;
572
+ break;
573
+ default:
574
+ val = null;
575
+ }
576
+ this._currentRow[col] = val;
577
+ if (col >= this.fieldCount) this.fieldCount = col + 1;
578
+ }
579
+ }
580
+ }
581
+ _initSheet(index) {
582
+ if (index >= this.sheets.length) return false;
583
+ const sheet = this.sheets[index];
584
+ const entry = this.zip.getEntry(sheet.path);
585
+ if (!entry) return false;
586
+ this._reader = new BiffReaderWriter(entry.getData());
587
+ this._eof = false;
588
+ this._pendingRowIndex = -1;
589
+ while (this._reader.readWorksheet()) {
590
+ if (this._reader._rowIndex !== -1) {
591
+ this._pendingRowIndex = this._reader._rowIndex;
592
+ return true;
593
+ }
594
+ }
595
+ this._eof = true;
596
+ return false;
597
+ }
598
+ getValue(i) {
599
+ if (i < 0 || i >= this._currentRow.length) return null;
600
+ return this._currentRow[i];
601
+ }
602
+ };
603
+
604
+ // src/XlsxReader.ts
605
+ var import_yauzl = __toESM(require("yauzl"));
606
+ var XlsxReader = class extends ExcelReaderAbstract {
607
+ constructor() {
608
+ super();
609
+ this.zipfile = null;
610
+ this.sharedStrings = [];
611
+ this.sheetNames = [];
612
+ this.sheets = [];
613
+ this.entries = /* @__PURE__ */ new Map();
614
+ this._currentSheetIndex = -1;
615
+ this._sheetXml = null;
616
+ this._xmlPos = 0;
617
+ this._currentRow = [];
618
+ this.xfIdToNumFmtId = [];
619
+ this.customDateFormats = /* @__PURE__ */ new Set();
620
+ }
621
+ async open(path2, readSharedStrings = true) {
622
+ return new Promise((resolve, reject) => {
623
+ import_yauzl.default.open(path2, { lazyEntries: true, autoClose: false }, async (err, zipfile) => {
624
+ if (err) return reject(err);
625
+ this.zipfile = zipfile;
626
+ this.entries = /* @__PURE__ */ new Map();
627
+ zipfile.on("entry", (entry) => {
628
+ this.entries.set(entry.fileName, entry);
629
+ zipfile.readEntry();
630
+ });
631
+ zipfile.on("end", async () => {
632
+ try {
633
+ const wbRelsContent = await this._readZipEntryContent("xl/_rels/workbook.xml.rels");
634
+ const rIdToTarget = {};
635
+ if (wbRelsContent) {
636
+ const relRegex = /<Relationship[^>]*Id="([^"]*)"[^>]*Target="([^"]*)"/g;
637
+ let match;
638
+ while ((match = relRegex.exec(wbRelsContent)) !== null) {
639
+ rIdToTarget[match[1]] = match[2];
640
+ }
641
+ }
642
+ const wbContent = await this._readZipEntryContent("xl/workbook.xml");
643
+ if (wbContent) {
644
+ const sheetRegex = /<sheet[^>]*name="([^"]*)"[^>]*sheetId="([^"]*)"[^>]*r:id="([^"]*)"/g;
645
+ let match;
646
+ while ((match = sheetRegex.exec(wbContent)) !== null) {
647
+ const name = this._unescapeXml(match[1]);
648
+ const sheetId = match[2];
649
+ const rId = match[3];
650
+ const target = rIdToTarget[rId];
651
+ let fullPath = target;
652
+ if (!fullPath.startsWith("xl/")) {
653
+ fullPath = "xl/" + fullPath;
654
+ }
655
+ this.sheetNames.push(name);
656
+ this.sheets.push({ name, sheetId, rId, path: fullPath });
657
+ }
658
+ }
659
+ if (readSharedStrings) {
660
+ const ssContent = await this._readZipEntryContent("xl/sharedStrings.xml");
661
+ if (ssContent) {
662
+ this._parseSharedStrings(ssContent);
663
+ }
664
+ }
665
+ const stylesContent = await this._readZipEntryContent("xl/styles.xml");
666
+ if (stylesContent) {
667
+ this._parseStyles(stylesContent);
668
+ }
669
+ this.resultsCount = this.sheets.length;
670
+ this._currentSheetIndex = -1;
671
+ resolve();
672
+ } catch (e) {
673
+ reject(e);
674
+ }
675
+ });
676
+ zipfile.readEntry();
677
+ });
678
+ });
679
+ }
680
+ async close() {
681
+ if (this.zipfile) {
682
+ this.zipfile.close();
683
+ }
684
+ }
685
+ async _readZipEntryContent(path2) {
686
+ const entry = this.entries.get(path2);
687
+ if (!entry) return null;
688
+ return new Promise((resolve, reject) => {
689
+ this.zipfile.openReadStream(entry, (err, readStream) => {
690
+ if (err) return reject(err);
691
+ const chunks = [];
692
+ readStream.on("data", (chunk) => chunks.push(chunk));
693
+ readStream.on("end", () => {
694
+ resolve(Buffer.concat(chunks).toString("utf8"));
695
+ });
696
+ readStream.on("error", reject);
697
+ });
698
+ });
699
+ }
700
+ _unescapeXml(str) {
701
+ if (!str) return "";
702
+ if (str.indexOf("&") === -1) return str;
703
+ return str.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'");
704
+ }
705
+ _parseSharedStrings(xml) {
706
+ let pos = 0;
707
+ while (true) {
708
+ const siStart = xml.indexOf("<si>", pos);
709
+ if (siStart === -1) break;
710
+ const siEnd = xml.indexOf("</si>", siStart);
711
+ if (siEnd === -1) break;
712
+ const content = xml.substring(siStart, siEnd);
713
+ let val = "";
714
+ let tPos = 0;
715
+ while (true) {
716
+ const tStart = content.indexOf("<t", tPos);
717
+ if (tStart === -1) break;
718
+ const tagEnd = content.indexOf(">", tStart);
719
+ const tEnd = content.indexOf("</t>", tagEnd);
720
+ if (tEnd === -1) break;
721
+ val += content.substring(tagEnd + 1, tEnd);
722
+ tPos = tEnd + 4;
723
+ }
724
+ this.sharedStrings.push(this._unescapeXml(val));
725
+ pos = siEnd + 5;
726
+ }
727
+ }
728
+ _parseStyles(xml) {
729
+ const numFmtRegex = /<numFmt\s+[^>]*numFmtId="(\d+)"[^>]*formatCode="([^"]*)"/g;
730
+ let match;
731
+ this.customDateFormats = /* @__PURE__ */ new Set();
732
+ while ((match = numFmtRegex.exec(xml)) !== null) {
733
+ const id = parseInt(match[1]);
734
+ const code = match[2];
735
+ if (code.toLowerCase().includes("yy") || code.toLowerCase().includes("mm") || code.toLowerCase().includes("dd") || code.toLowerCase().includes("h:mm")) {
736
+ this.customDateFormats.add(id);
737
+ }
738
+ }
739
+ this.xfIdToNumFmtId = [];
740
+ const cellXfsStart = xml.indexOf("<cellXfs");
741
+ if (cellXfsStart !== -1) {
742
+ const cellXfsEnd = xml.indexOf("</cellXfs>", cellXfsStart);
743
+ if (cellXfsEnd !== -1) {
744
+ const cellXfsContent = xml.substring(cellXfsStart, cellXfsEnd);
745
+ const xfRegex = /<xf\s+[^>]*numFmtId="(\d+)"/g;
746
+ while ((match = xfRegex.exec(cellXfsContent)) !== null) {
747
+ const numFmtId = parseInt(match[1]);
748
+ this.xfIdToNumFmtId.push(numFmtId);
749
+ }
750
+ }
751
+ }
752
+ }
753
+ getSheetNames() {
754
+ return this.sheetNames;
755
+ }
756
+ async read() {
757
+ if (this._currentSheetIndex === -1) {
758
+ this._currentSheetIndex = 0;
759
+ await this._initSheet(this._currentSheetIndex);
760
+ }
761
+ if (this._readNextRow()) {
762
+ return true;
763
+ } else {
764
+ return false;
765
+ }
766
+ }
767
+ async _initSheet(index) {
768
+ if (index >= this.sheets.length) return;
769
+ const sheet = this.sheets[index];
770
+ this.actualSheetName = sheet.name;
771
+ this._sheetXml = await this._readZipEntryContent(sheet.path);
772
+ if (!this._sheetXml) {
773
+ this._sheetXml = "";
774
+ }
775
+ this._xmlPos = 0;
776
+ const sd = this._sheetXml.indexOf("<sheetData>");
777
+ if (sd !== -1) this._xmlPos = sd + 11;
778
+ }
779
+ _readNextRow() {
780
+ if (!this._sheetXml) return false;
781
+ const rowStart = this._sheetXml.indexOf("<row", this._xmlPos);
782
+ if (rowStart === -1) return false;
783
+ const rowEnd = this._sheetXml.indexOf("</row>", rowStart);
784
+ if (rowEnd === -1) return false;
785
+ this._xmlPos = rowEnd + 6;
786
+ this._parseRowByIndex(rowStart, rowEnd);
787
+ return true;
788
+ }
789
+ _parseRowByIndex(rowStart, rowEnd) {
790
+ this._currentRow = [];
791
+ const xml = this._sheetXml;
792
+ let pos = xml.indexOf(">", rowStart) + 1;
793
+ while (pos < rowEnd) {
794
+ const cStart = xml.indexOf("<c", pos);
795
+ if (cStart === -1 || cStart >= rowEnd) break;
796
+ const nextTagClose = xml.indexOf(">", cStart);
797
+ let colIndex = -1;
798
+ let type = "n";
799
+ let styleIndex = 0;
800
+ let currentIdx = cStart + 2;
801
+ while (currentIdx < nextTagClose) {
802
+ while (xml.charCodeAt(currentIdx) <= 32 && currentIdx < nextTagClose) currentIdx++;
803
+ if (currentIdx >= nextTagClose) break;
804
+ const keyStart = currentIdx;
805
+ while (xml.charCodeAt(currentIdx) !== 61 && currentIdx < nextTagClose) currentIdx++;
806
+ const key = xml.substring(keyStart, currentIdx);
807
+ currentIdx++;
808
+ if (xml.charCodeAt(currentIdx) === 34) {
809
+ currentIdx++;
810
+ const valStart = currentIdx;
811
+ while (xml.charCodeAt(currentIdx) !== 34 && currentIdx < nextTagClose) currentIdx++;
812
+ const val2 = xml.substring(valStart, currentIdx);
813
+ currentIdx++;
814
+ if (key === "r") {
815
+ let letterLen = 0;
816
+ while (letterLen < val2.length && val2.charCodeAt(letterLen) >= 65) letterLen++;
817
+ colIndex = this._columnLetterToIndex(val2.substring(0, letterLen));
818
+ } else if (key === "t") {
819
+ type = val2;
820
+ } else if (key === "s") {
821
+ styleIndex = parseInt(val2, 10);
822
+ }
823
+ }
824
+ }
825
+ let val = null;
826
+ if (xml.charCodeAt(nextTagClose - 1) === 47) {
827
+ pos = nextTagClose + 1;
828
+ } else {
829
+ const cEnd = xml.indexOf("</c>", nextTagClose);
830
+ const cellContentEnd = cEnd !== -1 && cEnd < rowEnd ? cEnd : rowEnd;
831
+ const vStart = xml.indexOf("<v>", nextTagClose);
832
+ if (vStart !== -1 && vStart < cellContentEnd) {
833
+ const vInnerStart = vStart + 3;
834
+ const vEnd = xml.indexOf("</v>", vInnerStart);
835
+ if (vEnd !== -1 && vEnd < cellContentEnd) {
836
+ val = xml.substring(vInnerStart, vEnd);
837
+ }
838
+ } else {
839
+ if (type === "inlineStr") {
840
+ const tStart = xml.indexOf("<t", nextTagClose);
841
+ if (tStart !== -1 && tStart < cellContentEnd) {
842
+ const tContentStart = xml.indexOf(">", tStart) + 1;
843
+ const tEnd = xml.indexOf("</t>", tContentStart);
844
+ if (tEnd !== -1 && tEnd < cellContentEnd) {
845
+ val = xml.substring(tContentStart, tEnd);
846
+ }
847
+ }
848
+ }
849
+ }
850
+ pos = cellContentEnd + 4;
851
+ }
852
+ let finalVal = null;
853
+ if (val !== null) {
854
+ if (type === "s") {
855
+ const idx = parseInt(val, 10);
856
+ finalVal = this.sharedStrings[idx];
857
+ } else if (type === "b") {
858
+ finalVal = val === "1" || val === "true";
859
+ } else if (type === "inlineStr") {
860
+ finalVal = this._unescapeXml(val);
861
+ } else if (type === "n" || type === "") {
862
+ finalVal = parseFloat(val);
863
+ if (styleIndex > 0 && this.xfIdToNumFmtId) {
864
+ let numFmtId = 0;
865
+ if (styleIndex < this.xfIdToNumFmtId.length) {
866
+ numFmtId = this.xfIdToNumFmtId[styleIndex];
867
+ }
868
+ const isDate = numFmtId >= 14 && numFmtId <= 22 || numFmtId >= 45 && numFmtId <= 47 || this.customDateFormats && this.customDateFormats.has(numFmtId);
869
+ if (isDate) {
870
+ try {
871
+ finalVal = this.getDateTimeFromOaDate(finalVal);
872
+ } catch {
873
+ }
874
+ }
875
+ }
876
+ }
877
+ }
878
+ if (colIndex !== -1) {
879
+ this._currentRow[colIndex] = finalVal;
880
+ if (colIndex >= this.fieldCount) this.fieldCount = colIndex + 1;
881
+ }
882
+ }
883
+ }
884
+ _columnLetterToIndex(letter) {
885
+ let column = 0;
886
+ const length = letter.length;
887
+ for (let i = 0; i < length; i++) {
888
+ column += (letter.charCodeAt(i) - 64) * Math.pow(26, length - i - 1);
889
+ }
890
+ return column - 1;
891
+ }
892
+ getValue(i) {
893
+ if (i < 0 || i >= this._currentRow.length) return null;
894
+ return this._currentRow[i];
895
+ }
896
+ };
897
+
898
+ // src/ReaderFactory.ts
899
+ var path = __toESM(require("path"));
900
+ var ReaderFactory = class {
901
+ /**
902
+ * @param filePath Path ending in `.xlsb` or `.xlsx`
903
+ * @throws if the extension is unsupported
904
+ */
905
+ static create(filePath) {
906
+ const ext = path.extname(filePath).toLowerCase();
907
+ if (ext === ".xlsx") {
908
+ return new XlsxReader();
909
+ } else if (ext === ".xlsb") {
910
+ return new XlsbReader();
911
+ } else {
912
+ throw new Error(`Unsupported extension: ${ext}`);
913
+ }
914
+ }
915
+ };
916
+
917
+ // src/XlsbWriter.ts
918
+ var fs = __toESM(require("fs"));
919
+ var import_archiver = __toESM(require("archiver"));
920
+ var import_stream = require("stream");
921
+
922
+ // src/Formats.ts
923
+ var F = {
924
+ THOUSANDS_SEP: "#,##0",
925
+ CURRENCY_PLN: '#,##0.00 "z\u0142"',
926
+ CURRENCY_EUR: "#,##0.00 \u20AC",
927
+ PERCENTAGE: "0%",
928
+ SCIENTIFIC: "0.00E+00",
929
+ TWO_DECIMALS: "#,##0.00",
930
+ TEXT: "@",
931
+ LEADING_ZEROS: "000000000",
932
+ DATE_SHORT: "dd.mm.yyyy",
933
+ DATE_LONG: "d mmmm yyyy",
934
+ DATE_DAY_MONTH_YEAR: "dd-mm-yyyy",
935
+ DATE_ISO: "yyyy-mm-dd",
936
+ DATE_MONTH_YEAR: "mmmm yyyy",
937
+ DATE_WEEKDAY: "dddd, d mmmm yyyy",
938
+ DATE_DAY_MONTH: "d mmmm",
939
+ DATE_YEAR_ONLY: "yyyy",
940
+ DATETIME_SHORT: "dd.mm.yyyy hh:mm",
941
+ DATETIME_LONG: "d mmmm yyyy hh:mm:ss",
942
+ TIME_HH_MM: "hh:mm",
943
+ TIME_HH_MM_SS: "hh:mm:ss",
944
+ TIME_12H: "h:mm AM/PM",
945
+ DATETIME_24H: "dd.mm.yyyy hh:mm:ss",
946
+ DATETIME_ISO: 'yyyy-mm-dd"T"hh:mm:ss',
947
+ TIME_MS: "hh:mm:ss.000"
948
+ };
949
+ function isFormattedCell(val) {
950
+ return val !== null && val !== void 0 && typeof val === "object" && "format" in val && typeof val.format === "string";
951
+ }
952
+ function unwrapCell(val) {
953
+ if (isFormattedCell(val)) {
954
+ return val.value;
955
+ }
956
+ return val;
957
+ }
958
+ function getFormat(val) {
959
+ if (isFormattedCell(val)) {
960
+ return val.format;
961
+ }
962
+ return null;
963
+ }
964
+
965
+ // src/writerHelpers.ts
966
+ var INVALID_SHEET_NAME_CHARS = /[\\/*?[\]:]/g;
967
+ function sanitizeSheetName(name, sheetCount) {
968
+ if (!name || typeof name !== "string") {
969
+ return `Sheet${sheetCount + 1}`;
970
+ }
971
+ let sanitized = name.replace(INVALID_SHEET_NAME_CHARS, "_");
972
+ if (sanitized.length > 31) {
973
+ sanitized = sanitized.substring(0, 31);
974
+ }
975
+ if (sanitized.trim().length === 0) {
976
+ sanitized = `Sheet${sheetCount + 1}`;
977
+ }
978
+ return sanitized;
979
+ }
980
+ function initColWidths(columnCount) {
981
+ return new Array(columnCount).fill(-1);
982
+ }
983
+ function applyHeaderWidths(colWidths, headers, columnCount) {
984
+ for (let i = 0; i < columnCount; i++) {
985
+ const len = headers[i] ? headers[i].length + 1 : 0;
986
+ let width = 1.25 * len + 2;
987
+ if (width > 80) width = 80;
988
+ if (colWidths[i] < width) colWidths[i] = width;
989
+ }
990
+ }
991
+ function updateColWidthsFromRows(colWidths, rows, sampleLimit = 100) {
992
+ for (let r = 0; r < Math.min(rows.length, sampleLimit); r++) {
993
+ const row = rows[r];
994
+ for (let c = 0; c < row.length; c++) {
995
+ const raw = row[c];
996
+ if (raw === null || raw === void 0) continue;
997
+ const val = isFormattedCell(raw) ? raw.value : raw;
998
+ const len = val instanceof Date ? 20 : String(val).length + 1;
999
+ let width = 1.25 * len + 2;
1000
+ if (width > 80) width = 80;
1001
+ if (colWidths[c] < width) colWidths[c] = width;
1002
+ }
1003
+ }
1004
+ }
1005
+ function defaultColWidth(width, floor = false) {
1006
+ if (width > 0) {
1007
+ return floor ? Math.floor(width) : width;
1008
+ }
1009
+ return 10;
1010
+ }
1011
+
1012
+ // src/StreamingSheetState.ts
1013
+ var StreamingSheetState = class {
1014
+ constructor() {
1015
+ this.isStreaming = false;
1016
+ this.rowNum = 0;
1017
+ this.startCol = 0;
1018
+ this.endCol = 0;
1019
+ this.doAutofilter = false;
1020
+ this.colWidths = [];
1021
+ this.buffer = null;
1022
+ }
1023
+ /**
1024
+ * Begin a streaming sheet session.
1025
+ * @throws if already streaming
1026
+ */
1027
+ begin(columnCount, doAutofilter, buffer) {
1028
+ if (this.isStreaming) {
1029
+ throw new Error("Already in streaming mode. Call endSheet() first.");
1030
+ }
1031
+ this.isStreaming = true;
1032
+ this.buffer = buffer;
1033
+ this.rowNum = 0;
1034
+ this.startCol = 0;
1035
+ this.endCol = columnCount;
1036
+ this.doAutofilter = doAutofilter;
1037
+ this.colWidths = initColWidths(columnCount);
1038
+ }
1039
+ /** Assert streaming mode and return the active buffer. */
1040
+ assertStreaming() {
1041
+ if (!this.isStreaming || !this.buffer) {
1042
+ throw new Error("Not in streaming mode. Call startSheet() first.");
1043
+ }
1044
+ return this.buffer;
1045
+ }
1046
+ /** Reset after endSheet(). */
1047
+ end() {
1048
+ this.isStreaming = false;
1049
+ this.buffer = null;
1050
+ this.rowNum = 0;
1051
+ this.startCol = 0;
1052
+ this.endCol = 0;
1053
+ this.doAutofilter = false;
1054
+ this.colWidths = [];
1055
+ }
1056
+ };
1057
+
1058
+ // src/XlsbWriter.ts
1059
+ var XlsbWriter = class _XlsbWriter {
1060
+ /**
1061
+ * @param filePath Destination `.xlsb` path on disk.
1062
+ */
1063
+ constructor(filePath) {
1064
+ this.sheetCount = 0;
1065
+ this.sheetList = [];
1066
+ this.sstDic = /* @__PURE__ */ new Map();
1067
+ this.sstCntUnique = 0;
1068
+ this.sstCntAll = 0;
1069
+ this._autofilterIsOn = false;
1070
+ this._nextFmtId = 167;
1071
+ this._nextXfIdx = 4;
1072
+ this._stFmtRecords = /* @__PURE__ */ new Map();
1073
+ this.stream = new StreamingSheetState();
1074
+ this.output = fs.createWriteStream(filePath);
1075
+ this.archive = (0, import_archiver.default)("zip");
1076
+ this.archive.pipe(this.output);
1077
+ this._oaEpoch = Date.UTC(1899, 11, 30);
1078
+ this._sheet1Bytes = Buffer.from([
1079
+ 129,
1080
+ 1,
1081
+ 0,
1082
+ 147,
1083
+ 1,
1084
+ 23,
1085
+ 203,
1086
+ 4,
1087
+ 2,
1088
+ 0,
1089
+ 64,
1090
+ 0,
1091
+ 0,
1092
+ 0,
1093
+ 0,
1094
+ 0,
1095
+ 0,
1096
+ 255,
1097
+ 255,
1098
+ 255,
1099
+ 255,
1100
+ 255,
1101
+ 255,
1102
+ 255,
1103
+ 255,
1104
+ 0,
1105
+ 0,
1106
+ 0,
1107
+ 0,
1108
+ 148,
1109
+ 1,
1110
+ 16,
1111
+ 0,
1112
+ 0,
1113
+ 0,
1114
+ 0,
1115
+ 0,
1116
+ 0,
1117
+ 0,
1118
+ 0,
1119
+ 0,
1120
+ 0,
1121
+ 0,
1122
+ 0,
1123
+ 0,
1124
+ 0,
1125
+ 0,
1126
+ 0,
1127
+ 133,
1128
+ 1,
1129
+ 0,
1130
+ 137,
1131
+ 1,
1132
+ 30,
1133
+ 220,
1134
+ 3,
1135
+ 0,
1136
+ 0,
1137
+ 0,
1138
+ 0,
1139
+ 0,
1140
+ 0,
1141
+ 0,
1142
+ 0,
1143
+ 0,
1144
+ 0,
1145
+ 0,
1146
+ 0,
1147
+ 64,
1148
+ 0,
1149
+ 0,
1150
+ 0,
1151
+ 100,
1152
+ 0,
1153
+ 0,
1154
+ 0,
1155
+ 0,
1156
+ 0,
1157
+ 0,
1158
+ 0,
1159
+ 0,
1160
+ 0,
1161
+ 0,
1162
+ 0,
1163
+ 152,
1164
+ 1,
1165
+ 36,
1166
+ 3,
1167
+ 0,
1168
+ 0,
1169
+ 0,
1170
+ 0,
1171
+ 0,
1172
+ 0,
1173
+ 0,
1174
+ 0,
1175
+ 0,
1176
+ 0,
1177
+ 0,
1178
+ 0,
1179
+ 0,
1180
+ 0,
1181
+ 0,
1182
+ 1,
1183
+ 0,
1184
+ 0,
1185
+ 0,
1186
+ 0,
1187
+ 0,
1188
+ 0,
1189
+ 0,
1190
+ 0,
1191
+ 0,
1192
+ 0,
1193
+ 0,
1194
+ 0,
1195
+ 0,
1196
+ 0,
1197
+ 0,
1198
+ 0,
1199
+ 0,
1200
+ 0,
1201
+ 0,
1202
+ 138,
1203
+ 1,
1204
+ 0,
1205
+ 134,
1206
+ 1,
1207
+ 0,
1208
+ 37,
1209
+ 6,
1210
+ 1,
1211
+ 0,
1212
+ 2,
1213
+ 14,
1214
+ 0,
1215
+ 128,
1216
+ 149,
1217
+ 8,
1218
+ 2,
1219
+ 5,
1220
+ 0,
1221
+ 38,
1222
+ 0,
1223
+ 229,
1224
+ 3,
1225
+ 12,
1226
+ 255,
1227
+ 255,
1228
+ 255,
1229
+ 255,
1230
+ 8,
1231
+ 0,
1232
+ 44,
1233
+ 1,
1234
+ 0,
1235
+ 0,
1236
+ 0,
1237
+ 0,
1238
+ 145,
1239
+ 1,
1240
+ 0,
1241
+ 37,
1242
+ 6,
1243
+ 1,
1244
+ 0,
1245
+ 2,
1246
+ 14,
1247
+ 0,
1248
+ 128,
1249
+ 128,
1250
+ 8,
1251
+ 2,
1252
+ 5,
1253
+ 0,
1254
+ 38,
1255
+ 0,
1256
+ 0,
1257
+ 25,
1258
+ 0,
1259
+ 0,
1260
+ 0,
1261
+ 0,
1262
+ 0,
1263
+ 0,
1264
+ 0,
1265
+ 0,
1266
+ 44,
1267
+ 1,
1268
+ 0,
1269
+ 0,
1270
+ 0,
1271
+ 1,
1272
+ 0,
1273
+ 0,
1274
+ 0,
1275
+ 0,
1276
+ 0,
1277
+ 0,
1278
+ 0,
1279
+ 0,
1280
+ 0,
1281
+ 0,
1282
+ 0,
1283
+ 7,
1284
+ 12,
1285
+ 0,
1286
+ 0,
1287
+ 0,
1288
+ 0,
1289
+ 0,
1290
+ 0,
1291
+ 0,
1292
+ 0,
1293
+ 0,
1294
+ 0,
1295
+ 0,
1296
+ 0,
1297
+ 146,
1298
+ 1,
1299
+ 0,
1300
+ 151,
1301
+ 4,
1302
+ 66,
1303
+ 0,
1304
+ 0,
1305
+ 0,
1306
+ 0,
1307
+ 0,
1308
+ 0,
1309
+ 1,
1310
+ 0,
1311
+ 0,
1312
+ 0,
1313
+ 1,
1314
+ 0,
1315
+ 0,
1316
+ 0,
1317
+ 0,
1318
+ 0,
1319
+ 0,
1320
+ 0,
1321
+ 0,
1322
+ 0,
1323
+ 0,
1324
+ 0,
1325
+ 0,
1326
+ 0,
1327
+ 0,
1328
+ 0,
1329
+ 0,
1330
+ 0,
1331
+ 0,
1332
+ 0,
1333
+ 0,
1334
+ 0,
1335
+ 0,
1336
+ 0,
1337
+ 0,
1338
+ 0,
1339
+ 0,
1340
+ 0,
1341
+ 0,
1342
+ 0,
1343
+ 0,
1344
+ 0,
1345
+ 0,
1346
+ 0,
1347
+ 0,
1348
+ 0,
1349
+ 1,
1350
+ 0,
1351
+ 0,
1352
+ 0,
1353
+ 0,
1354
+ 0,
1355
+ 0,
1356
+ 0,
1357
+ 0,
1358
+ 0,
1359
+ 0,
1360
+ 0,
1361
+ 0,
1362
+ 0,
1363
+ 0,
1364
+ 0,
1365
+ 1,
1366
+ 0,
1367
+ 0,
1368
+ 0,
1369
+ 221,
1370
+ 3,
1371
+ 2,
1372
+ 16,
1373
+ 0,
1374
+ 220,
1375
+ 3,
1376
+ 48,
1377
+ 102,
1378
+ 102,
1379
+ 102,
1380
+ 102,
1381
+ 102,
1382
+ 102,
1383
+ 230,
1384
+ 63,
1385
+ 102,
1386
+ 102,
1387
+ 102,
1388
+ 102,
1389
+ 102,
1390
+ 102,
1391
+ 230,
1392
+ 63,
1393
+ 0,
1394
+ 0,
1395
+ 0,
1396
+ 0,
1397
+ 0,
1398
+ 0,
1399
+ 232,
1400
+ 63,
1401
+ 0,
1402
+ 0,
1403
+ 0,
1404
+ 0,
1405
+ 0,
1406
+ 0,
1407
+ 232,
1408
+ 63,
1409
+ 51,
1410
+ 51,
1411
+ 51,
1412
+ 51,
1413
+ 51,
1414
+ 51,
1415
+ 211,
1416
+ 63,
1417
+ 51,
1418
+ 51,
1419
+ 51,
1420
+ 51,
1421
+ 51,
1422
+ 51,
1423
+ 211,
1424
+ 63,
1425
+ 37,
1426
+ 6,
1427
+ 1,
1428
+ 0,
1429
+ 0,
1430
+ 16,
1431
+ 0,
1432
+ 128,
1433
+ 128,
1434
+ 24,
1435
+ 16,
1436
+ 0,
1437
+ 0,
1438
+ 0,
1439
+ 0,
1440
+ 1,
1441
+ 0,
1442
+ 0,
1443
+ 0,
1444
+ 0,
1445
+ 0,
1446
+ 0,
1447
+ 0,
1448
+ 0,
1449
+ 0,
1450
+ 0,
1451
+ 0,
1452
+ 38,
1453
+ 0,
1454
+ 130,
1455
+ 1,
1456
+ 0
1457
+ ]);
1458
+ this._workbookBinStart = Buffer.from([
1459
+ 131,
1460
+ 1,
1461
+ 0,
1462
+ 128,
1463
+ 1,
1464
+ 50,
1465
+ 0,
1466
+ 0,
1467
+ 0,
1468
+ 0,
1469
+ 0,
1470
+ 0,
1471
+ 0,
1472
+ 0,
1473
+ 0,
1474
+ 0,
1475
+ 0,
1476
+ 0,
1477
+ 0,
1478
+ 0,
1479
+ 0,
1480
+ 0,
1481
+ 2,
1482
+ 0,
1483
+ 0,
1484
+ 0,
1485
+ 120,
1486
+ 0,
1487
+ 108,
1488
+ 0,
1489
+ 1,
1490
+ 0,
1491
+ 0,
1492
+ 0,
1493
+ 55,
1494
+ 0,
1495
+ 1,
1496
+ 0,
1497
+ 0,
1498
+ 0,
1499
+ 54,
1500
+ 0,
1501
+ 5,
1502
+ 0,
1503
+ 0,
1504
+ 0,
1505
+ 50,
1506
+ 0,
1507
+ 52,
1508
+ 0,
1509
+ 51,
1510
+ 0,
1511
+ 50,
1512
+ 0,
1513
+ 54,
1514
+ 0,
1515
+ 153,
1516
+ 1,
1517
+ 12,
1518
+ 32,
1519
+ 0,
1520
+ 1,
1521
+ 0,
1522
+ 0,
1523
+ 0,
1524
+ 0,
1525
+ 0,
1526
+ 0,
1527
+ 0,
1528
+ 0,
1529
+ 0,
1530
+ 37,
1531
+ 6,
1532
+ 1,
1533
+ 0,
1534
+ 3,
1535
+ 15,
1536
+ 0,
1537
+ 128,
1538
+ 151,
1539
+ 16,
1540
+ 52,
1541
+ 24,
1542
+ 0,
1543
+ 0,
1544
+ 0,
1545
+ 67,
1546
+ 0,
1547
+ 58,
1548
+ 0,
1549
+ 92,
1550
+ 0,
1551
+ 115,
1552
+ 0,
1553
+ 113,
1554
+ 0,
1555
+ 108,
1556
+ 0,
1557
+ 115,
1558
+ 0,
1559
+ 92,
1560
+ 0,
1561
+ 84,
1562
+ 0,
1563
+ 101,
1564
+ 0,
1565
+ 115,
1566
+ 0,
1567
+ 116,
1568
+ 0,
1569
+ 121,
1570
+ 0,
1571
+ 90,
1572
+ 0,
1573
+ 97,
1574
+ 0,
1575
+ 112,
1576
+ 0,
1577
+ 105,
1578
+ 0,
1579
+ 115,
1580
+ 0,
1581
+ 117,
1582
+ 0,
1583
+ 88,
1584
+ 0,
1585
+ 108,
1586
+ 0,
1587
+ 115,
1588
+ 0,
1589
+ 98,
1590
+ 0,
1591
+ 92,
1592
+ 0,
1593
+ 38,
1594
+ 0,
1595
+ 37,
1596
+ 6,
1597
+ 1,
1598
+ 0,
1599
+ 0,
1600
+ 16,
1601
+ 0,
1602
+ 128,
1603
+ 129,
1604
+ 24,
1605
+ 130,
1606
+ 1,
1607
+ 0,
1608
+ 0,
1609
+ 0,
1610
+ 0,
1611
+ 0,
1612
+ 0,
1613
+ 0,
1614
+ 0,
1615
+ 47,
1616
+ 0,
1617
+ 0,
1618
+ 0,
1619
+ 49,
1620
+ 0,
1621
+ 51,
1622
+ 0,
1623
+ 95,
1624
+ 0,
1625
+ 110,
1626
+ 0,
1627
+ 99,
1628
+ 0,
1629
+ 114,
1630
+ 0,
1631
+ 58,
1632
+ 0,
1633
+ 49,
1634
+ 0,
1635
+ 95,
1636
+ 0,
1637
+ 123,
1638
+ 0,
1639
+ 49,
1640
+ 0,
1641
+ 54,
1642
+ 0,
1643
+ 53,
1644
+ 0,
1645
+ 48,
1646
+ 0,
1647
+ 56,
1648
+ 0,
1649
+ 68,
1650
+ 0,
1651
+ 54,
1652
+ 0,
1653
+ 57,
1654
+ 0,
1655
+ 45,
1656
+ 0,
1657
+ 67,
1658
+ 0,
1659
+ 70,
1660
+ 0,
1661
+ 56,
1662
+ 0,
1663
+ 55,
1664
+ 0,
1665
+ 45,
1666
+ 0,
1667
+ 52,
1668
+ 0,
1669
+ 55,
1670
+ 0,
1671
+ 54,
1672
+ 0,
1673
+ 57,
1674
+ 0,
1675
+ 45,
1676
+ 0,
1677
+ 56,
1678
+ 0,
1679
+ 52,
1680
+ 0,
1681
+ 53,
1682
+ 0,
1683
+ 54,
1684
+ 0,
1685
+ 45,
1686
+ 0,
1687
+ 68,
1688
+ 0,
1689
+ 52,
1690
+ 0,
1691
+ 65,
1692
+ 0,
1693
+ 52,
1694
+ 0,
1695
+ 48,
1696
+ 0,
1697
+ 49,
1698
+ 0,
1699
+ 49,
1700
+ 0,
1701
+ 51,
1702
+ 0,
1703
+ 49,
1704
+ 0,
1705
+ 53,
1706
+ 0,
1707
+ 54,
1708
+ 0,
1709
+ 55,
1710
+ 0,
1711
+ 125,
1712
+ 0,
1713
+ 47,
1714
+ 0,
1715
+ 0,
1716
+ 0,
1717
+ 47,
1718
+ 0,
1719
+ 0,
1720
+ 0,
1721
+ 0,
1722
+ 0,
1723
+ 0,
1724
+ 0,
1725
+ 0,
1726
+ 0,
1727
+ 0,
1728
+ 0,
1729
+ 0,
1730
+ 0,
1731
+ 0,
1732
+ 0,
1733
+ 0,
1734
+ 0,
1735
+ 0,
1736
+ 0,
1737
+ 38,
1738
+ 0,
1739
+ 135,
1740
+ 1,
1741
+ 0,
1742
+ 37,
1743
+ 6,
1744
+ 1,
1745
+ 0,
1746
+ 2,
1747
+ 16,
1748
+ 0,
1749
+ 128,
1750
+ 128,
1751
+ 24,
1752
+ 16,
1753
+ 0,
1754
+ 0,
1755
+ 0,
1756
+ 0,
1757
+ 13,
1758
+ 0,
1759
+ 0,
1760
+ 0,
1761
+ 255,
1762
+ 255,
1763
+ 255,
1764
+ 255,
1765
+ 0,
1766
+ 0,
1767
+ 0,
1768
+ 0,
1769
+ 38,
1770
+ 0,
1771
+ 158,
1772
+ 1,
1773
+ 29,
1774
+ 0,
1775
+ 0,
1776
+ 0,
1777
+ 0,
1778
+ 158,
1779
+ 22,
1780
+ 0,
1781
+ 0,
1782
+ 180,
1783
+ 105,
1784
+ 0,
1785
+ 0,
1786
+ 232,
1787
+ 38,
1788
+ 0,
1789
+ 0,
1790
+ 88,
1791
+ 2,
1792
+ 0,
1793
+ 0,
1794
+ 0,
1795
+ 0,
1796
+ 0,
1797
+ 0,
1798
+ 0,
1799
+ 0,
1800
+ 0,
1801
+ 0,
1802
+ 120,
1803
+ 136,
1804
+ 1,
1805
+ 0,
1806
+ 143,
1807
+ 1,
1808
+ 0
1809
+ ]);
1810
+ this._workbookBinMiddle = Buffer.from([144, 1, 0]);
1811
+ this._workbookBinEnd = Buffer.from([
1812
+ 157,
1813
+ 1,
1814
+ 26,
1815
+ 53,
1816
+ 234,
1817
+ 2,
1818
+ 0,
1819
+ 1,
1820
+ 0,
1821
+ 0,
1822
+ 0,
1823
+ 100,
1824
+ 0,
1825
+ 0,
1826
+ 0,
1827
+ 252,
1828
+ 169,
1829
+ 241,
1830
+ 210,
1831
+ 77,
1832
+ 98,
1833
+ 80,
1834
+ 63,
1835
+ 1,
1836
+ 0,
1837
+ 0,
1838
+ 0,
1839
+ 106,
1840
+ 0,
1841
+ 155,
1842
+ 1,
1843
+ 1,
1844
+ 0,
1845
+ 35,
1846
+ 4,
1847
+ 3,
1848
+ 15,
1849
+ 0,
1850
+ 0,
1851
+ 171,
1852
+ 16,
1853
+ 1,
1854
+ 1,
1855
+ 36,
1856
+ 0,
1857
+ 132,
1858
+ 1,
1859
+ 0
1860
+ ]);
1861
+ this._stylesBin = Buffer.from([
1862
+ 150,
1863
+ 2,
1864
+ 0,
1865
+ 231,
1866
+ 4,
1867
+ 4,
1868
+ 2,
1869
+ 0,
1870
+ 0,
1871
+ 0,
1872
+ 44,
1873
+ 44,
1874
+ 164,
1875
+ 0,
1876
+ 19,
1877
+ 0,
1878
+ 0,
1879
+ 0,
1880
+ 121,
1881
+ 0,
1882
+ 121,
1883
+ 0,
1884
+ 121,
1885
+ 0,
1886
+ 121,
1887
+ 0,
1888
+ 92,
1889
+ 0,
1890
+ 45,
1891
+ 0,
1892
+ 109,
1893
+ 0,
1894
+ 109,
1895
+ 0,
1896
+ 92,
1897
+ 0,
1898
+ 45,
1899
+ 0,
1900
+ 100,
1901
+ 0,
1902
+ 100,
1903
+ 0,
1904
+ 92,
1905
+ 0,
1906
+ 32,
1907
+ 0,
1908
+ 104,
1909
+ 0,
1910
+ 104,
1911
+ 0,
1912
+ 58,
1913
+ 0,
1914
+ 109,
1915
+ 0,
1916
+ 109,
1917
+ 0,
1918
+ 44,
1919
+ 30,
1920
+ 166,
1921
+ 0,
1922
+ 12,
1923
+ 0,
1924
+ 0,
1925
+ 0,
1926
+ 121,
1927
+ 0,
1928
+ 121,
1929
+ 0,
1930
+ 121,
1931
+ 0,
1932
+ 121,
1933
+ 0,
1934
+ 92,
1935
+ 0,
1936
+ 45,
1937
+ 0,
1938
+ 109,
1939
+ 0,
1940
+ 109,
1941
+ 0,
1942
+ 92,
1943
+ 0,
1944
+ 45,
1945
+ 0,
1946
+ 100,
1947
+ 0,
1948
+ 100,
1949
+ 0,
1950
+ 232,
1951
+ 4,
1952
+ 0,
1953
+ 227,
1954
+ 4,
1955
+ 4,
1956
+ 1,
1957
+ 0,
1958
+ 0,
1959
+ 0,
1960
+ 43,
1961
+ 39,
1962
+ 220,
1963
+ 0,
1964
+ 0,
1965
+ 0,
1966
+ 144,
1967
+ 1,
1968
+ 0,
1969
+ 0,
1970
+ 0,
1971
+ 2,
1972
+ 0,
1973
+ 0,
1974
+ 7,
1975
+ 1,
1976
+ 0,
1977
+ 0,
1978
+ 0,
1979
+ 0,
1980
+ 0,
1981
+ 255,
1982
+ 2,
1983
+ 7,
1984
+ 0,
1985
+ 0,
1986
+ 0,
1987
+ 67,
1988
+ 0,
1989
+ 97,
1990
+ 0,
1991
+ 108,
1992
+ 0,
1993
+ 105,
1994
+ 0,
1995
+ 98,
1996
+ 0,
1997
+ 114,
1998
+ 0,
1999
+ 105,
2000
+ 0,
2001
+ 43,
2002
+ 39,
2003
+ 220,
2004
+ 0,
2005
+ 1,
2006
+ 0,
2007
+ 188,
2008
+ 2,
2009
+ 0,
2010
+ 0,
2011
+ 0,
2012
+ 2,
2013
+ 238,
2014
+ 0,
2015
+ 7,
2016
+ 1,
2017
+ 0,
2018
+ 0,
2019
+ 0,
2020
+ 0,
2021
+ 0,
2022
+ 255,
2023
+ 2,
2024
+ 7,
2025
+ 0,
2026
+ 0,
2027
+ 0,
2028
+ 67,
2029
+ 0,
2030
+ 97,
2031
+ 0,
2032
+ 108,
2033
+ 0,
2034
+ 105,
2035
+ 0,
2036
+ 98,
2037
+ 0,
2038
+ 114,
2039
+ 0,
2040
+ 105,
2041
+ 0,
2042
+ 37,
2043
+ 6,
2044
+ 1,
2045
+ 0,
2046
+ 2,
2047
+ 14,
2048
+ 0,
2049
+ 128,
2050
+ 129,
2051
+ 8,
2052
+ 0,
2053
+ 38,
2054
+ 0,
2055
+ 228,
2056
+ 4,
2057
+ 0,
2058
+ 219,
2059
+ 4,
2060
+ 4,
2061
+ 2,
2062
+ 0,
2063
+ 0,
2064
+ 0,
2065
+ 45,
2066
+ 68,
2067
+ 0,
2068
+ 0,
2069
+ 0,
2070
+ 0,
2071
+ 3,
2072
+ 64,
2073
+ 0,
2074
+ 0,
2075
+ 0,
2076
+ 0,
2077
+ 0,
2078
+ 255,
2079
+ 3,
2080
+ 65,
2081
+ 0,
2082
+ 0,
2083
+ 255,
2084
+ 255,
2085
+ 255,
2086
+ 255,
2087
+ 0,
2088
+ 0,
2089
+ 0,
2090
+ 0,
2091
+ 0,
2092
+ 0,
2093
+ 0,
2094
+ 0,
2095
+ 0,
2096
+ 0,
2097
+ 0,
2098
+ 0,
2099
+ 0,
2100
+ 0,
2101
+ 0,
2102
+ 0,
2103
+ 0,
2104
+ 0,
2105
+ 0,
2106
+ 0,
2107
+ 0,
2108
+ 0,
2109
+ 0,
2110
+ 0,
2111
+ 0,
2112
+ 0,
2113
+ 0,
2114
+ 0,
2115
+ 0,
2116
+ 0,
2117
+ 0,
2118
+ 0,
2119
+ 0,
2120
+ 0,
2121
+ 0,
2122
+ 0,
2123
+ 0,
2124
+ 0,
2125
+ 0,
2126
+ 0,
2127
+ 0,
2128
+ 0,
2129
+ 0,
2130
+ 0,
2131
+ 0,
2132
+ 0,
2133
+ 0,
2134
+ 0,
2135
+ 45,
2136
+ 68,
2137
+ 17,
2138
+ 0,
2139
+ 0,
2140
+ 0,
2141
+ 3,
2142
+ 64,
2143
+ 0,
2144
+ 0,
2145
+ 0,
2146
+ 0,
2147
+ 0,
2148
+ 255,
2149
+ 3,
2150
+ 65,
2151
+ 0,
2152
+ 0,
2153
+ 255,
2154
+ 255,
2155
+ 255,
2156
+ 255,
2157
+ 0,
2158
+ 0,
2159
+ 0,
2160
+ 0,
2161
+ 0,
2162
+ 0,
2163
+ 0,
2164
+ 0,
2165
+ 0,
2166
+ 0,
2167
+ 0,
2168
+ 0,
2169
+ 0,
2170
+ 0,
2171
+ 0,
2172
+ 0,
2173
+ 0,
2174
+ 0,
2175
+ 0,
2176
+ 0,
2177
+ 0,
2178
+ 0,
2179
+ 0,
2180
+ 0,
2181
+ 0,
2182
+ 0,
2183
+ 0,
2184
+ 0,
2185
+ 0,
2186
+ 0,
2187
+ 0,
2188
+ 0,
2189
+ 0,
2190
+ 0,
2191
+ 0,
2192
+ 0,
2193
+ 0,
2194
+ 0,
2195
+ 0,
2196
+ 0,
2197
+ 0,
2198
+ 0,
2199
+ 0,
2200
+ 0,
2201
+ 0,
2202
+ 0,
2203
+ 0,
2204
+ 0,
2205
+ 220,
2206
+ 4,
2207
+ 0,
2208
+ 229,
2209
+ 4,
2210
+ 4,
2211
+ 1,
2212
+ 0,
2213
+ 0,
2214
+ 0,
2215
+ 46,
2216
+ 51,
2217
+ 0,
2218
+ 0,
2219
+ 0,
2220
+ 1,
2221
+ 0,
2222
+ 0,
2223
+ 0,
2224
+ 0,
2225
+ 0,
2226
+ 0,
2227
+ 0,
2228
+ 0,
2229
+ 0,
2230
+ 1,
2231
+ 0,
2232
+ 0,
2233
+ 0,
2234
+ 0,
2235
+ 0,
2236
+ 0,
2237
+ 0,
2238
+ 0,
2239
+ 0,
2240
+ 1,
2241
+ 0,
2242
+ 0,
2243
+ 0,
2244
+ 0,
2245
+ 0,
2246
+ 0,
2247
+ 0,
2248
+ 0,
2249
+ 0,
2250
+ 1,
2251
+ 0,
2252
+ 0,
2253
+ 0,
2254
+ 0,
2255
+ 0,
2256
+ 0,
2257
+ 0,
2258
+ 0,
2259
+ 0,
2260
+ 1,
2261
+ 0,
2262
+ 0,
2263
+ 0,
2264
+ 0,
2265
+ 0,
2266
+ 0,
2267
+ 0,
2268
+ 230,
2269
+ 4,
2270
+ 0,
2271
+ 242,
2272
+ 4,
2273
+ 4,
2274
+ 1,
2275
+ 0,
2276
+ 0,
2277
+ 0,
2278
+ 47,
2279
+ 16,
2280
+ 255,
2281
+ 255,
2282
+ 0,
2283
+ 0,
2284
+ 0,
2285
+ 0,
2286
+ 0,
2287
+ 0,
2288
+ 0,
2289
+ 0,
2290
+ 0,
2291
+ 0,
2292
+ 16,
2293
+ 16,
2294
+ 0,
2295
+ 0,
2296
+ 243,
2297
+ 4,
2298
+ 0,
2299
+ 233,
2300
+ 4,
2301
+ 4,
2302
+ 4,
2303
+ 0,
2304
+ 0,
2305
+ 0,
2306
+ 47,
2307
+ 16,
2308
+ 0,
2309
+ 0,
2310
+ 0,
2311
+ 0,
2312
+ 0,
2313
+ 0,
2314
+ 0,
2315
+ 0,
2316
+ 0,
2317
+ 0,
2318
+ 0,
2319
+ 0,
2320
+ 16,
2321
+ 16,
2322
+ 0,
2323
+ 0,
2324
+ 47,
2325
+ 16,
2326
+ 0,
2327
+ 0,
2328
+ 164,
2329
+ 0,
2330
+ 0,
2331
+ 0,
2332
+ 0,
2333
+ 0,
2334
+ 0,
2335
+ 0,
2336
+ 0,
2337
+ 0,
2338
+ 16,
2339
+ 16,
2340
+ 1,
2341
+ 0,
2342
+ 47,
2343
+ 16,
2344
+ 0,
2345
+ 0,
2346
+ 166,
2347
+ 0,
2348
+ 0,
2349
+ 0,
2350
+ 0,
2351
+ 0,
2352
+ 0,
2353
+ 0,
2354
+ 0,
2355
+ 0,
2356
+ 16,
2357
+ 16,
2358
+ 1,
2359
+ 0,
2360
+ 47,
2361
+ 16,
2362
+ 0,
2363
+ 0,
2364
+ 0,
2365
+ 1,
2366
+ 1,
2367
+ 0,
2368
+ 0,
2369
+ 0,
2370
+ 0,
2371
+ 0,
2372
+ 0,
2373
+ 0,
2374
+ 16,
2375
+ 16,
2376
+ 0,
2377
+ 0,
2378
+ 234,
2379
+ 4,
2380
+ 0,
2381
+ 235,
2382
+ 4,
2383
+ 4,
2384
+ 1,
2385
+ 0,
2386
+ 0,
2387
+ 0,
2388
+ 37,
2389
+ 6,
2390
+ 1,
2391
+ 0,
2392
+ 2,
2393
+ 17,
2394
+ 0,
2395
+ 128,
2396
+ 128,
2397
+ 24,
2398
+ 16,
2399
+ 0,
2400
+ 0,
2401
+ 0,
2402
+ 0,
2403
+ 0,
2404
+ 0,
2405
+ 0,
2406
+ 0,
2407
+ 0,
2408
+ 0,
2409
+ 0,
2410
+ 0,
2411
+ 0,
2412
+ 0,
2413
+ 0,
2414
+ 0,
2415
+ 38,
2416
+ 0,
2417
+ 48,
2418
+ 28,
2419
+ 0,
2420
+ 0,
2421
+ 0,
2422
+ 0,
2423
+ 1,
2424
+ 0,
2425
+ 0,
2426
+ 0,
2427
+ 8,
2428
+ 0,
2429
+ 0,
2430
+ 0,
2431
+ 78,
2432
+ 0,
2433
+ 111,
2434
+ 0,
2435
+ 114,
2436
+ 0,
2437
+ 109,
2438
+ 0,
2439
+ 97,
2440
+ 0,
2441
+ 108,
2442
+ 0,
2443
+ 110,
2444
+ 0,
2445
+ 121,
2446
+ 0,
2447
+ 236,
2448
+ 4,
2449
+ 0,
2450
+ 249,
2451
+ 3,
2452
+ 4,
2453
+ 0,
2454
+ 0,
2455
+ 0,
2456
+ 0,
2457
+ 250,
2458
+ 3,
2459
+ 0,
2460
+ 252,
2461
+ 3,
2462
+ 80,
2463
+ 0,
2464
+ 0,
2465
+ 0,
2466
+ 0,
2467
+ 17,
2468
+ 0,
2469
+ 0,
2470
+ 0,
2471
+ 84,
2472
+ 0,
2473
+ 97,
2474
+ 0,
2475
+ 98,
2476
+ 0,
2477
+ 108,
2478
+ 0,
2479
+ 101,
2480
+ 0,
2481
+ 83,
2482
+ 0,
2483
+ 116,
2484
+ 0,
2485
+ 121,
2486
+ 0,
2487
+ 108,
2488
+ 0,
2489
+ 101,
2490
+ 0,
2491
+ 77,
2492
+ 0,
2493
+ 101,
2494
+ 0,
2495
+ 100,
2496
+ 0,
2497
+ 105,
2498
+ 0,
2499
+ 117,
2500
+ 0,
2501
+ 109,
2502
+ 0,
2503
+ 50,
2504
+ 0,
2505
+ 17,
2506
+ 0,
2507
+ 0,
2508
+ 0,
2509
+ 80,
2510
+ 0,
2511
+ 105,
2512
+ 0,
2513
+ 118,
2514
+ 0,
2515
+ 111,
2516
+ 0,
2517
+ 116,
2518
+ 0,
2519
+ 83,
2520
+ 0,
2521
+ 116,
2522
+ 0,
2523
+ 121,
2524
+ 0,
2525
+ 108,
2526
+ 0,
2527
+ 101,
2528
+ 0,
2529
+ 76,
2530
+ 0,
2531
+ 105,
2532
+ 0,
2533
+ 103,
2534
+ 0,
2535
+ 104,
2536
+ 0,
2537
+ 116,
2538
+ 0,
2539
+ 49,
2540
+ 0,
2541
+ 54,
2542
+ 0,
2543
+ 253,
2544
+ 3,
2545
+ 0,
2546
+ 35,
2547
+ 4,
2548
+ 2,
2549
+ 14,
2550
+ 0,
2551
+ 0,
2552
+ 235,
2553
+ 8,
2554
+ 0,
2555
+ 246,
2556
+ 8,
2557
+ 42,
2558
+ 0,
2559
+ 0,
2560
+ 0,
2561
+ 0,
2562
+ 17,
2563
+ 0,
2564
+ 0,
2565
+ 0,
2566
+ 83,
2567
+ 0,
2568
+ 108,
2569
+ 0,
2570
+ 105,
2571
+ 0,
2572
+ 99,
2573
+ 0,
2574
+ 101,
2575
+ 0,
2576
+ 114,
2577
+ 0,
2578
+ 83,
2579
+ 0,
2580
+ 116,
2581
+ 0,
2582
+ 121,
2583
+ 0,
2584
+ 108,
2585
+ 0,
2586
+ 101,
2587
+ 0,
2588
+ 76,
2589
+ 0,
2590
+ 105,
2591
+ 0,
2592
+ 103,
2593
+ 0,
2594
+ 104,
2595
+ 0,
2596
+ 116,
2597
+ 0,
2598
+ 49,
2599
+ 0,
2600
+ 247,
2601
+ 8,
2602
+ 0,
2603
+ 236,
2604
+ 8,
2605
+ 0,
2606
+ 36,
2607
+ 0,
2608
+ 35,
2609
+ 4,
2610
+ 3,
2611
+ 15,
2612
+ 0,
2613
+ 0,
2614
+ 176,
2615
+ 16,
2616
+ 0,
2617
+ 178,
2618
+ 16,
2619
+ 50,
2620
+ 0,
2621
+ 0,
2622
+ 0,
2623
+ 0,
2624
+ 21,
2625
+ 0,
2626
+ 0,
2627
+ 0,
2628
+ 84,
2629
+ 0,
2630
+ 105,
2631
+ 0,
2632
+ 109,
2633
+ 0,
2634
+ 101,
2635
+ 0,
2636
+ 83,
2637
+ 0,
2638
+ 108,
2639
+ 0,
2640
+ 105,
2641
+ 0,
2642
+ 99,
2643
+ 0,
2644
+ 101,
2645
+ 0,
2646
+ 114,
2647
+ 0,
2648
+ 83,
2649
+ 0,
2650
+ 116,
2651
+ 0,
2652
+ 121,
2653
+ 0,
2654
+ 108,
2655
+ 0,
2656
+ 101,
2657
+ 0,
2658
+ 76,
2659
+ 0,
2660
+ 105,
2661
+ 0,
2662
+ 103,
2663
+ 0,
2664
+ 104,
2665
+ 0,
2666
+ 116,
2667
+ 0,
2668
+ 49,
2669
+ 0,
2670
+ 179,
2671
+ 16,
2672
+ 0,
2673
+ 177,
2674
+ 16,
2675
+ 0,
2676
+ 36,
2677
+ 0,
2678
+ 151,
2679
+ 2,
2680
+ 0
2681
+ ]);
2682
+ this._binaryIndexBin = Buffer.from([
2683
+ 42,
2684
+ 24,
2685
+ 0,
2686
+ 0,
2687
+ 0,
2688
+ 0,
2689
+ 32,
2690
+ 0,
2691
+ 0,
2692
+ 0,
2693
+ 0,
2694
+ 0,
2695
+ 0,
2696
+ 0,
2697
+ 0,
2698
+ 0,
2699
+ 0,
2700
+ 0,
2701
+ 0,
2702
+ 0,
2703
+ 0,
2704
+ 0,
2705
+ 0,
2706
+ 0,
2707
+ 0,
2708
+ 0,
2709
+ 149,
2710
+ 2,
2711
+ 0
2712
+ ]);
2713
+ this._rRkIntegerLowerLimit = -1 << 29;
2714
+ this._rRkIntegerUpperLimit = (1 << 29) - 1;
2715
+ this._autoFilterStartBytes = Buffer.from([161, 1, 16]);
2716
+ this._autoFilterEndBytes = Buffer.from([162, 1, 0]);
2717
+ this._stickHeaderA1bytes = Buffer.from([
2718
+ 151,
2719
+ 1,
2720
+ 29,
2721
+ 0,
2722
+ 0,
2723
+ 0,
2724
+ 0,
2725
+ 0,
2726
+ 0,
2727
+ 0,
2728
+ 0,
2729
+ 0,
2730
+ 0,
2731
+ 0,
2732
+ 0,
2733
+ 0,
2734
+ 0,
2735
+ 240,
2736
+ 63,
2737
+ 1,
2738
+ 0,
2739
+ 0,
2740
+ 0,
2741
+ 0,
2742
+ 0,
2743
+ 0,
2744
+ 0,
2745
+ 2,
2746
+ 0,
2747
+ 0,
2748
+ 0,
2749
+ 3
2750
+ ]);
2751
+ this._magicFilterExcel2016Fix0 = Buffer.from([225, 2, 0, 229, 2, 0, 234, 2]);
2752
+ this._magicFilterExcel2016Fix1 = Buffer.from([
2753
+ 39,
2754
+ 70,
2755
+ 33,
2756
+ 0,
2757
+ 0,
2758
+ 0,
2759
+ 0,
2760
+ 255,
2761
+ 0,
2762
+ 0,
2763
+ 0,
2764
+ 15,
2765
+ 0,
2766
+ 0,
2767
+ 0,
2768
+ 95,
2769
+ 0,
2770
+ 70,
2771
+ 0,
2772
+ 105,
2773
+ 0,
2774
+ 108,
2775
+ 0,
2776
+ 116,
2777
+ 0,
2778
+ 101,
2779
+ 0,
2780
+ 114,
2781
+ 0,
2782
+ 68,
2783
+ 0,
2784
+ 97,
2785
+ 0,
2786
+ 116,
2787
+ 0,
2788
+ 97,
2789
+ 0,
2790
+ 98,
2791
+ 0,
2792
+ 97,
2793
+ 0,
2794
+ 115,
2795
+ 0,
2796
+ 101,
2797
+ 0,
2798
+ 15,
2799
+ 0,
2800
+ 0,
2801
+ 0,
2802
+ 59,
2803
+ 255,
2804
+ 0
2805
+ ]);
2806
+ this._magicFilterExcel2016Fix2 = Buffer.from([0, 0, 0, 0, 255, 255, 255, 255]);
2807
+ }
2808
+ /** @deprecated Internal; kept for unit-test access. Prefer sanitizeSheetName(). */
2809
+ _sanitizeSheetName(name) {
2810
+ return sanitizeSheetName(name, this.sheetCount);
2811
+ }
2812
+ _registerFormat(fmtString) {
2813
+ if (this._stFmtRecords.has(fmtString)) {
2814
+ return this._stFmtRecords.get(fmtString).xfIndex;
2815
+ }
2816
+ const numfmtId = this._nextFmtId++;
2817
+ const xfIndex = this._nextXfIdx++;
2818
+ this._stFmtRecords.set(fmtString, { numfmtId, xfIndex });
2819
+ return xfIndex;
2820
+ }
2821
+ static _buildBrtRecord(type, data) {
2822
+ const header = _XlsbWriter._encodeVlq(type);
2823
+ header.push(..._XlsbWriter._encodeVlq(data.length));
2824
+ return Buffer.concat([Buffer.from(header), data]);
2825
+ }
2826
+ static _encodeVlq(value) {
2827
+ const result = [];
2828
+ while (value >= 128) {
2829
+ result.push(value & 127 | 128);
2830
+ value >>>= 7;
2831
+ }
2832
+ result.push(value & 127);
2833
+ return result;
2834
+ }
2835
+ static _buildStFmtRecord(ifmt, fmtString) {
2836
+ const cch = fmtString.length;
2837
+ const remaining = 2 + 4 + cch * 2;
2838
+ const data = Buffer.alloc(2 + remaining);
2839
+ data[0] = 44;
2840
+ data[1] = remaining;
2841
+ data.writeUInt16LE(ifmt, 2);
2842
+ data.writeUInt32LE(cch, 4);
2843
+ data.write(fmtString, 8, cch * 2, "utf16le");
2844
+ return data;
2845
+ }
2846
+ static _buildXfRecord(fontId, ifmt, flags, byte6Extra = 0) {
2847
+ const data = Buffer.alloc(18);
2848
+ data[0] = 47;
2849
+ data[1] = 16;
2850
+ data.writeUInt16LE(fontId, 2);
2851
+ data.writeUInt16LE(ifmt, 4);
2852
+ data[6] = byte6Extra;
2853
+ data[14] = 16;
2854
+ data[15] = 16;
2855
+ data.writeUInt16LE(flags, 16);
2856
+ return data;
2857
+ }
2858
+ _buildStylesBin() {
2859
+ if (this._stFmtRecords.size === 0) {
2860
+ return this._stylesBin;
2861
+ }
2862
+ const base = this._stylesBin;
2863
+ let fontEndOff = -1;
2864
+ for (let i = 3; i < base.length - 3; i++) {
2865
+ if (base[i] === 232 && base[i + 1] === 4 && base[i + 2] === 0) {
2866
+ fontEndOff = i;
2867
+ break;
2868
+ }
2869
+ }
2870
+ let xfBeginOff = -1;
2871
+ for (let i = fontEndOff + 3; i < base.length - 2; i++) {
2872
+ if (base[i] === 233 && base[i + 1] === 4) {
2873
+ xfBeginOff = i;
2874
+ break;
2875
+ }
2876
+ }
2877
+ let xfEndOff = -1;
2878
+ for (let i = xfBeginOff; i < base.length - 3; i++) {
2879
+ if (base[i] === 234 && base[i + 1] === 4 && base[i + 2] === 0) {
2880
+ xfEndOff = i;
2881
+ break;
2882
+ }
2883
+ }
2884
+ let fillBeginOff = -1;
2885
+ for (let i = fontEndOff + 3; i < base.length - 2; i++) {
2886
+ if (base[i] === 227 && base[i + 1] === 4) {
2887
+ fillBeginOff = i;
2888
+ break;
2889
+ }
2890
+ }
2891
+ const totalFmt = 2 + this._stFmtRecords.size;
2892
+ const totalXf = 4 + this._stFmtRecords.size;
2893
+ const parts = [];
2894
+ parts.push(base.subarray(0, 3));
2895
+ const fmtHeader = Buffer.alloc(4);
2896
+ fmtHeader.writeUInt16LE(totalFmt, 0);
2897
+ parts.push(_XlsbWriter._buildBrtRecord(615, fmtHeader));
2898
+ parts.push(_XlsbWriter._buildStFmtRecord(164, "yyyy\\-mm\\-dd\\ hh:mm"));
2899
+ parts.push(_XlsbWriter._buildStFmtRecord(166, "yyyy\\-mm\\-dd"));
2900
+ for (const [fmtString, st] of this._stFmtRecords) {
2901
+ parts.push(_XlsbWriter._buildStFmtRecord(st.numfmtId, fmtString));
2902
+ }
2903
+ parts.push(_XlsbWriter._buildBrtRecord(616, Buffer.alloc(0)));
2904
+ parts.push(base.subarray(fillBeginOff, xfBeginOff));
2905
+ const xfHeader = Buffer.alloc(4);
2906
+ xfHeader.writeUInt16LE(totalXf, 0);
2907
+ parts.push(_XlsbWriter._buildBrtRecord(617, xfHeader));
2908
+ parts.push(_XlsbWriter._buildXfRecord(0, 0, 0));
2909
+ parts.push(_XlsbWriter._buildXfRecord(0, 164, 1));
2910
+ parts.push(_XlsbWriter._buildXfRecord(0, 166, 1));
2911
+ parts.push(_XlsbWriter._buildXfRecord(1, 0, 0, 1));
2912
+ const sortedXf = [...this._stFmtRecords.entries()].sort((a, b) => a[1].xfIndex - b[1].xfIndex);
2913
+ for (const [, st] of sortedXf) {
2914
+ parts.push(_XlsbWriter._buildXfRecord(0, st.numfmtId, 1));
2915
+ }
2916
+ parts.push(_XlsbWriter._buildBrtRecord(618, Buffer.alloc(0)));
2917
+ parts.push(base.subarray(xfEndOff + 3));
2918
+ return Buffer.concat(parts);
2919
+ }
2920
+ /**
2921
+ * Register a worksheet (metadata only). Prefer `writeSheet` / `startSheet` for data.
2922
+ * @param sheetName Display name (sanitized to Excel rules)
2923
+ * @param hidden Whether the sheet is hidden in Excel
2924
+ */
2925
+ addSheet(sheetName, hidden = false) {
2926
+ const sanitizedName = sanitizeSheetName(sheetName, this.sheetCount);
2927
+ this.sheetCount++;
2928
+ this.sheetList.push({
2929
+ name: sanitizedName,
2930
+ pathInArchive: `xl/worksheets/sheet${this.sheetCount}.bin`,
2931
+ hidden,
2932
+ nameInArchive: `sheet${this.sheetCount}.bin`,
2933
+ sheetId: this.sheetCount,
2934
+ filterHeaderRange: null
2935
+ });
2936
+ }
2937
+ /**
2938
+ * Start a new sheet in streaming mode. Call writeRow() for each row, then endSheet() when done.
2939
+ * @param sheetName Name of the sheet
2940
+ * @param columnCount Number of columns in the sheet
2941
+ * @param headers Optional header row
2942
+ * @param options Optional settings (hidden, doAutofilter)
2943
+ */
2944
+ startSheet(sheetName, columnCount, headers, options = {}) {
2945
+ const { hidden = false, doAutofilter = true, sampleRows } = options;
2946
+ this.addSheet(sheetName, hidden);
2947
+ this.stream.begin(columnCount, doAutofilter && headers !== void 0, new BigBuffer());
2948
+ const bigBuf = this.stream.buffer;
2949
+ if (headers) {
2950
+ applyHeaderWidths(this.stream.colWidths, headers, columnCount);
2951
+ }
2952
+ if (sampleRows) {
2953
+ updateColWidthsFromRows(this.stream.colWidths, sampleRows);
2954
+ }
2955
+ const sheetHeader = Buffer.from(this._sheet1Bytes);
2956
+ sheetHeader.writeInt32LE(this.stream.startCol, 40);
2957
+ sheetHeader.writeInt32LE(this.stream.endCol, 44);
2958
+ if (this.sheetCount !== 1) {
2959
+ sheetHeader[54] = 156;
2960
+ }
2961
+ bigBuf.write(sheetHeader.subarray(0, 84));
2962
+ if (headers) {
2963
+ bigBuf.write(this._stickHeaderA1bytes);
2964
+ }
2965
+ bigBuf.write(sheetHeader.subarray(84, 159));
2966
+ bigBuf.writeByte(134);
2967
+ bigBuf.writeByte(3);
2968
+ for (let i = this.stream.startCol; i < this.stream.endCol; i++) {
2969
+ bigBuf.writeByte(0);
2970
+ bigBuf.writeByte(60);
2971
+ bigBuf.writeByte(18);
2972
+ bigBuf.writeInt32LE(i);
2973
+ bigBuf.writeInt32LE(i);
2974
+ const width = defaultColWidth(this.stream.colWidths[i], true);
2975
+ bigBuf.writeByte(0);
2976
+ bigBuf.writeByte(Math.max(0, Math.min(255, width)));
2977
+ bigBuf.writeByte(0);
2978
+ bigBuf.writeByte(0);
2979
+ bigBuf.writeByte(0);
2980
+ bigBuf.writeByte(0);
2981
+ bigBuf.writeByte(0);
2982
+ bigBuf.writeByte(0);
2983
+ bigBuf.writeByte(2);
2984
+ }
2985
+ bigBuf.writeByte(0);
2986
+ bigBuf.writeByte(135);
2987
+ bigBuf.writeByte(3);
2988
+ bigBuf.writeByte(0);
2989
+ bigBuf.write(sheetHeader.subarray(159, 175));
2990
+ bigBuf.write(Buffer.from([38, 0]));
2991
+ if (headers) {
2992
+ this.createRowHeader(bigBuf, this.stream.rowNum, this.stream.startCol, this.stream.endCol);
2993
+ for (let c = 0; c < headers.length; c++) {
2994
+ this.writeString(bigBuf, headers[c], c, true);
2995
+ }
2996
+ this.stream.rowNum++;
2997
+ }
2998
+ }
2999
+ /**
3000
+ * Write a single row in streaming mode. Must be called between startSheet() and endSheet().
3001
+ * @param row Array of cell values
3002
+ */
3003
+ writeRow(row) {
3004
+ const bigBuf = this.stream.assertStreaming();
3005
+ if (row.length !== this.stream.endCol - this.stream.startCol) {
3006
+ throw new Error(
3007
+ `Row length mismatch. Expected ${this.stream.endCol - this.stream.startCol} columns, got ${row.length}`
3008
+ );
3009
+ }
3010
+ this.createRowHeader(bigBuf, this.stream.rowNum, this.stream.startCol, this.stream.endCol);
3011
+ for (let c = 0; c < row.length; c++) {
3012
+ const raw = row[c];
3013
+ if (raw === null || raw === void 0) continue;
3014
+ const fmtString = getFormat(raw);
3015
+ const val = fmtString !== null ? unwrapCell(raw) : raw;
3016
+ const styleNum = fmtString !== null ? this._registerFormat(fmtString) : 0;
3017
+ if (typeof val === "number") {
3018
+ if (Number.isInteger(val)) {
3019
+ if (val >= this._rRkIntegerLowerLimit && val <= this._rRkIntegerUpperLimit) {
3020
+ this.writeRkNumberInteger(bigBuf, val, c, styleNum);
3021
+ } else {
3022
+ this.writeDouble(bigBuf, val, c, styleNum);
3023
+ }
3024
+ } else {
3025
+ this.writeDouble(bigBuf, val, c, styleNum);
3026
+ }
3027
+ } else if (typeof val === "bigint") {
3028
+ this.writeString(bigBuf, val.toString(), c);
3029
+ } else if (typeof val === "boolean") {
3030
+ this.writeBool(bigBuf, val, c);
3031
+ } else if (val instanceof Date) {
3032
+ const oaDate = (val.getTime() - this._oaEpoch) / 864e5;
3033
+ this.writeDouble(bigBuf, oaDate, c, fmtString !== null ? styleNum : 1);
3034
+ } else if (val !== null && val !== void 0) {
3035
+ this.writeString(bigBuf, val.toString(), c, false, fmtString !== null ? styleNum : void 0);
3036
+ }
3037
+ }
3038
+ this.stream.rowNum++;
3039
+ }
3040
+ /**
3041
+ * Finalize the current streaming sheet and add it to the archive.
3042
+ * Must be called after startSheet() and writeRow() calls.
3043
+ */
3044
+ endSheet() {
3045
+ const bigBuf = this.stream.assertStreaming();
3046
+ const sheetHeader = Buffer.from(this._sheet1Bytes);
3047
+ bigBuf.write(sheetHeader.subarray(218, 290));
3048
+ if (this.stream.doAutofilter) {
3049
+ this._autofilterIsOn = true;
3050
+ const endRow = this.stream.rowNum;
3051
+ bigBuf.write(this._autoFilterStartBytes);
3052
+ const rowBuf = Buffer.alloc(8);
3053
+ rowBuf.writeInt32LE(0, 0);
3054
+ rowBuf.writeInt32LE(endRow - 1, 4);
3055
+ bigBuf.write(rowBuf);
3056
+ const colBuf = Buffer.alloc(8);
3057
+ colBuf.writeInt32LE(this.stream.startCol, 0);
3058
+ colBuf.writeInt32LE(this.stream.endCol - 1, 4);
3059
+ bigBuf.write(colBuf);
3060
+ bigBuf.write(this._autoFilterEndBytes);
3061
+ const sheet = this.sheetList[this.sheetCount - 1];
3062
+ sheet.filterData = {
3063
+ startRow: 0,
3064
+ endRow: endRow - 1,
3065
+ startColumn: this.stream.startCol,
3066
+ endColumn: this.stream.endCol - 1
3067
+ };
3068
+ }
3069
+ bigBuf.write(sheetHeader.subarray(290));
3070
+ this.archive.append(import_stream.Readable.from(bigBuf.getChunks()), {
3071
+ name: this.sheetList[this.sheetCount - 1].pathInArchive
3072
+ });
3073
+ this.stream.end();
3074
+ }
3075
+ /**
3076
+ * Write an entire sheet in one call (batch mode).
3077
+ * @param rows Data rows (`CellValue` cells; null/undefined = blank)
3078
+ * @param headers Optional header row (bold + frozen + autofilter when enabled)
3079
+ * @param doAutofilter Enable autofilter when headers are present (default true)
3080
+ */
3081
+ writeSheet(rows, headers = null, doAutofilter = true) {
3082
+ const bigBuf = new BigBuffer();
3083
+ let columnCount = 0;
3084
+ if (rows.length > 0) {
3085
+ columnCount = rows[0].length;
3086
+ } else if (headers) {
3087
+ columnCount = headers.length;
3088
+ }
3089
+ const colWidths = initColWidths(columnCount);
3090
+ if (headers) {
3091
+ applyHeaderWidths(colWidths, headers, columnCount);
3092
+ }
3093
+ updateColWidthsFromRows(colWidths, rows);
3094
+ const sheetHeader = Buffer.from(this._sheet1Bytes);
3095
+ const startCol = 0;
3096
+ const endCol = columnCount;
3097
+ sheetHeader.writeInt32LE(startCol, 40);
3098
+ sheetHeader.writeInt32LE(endCol, 44);
3099
+ if (this.sheetCount !== 1) {
3100
+ sheetHeader[54] = 156;
3101
+ }
3102
+ bigBuf.write(sheetHeader.subarray(0, 84));
3103
+ if (headers) {
3104
+ bigBuf.write(this._stickHeaderA1bytes);
3105
+ }
3106
+ bigBuf.write(sheetHeader.subarray(84, 159));
3107
+ bigBuf.writeByte(134);
3108
+ bigBuf.writeByte(3);
3109
+ for (let i = startCol; i < endCol; i++) {
3110
+ bigBuf.writeByte(0);
3111
+ bigBuf.writeByte(60);
3112
+ bigBuf.writeByte(18);
3113
+ bigBuf.writeInt32LE(i);
3114
+ bigBuf.writeInt32LE(i);
3115
+ const width = defaultColWidth(colWidths[i], true);
3116
+ bigBuf.writeByte(0);
3117
+ bigBuf.writeByte(Math.max(0, Math.min(255, width)));
3118
+ bigBuf.writeByte(0);
3119
+ bigBuf.writeByte(0);
3120
+ bigBuf.writeByte(0);
3121
+ bigBuf.writeByte(0);
3122
+ bigBuf.writeByte(0);
3123
+ bigBuf.writeByte(0);
3124
+ bigBuf.writeByte(2);
3125
+ }
3126
+ bigBuf.writeByte(0);
3127
+ bigBuf.writeByte(135);
3128
+ bigBuf.writeByte(3);
3129
+ bigBuf.writeByte(0);
3130
+ bigBuf.write(sheetHeader.subarray(159, 175));
3131
+ bigBuf.write(Buffer.from([38, 0]));
3132
+ let rowNum = 0;
3133
+ if (headers) {
3134
+ this.createRowHeader(bigBuf, rowNum, startCol, endCol);
3135
+ for (let c = 0; c < headers.length; c++) {
3136
+ this.writeString(bigBuf, headers[c], c, true);
3137
+ }
3138
+ rowNum++;
3139
+ }
3140
+ for (let r = 0; r < rows.length; r++) {
3141
+ this.createRowHeader(bigBuf, rowNum, startCol, endCol);
3142
+ const row = rows[r];
3143
+ for (let c = 0; c < row.length; c++) {
3144
+ const raw = row[c];
3145
+ if (raw === null || raw === void 0) continue;
3146
+ const fmtString = getFormat(raw);
3147
+ const val = fmtString !== null ? unwrapCell(raw) : raw;
3148
+ const styleNum = fmtString !== null ? this._registerFormat(fmtString) : 0;
3149
+ if (typeof val === "number") {
3150
+ if (Number.isInteger(val)) {
3151
+ if (val >= this._rRkIntegerLowerLimit && val <= this._rRkIntegerUpperLimit) {
3152
+ this.writeRkNumberInteger(bigBuf, val, c, styleNum);
3153
+ } else {
3154
+ this.writeDouble(bigBuf, val, c, styleNum);
3155
+ }
3156
+ } else {
3157
+ this.writeDouble(bigBuf, val, c, styleNum);
3158
+ }
3159
+ } else if (typeof val === "bigint") {
3160
+ this.writeString(bigBuf, val.toString(), c);
3161
+ } else if (typeof val === "boolean") {
3162
+ this.writeBool(bigBuf, val, c);
3163
+ } else if (val instanceof Date) {
3164
+ const oaDate = (val.getTime() - this._oaEpoch) / 864e5;
3165
+ this.writeDouble(bigBuf, oaDate, c, fmtString !== null ? styleNum : 1);
3166
+ } else if (val !== null && val !== void 0) {
3167
+ this.writeString(bigBuf, val.toString(), c, false, fmtString !== null ? styleNum : void 0);
3168
+ }
3169
+ }
3170
+ rowNum++;
3171
+ }
3172
+ bigBuf.write(sheetHeader.subarray(218, 290));
3173
+ if (doAutofilter && headers) {
3174
+ this._autofilterIsOn = true;
3175
+ const endRow = rows.length + 1;
3176
+ bigBuf.write(this._autoFilterStartBytes);
3177
+ const rowBuf = Buffer.alloc(8);
3178
+ rowBuf.writeInt32LE(0, 0);
3179
+ rowBuf.writeInt32LE(endRow - 1, 4);
3180
+ bigBuf.write(rowBuf);
3181
+ const colBuf = Buffer.alloc(8);
3182
+ colBuf.writeInt32LE(startCol, 0);
3183
+ colBuf.writeInt32LE(endCol - 1, 4);
3184
+ bigBuf.write(colBuf);
3185
+ bigBuf.write(this._autoFilterEndBytes);
3186
+ const sheet = this.sheetList[this.sheetCount - 1];
3187
+ sheet.filterData = {
3188
+ startRow: 0,
3189
+ endRow: rows.length,
3190
+ startColumn: startCol,
3191
+ endColumn: endCol - 1
3192
+ };
3193
+ }
3194
+ bigBuf.write(sheetHeader.subarray(290));
3195
+ this.archive.append(import_stream.Readable.from(bigBuf.getChunks()), { name: this.sheetList[this.sheetCount - 1].pathInArchive });
3196
+ }
3197
+ createRowHeader(bigBuf, rowNumber, startCol, endCol) {
3198
+ bigBuf.ensureCapacity(27);
3199
+ bigBuf.writeUnsafeByte(0);
3200
+ bigBuf.writeUnsafeByte(25);
3201
+ bigBuf.writeUnsafeInt32LE(rowNumber);
3202
+ bigBuf.writeUnsafeInt32LE(0);
3203
+ bigBuf.writeUnsafeByte(44);
3204
+ bigBuf.writeUnsafeByte(1);
3205
+ bigBuf.writeUnsafeByte(0);
3206
+ bigBuf.writeUnsafeByte(0);
3207
+ bigBuf.writeUnsafeByte(0);
3208
+ bigBuf.writeUnsafeByte(1);
3209
+ bigBuf.writeUnsafeByte(0);
3210
+ bigBuf.writeUnsafeByte(0);
3211
+ bigBuf.writeUnsafeByte(0);
3212
+ bigBuf.writeUnsafeInt32LE(startCol);
3213
+ bigBuf.writeUnsafeInt32LE(endCol);
3214
+ }
3215
+ writeRkNumberInteger(bigBuf, val, colNum, styleNum = 0) {
3216
+ bigBuf.ensureCapacity(14);
3217
+ bigBuf.writeUnsafeByte(2);
3218
+ bigBuf.writeUnsafeByte(12);
3219
+ bigBuf.writeUnsafeInt32LE(colNum);
3220
+ bigBuf.writeUnsafeByte(styleNum);
3221
+ bigBuf.writeUnsafeByte(0);
3222
+ bigBuf.writeUnsafeByte(0);
3223
+ bigBuf.writeUnsafeByte(0);
3224
+ const rkVal = val << 2 | 2;
3225
+ bigBuf.writeUnsafeInt32LE(rkVal);
3226
+ }
3227
+ writeDouble(bigBuf, val, colNum, styleNum = 0) {
3228
+ bigBuf.ensureCapacity(18);
3229
+ bigBuf.writeUnsafeByte(5);
3230
+ bigBuf.writeUnsafeByte(16);
3231
+ bigBuf.writeUnsafeInt32LE(colNum);
3232
+ bigBuf.writeUnsafeByte(styleNum);
3233
+ bigBuf.writeUnsafeByte(0);
3234
+ bigBuf.writeUnsafeByte(0);
3235
+ bigBuf.writeUnsafeByte(0);
3236
+ bigBuf.writeUnsafeDoubleLE(val);
3237
+ }
3238
+ writeBool(bigBuf, val, colNum) {
3239
+ bigBuf.ensureCapacity(13);
3240
+ bigBuf.writeUnsafeByte(4);
3241
+ bigBuf.writeUnsafeByte(9);
3242
+ bigBuf.writeUnsafeInt32LE(colNum);
3243
+ bigBuf.writeUnsafeInt32LE(0);
3244
+ bigBuf.writeUnsafeByte(val ? 1 : 0);
3245
+ }
3246
+ writeDateTime(bigBuf, date, colNum) {
3247
+ const oaDate = (date.getTime() - this._oaEpoch) / 864e5;
3248
+ this.writeDouble(bigBuf, oaDate, colNum, 1);
3249
+ }
3250
+ _getDateWidth(_date) {
3251
+ return 19;
3252
+ }
3253
+ writeString(bigBuf, val, colNum, bolded = false, styleOverride) {
3254
+ let index;
3255
+ if (this.sstDic.has(val)) {
3256
+ index = this.sstDic.get(val);
3257
+ } else {
3258
+ index = this.sstCntUnique;
3259
+ this.sstDic.set(val, index);
3260
+ this.sstCntUnique++;
3261
+ }
3262
+ this.sstCntAll++;
3263
+ const styleNum = styleOverride !== void 0 ? styleOverride : bolded ? 3 : 0;
3264
+ bigBuf.ensureCapacity(17);
3265
+ bigBuf.writeUnsafeByte(7);
3266
+ bigBuf.writeUnsafeByte(12);
3267
+ bigBuf.writeUnsafeInt32LE(colNum);
3268
+ bigBuf.writeUnsafeByte(styleNum);
3269
+ bigBuf.writeUnsafeByte(0);
3270
+ bigBuf.writeUnsafeByte(0);
3271
+ bigBuf.writeUnsafeByte(0);
3272
+ bigBuf.writeUnsafeInt32LE(index);
3273
+ }
3274
+ saveSst() {
3275
+ const bigBuf = new BigBuffer();
3276
+ bigBuf.writeByte(159);
3277
+ bigBuf.writeByte(1);
3278
+ bigBuf.writeByte(8);
3279
+ bigBuf.writeInt32LE(this.sstCntUnique);
3280
+ bigBuf.writeInt32LE(this.sstCntAll);
3281
+ for (const [txt] of this.sstDic) {
3282
+ const txtLen = txt.length;
3283
+ bigBuf.writeByte(19);
3284
+ const recLen = 5 + 2 * txtLen;
3285
+ if (recLen >= 128) {
3286
+ bigBuf.writeByte(128 + recLen % 128);
3287
+ const tmp = recLen >> 7;
3288
+ if (tmp >= 256) {
3289
+ bigBuf.writeByte(128 + tmp % 128);
3290
+ } else {
3291
+ bigBuf.writeByte(tmp);
3292
+ }
3293
+ bigBuf.writeByte(recLen >> 14);
3294
+ if (recLen >> 14 > 0) {
3295
+ bigBuf.writeByte(0);
3296
+ }
3297
+ } else {
3298
+ bigBuf.writeByte(recLen & 255);
3299
+ bigBuf.writeByte(recLen >> 8 & 255);
3300
+ }
3301
+ bigBuf.writeInt32LE(txtLen);
3302
+ bigBuf.writeUtf16LE(txt);
3303
+ }
3304
+ bigBuf.writeByte(160);
3305
+ bigBuf.writeByte(1);
3306
+ bigBuf.writeByte(0);
3307
+ this.archive.append(import_stream.Readable.from(bigBuf.getChunks()), { name: "xl/sharedStrings.bin" });
3308
+ }
3309
+ _writeFilterDefinedName(wbBuffers, sheet, sheetNum) {
3310
+ const filterData = sheet.filterData;
3311
+ const sheetIndex = sheet.sheetId - 1;
3312
+ const fix1 = Buffer.alloc(this._magicFilterExcel2016Fix1.length);
3313
+ this._magicFilterExcel2016Fix1.copy(fix1);
3314
+ const lastIdx = this._magicFilterExcel2016Fix1.length - 2;
3315
+ fix1[7] = sheetIndex;
3316
+ fix1[lastIdx] = sheetNum;
3317
+ wbBuffers.push(fix1);
3318
+ const rowBuf = Buffer.alloc(8);
3319
+ rowBuf.writeInt32LE(filterData.startRow, 0);
3320
+ rowBuf.writeInt32LE(filterData.endRow, 4);
3321
+ wbBuffers.push(rowBuf);
3322
+ const colBuf = Buffer.alloc(4);
3323
+ colBuf.writeInt16LE(filterData.startColumn, 0);
3324
+ colBuf.writeInt16LE(filterData.endColumn, 2);
3325
+ wbBuffers.push(colBuf);
3326
+ wbBuffers.push(this._magicFilterExcel2016Fix2);
3327
+ }
3328
+ /**
3329
+ * Finalize the ZIP package and close the output stream.
3330
+ * Must be awaited before the file is fully written.
3331
+ */
3332
+ finalize() {
3333
+ return new Promise((resolve, reject) => {
3334
+ try {
3335
+ this.saveSst();
3336
+ this.archive.append(this._buildStylesBin(), { name: "xl/styles.bin" });
3337
+ const wbBuffers = [];
3338
+ wbBuffers.push(this._workbookBinStart);
3339
+ for (const sheet of this.sheetList) {
3340
+ const rId = `rId${sheet.sheetId}`;
3341
+ const recLen = 4 + 12 + sheet.name.length * 2 + rId.length * 2;
3342
+ const buf = Buffer.alloc(3 + recLen);
3343
+ buf[0] = 156;
3344
+ buf[1] = 1;
3345
+ buf[2] = recLen;
3346
+ let pos = 3;
3347
+ buf.writeInt32LE(sheet.hidden ? 1 : 0, pos);
3348
+ pos += 4;
3349
+ buf.writeInt32LE(sheet.sheetId, pos);
3350
+ pos += 4;
3351
+ buf.writeInt32LE(rId.length, pos);
3352
+ pos += 4;
3353
+ for (let i = 0; i < rId.length; i++) {
3354
+ const c = rId.charCodeAt(i);
3355
+ buf[pos++] = c & 255;
3356
+ buf[pos++] = c >> 8 & 255;
3357
+ }
3358
+ buf.writeInt32LE(sheet.name.length, pos);
3359
+ pos += 4;
3360
+ for (let i = 0; i < sheet.name.length; i++) {
3361
+ const c = sheet.name.charCodeAt(i);
3362
+ buf[pos++] = c & 255;
3363
+ buf[pos++] = c >> 8 & 255;
3364
+ }
3365
+ wbBuffers.push(buf);
3366
+ }
3367
+ wbBuffers.push(this._workbookBinMiddle);
3368
+ if (this._autofilterIsOn) {
3369
+ const filteredSheets = this.sheetList.filter((s) => s.filterData);
3370
+ const cnt = filteredSheets.length;
3371
+ if (cnt > 0) {
3372
+ wbBuffers.push(this._magicFilterExcel2016Fix0);
3373
+ const firstByte = cnt <= 20 ? 16 + (cnt - 1) * 12 : 128 + (cnt - 21) * 12;
3374
+ const countBuf = cnt <= 10 ? Buffer.from([firstByte, cnt, 0, 0, 0]) : Buffer.from([firstByte, Math.floor((cnt - 1) / 10), cnt, 0, 0, 0]);
3375
+ wbBuffers.push(countBuf);
3376
+ for (let nm = 0; nm < cnt; nm++) {
3377
+ const sheetIndex = filteredSheets[nm].sheetId - 1;
3378
+ const idxBuf = Buffer.alloc(12);
3379
+ idxBuf.writeInt32LE(0, 0);
3380
+ idxBuf[4] = sheetIndex;
3381
+ idxBuf[8] = sheetIndex;
3382
+ wbBuffers.push(idxBuf);
3383
+ }
3384
+ wbBuffers.push(Buffer.from([226, 2, 0]));
3385
+ for (let sheetNum = 0; sheetNum < cnt; sheetNum++) {
3386
+ const sheet = filteredSheets[sheetNum];
3387
+ this._writeFilterDefinedName(wbBuffers, sheet, sheetNum);
3388
+ }
3389
+ }
3390
+ }
3391
+ wbBuffers.push(this._workbookBinEnd);
3392
+ this.archive.append(Buffer.concat(wbBuffers), { name: "xl/workbook.bin" });
3393
+ for (const sheet of this.sheetList) {
3394
+ this.archive.append(this._binaryIndexBin, { name: `xl/worksheets/binaryIndex${sheet.sheetId}.bin` });
3395
+ }
3396
+ let contentTypes = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3397
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
3398
+ <Default Extension="bin" ContentType="application/vnd.ms-excel.sheet.binary.macroEnabled.main"/>
3399
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
3400
+ <Default Extension="xml" ContentType="application/xml"/>`;
3401
+ for (const sheet of this.sheetList) {
3402
+ contentTypes += `<Override PartName="/${sheet.pathInArchive}" ContentType="application/vnd.ms-excel.worksheet"/>`;
3403
+ contentTypes += `<Override PartName="/xl/worksheets/binaryIndex${sheet.sheetId}.bin" ContentType="application/vnd.ms-excel.binIndexWs"/>`;
3404
+ }
3405
+ contentTypes += `<Override PartName="/xl/styles.bin" ContentType="application/vnd.ms-excel.styles"/>
3406
+ <Override PartName="/xl/sharedStrings.bin" ContentType="application/vnd.ms-excel.sharedStrings"/>
3407
+ </Types>`;
3408
+ this.archive.append(contentTypes, { name: "[Content_Types].xml" });
3409
+ let wbRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3410
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`;
3411
+ for (const sheet of this.sheetList) {
3412
+ const rId = `rId${sheet.sheetId}`;
3413
+ wbRels += `<Relationship Id="${rId}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/${sheet.nameInArchive}"/>`;
3414
+ }
3415
+ wbRels += `<Relationship Id="rId${this.sheetList.length + 2}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.bin"/>
3416
+ <Relationship Id="rId${this.sheetList.length + 3}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.bin"/>
3417
+ </Relationships>`;
3418
+ this.archive.append(wbRels, { name: "xl/_rels/workbook.bin.rels" });
3419
+ const globalRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3420
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
3421
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.bin"/>
3422
+ </Relationships>`;
3423
+ this.archive.append(globalRels, { name: "_rels/.rels" });
3424
+ for (const sheet of this.sheetList) {
3425
+ const wsRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3426
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
3427
+ <Relationship Id="rId1" Type="http://schemas.microsoft.com/office/2006/relationships/xlBinaryIndex" Target="binaryIndex${sheet.sheetId}.bin"/>
3428
+ </Relationships>`;
3429
+ this.archive.append(wsRels, { name: `xl/worksheets/_rels/${sheet.nameInArchive}.rels` });
3430
+ }
3431
+ this.output.on("close", () => resolve());
3432
+ this.archive.on("error", (err) => reject(err));
3433
+ this.archive.finalize();
3434
+ } catch (err) {
3435
+ reject(err);
3436
+ }
3437
+ });
3438
+ }
3439
+ };
3440
+
3441
+ // src/XlsxWriter.ts
3442
+ var fs2 = __toESM(require("fs"));
3443
+ var import_archiver2 = __toESM(require("archiver"));
3444
+ var import_stream2 = require("stream");
3445
+ var COLUMN_LETTERS = (() => {
3446
+ const letters = [];
3447
+ for (let i = 65; i < 91; i++) {
3448
+ letters.push(String.fromCharCode(i));
3449
+ }
3450
+ const temp = [];
3451
+ for (const p of letters) {
3452
+ for (let i = 65; i < 91; i++) {
3453
+ temp.push(p + String.fromCharCode(i));
3454
+ }
3455
+ }
3456
+ letters.push(...temp);
3457
+ return letters;
3458
+ })();
3459
+ var XlsxWriter = class {
3460
+ /**
3461
+ * @param filePath Destination `.xlsx` path on disk.
3462
+ */
3463
+ constructor(filePath) {
3464
+ this.sheetCount = 0;
3465
+ this.sheetList = [];
3466
+ this.sstArray = [];
3467
+ this.sstMap = /* @__PURE__ */ new Map();
3468
+ this.sstCntAll = 0;
3469
+ this._autofilterIsOn = false;
3470
+ // Format registry
3471
+ this._formatRegistry = /* @__PURE__ */ new Map();
3472
+ this._formatXfMap = /* @__PURE__ */ new Map();
3473
+ this._nextNumfmtId = 165;
3474
+ this._nextXfIndex = 4;
3475
+ this.stream = new StreamingSheetState();
3476
+ this.currentColLetters = [];
3477
+ this.output = fs2.createWriteStream(filePath);
3478
+ this.archive = (0, import_archiver2.default)("zip");
3479
+ this.archive.pipe(this.output);
3480
+ this._oaEpoch = Date.UTC(1899, 11, 30);
3481
+ }
3482
+ _getColumnLetter(colIndex) {
3483
+ return colIndex < COLUMN_LETTERS.length ? COLUMN_LETTERS[colIndex] : "A";
3484
+ }
3485
+ /** @deprecated Internal; kept for unit-test access. Prefer sanitizeSheetName(). */
3486
+ _sanitizeSheetName(name) {
3487
+ return sanitizeSheetName(name, this.sheetCount);
3488
+ }
3489
+ _escapeSheetNameForXml(name) {
3490
+ return name.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
3491
+ }
3492
+ _formatSheetNameForFormula(name) {
3493
+ if (/[\s\-+=()!@#$%^&]/.test(name) || /^[0-9]/.test(name)) {
3494
+ const escaped = name.replace(/'/g, "''");
3495
+ return `'${escaped}'`;
3496
+ }
3497
+ return name;
3498
+ }
3499
+ /**
3500
+ * Register a worksheet (metadata only). Prefer `writeSheet` / `startSheet` for data.
3501
+ */
3502
+ addSheet(sheetName, hidden = false) {
3503
+ const sanitizedName = sanitizeSheetName(sheetName, this.sheetCount);
3504
+ this.sheetCount++;
3505
+ const rId = `rId${this.sheetCount}`;
3506
+ const sheetFileName = `sheet${this.sheetCount}.xml`;
3507
+ this.sheetList.push({
3508
+ name: sanitizedName,
3509
+ pathInArchive: `xl/worksheets/${sheetFileName}`,
3510
+ hidden,
3511
+ nameInArchive: sheetFileName,
3512
+ sheetId: this.sheetCount,
3513
+ rId,
3514
+ filterHeaderRange: null
3515
+ });
3516
+ }
3517
+ _needsEscape(str) {
3518
+ for (let i = 0; i < str.length; i++) {
3519
+ const c = str.charCodeAt(i);
3520
+ if (c === 38 || c === 60 || c === 62 || c === 34 || c === 39 || c >= 0 && c <= 8 || c === 11 || c === 12 || c >= 14 && c <= 31) {
3521
+ return true;
3522
+ }
3523
+ }
3524
+ return false;
3525
+ }
3526
+ _escape(str) {
3527
+ if (typeof str !== "string") return str;
3528
+ if (!this._needsEscape(str)) return str;
3529
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g, "");
3530
+ }
3531
+ /**
3532
+ * Start streaming a sheet. Call `writeRow` for each row, then `endSheet`.
3533
+ */
3534
+ startSheet(sheetName, columnCount, headers, options = {}) {
3535
+ const { hidden = false, doAutofilter = true, sampleRows } = options;
3536
+ this.addSheet(sheetName, hidden);
3537
+ this.stream.begin(columnCount, doAutofilter && headers !== void 0, new BigBuffer());
3538
+ const bigBuf = this.stream.buffer;
3539
+ const colLetters = new Array(columnCount);
3540
+ for (let i = 0; i < columnCount; i++) {
3541
+ colLetters[i] = this._getColumnLetter(i);
3542
+ }
3543
+ this.currentColLetters = colLetters;
3544
+ if (headers) {
3545
+ applyHeaderWidths(this.stream.colWidths, headers, columnCount);
3546
+ }
3547
+ if (sampleRows) {
3548
+ updateColWidthsFromRows(this.stream.colWidths, sampleRows);
3549
+ }
3550
+ bigBuf.writeString('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
3551
+ bigBuf.writeString('<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
3552
+ bigBuf.writeString('<dimension ref="A1"/>');
3553
+ const isFirstSheet = this.sheetCount === 1;
3554
+ if (headers) {
3555
+ if (isFirstSheet) {
3556
+ bigBuf.writeString('<sheetViews><sheetView tabSelected="1" workbookViewId="0"><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen" /><selection pane="bottomLeft" /></sheetView></sheetViews><sheetFormatPr defaultRowHeight="15"/>');
3557
+ } else {
3558
+ bigBuf.writeString('<sheetViews><sheetView workbookViewId="0"><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen" /><selection pane="bottomLeft" /></sheetView></sheetViews><sheetFormatPr defaultRowHeight="15"/>');
3559
+ }
3560
+ } else {
3561
+ if (isFirstSheet) {
3562
+ bigBuf.writeString('<sheetViews><sheetView tabSelected="1" workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/>');
3563
+ } else {
3564
+ bigBuf.writeString('<sheetViews><sheetView workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/>');
3565
+ }
3566
+ }
3567
+ bigBuf.writeString("<cols>");
3568
+ for (let i = 0; i < columnCount; i++) {
3569
+ const width = defaultColWidth(this.stream.colWidths[i]);
3570
+ bigBuf.writeString(`<col min="${i + 1}" max="${i + 1}" width="${width}" bestFit="1" customWidth="1" />`);
3571
+ }
3572
+ bigBuf.writeString("</cols><sheetData>");
3573
+ if (headers) {
3574
+ this.stream.rowNum++;
3575
+ bigBuf.writeString(`<row r="${this.stream.rowNum}">`);
3576
+ for (let c = 0; c < headers.length; c++) {
3577
+ this._writeStringCell(bigBuf, headers[c], colLetters[c], this.stream.rowNum, 3);
3578
+ }
3579
+ bigBuf.writeString("</row>");
3580
+ }
3581
+ }
3582
+ /** Write one data row in streaming mode. */
3583
+ writeRow(row) {
3584
+ const bigBuf = this.stream.assertStreaming();
3585
+ if (row.length !== this.stream.endCol - this.stream.startCol) {
3586
+ throw new Error(
3587
+ `Row length mismatch. Expected ${this.stream.endCol - this.stream.startCol} columns, got ${row.length}`
3588
+ );
3589
+ }
3590
+ this.stream.rowNum++;
3591
+ bigBuf.writeString(`<row r="${this.stream.rowNum}">`);
3592
+ for (let c = 0; c < row.length; c++) {
3593
+ const raw = row[c];
3594
+ if (raw === null || raw === void 0) continue;
3595
+ const fmtString = getFormat(raw);
3596
+ const val = fmtString !== null ? unwrapCell(raw) : raw;
3597
+ const xfIdx = fmtString !== null ? this._registerFormat(fmtString) : -1;
3598
+ const styleAttr = xfIdx >= 0 ? ` s="${xfIdx}"` : "";
3599
+ const colRef = this.currentColLetters[c];
3600
+ if (typeof val === "number") {
3601
+ if (Number.isFinite(val)) {
3602
+ bigBuf.writeString(`<c r="${colRef}${this.stream.rowNum}"${styleAttr}><v>${val}</v></c>`);
3603
+ } else {
3604
+ this._writeStringCell(bigBuf, val.toString(), colRef, this.stream.rowNum, xfIdx >= 0 ? xfIdx : void 0);
3605
+ }
3606
+ } else if (typeof val === "bigint") {
3607
+ this._writeStringCell(bigBuf, val.toString(), colRef, this.stream.rowNum, xfIdx >= 0 ? xfIdx : void 0);
3608
+ } else if (typeof val === "boolean") {
3609
+ bigBuf.writeString(`<c r="${colRef}${this.stream.rowNum}" t="b"${styleAttr}><v>${val ? 1 : 0}</v></c>`);
3610
+ } else if (val instanceof Date) {
3611
+ const oaDate = this._toOADate(val);
3612
+ if (Number.isFinite(oaDate)) {
3613
+ const finalStyle = xfIdx >= 0 ? xfIdx : 1;
3614
+ bigBuf.writeString(`<c r="${colRef}${this.stream.rowNum}" s="${finalStyle}"><v>${oaDate}</v></c>`);
3615
+ } else {
3616
+ this._writeStringCell(bigBuf, val.toString(), colRef, this.stream.rowNum, xfIdx >= 0 ? xfIdx : void 0);
3617
+ }
3618
+ } else if (val !== null && val !== void 0) {
3619
+ this._writeStringCell(bigBuf, val.toString(), colRef, this.stream.rowNum, xfIdx >= 0 ? xfIdx : void 0);
3620
+ }
3621
+ }
3622
+ bigBuf.writeString("</row>");
3623
+ }
3624
+ /** Finish the current streaming sheet and append it to the archive. */
3625
+ endSheet() {
3626
+ const bigBuf = this.stream.assertStreaming();
3627
+ bigBuf.writeString("</sheetData>");
3628
+ if (this.stream.doAutofilter && this.stream.endCol > 0) {
3629
+ this._autofilterIsOn = true;
3630
+ const filterRef = `A1:${this.currentColLetters[this.stream.endCol - 1]}${this.stream.rowNum}`;
3631
+ bigBuf.writeString(`<autoFilter ref="${filterRef}"/>`);
3632
+ const sheet = this.sheetList[this.sheetCount - 1];
3633
+ const formulaSheetName = this._formatSheetNameForFormula(sheet.name);
3634
+ sheet.filterHeaderRange = `${formulaSheetName}!$A$1:$${this.currentColLetters[this.stream.endCol - 1]}$${this.stream.rowNum}`;
3635
+ }
3636
+ bigBuf.writeString("</worksheet>");
3637
+ this.archive.append(import_stream2.Readable.from(bigBuf.getChunks()), {
3638
+ name: this.sheetList[this.sheetCount - 1].pathInArchive
3639
+ });
3640
+ this.stream.end();
3641
+ this.currentColLetters = [];
3642
+ }
3643
+ /**
3644
+ * Write an entire sheet in one call (batch mode).
3645
+ */
3646
+ writeSheet(rows, headers = null, doAutofilter = true) {
3647
+ const bigBuf = new BigBuffer();
3648
+ let columnCount = 0;
3649
+ if (rows.length > 0) {
3650
+ columnCount = rows[0].length;
3651
+ } else if (headers) {
3652
+ columnCount = headers.length;
3653
+ }
3654
+ const colWidths = initColWidths(columnCount);
3655
+ const colLetters = new Array(columnCount);
3656
+ for (let i = 0; i < columnCount; i++) {
3657
+ colLetters[i] = this._getColumnLetter(i);
3658
+ }
3659
+ if (headers) {
3660
+ applyHeaderWidths(colWidths, headers, columnCount);
3661
+ }
3662
+ updateColWidthsFromRows(colWidths, rows);
3663
+ bigBuf.writeString('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
3664
+ bigBuf.writeString('<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">');
3665
+ const totalRows = rows.length + (headers ? 1 : 0);
3666
+ if (totalRows > 0 && columnCount > 0) {
3667
+ bigBuf.writeString(`<dimension ref="A1:${colLetters[columnCount - 1]}${totalRows}"/>`);
3668
+ } else {
3669
+ bigBuf.writeString('<dimension ref="A1"/>');
3670
+ }
3671
+ const isFirstSheet = this.sheetCount === 1;
3672
+ if (headers) {
3673
+ if (isFirstSheet) {
3674
+ bigBuf.writeString('<sheetViews><sheetView tabSelected="1" workbookViewId="0"><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen" /><selection pane="bottomLeft" /></sheetView></sheetViews><sheetFormatPr defaultRowHeight="15"/>');
3675
+ } else {
3676
+ bigBuf.writeString('<sheetViews><sheetView workbookViewId="0"><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen" /><selection pane="bottomLeft" /></sheetView></sheetViews><sheetFormatPr defaultRowHeight="15"/>');
3677
+ }
3678
+ } else {
3679
+ if (isFirstSheet) {
3680
+ bigBuf.writeString('<sheetViews><sheetView tabSelected="1" workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/>');
3681
+ } else {
3682
+ bigBuf.writeString('<sheetViews><sheetView workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/>');
3683
+ }
3684
+ }
3685
+ bigBuf.writeString("<cols>");
3686
+ for (let i = 0; i < columnCount; i++) {
3687
+ const width = defaultColWidth(colWidths[i]);
3688
+ bigBuf.writeString(`<col min="${i + 1}" max="${i + 1}" width="${width}" bestFit="1" customWidth="1" />`);
3689
+ }
3690
+ bigBuf.writeString("</cols><sheetData>");
3691
+ let rowNum = 0;
3692
+ if (headers) {
3693
+ rowNum++;
3694
+ bigBuf.writeString(`<row r="${rowNum}">`);
3695
+ for (let c = 0; c < headers.length; c++) {
3696
+ this._writeStringCell(bigBuf, headers[c], colLetters[c], rowNum, 3);
3697
+ }
3698
+ bigBuf.writeString("</row>");
3699
+ }
3700
+ for (let r = 0; r < rows.length; r++) {
3701
+ rowNum++;
3702
+ bigBuf.writeString(`<row r="${rowNum}">`);
3703
+ const row = rows[r];
3704
+ for (let c = 0; c < row.length; c++) {
3705
+ const raw = row[c];
3706
+ if (raw === null || raw === void 0) continue;
3707
+ const fmtString = getFormat(raw);
3708
+ const val = fmtString !== null ? unwrapCell(raw) : raw;
3709
+ const xfIdx = fmtString !== null ? this._registerFormat(fmtString) : -1;
3710
+ const styleAttr = xfIdx >= 0 ? ` s="${xfIdx}"` : "";
3711
+ const colRef = colLetters[c];
3712
+ if (typeof val === "number") {
3713
+ if (Number.isFinite(val)) {
3714
+ bigBuf.writeString(`<c r="${colRef}${rowNum}"${styleAttr}><v>${val}</v></c>`);
3715
+ } else {
3716
+ this._writeStringCell(bigBuf, val.toString(), colRef, rowNum, xfIdx >= 0 ? xfIdx : void 0);
3717
+ }
3718
+ } else if (typeof val === "bigint") {
3719
+ this._writeStringCell(bigBuf, val.toString(), colRef, rowNum, xfIdx >= 0 ? xfIdx : void 0);
3720
+ } else if (typeof val === "boolean") {
3721
+ bigBuf.writeString(`<c r="${colRef}${rowNum}" t="b"${styleAttr}><v>${val ? 1 : 0}</v></c>`);
3722
+ } else if (val instanceof Date) {
3723
+ const oaDate = this._toOADate(val);
3724
+ if (Number.isFinite(oaDate)) {
3725
+ const finalStyle = xfIdx >= 0 ? xfIdx : 1;
3726
+ bigBuf.writeString(`<c r="${colRef}${rowNum}" s="${finalStyle}"><v>${oaDate}</v></c>`);
3727
+ } else {
3728
+ this._writeStringCell(bigBuf, val.toString(), colRef, rowNum, xfIdx >= 0 ? xfIdx : void 0);
3729
+ }
3730
+ } else if (val !== null && val !== void 0) {
3731
+ this._writeStringCell(bigBuf, val.toString(), colRef, rowNum, xfIdx >= 0 ? xfIdx : void 0);
3732
+ }
3733
+ }
3734
+ bigBuf.writeString("</row>");
3735
+ }
3736
+ bigBuf.writeString("</sheetData>");
3737
+ if (doAutofilter && headers && columnCount > 0) {
3738
+ this._autofilterIsOn = true;
3739
+ const filterRef = `A1:${colLetters[columnCount - 1]}${totalRows}`;
3740
+ bigBuf.writeString(`<autoFilter ref="${filterRef}"/>`);
3741
+ const sheet = this.sheetList[this.sheetCount - 1];
3742
+ const formulaSheetName = this._formatSheetNameForFormula(sheet.name);
3743
+ sheet.filterHeaderRange = `${formulaSheetName}!$A$1:$${colLetters[columnCount - 1]}$${totalRows}`;
3744
+ }
3745
+ bigBuf.writeString("</worksheet>");
3746
+ this.archive.append(import_stream2.Readable.from(bigBuf.getChunks()), {
3747
+ name: this.sheetList[this.sheetCount - 1].pathInArchive
3748
+ });
3749
+ }
3750
+ _writeStringCell(bigBuf, val, colRef, rowNum, styleOverride) {
3751
+ let index = this.sstMap.get(val);
3752
+ if (index === void 0) {
3753
+ index = this.sstArray.length;
3754
+ this.sstArray.push(val);
3755
+ this.sstMap.set(val, index);
3756
+ }
3757
+ this.sstCntAll++;
3758
+ const styleAttr = styleOverride !== void 0 ? ` s="${styleOverride}"` : "";
3759
+ bigBuf.writeString(`<c r="${colRef}${rowNum}" t="s"${styleAttr}><v>${index}</v></c>`);
3760
+ }
3761
+ _registerFormat(fmtString) {
3762
+ if (this._formatXfMap.has(fmtString)) {
3763
+ return this._formatXfMap.get(fmtString);
3764
+ }
3765
+ const numfmtId = this._nextNumfmtId++;
3766
+ this._formatRegistry.set(fmtString, numfmtId);
3767
+ const xfIndex = this._nextXfIndex++;
3768
+ this._formatXfMap.set(fmtString, xfIndex);
3769
+ return xfIndex;
3770
+ }
3771
+ _toOADate(date) {
3772
+ return (date.getTime() - this._oaEpoch) / 864e5;
3773
+ }
3774
+ _getDateWidth(_date) {
3775
+ return 19;
3776
+ }
3777
+ /** Finalize the ZIP package and close the output stream. */
3778
+ finalize() {
3779
+ return new Promise((resolve, reject) => {
3780
+ try {
3781
+ this._writeSharedStrings();
3782
+ this._writeStyles();
3783
+ this._writeWorkbook();
3784
+ this._writeContentTypes();
3785
+ this._writeRels();
3786
+ this.output.on("close", () => {
3787
+ resolve();
3788
+ });
3789
+ this.archive.on("error", (err) => {
3790
+ reject(err);
3791
+ });
3792
+ this.archive.finalize();
3793
+ } catch (err) {
3794
+ reject(err);
3795
+ }
3796
+ });
3797
+ }
3798
+ _writeSharedStrings() {
3799
+ const bigBuf = new BigBuffer();
3800
+ bigBuf.writeString('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
3801
+ bigBuf.writeString(`<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="${this.sstCntAll}" uniqueCount="${this.sstArray.length}">`);
3802
+ for (let i = 0; i < this.sstArray.length; i++) {
3803
+ const txt = this.sstArray[i];
3804
+ const cleanTxt = this._escape(txt);
3805
+ if (cleanTxt.length > 0 && (cleanTxt[0] === " " || cleanTxt[cleanTxt.length - 1] === " " || /[\t\n\r]/.test(cleanTxt))) {
3806
+ bigBuf.writeString(`<si><t xml:space="preserve">${cleanTxt}</t></si>`);
3807
+ } else {
3808
+ bigBuf.writeString(`<si><t>${cleanTxt}</t></si>`);
3809
+ }
3810
+ }
3811
+ bigBuf.writeString("</sst>");
3812
+ this.archive.append(import_stream2.Readable.from(bigBuf.getChunks()), { name: "xl/sharedStrings.xml" });
3813
+ }
3814
+ _writeStyles() {
3815
+ let numFmts = "";
3816
+ let numFmtCount = 0;
3817
+ const xfEntries = [];
3818
+ xfEntries.push('<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>');
3819
+ xfEntries.push('<xf numFmtId="14" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>');
3820
+ xfEntries.push('<xf numFmtId="22" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>');
3821
+ xfEntries.push('<xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" applyFont="1"/>');
3822
+ for (const [fmtString, numfmtId] of this._formatRegistry) {
3823
+ const escapedFmt = fmtString.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
3824
+ numFmts += `<numFmt numFmtId="${numfmtId}" formatCode="${escapedFmt}"/>`;
3825
+ numFmtCount++;
3826
+ }
3827
+ const sortedFormats = [...this._formatXfMap.entries()].sort((a, b) => a[1] - b[1]);
3828
+ for (const [fmtString] of sortedFormats) {
3829
+ const numfmtId = this._formatRegistry.get(fmtString);
3830
+ xfEntries.push(`<xf numFmtId="${numfmtId}" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>`);
3831
+ }
3832
+ const totalXf = xfEntries.length;
3833
+ const numFmtsSection = numFmtCount > 0 ? `<numFmts count="${numFmtCount}">${numFmts}</numFmts>` : "";
3834
+ const styles = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3835
+ <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
3836
+ ${numFmtsSection}
3837
+ <fonts count="2">
3838
+ <font><sz val="11"/><color theme="1"/><name val="Calibri"/><family val="2"/><scheme val="minor"/></font>
3839
+ <font><b/><sz val="11"/><color theme="1"/><name val="Calibri"/><family val="2"/><scheme val="minor"/></font>
3840
+ </fonts>
3841
+ <fills count="2">
3842
+ <fill><patternFill patternType="none"/></fill>
3843
+ <fill><patternFill patternType="gray125"/></fill>
3844
+ </fills>
3845
+ <borders count="1">
3846
+ <border><left/><right/><top/><bottom/><diagonal/></border>
3847
+ </borders>
3848
+ <cellStyleXfs count="1">
3849
+ <xf numFmtId="0" fontId="0" fillId="0" borderId="0"/>
3850
+ </cellStyleXfs>
3851
+ <cellXfs count="${totalXf}">
3852
+ ${xfEntries.join("\n")}
3853
+ </cellXfs>
3854
+ <cellStyles count="1">
3855
+ <cellStyle name="Normal" xfId="0" builtinId="0"/>
3856
+ </cellStyles>
3857
+ <dxfs count="0"/>
3858
+ <tableStyles count="0" defaultTableStyle="TableStyleMedium2" defaultPivotStyle="PivotStyleLight16"/>
3859
+ </styleSheet>`;
3860
+ this.archive.append(styles, { name: "xl/styles.xml" });
3861
+ }
3862
+ _writeWorkbook() {
3863
+ let xml = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3864
+ <workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
3865
+ <fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4505"/>
3866
+ <workbookPr defaultThemeVersion="124226"/>
3867
+ <bookViews><workbookView xWindow="240" yWindow="15" windowWidth="16095" windowHeight="9660"/></bookViews>
3868
+ <sheets>`;
3869
+ for (const sheet of this.sheetList) {
3870
+ const state = sheet.hidden ? ' state="hidden"' : "";
3871
+ const escapedName = this._escapeSheetNameForXml(sheet.name);
3872
+ xml += `<sheet name="${escapedName}" sheetId="${sheet.sheetId}"${state} r:id="${sheet.rId}"/>`;
3873
+ }
3874
+ xml += `</sheets>`;
3875
+ if (this._autofilterIsOn) {
3876
+ xml += "<definedNames>";
3877
+ for (const sheet of this.sheetList) {
3878
+ if (sheet.filterHeaderRange) {
3879
+ const localSheetId = sheet.sheetId - 1;
3880
+ const escapedRange = this._escape(sheet.filterHeaderRange);
3881
+ xml += `<definedName name="_xlnm._FilterDatabase" localSheetId="${localSheetId}" hidden="1">${escapedRange}</definedName>`;
3882
+ }
3883
+ }
3884
+ xml += "</definedNames>";
3885
+ }
3886
+ xml += '<calcPr calcId="124519" fullCalcOnLoad="1"/>';
3887
+ xml += `</workbook>`;
3888
+ this.archive.append(xml, { name: "xl/workbook.xml" });
3889
+ }
3890
+ _writeContentTypes() {
3891
+ let xml = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3892
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
3893
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
3894
+ <Default Extension="xml" ContentType="application/xml"/>
3895
+ <Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
3896
+ <Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>
3897
+ <Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>`;
3898
+ for (const sheet of this.sheetList) {
3899
+ xml += `<Override PartName="/${sheet.pathInArchive}" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>`;
3900
+ }
3901
+ xml += `</Types>`;
3902
+ this.archive.append(xml, { name: "[Content_Types].xml" });
3903
+ }
3904
+ _writeRels() {
3905
+ const globalRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3906
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
3907
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
3908
+ </Relationships>`;
3909
+ this.archive.append(globalRels, { name: "_rels/.rels" });
3910
+ let wbRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3911
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`;
3912
+ for (const sheet of this.sheetList) {
3913
+ wbRels += `<Relationship Id="${sheet.rId}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/${sheet.nameInArchive}"/>`;
3914
+ }
3915
+ let nextId = this.sheetList.length + 1;
3916
+ wbRels += `<Relationship Id="rId${nextId++}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>`;
3917
+ wbRels += `<Relationship Id="rId${nextId++}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>`;
3918
+ wbRels += `</Relationships>`;
3919
+ this.archive.append(wbRels, { name: "xl/_rels/workbook.xml.rels" });
3920
+ }
3921
+ };
3922
+ // Annotate the CommonJS export names for ESM import in node:
3923
+ 0 && (module.exports = {
3924
+ BiffReaderWriter,
3925
+ BigBuffer,
3926
+ ExcelReaderAbstract,
3927
+ F,
3928
+ INVALID_SHEET_NAME_CHARS,
3929
+ ReaderFactory,
3930
+ StreamingSheetState,
3931
+ XlsbReader,
3932
+ XlsbWriter,
3933
+ XlsxReader,
3934
+ XlsxWriter,
3935
+ applyHeaderWidths,
3936
+ defaultColWidth,
3937
+ getFormat,
3938
+ initColWidths,
3939
+ isFormattedCell,
3940
+ sanitizeSheetName,
3941
+ unwrapCell,
3942
+ updateColWidthsFromRows
3943
+ });
3944
+ //# sourceMappingURL=index.js.map