javascript-excel 2.0.0-alpha.2 → 2.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +151 -21
- package/dist/address-DUn7-5OS.js +75 -0
- package/dist/address-DZBHchLv.cjs +122 -0
- package/dist/{auto-width-2oBzjeNG.d.cts → auto-width-DRHsPKNk.d.cts} +1 -1
- package/dist/cells-CPXU722t.cjs +33 -0
- package/dist/cells-CrMF8h_t.js +28 -0
- package/dist/colors-B8Nf_xTx.js +114 -0
- package/dist/colors-oBpjx97l.cjs +119 -0
- package/dist/csv.d.cts +4 -1
- package/dist/csv.d.ts +4 -1
- package/dist/dataset-KeMzHCGl.js +664 -0
- package/dist/dataset-UUZCzsi3.cjs +687 -0
- package/dist/dates-BXcSWf9_.js +64 -0
- package/dist/dates-CA1dCizp.cjs +75 -0
- package/dist/dom.cjs +5 -2
- package/dist/dom.d.cts +5 -2
- package/dist/dom.d.ts +4 -1
- package/dist/dom.js +4 -1
- package/dist/{numfmt-Dv6AjopS.cjs → dos-time-FZ7-1tot.cjs} +0 -199
- package/dist/{numfmt-BBgB7iQA.js → dos-time-dD0z1YWU.js} +2 -177
- package/dist/format.cjs +1264 -0
- package/dist/format.d.cts +59 -0
- package/dist/format.d.ts +59 -0
- package/dist/format.js +1262 -0
- package/dist/import.cjs +10 -0
- package/dist/import.d.cts +10 -0
- package/dist/import.d.ts +10 -0
- package/dist/import.js +1 -0
- package/dist/index.cjs +24 -607
- package/dist/index.d.cts +32 -6
- package/dist/index.d.ts +31 -5
- package/dist/index.js +10 -594
- package/dist/{warnings-C_12PT4t.d.cts → model-0JikLfuM.d.cts} +1 -41
- package/dist/{warnings-DXJKe1lx.d.ts → model-0JikLfuM.d.ts} +1 -41
- package/dist/numfmt-BmEbm78Y.cjs +125 -0
- package/dist/numfmt-DCDrX9P1.js +114 -0
- package/dist/pipeline-BAJtzBdW.js +1085 -0
- package/dist/pipeline-Bnf7EU3X.cjs +1132 -0
- package/dist/pipeline-CctEa86r.d.cts +186 -0
- package/dist/pipeline-I8SLmV9S.d.ts +186 -0
- package/dist/{read-Ym1voUct.cjs → read-CZEWV4rK.cjs} +181 -17
- package/dist/{read-DDN5ZsPe.js → read-LWti17lz.js} +169 -5
- package/dist/read.cjs +1 -1
- package/dist/read.d.cts +78 -4
- package/dist/read.d.ts +78 -4
- package/dist/read.js +1 -1
- package/dist/render.cjs +751 -0
- package/dist/render.d.cts +215 -0
- package/dist/render.d.ts +215 -0
- package/dist/render.js +732 -0
- package/dist/{sheet-names-uT2EH5Ui.js → sheet-names-7p-joVsG.js} +2 -101
- package/dist/{sheet-names-qpXsvMpM.cjs → sheet-names-B8U5RAW0.cjs} +14 -167
- package/dist/warnings-B1v58nCZ.d.cts +41 -0
- package/dist/warnings-B1v58nCZ.d.ts +41 -0
- package/dist/worker.cjs +10 -2
- package/dist/worker.d.cts +10 -4
- package/dist/worker.d.ts +10 -4
- package/dist/worker.js +10 -2
- package/dist/{write-CYpLGuzl.d.ts → write-DM6ieuQY.d.ts} +2 -1
- package/dist/{write-DubvcG-x.js → write-DjgWy1PK.js} +5 -2
- package/dist/{write-C5JgeIar.d.cts → write-DtjfdIFm.d.cts} +2 -1
- package/dist/{write-BOh9jfu1.cjs → write-f9kcYf5K.cjs} +31 -28
- package/package.json +32 -1
- package/dist/read-C6L7Nyy3.d.cts +0 -78
- package/dist/read-Ddkks7qC.d.ts +0 -78
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const require_infer = require("./infer-D9EC9vJ-.cjs");
|
|
2
2
|
const require_errors = require("./errors-DOPrrGS4.cjs");
|
|
3
|
-
const
|
|
3
|
+
const require_dos_time = require("./dos-time-FZ7-1tot.cjs");
|
|
4
|
+
const require_numfmt = require("./numfmt-BmEbm78Y.cjs");
|
|
5
|
+
const require_dates = require("./dates-CA1dCizp.cjs");
|
|
4
6
|
// src/internal/read/limits.ts
|
|
5
7
|
/** Default limits (docs/api.md §5.2; the measurements behind each value are listed there). */
|
|
6
8
|
const DEFAULT_LIMITS = Object.freeze({
|
|
@@ -100,14 +102,14 @@ var Cursor = class {
|
|
|
100
102
|
};
|
|
101
103
|
function decodeName(raw, flags, extra) {
|
|
102
104
|
if (flags & FLAG_UTF8) try {
|
|
103
|
-
return
|
|
105
|
+
return require_dos_time.decodeUtf8Strict(raw);
|
|
104
106
|
} catch {
|
|
105
107
|
throw invalid("Entry name is not valid UTF-8.");
|
|
106
108
|
}
|
|
107
109
|
const unicode = findExtra(extra, EXTRA_UNICODE_PATH);
|
|
108
110
|
if (unicode && unicode.length >= 5 && unicode[0] === 1) {
|
|
109
|
-
if (new Cursor(unicode, 1).u32() ===
|
|
110
|
-
return
|
|
111
|
+
if (new Cursor(unicode, 1).u32() === require_dos_time.crc32(raw)) try {
|
|
112
|
+
return require_dos_time.decodeUtf8Strict(unicode.subarray(5));
|
|
111
113
|
} catch {}
|
|
112
114
|
}
|
|
113
115
|
let s = "";
|
|
@@ -140,7 +142,7 @@ function openZip(bytes, options = {}) {
|
|
|
140
142
|
...DEFAULT_ZIP_LIMITS,
|
|
141
143
|
...options.limits
|
|
142
144
|
};
|
|
143
|
-
const codec = options.codec ??
|
|
145
|
+
const codec = options.codec ?? require_dos_time.nativeCodec;
|
|
144
146
|
if (bytes.length > limits.maxInputBytes) throw limitError("maxInputBytes", bytes.length, limits.maxInputBytes, "Input size");
|
|
145
147
|
if (bytes.length < 22) throw invalid("Not a zip file: too short.");
|
|
146
148
|
const eocdPos = findEocd(bytes);
|
|
@@ -253,7 +255,7 @@ function openZip(bytes, options = {}) {
|
|
|
253
255
|
crc32: crc,
|
|
254
256
|
compressedSize,
|
|
255
257
|
size,
|
|
256
|
-
modified:
|
|
258
|
+
modified: require_dos_time.fromDosDateTime(date, time),
|
|
257
259
|
dataOffset
|
|
258
260
|
});
|
|
259
261
|
entries.push(info);
|
|
@@ -273,14 +275,14 @@ function openZip(bytes, options = {}) {
|
|
|
273
275
|
};
|
|
274
276
|
async function* stream(entry, signal) {
|
|
275
277
|
const info = resolve(entry);
|
|
276
|
-
|
|
278
|
+
require_dos_time.throwIfAborted(signal);
|
|
277
279
|
if (info.size > limits.maxEntryBytes) throw limitError("maxEntryBytes", info.size, limits.maxEntryBytes, `Entry ${info.name}`);
|
|
278
280
|
const data = bytes.subarray(info.dataOffset, info.dataOffset + info.compressedSize);
|
|
279
281
|
let crc = 0;
|
|
280
282
|
let produced = 0;
|
|
281
283
|
if (info.method === 0) {
|
|
282
284
|
countTotal(data.length);
|
|
283
|
-
crc =
|
|
285
|
+
crc = require_dos_time.crc32(data);
|
|
284
286
|
produced = data.length;
|
|
285
287
|
if (crc !== info.crc32) throw crcMismatch(info);
|
|
286
288
|
yield data;
|
|
@@ -294,7 +296,7 @@ function openZip(bytes, options = {}) {
|
|
|
294
296
|
produced += chunk.length;
|
|
295
297
|
if (produced > info.size) throw invalid(`Entry ${info.name} is larger than declared.`, { entry: info.name });
|
|
296
298
|
countTotal(chunk.length);
|
|
297
|
-
crc =
|
|
299
|
+
crc = require_dos_time.crc32(chunk, crc);
|
|
298
300
|
yield chunk;
|
|
299
301
|
}
|
|
300
302
|
if (produced !== info.size) throw invalid(`Entry ${info.name} is smaller than declared.`, { entry: info.name });
|
|
@@ -307,7 +309,7 @@ function openZip(bytes, options = {}) {
|
|
|
307
309
|
async read(entry, signal) {
|
|
308
310
|
const parts = [];
|
|
309
311
|
for await (const chunk of stream(entry, signal)) parts.push(chunk);
|
|
310
|
-
return
|
|
312
|
+
return require_dos_time.concatBytes(parts);
|
|
311
313
|
},
|
|
312
314
|
get totalBytesRead() {
|
|
313
315
|
return totalBytesRead;
|
|
@@ -378,12 +380,24 @@ var XmlTokenizer = class {
|
|
|
378
380
|
maxDepth;
|
|
379
381
|
buf = "";
|
|
380
382
|
stack = [];
|
|
383
|
+
/** While skipping: the end tag being searched for ("</qname"), and the depth to keep. */
|
|
384
|
+
skipTag;
|
|
385
|
+
skipDepth = 0;
|
|
381
386
|
rootSeen = false;
|
|
382
387
|
rootClosed = false;
|
|
383
388
|
pendingCR = false;
|
|
384
389
|
constructor(handler, maxDepth) {
|
|
385
390
|
this.handler = handler;
|
|
386
391
|
this.maxDepth = maxDepth;
|
|
392
|
+
handler.attach?.(this);
|
|
393
|
+
}
|
|
394
|
+
depth() {
|
|
395
|
+
return this.stack.length;
|
|
396
|
+
}
|
|
397
|
+
skipToEndOf(depth) {
|
|
398
|
+
if (depth < 1 || depth > this.stack.length) throw new RangeError(`skipToEndOf: no open element at depth ${depth}`);
|
|
399
|
+
this.skipTag = `</${this.stack[depth - 1]}`;
|
|
400
|
+
this.skipDepth = depth;
|
|
387
401
|
}
|
|
388
402
|
feed(chunk) {
|
|
389
403
|
this.buf = this.buf.length === 0 ? chunk : this.buf + chunk;
|
|
@@ -400,6 +414,20 @@ var XmlTokenizer = class {
|
|
|
400
414
|
const len = buf.length;
|
|
401
415
|
let i = 0;
|
|
402
416
|
while (i < len) {
|
|
417
|
+
if (this.skipTag !== void 0) {
|
|
418
|
+
const tag = this.skipTag;
|
|
419
|
+
let at = buf.indexOf(tag, i);
|
|
420
|
+
while (at !== -1 && at + tag.length < len && !isNameEnd(buf.charCodeAt(at + tag.length))) at = buf.indexOf(tag, at + 1);
|
|
421
|
+
if (at === -1 || at + tag.length >= len) {
|
|
422
|
+
if (final) throw malformed(`Element <${tag.slice(2)}> is not closed.`);
|
|
423
|
+
i = Math.max(i, len - tag.length);
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
this.stack.length = this.skipDepth;
|
|
427
|
+
this.skipTag = void 0;
|
|
428
|
+
i = at;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
403
431
|
if (buf.charCodeAt(i) !== 60) {
|
|
404
432
|
let j = buf.indexOf("<", i);
|
|
405
433
|
if (j === -1) {
|
|
@@ -534,6 +562,9 @@ var XmlTokenizer = class {
|
|
|
534
562
|
this.handler.open(localName(qname), attrs, selfClosing);
|
|
535
563
|
}
|
|
536
564
|
};
|
|
565
|
+
function isNameEnd(c) {
|
|
566
|
+
return c === 62 || isSpace(c);
|
|
567
|
+
}
|
|
537
568
|
function isSpace(c) {
|
|
538
569
|
return c === 32 || c === 9 || c === 10 || c === 13;
|
|
539
570
|
}
|
|
@@ -626,7 +657,7 @@ var ReadContext = class {
|
|
|
626
657
|
this.limits = limits;
|
|
627
658
|
this.signal = signal;
|
|
628
659
|
this.onWarning = onWarning;
|
|
629
|
-
this.onProgress =
|
|
660
|
+
this.onProgress = require_dos_time.throttleProgress(onProgress);
|
|
630
661
|
}
|
|
631
662
|
onProgress;
|
|
632
663
|
warn(code, message, where) {
|
|
@@ -660,7 +691,7 @@ var ReadContext = class {
|
|
|
660
691
|
} });
|
|
661
692
|
}
|
|
662
693
|
checkAbort() {
|
|
663
|
-
|
|
694
|
+
require_dos_time.throwIfAborted(this.signal);
|
|
664
695
|
}
|
|
665
696
|
progress(p) {
|
|
666
697
|
this.onProgress?.(p);
|
|
@@ -1592,14 +1623,37 @@ var StringItem = class {
|
|
|
1592
1623
|
var SharedStringsParser = class {
|
|
1593
1624
|
mode;
|
|
1594
1625
|
max;
|
|
1626
|
+
stopAfter;
|
|
1595
1627
|
strings = [];
|
|
1596
1628
|
item;
|
|
1597
1629
|
depth = 0;
|
|
1598
|
-
|
|
1630
|
+
control;
|
|
1631
|
+
/**
|
|
1632
|
+
* `stopAfter`: decode only the first `stopAfter` items, then jump to the
|
|
1633
|
+
* end of the part without tokenizing the rest (previews, ReadOptions.maxRows).
|
|
1634
|
+
*/
|
|
1635
|
+
constructor(mode, max, stopAfter = 1e400) {
|
|
1599
1636
|
this.mode = mode;
|
|
1600
1637
|
this.max = max;
|
|
1638
|
+
this.stopAfter = stopAfter;
|
|
1639
|
+
}
|
|
1640
|
+
attach(control) {
|
|
1641
|
+
this.control = control;
|
|
1642
|
+
if (this.stopAfter <= 0) this.stopped = true;
|
|
1643
|
+
}
|
|
1644
|
+
/** True once stopAfter items were decoded and the rest of the part is skipped. */
|
|
1645
|
+
stopped = false;
|
|
1646
|
+
pushed() {
|
|
1647
|
+
if (this.strings.length >= this.stopAfter && !this.stopped && this.control) {
|
|
1648
|
+
this.stopped = true;
|
|
1649
|
+
this.control.skipToEndOf(1);
|
|
1650
|
+
}
|
|
1601
1651
|
}
|
|
1602
1652
|
open(name, a, empty) {
|
|
1653
|
+
if (this.stopped && !this.item && name === "si") {
|
|
1654
|
+
if (!empty) this.control?.skipToEndOf(1);
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1603
1657
|
if (this.item) {
|
|
1604
1658
|
if (!empty) this.depth++;
|
|
1605
1659
|
this.item.open(name, a);
|
|
@@ -1612,8 +1666,10 @@ var SharedStringsParser = class {
|
|
|
1612
1666
|
value: this.strings.length + 1,
|
|
1613
1667
|
max: this.max
|
|
1614
1668
|
} });
|
|
1615
|
-
if (empty)
|
|
1616
|
-
|
|
1669
|
+
if (empty) {
|
|
1670
|
+
this.strings.push("");
|
|
1671
|
+
this.pushed();
|
|
1672
|
+
} else {
|
|
1617
1673
|
this.item = new StringItem();
|
|
1618
1674
|
this.depth = 0;
|
|
1619
1675
|
}
|
|
@@ -1624,6 +1680,7 @@ var SharedStringsParser = class {
|
|
|
1624
1680
|
if (this.depth === 0 && name === "si") {
|
|
1625
1681
|
this.strings.push(this.item.value(this.mode));
|
|
1626
1682
|
this.item = void 0;
|
|
1683
|
+
this.pushed();
|
|
1627
1684
|
return;
|
|
1628
1685
|
}
|
|
1629
1686
|
this.depth--;
|
|
@@ -1655,6 +1712,39 @@ const ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
1655
1712
|
"#PYTHON!",
|
|
1656
1713
|
"#EXTERNAL!"
|
|
1657
1714
|
]);
|
|
1715
|
+
/**
|
|
1716
|
+
* Shared-string cells whose text is filled in after the sheets are parsed
|
|
1717
|
+
* (ReadOptions.maxRows): the reader then decodes only the shared strings
|
|
1718
|
+
* up to the highest index the read rows use. Parallel arrays, one entry per
|
|
1719
|
+
* cell, kept small because a capped read can still hold many cells.
|
|
1720
|
+
*/
|
|
1721
|
+
var DeferredStrings = class {
|
|
1722
|
+
cells = [];
|
|
1723
|
+
indexes = [];
|
|
1724
|
+
rows = [];
|
|
1725
|
+
cols = [];
|
|
1726
|
+
refs = [];
|
|
1727
|
+
sheets = [];
|
|
1728
|
+
parts = [];
|
|
1729
|
+
maxIndex = -1;
|
|
1730
|
+
/** Fills each cell from `sst`; a missing entry is reported and the cell dropped unless it has a formula or style, as on the full path. */
|
|
1731
|
+
resolve(sst, warn) {
|
|
1732
|
+
for (let i = 0; i < this.cells.length; i++) {
|
|
1733
|
+
const cell = this.cells[i];
|
|
1734
|
+
const str = sst[this.indexes[i]];
|
|
1735
|
+
if (str === void 0) {
|
|
1736
|
+
warn(this.refs[i], this.sheets[i], this.parts[i], this.indexes[i]);
|
|
1737
|
+
delete cell.value;
|
|
1738
|
+
cell.type = "empty";
|
|
1739
|
+
const row = this.rows[i];
|
|
1740
|
+
if (cell.formula === void 0 && cell.style === void 0 && row[this.cols[i]] === cell) row[this.cols[i]] = void 0;
|
|
1741
|
+
continue;
|
|
1742
|
+
}
|
|
1743
|
+
cell.value = str;
|
|
1744
|
+
cell.type = typeof str === "string" ? "string" : "richText";
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1658
1748
|
/** Maximum digit width of Calibri 11 in pixels; the writer uses the same value (internal/write/sheet-features.ts). */
|
|
1659
1749
|
const MAX_DIGIT_WIDTH = 7;
|
|
1660
1750
|
/**
|
|
@@ -1708,7 +1798,7 @@ function cleanRange(ref) {
|
|
|
1708
1798
|
function dateOf(serial, date1904, dateZone) {
|
|
1709
1799
|
if (!date1904 && Math.floor(serial) === 60) return void 0;
|
|
1710
1800
|
try {
|
|
1711
|
-
return
|
|
1801
|
+
return require_dates.serialToDate(serial, {
|
|
1712
1802
|
date1904,
|
|
1713
1803
|
dateZone
|
|
1714
1804
|
});
|
|
@@ -1748,6 +1838,8 @@ var SheetParser = class {
|
|
|
1748
1838
|
minCol = 1e400;
|
|
1749
1839
|
maxRow = -1;
|
|
1750
1840
|
maxCol = -1;
|
|
1841
|
+
truncated = false;
|
|
1842
|
+
control;
|
|
1751
1843
|
constructor(name, state, ctx, styles, opts, part) {
|
|
1752
1844
|
this.ctx = ctx;
|
|
1753
1845
|
this.styles = styles;
|
|
@@ -1759,6 +1851,9 @@ var SheetParser = class {
|
|
|
1759
1851
|
};
|
|
1760
1852
|
if (state && state !== "visible") this.sheet.state = state;
|
|
1761
1853
|
}
|
|
1854
|
+
attach(control) {
|
|
1855
|
+
this.control = control;
|
|
1856
|
+
}
|
|
1762
1857
|
open(name, a, empty) {
|
|
1763
1858
|
if (this.inline) {
|
|
1764
1859
|
if (!empty) this.inlineDepth++;
|
|
@@ -1933,6 +2028,10 @@ var SheetParser = class {
|
|
|
1933
2028
|
} else this.curRow++;
|
|
1934
2029
|
this.nextCol = 0;
|
|
1935
2030
|
if (this.curRow >= 1048576) return;
|
|
2031
|
+
if (this.curRow >= this.opts.maxRows) {
|
|
2032
|
+
this.truncate();
|
|
2033
|
+
return;
|
|
2034
|
+
}
|
|
1936
2035
|
const p = {};
|
|
1937
2036
|
const ht = num(a.get("ht"));
|
|
1938
2037
|
if (ht !== void 0 && bool(a.get("customHeight"), false)) p.height = ht;
|
|
@@ -1985,6 +2084,11 @@ var SheetParser = class {
|
|
|
1985
2084
|
}
|
|
1986
2085
|
if (row < 0) row = 0;
|
|
1987
2086
|
this.nextCol = col + 1;
|
|
2087
|
+
if (row >= this.opts.maxRows && row < 1048576) {
|
|
2088
|
+
this.truncate();
|
|
2089
|
+
if (!this.control) this.skipCell(empty);
|
|
2090
|
+
return;
|
|
2091
|
+
}
|
|
1988
2092
|
if (row >= 1048576 || col >= 16384) {
|
|
1989
2093
|
this.ctx.warn("CELL_OUT_OF_BOUNDS", `Cell ${r ?? `${colLetters(col + 1)}${row + 1}`} is beyond the format limits; it was skipped.`, {
|
|
1990
2094
|
part: this.part,
|
|
@@ -2008,6 +2112,23 @@ var SheetParser = class {
|
|
|
2008
2112
|
};
|
|
2009
2113
|
if (empty) this.finishCell();
|
|
2010
2114
|
}
|
|
2115
|
+
/** maxRows reached: the rest of sheetData is tokenized but no cells are built; later elements (merges, views, …) are still read. */
|
|
2116
|
+
truncate() {
|
|
2117
|
+
if (this.truncated) return;
|
|
2118
|
+
this.truncated = true;
|
|
2119
|
+
this.ctx.warn("ROWS_TRUNCATED", `Sheet "${this.sheet.name}" has rows beyond maxRows (${this.opts.maxRows}); they were not read.`, {
|
|
2120
|
+
part: this.part,
|
|
2121
|
+
sheet: this.sheet.name
|
|
2122
|
+
});
|
|
2123
|
+
const depth = this.path.lastIndexOf("sheetData") + 1;
|
|
2124
|
+
if (this.control && depth > 0) {
|
|
2125
|
+
this.cell = void 0;
|
|
2126
|
+
this.inline = void 0;
|
|
2127
|
+
this.textTarget = void 0;
|
|
2128
|
+
this.path.length = depth;
|
|
2129
|
+
this.control.skipToEndOf(depth);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2011
2132
|
skipCell(empty) {
|
|
2012
2133
|
this.cell = void 0;
|
|
2013
2134
|
if (!empty) this.cell = {
|
|
@@ -2039,6 +2160,18 @@ var SheetParser = class {
|
|
|
2039
2160
|
ref: p.ref
|
|
2040
2161
|
});
|
|
2041
2162
|
row[p.col] = cell;
|
|
2163
|
+
if (this.pendingIndex >= 0) {
|
|
2164
|
+
const d = this.deferred;
|
|
2165
|
+
d.cells.push(cell);
|
|
2166
|
+
d.indexes.push(this.pendingIndex);
|
|
2167
|
+
d.rows.push(row);
|
|
2168
|
+
d.cols.push(p.col);
|
|
2169
|
+
d.refs.push(p.ref);
|
|
2170
|
+
d.sheets.push(this.sheet.name);
|
|
2171
|
+
d.parts.push(this.part);
|
|
2172
|
+
if (this.pendingIndex > d.maxIndex) d.maxIndex = this.pendingIndex;
|
|
2173
|
+
this.pendingIndex = -1;
|
|
2174
|
+
}
|
|
2042
2175
|
if (p.row < this.minRow) this.minRow = p.row;
|
|
2043
2176
|
if (p.row > this.maxRow) this.maxRow = p.row;
|
|
2044
2177
|
if (p.col < this.minCol) this.minCol = p.col;
|
|
@@ -2048,11 +2181,18 @@ var SheetParser = class {
|
|
|
2048
2181
|
const style = this.styles.style(p.s);
|
|
2049
2182
|
let value;
|
|
2050
2183
|
let type = "empty";
|
|
2184
|
+
let deferredIndex = -1;
|
|
2051
2185
|
const v = p.v;
|
|
2052
2186
|
switch (p.t) {
|
|
2053
2187
|
case "s": {
|
|
2054
2188
|
if (v === void 0) break;
|
|
2055
2189
|
const idx = Number(v);
|
|
2190
|
+
if (this.deferred && Number.isInteger(idx) && idx >= 0) {
|
|
2191
|
+
value = "";
|
|
2192
|
+
type = "string";
|
|
2193
|
+
deferredIndex = idx;
|
|
2194
|
+
break;
|
|
2195
|
+
}
|
|
2056
2196
|
const sst = this.sharedStrings;
|
|
2057
2197
|
const str = Number.isInteger(idx) && idx >= 0 ? sst[idx] : void 0;
|
|
2058
2198
|
if (str === void 0) {
|
|
@@ -2144,8 +2284,11 @@ var SheetParser = class {
|
|
|
2144
2284
|
if (formula.arrayRef) cell.arrayRef = formula.arrayRef;
|
|
2145
2285
|
}
|
|
2146
2286
|
if (style) cell.style = style;
|
|
2287
|
+
if (deferredIndex >= 0) this.pendingIndex = deferredIndex;
|
|
2147
2288
|
return cell;
|
|
2148
2289
|
}
|
|
2290
|
+
/** Set by convert() for a deferred shared-string cell; consumed by finishCell(). */
|
|
2291
|
+
pendingIndex = -1;
|
|
2149
2292
|
formula(p) {
|
|
2150
2293
|
if (p.f === void 0 || !this.opts.formulas) return void 0;
|
|
2151
2294
|
if (p.fType === "shared" && p.fSi !== void 0) {
|
|
@@ -2179,6 +2322,8 @@ var SheetParser = class {
|
|
|
2179
2322
|
}
|
|
2180
2323
|
/** Set before parsing; the shared strings table. */
|
|
2181
2324
|
sharedStrings = [];
|
|
2325
|
+
/** When set, shared-string cells are collected here and filled in later (ReadOptions.maxRows). */
|
|
2326
|
+
deferred;
|
|
2182
2327
|
openView(a) {
|
|
2183
2328
|
this.viewCount++;
|
|
2184
2329
|
if (this.viewCount !== 1) return;
|
|
@@ -2663,6 +2808,7 @@ async function readImpl(input, options, internal) {
|
|
|
2663
2808
|
checkEnum("dates", o.dates, ["date", "serial"]);
|
|
2664
2809
|
checkEnum("dateZone", o.dateZone, ["local", "utc"]);
|
|
2665
2810
|
checkEnum("richText", o.richText, ["runs", "plain"]);
|
|
2811
|
+
if (o.maxRows !== void 0 && (!Number.isInteger(o.maxRows) || o.maxRows < 0)) throw new TypeError(`maxRows must be a non-negative integer, got ${String(o.maxRows)}`);
|
|
2666
2812
|
throwIfAborted(o.signal);
|
|
2667
2813
|
const bytes = await require_infer.toBytes(input, "read");
|
|
2668
2814
|
throwIfAborted(o.signal);
|
|
@@ -2719,10 +2865,13 @@ async function readImpl(input, options, internal) {
|
|
|
2719
2865
|
}
|
|
2720
2866
|
}
|
|
2721
2867
|
let sst = [];
|
|
2868
|
+
const deferred = o.maxRows !== void 0 ? new DeferredStrings() : void 0;
|
|
2869
|
+
let sstEntry;
|
|
2722
2870
|
const sstRel = relOf("sharedStrings");
|
|
2723
2871
|
if (sstRel) {
|
|
2724
2872
|
const entry = pkg.part(sstRel.target);
|
|
2725
2873
|
if (!entry) ctx.warn("MISSING_PART", `The shared strings part ${sstRel.target} is missing; cells that use it are empty.`, { part: sstRel.target });
|
|
2874
|
+
else if (deferred) sstEntry = entry;
|
|
2726
2875
|
else {
|
|
2727
2876
|
const sp = new SharedStringsParser(o.richText ?? "runs", limits.maxSharedStrings);
|
|
2728
2877
|
await ctx.parse(entry, sp);
|
|
@@ -2746,9 +2895,11 @@ async function readImpl(input, options, internal) {
|
|
|
2746
2895
|
dates: o.dates ?? "date",
|
|
2747
2896
|
dateZone: o.dateZone ?? "local",
|
|
2748
2897
|
richText: o.richText ?? "runs",
|
|
2749
|
-
date1904: wbp.date1904
|
|
2898
|
+
date1904: wbp.date1904,
|
|
2899
|
+
maxRows: o.maxRows ?? 1048576
|
|
2750
2900
|
}, rel?.target ?? workbookPart);
|
|
2751
2901
|
parser.sharedStrings = sst;
|
|
2902
|
+
parser.deferred = deferred;
|
|
2752
2903
|
const part = rel ? pkg.part(rel.target) : void 0;
|
|
2753
2904
|
if (!part) {
|
|
2754
2905
|
ctx.warn("MISSING_PART", `The part for sheet "${entry.name}" is missing; the sheet is empty.`, { sheet: entry.name });
|
|
@@ -2779,6 +2930,19 @@ async function readImpl(input, options, internal) {
|
|
|
2779
2930
|
doneBytes += part.size;
|
|
2780
2931
|
sheets.push(parser.finish(sheetRels));
|
|
2781
2932
|
}
|
|
2933
|
+
if (sstEntry && deferred && deferred.cells.length === 0) ctx.consumed.add(sstEntry.name);
|
|
2934
|
+
if (deferred && deferred.cells.length > 0) {
|
|
2935
|
+
if (sstEntry) {
|
|
2936
|
+
const sp = new SharedStringsParser(o.richText ?? "runs", limits.maxSharedStrings, deferred.maxIndex + 1);
|
|
2937
|
+
await ctx.parse(sstEntry, sp);
|
|
2938
|
+
sst = sp.strings;
|
|
2939
|
+
}
|
|
2940
|
+
deferred.resolve(sst, (ref, sheet, part, index) => ctx.warn("INVALID_SHARED_STRING", `Cell ${ref} refers to shared string ${index}, which does not exist; the cell was left empty.`, {
|
|
2941
|
+
part,
|
|
2942
|
+
sheet,
|
|
2943
|
+
ref
|
|
2944
|
+
}));
|
|
2945
|
+
}
|
|
2782
2946
|
const bookToSheet = /* @__PURE__ */ new Map();
|
|
2783
2947
|
listed.forEach((s, i) => bookToSheet.set(s.bookIndex, i));
|
|
2784
2948
|
const definedNames = [];
|