javascript-excel 1.0.3 → 2.0.0-alpha.2
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 +69 -2
- package/dist/auto-width-2oBzjeNG.d.cts +11 -0
- package/dist/auto-width-CT-BihTW.d.ts +10 -0
- package/dist/csv-DyVH9y7S.cjs +647 -0
- package/dist/csv-pXfaputs.js +618 -0
- package/dist/csv.cjs +7 -0
- package/dist/csv.d.cts +89 -0
- package/dist/csv.d.ts +89 -0
- package/dist/csv.js +1 -0
- package/dist/dom.cjs +440 -0
- package/dist/dom.d.cts +78 -0
- package/dist/dom.d.ts +78 -0
- package/dist/dom.js +437 -0
- package/dist/errors-CvGlfw0E.js +28 -0
- package/dist/errors-DOPrrGS4.cjs +69 -0
- package/dist/index.cjs +627 -0
- package/dist/index.d.cts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +597 -0
- package/dist/infer-BR-J9BZa.js +88 -0
- package/dist/infer-D9EC9vJ-.cjs +105 -0
- package/dist/iso-date-3TY1OlGd.cjs +57 -0
- package/dist/iso-date-CXnn-9mT.js +46 -0
- package/dist/numfmt-BBgB7iQA.js +429 -0
- package/dist/numfmt-Dv6AjopS.cjs +512 -0
- package/dist/read-C6L7Nyy3.d.cts +78 -0
- package/dist/read-DDN5ZsPe.js +2909 -0
- package/dist/read-Ddkks7qC.d.ts +78 -0
- package/dist/read-Ym1voUct.cjs +2932 -0
- package/dist/read.cjs +6 -0
- package/dist/read.d.cts +15 -0
- package/dist/read.d.ts +15 -0
- package/dist/read.js +1 -0
- package/dist/sheet-names-qpXsvMpM.cjs +1005 -0
- package/dist/sheet-names-uT2EH5Ui.js +832 -0
- package/dist/signal-Dz0ZYe6d.d.cts +13 -0
- package/dist/signal-Dz0ZYe6d.d.ts +13 -0
- package/dist/warnings-C_12PT4t.d.cts +410 -0
- package/dist/warnings-DXJKe1lx.d.ts +410 -0
- package/dist/worker.cjs +240 -0
- package/dist/worker.d.cts +65 -0
- package/dist/worker.d.ts +65 -0
- package/dist/worker.js +238 -0
- package/dist/write-BOh9jfu1.cjs +1487 -0
- package/dist/write-C5JgeIar.d.cts +29 -0
- package/dist/write-CYpLGuzl.d.ts +29 -0
- package/dist/write-DubvcG-x.js +1470 -0
- package/package.json +101 -51
- package/.babelrc +0 -10
- package/.circleci/config.yml +0 -39
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -22
- package/lib/javascript-excel.js +0 -17703
- package/src/index.tsx +0 -11
- package/test/unit/sample.spec.js +0 -5
- package/tsconfig.json +0 -54
- package/webpack.config.js +0 -19
- /package/{LICENSE.md → LICENSE} +0 -0
|
@@ -0,0 +1,2909 @@
|
|
|
1
|
+
import { n as parseIsoDate, r as toBytes } from "./infer-BR-J9BZa.js";
|
|
2
|
+
import { a as LimitError, i as FormatError } from "./errors-CvGlfw0E.js";
|
|
3
|
+
import { a as fromDosDateTime, c as nativeCodec, d as throttleProgress, i as serialToDate, l as decodeUtf8Strict, m as throwIfAborted$1, n as isDateFormat, p as concatBytes, s as crc32 } from "./numfmt-BBgB7iQA.js";
|
|
4
|
+
// src/internal/read/limits.ts
|
|
5
|
+
/** Default limits (docs/api.md §5.2; the measurements behind each value are listed there). */
|
|
6
|
+
const DEFAULT_LIMITS = Object.freeze({
|
|
7
|
+
maxInputBytes: 268435456,
|
|
8
|
+
maxEntries: 1e4,
|
|
9
|
+
maxEntryBytes: 536870912,
|
|
10
|
+
maxTotalBytes: 1073741824,
|
|
11
|
+
maxRatio: 1e3,
|
|
12
|
+
maxXmlDepth: 64,
|
|
13
|
+
maxCells: 1e7,
|
|
14
|
+
maxSharedStrings: 5e6,
|
|
15
|
+
maxWarnings: 1e3
|
|
16
|
+
});
|
|
17
|
+
// src/internal/zip/read.ts
|
|
18
|
+
/**
|
|
19
|
+
* Zip container reader (docs/api.md §6, §8). Internal.
|
|
20
|
+
*
|
|
21
|
+
* `openZip` parses the central directory synchronously and validates the whole
|
|
22
|
+
* layout before any data is inflated:
|
|
23
|
+
* - end-of-central-directory record, with zip64 records when present;
|
|
24
|
+
* - single-disk archives only;
|
|
25
|
+
* - every entry's local header must agree with its central record;
|
|
26
|
+
* - entry data must not overlap other entries or the central directory;
|
|
27
|
+
* - duplicate names, encryption and methods other than 0 and 8 are rejected.
|
|
28
|
+
*
|
|
29
|
+
* Reading an entry counts the actual decompressed bytes against the limits
|
|
30
|
+
* (never trusting declared sizes), stops when an entry produces more than it
|
|
31
|
+
* declared, and verifies its CRC-32.
|
|
32
|
+
*/
|
|
33
|
+
/** The zip-related defaults of docs/api.md §5.2, the same values as DEFAULT_READ_LIMITS (measured in JSE-6). */
|
|
34
|
+
const DEFAULT_ZIP_LIMITS = Object.freeze({
|
|
35
|
+
maxInputBytes: 268435456,
|
|
36
|
+
maxEntries: 1e4,
|
|
37
|
+
maxEntryBytes: 536870912,
|
|
38
|
+
maxTotalBytes: 1073741824,
|
|
39
|
+
maxRatio: 1e3
|
|
40
|
+
});
|
|
41
|
+
const SIG_LOCAL = 67324752;
|
|
42
|
+
const SIG_CENTRAL = 33639248;
|
|
43
|
+
const SIG_EOCD = 101010256;
|
|
44
|
+
const SIG_ZIP64_EOCD = 101075792;
|
|
45
|
+
const SIG_ZIP64_LOCATOR = 117853008;
|
|
46
|
+
const FLAG_ENCRYPTED = 1;
|
|
47
|
+
const FLAG_DATA_DESCRIPTOR = 8;
|
|
48
|
+
const FLAG_UTF8 = 2048;
|
|
49
|
+
const EXTRA_ZIP64 = 1;
|
|
50
|
+
const EXTRA_UNICODE_PATH = 28789;
|
|
51
|
+
const METHOD_AES = 99;
|
|
52
|
+
/** Code page 437, bytes 0x80..0xFF: the spec's default encoding for names without bit 11. */
|
|
53
|
+
const CP437_HIGH = "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0";
|
|
54
|
+
function invalid(message, details) {
|
|
55
|
+
return new FormatError("ZIP_INVALID", message, details ? { details } : void 0);
|
|
56
|
+
}
|
|
57
|
+
function limitError(limit, value, max, what) {
|
|
58
|
+
return new LimitError("LIMIT_EXCEEDED", `${what} exceeds the ${limit} limit (${max}).`, { details: {
|
|
59
|
+
limit,
|
|
60
|
+
value,
|
|
61
|
+
max
|
|
62
|
+
} });
|
|
63
|
+
}
|
|
64
|
+
var Cursor = class {
|
|
65
|
+
bytes;
|
|
66
|
+
pos;
|
|
67
|
+
view;
|
|
68
|
+
constructor(bytes, pos) {
|
|
69
|
+
this.bytes = bytes;
|
|
70
|
+
this.pos = pos;
|
|
71
|
+
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
72
|
+
}
|
|
73
|
+
need(n) {
|
|
74
|
+
if (this.pos < 0 || this.pos + n > this.bytes.length) throw invalid("Unexpected end of zip data.");
|
|
75
|
+
}
|
|
76
|
+
u16() {
|
|
77
|
+
this.need(2);
|
|
78
|
+
const v = this.view.getUint16(this.pos, true);
|
|
79
|
+
this.pos += 2;
|
|
80
|
+
return v;
|
|
81
|
+
}
|
|
82
|
+
u32() {
|
|
83
|
+
this.need(4);
|
|
84
|
+
const v = this.view.getUint32(this.pos, true);
|
|
85
|
+
this.pos += 4;
|
|
86
|
+
return v;
|
|
87
|
+
}
|
|
88
|
+
u64() {
|
|
89
|
+
const lo = this.u32();
|
|
90
|
+
const v = this.u32() * 4294967296 + lo;
|
|
91
|
+
if (!Number.isSafeInteger(v)) throw invalid("Zip64 value out of range.");
|
|
92
|
+
return v;
|
|
93
|
+
}
|
|
94
|
+
take(n) {
|
|
95
|
+
this.need(n);
|
|
96
|
+
const out = this.bytes.subarray(this.pos, this.pos + n);
|
|
97
|
+
this.pos += n;
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
function decodeName(raw, flags, extra) {
|
|
102
|
+
if (flags & FLAG_UTF8) try {
|
|
103
|
+
return decodeUtf8Strict(raw);
|
|
104
|
+
} catch {
|
|
105
|
+
throw invalid("Entry name is not valid UTF-8.");
|
|
106
|
+
}
|
|
107
|
+
const unicode = findExtra(extra, EXTRA_UNICODE_PATH);
|
|
108
|
+
if (unicode && unicode.length >= 5 && unicode[0] === 1) {
|
|
109
|
+
if (new Cursor(unicode, 1).u32() === crc32(raw)) try {
|
|
110
|
+
return decodeUtf8Strict(unicode.subarray(5));
|
|
111
|
+
} catch {}
|
|
112
|
+
}
|
|
113
|
+
let s = "";
|
|
114
|
+
for (const b of raw) s += b < 128 ? String.fromCharCode(b) : CP437_HIGH[b - 128];
|
|
115
|
+
return s;
|
|
116
|
+
}
|
|
117
|
+
function findExtra(extra, id) {
|
|
118
|
+
const c = new Cursor(extra, 0);
|
|
119
|
+
while (c.pos + 4 <= extra.length) {
|
|
120
|
+
const tag = c.u16();
|
|
121
|
+
const len = c.u16();
|
|
122
|
+
if (c.pos + len > extra.length) return void 0;
|
|
123
|
+
const body = c.take(len);
|
|
124
|
+
if (tag === id) return body;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function findEocd(bytes) {
|
|
128
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
129
|
+
const last = bytes.length - 22;
|
|
130
|
+
const first = Math.max(0, last - 65535);
|
|
131
|
+
for (let p = last; p >= first; p--) if (view.getUint32(p, true) === SIG_EOCD) {
|
|
132
|
+
const commentLength = view.getUint16(p + 20, true);
|
|
133
|
+
if (p + 22 + commentLength <= bytes.length) return p;
|
|
134
|
+
}
|
|
135
|
+
throw invalid("Not a zip file: no end-of-central-directory record.");
|
|
136
|
+
}
|
|
137
|
+
/** Parses and validates the archive layout. Does not inflate anything. */
|
|
138
|
+
function openZip(bytes, options = {}) {
|
|
139
|
+
const limits = {
|
|
140
|
+
...DEFAULT_ZIP_LIMITS,
|
|
141
|
+
...options.limits
|
|
142
|
+
};
|
|
143
|
+
const codec = options.codec ?? nativeCodec;
|
|
144
|
+
if (bytes.length > limits.maxInputBytes) throw limitError("maxInputBytes", bytes.length, limits.maxInputBytes, "Input size");
|
|
145
|
+
if (bytes.length < 22) throw invalid("Not a zip file: too short.");
|
|
146
|
+
const eocdPos = findEocd(bytes);
|
|
147
|
+
const e = new Cursor(bytes, eocdPos + 4);
|
|
148
|
+
const disk = e.u16();
|
|
149
|
+
const cdDisk = e.u16();
|
|
150
|
+
const entriesOnDisk = e.u16();
|
|
151
|
+
let entryCount = e.u16();
|
|
152
|
+
let cdSize = e.u32();
|
|
153
|
+
let cdOffset = e.u32();
|
|
154
|
+
let cdLimit = eocdPos;
|
|
155
|
+
if (eocdPos >= 20 && new Cursor(bytes, eocdPos - 20).u32() === SIG_ZIP64_LOCATOR) {
|
|
156
|
+
const l = new Cursor(bytes, eocdPos - 16);
|
|
157
|
+
const z64Disk = l.u32();
|
|
158
|
+
const z64Pos = l.u64();
|
|
159
|
+
const totalDisks = l.u32();
|
|
160
|
+
if (z64Disk !== 0 || totalDisks > 1) throw invalid("Multi-disk zip archives are not supported.");
|
|
161
|
+
if (z64Pos + 56 > eocdPos - 20) throw invalid("Zip64 end-of-central-directory record out of range.");
|
|
162
|
+
const z = new Cursor(bytes, z64Pos);
|
|
163
|
+
if (z.u32() !== SIG_ZIP64_EOCD) throw invalid("Bad zip64 end-of-central-directory signature.");
|
|
164
|
+
z.u64();
|
|
165
|
+
z.u16();
|
|
166
|
+
z.u16();
|
|
167
|
+
const z64ThisDisk = z.u32();
|
|
168
|
+
const z64CdDisk = z.u32();
|
|
169
|
+
z.u64();
|
|
170
|
+
entryCount = z.u64();
|
|
171
|
+
cdSize = z.u64();
|
|
172
|
+
cdOffset = z.u64();
|
|
173
|
+
if (z64ThisDisk !== 0 || z64CdDisk !== 0) throw invalid("Multi-disk zip archives are not supported.");
|
|
174
|
+
cdLimit = z64Pos;
|
|
175
|
+
} else {
|
|
176
|
+
if (disk !== 0 || cdDisk !== 0 || entriesOnDisk !== entryCount) throw invalid("Multi-disk zip archives are not supported.");
|
|
177
|
+
if (entryCount === 65535 || cdSize === 4294967295 || cdOffset === 4294967295) throw invalid("Zip64 values without a zip64 end-of-central-directory locator.");
|
|
178
|
+
}
|
|
179
|
+
if (entryCount > limits.maxEntries) throw limitError("maxEntries", entryCount, limits.maxEntries, "Entry count");
|
|
180
|
+
if (cdOffset + cdSize > cdLimit) throw invalid("Central directory out of range.");
|
|
181
|
+
if (entryCount * 46 > cdSize) throw invalid("Central directory too small for its entry count.");
|
|
182
|
+
const entries = [];
|
|
183
|
+
const byName = /* @__PURE__ */ new Map();
|
|
184
|
+
const spans = [];
|
|
185
|
+
const c = new Cursor(bytes.subarray(0, cdOffset + cdSize), cdOffset);
|
|
186
|
+
for (let i = 0; i < entryCount; i++) {
|
|
187
|
+
if (c.u32() !== SIG_CENTRAL) throw invalid("Bad central directory signature.", { index: i });
|
|
188
|
+
c.u16();
|
|
189
|
+
c.u16();
|
|
190
|
+
const flags = c.u16();
|
|
191
|
+
const method = c.u16();
|
|
192
|
+
const time = c.u16();
|
|
193
|
+
const date = c.u16();
|
|
194
|
+
const crc = c.u32();
|
|
195
|
+
let compressedSize = c.u32();
|
|
196
|
+
let size = c.u32();
|
|
197
|
+
const nameLength = c.u16();
|
|
198
|
+
const extraLength = c.u16();
|
|
199
|
+
const commentLength = c.u16();
|
|
200
|
+
let diskStart = c.u16();
|
|
201
|
+
c.u16();
|
|
202
|
+
c.u32();
|
|
203
|
+
let localOffset = c.u32();
|
|
204
|
+
const rawName = c.take(nameLength);
|
|
205
|
+
const extra = c.take(extraLength);
|
|
206
|
+
c.take(commentLength);
|
|
207
|
+
const z64 = findExtra(extra, EXTRA_ZIP64);
|
|
208
|
+
if (z64) {
|
|
209
|
+
const x = new Cursor(z64, 0);
|
|
210
|
+
if (size === 4294967295) size = x.u64();
|
|
211
|
+
if (compressedSize === 4294967295) compressedSize = x.u64();
|
|
212
|
+
if (localOffset === 4294967295) localOffset = x.u64();
|
|
213
|
+
if (diskStart === 65535) diskStart = x.u32();
|
|
214
|
+
}
|
|
215
|
+
if (diskStart !== 0) throw invalid("Multi-disk zip archives are not supported.");
|
|
216
|
+
const name = decodeName(rawName, flags, extra);
|
|
217
|
+
if (flags & 65 || method === METHOD_AES) throw new FormatError("ZIP_ENCRYPTED", `Entry ${name} is encrypted.`, { details: { entry: name } });
|
|
218
|
+
if (method !== 0 && method !== 8) throw new FormatError("ZIP_UNSUPPORTED_METHOD", `Entry ${name} uses compression method ${method}.`, { details: {
|
|
219
|
+
entry: name,
|
|
220
|
+
method
|
|
221
|
+
} });
|
|
222
|
+
if (method === 0 && compressedSize !== size) throw invalid(`Stored entry ${name} has mismatched sizes.`);
|
|
223
|
+
if (byName.has(name)) throw invalid(`Duplicate entry name: ${name}`, { entry: name });
|
|
224
|
+
const l = new Cursor(bytes, localOffset);
|
|
225
|
+
if (localOffset + 30 > cdOffset || l.u32() !== SIG_LOCAL) throw invalid(`Bad local header for ${name}.`, { entry: name });
|
|
226
|
+
l.u16();
|
|
227
|
+
const lFlags = l.u16();
|
|
228
|
+
const lMethod = l.u16();
|
|
229
|
+
l.u16();
|
|
230
|
+
l.u16();
|
|
231
|
+
const lCrc = l.u32();
|
|
232
|
+
const lCompressed = l.u32();
|
|
233
|
+
const lSize = l.u32();
|
|
234
|
+
const lNameLength = l.u16();
|
|
235
|
+
const lExtraLength = l.u16();
|
|
236
|
+
const lName = l.take(lNameLength);
|
|
237
|
+
l.take(lExtraLength);
|
|
238
|
+
let agrees = lNameLength === nameLength && lName.every((b, k) => b === rawName[k]) && lMethod === method && (lFlags & FLAG_ENCRYPTED) === 0;
|
|
239
|
+
if (agrees && !(lFlags & FLAG_DATA_DESCRIPTOR)) agrees = lCrc === crc && (lCompressed === compressedSize || lCompressed === 4294967295) && (lSize === size || lSize === 4294967295);
|
|
240
|
+
if (!agrees) throw invalid(`Local header disagrees with the central directory for ${name}.`, { entry: name });
|
|
241
|
+
const dataOffset = l.pos;
|
|
242
|
+
const dataEnd = dataOffset + compressedSize;
|
|
243
|
+
if (dataEnd > cdOffset) throw invalid(`Data of ${name} runs into the central directory.`, { entry: name });
|
|
244
|
+
spans.push({
|
|
245
|
+
start: localOffset,
|
|
246
|
+
end: dataEnd,
|
|
247
|
+
name
|
|
248
|
+
});
|
|
249
|
+
const info = Object.freeze({
|
|
250
|
+
name,
|
|
251
|
+
method,
|
|
252
|
+
flags,
|
|
253
|
+
crc32: crc,
|
|
254
|
+
compressedSize,
|
|
255
|
+
size,
|
|
256
|
+
modified: fromDosDateTime(date, time),
|
|
257
|
+
dataOffset
|
|
258
|
+
});
|
|
259
|
+
entries.push(info);
|
|
260
|
+
byName.set(name, info);
|
|
261
|
+
}
|
|
262
|
+
spans.sort((a, b) => a.start - b.start);
|
|
263
|
+
for (let i = 1; i < spans.length; i++) if (spans[i].start < spans[i - 1].end) throw invalid(`Entries ${spans[i - 1].name} and ${spans[i].name} overlap.`);
|
|
264
|
+
let totalBytesRead = 0;
|
|
265
|
+
const resolve = (entry) => {
|
|
266
|
+
const info = typeof entry === "string" ? byName.get(entry) : entry;
|
|
267
|
+
if (!info || byName.get(info.name) !== info) throw new Error(`No such zip entry: ${typeof entry === "string" ? entry : entry.name}`);
|
|
268
|
+
return info;
|
|
269
|
+
};
|
|
270
|
+
const countTotal = (n) => {
|
|
271
|
+
totalBytesRead += n;
|
|
272
|
+
if (totalBytesRead > limits.maxTotalBytes) throw limitError("maxTotalBytes", totalBytesRead, limits.maxTotalBytes, "Total decompressed size");
|
|
273
|
+
};
|
|
274
|
+
async function* stream(entry, signal) {
|
|
275
|
+
const info = resolve(entry);
|
|
276
|
+
throwIfAborted$1(signal);
|
|
277
|
+
if (info.size > limits.maxEntryBytes) throw limitError("maxEntryBytes", info.size, limits.maxEntryBytes, `Entry ${info.name}`);
|
|
278
|
+
const data = bytes.subarray(info.dataOffset, info.dataOffset + info.compressedSize);
|
|
279
|
+
let crc = 0;
|
|
280
|
+
let produced = 0;
|
|
281
|
+
if (info.method === 0) {
|
|
282
|
+
countTotal(data.length);
|
|
283
|
+
crc = crc32(data);
|
|
284
|
+
produced = data.length;
|
|
285
|
+
if (crc !== info.crc32) throw crcMismatch(info);
|
|
286
|
+
yield data;
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const chunks = codec.inflateRaw(data, {
|
|
290
|
+
maxOutputBytes: limits.maxEntryBytes,
|
|
291
|
+
maxRatio: limits.maxRatio
|
|
292
|
+
}, signal);
|
|
293
|
+
for await (const chunk of chunks) {
|
|
294
|
+
produced += chunk.length;
|
|
295
|
+
if (produced > info.size) throw invalid(`Entry ${info.name} is larger than declared.`, { entry: info.name });
|
|
296
|
+
countTotal(chunk.length);
|
|
297
|
+
crc = crc32(chunk, crc);
|
|
298
|
+
yield chunk;
|
|
299
|
+
}
|
|
300
|
+
if (produced !== info.size) throw invalid(`Entry ${info.name} is smaller than declared.`, { entry: info.name });
|
|
301
|
+
if (crc !== info.crc32) throw crcMismatch(info);
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
entries,
|
|
305
|
+
get: (name) => byName.get(name),
|
|
306
|
+
stream,
|
|
307
|
+
async read(entry, signal) {
|
|
308
|
+
const parts = [];
|
|
309
|
+
for await (const chunk of stream(entry, signal)) parts.push(chunk);
|
|
310
|
+
return concatBytes(parts);
|
|
311
|
+
},
|
|
312
|
+
get totalBytesRead() {
|
|
313
|
+
return totalBytesRead;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function crcMismatch(info) {
|
|
318
|
+
return new FormatError("ZIP_CRC_MISMATCH", `CRC-32 mismatch in ${info.name}.`, { details: { entry: info.name } });
|
|
319
|
+
}
|
|
320
|
+
// src/internal/read/xml-reader.ts
|
|
321
|
+
/**
|
|
322
|
+
* Streaming XML pull tokenizer for the reader (docs/api.md §5.2, §8). Internal.
|
|
323
|
+
*
|
|
324
|
+
* - Push-fed: `feed()` text chunks as they are inflated, then `end()`. Only
|
|
325
|
+
* the unfinished tail of a chunk is kept, so a part is never held whole.
|
|
326
|
+
* - Iterative, never recursive. Element depth is limited (`maxXmlDepth`).
|
|
327
|
+
* - Any `<!DOCTYPE` is rejected (XML_DTD_FORBIDDEN), so there is no entity
|
|
328
|
+
* expansion and nothing external is ever fetched. Only the five predefined
|
|
329
|
+
* entities and numeric character references are decoded.
|
|
330
|
+
* - Well-formedness is checked as far as the reader needs: tags must nest and
|
|
331
|
+
* match, attributes must be quoted, references must be valid.
|
|
332
|
+
* - Names are reported without their namespace prefix (`x:row` -> `row`), so
|
|
333
|
+
* prefixed SpreadsheetML and ISO 29500 Strict parts read like transitional
|
|
334
|
+
* ones. Attributes keep their qualified names; see `XmlAttrs`.
|
|
335
|
+
*/
|
|
336
|
+
/** Attributes of one start tag. Names are never used as object keys. */
|
|
337
|
+
var XmlAttrs = class {
|
|
338
|
+
items;
|
|
339
|
+
/** Flat [qname, value, qname, value, ...]. */
|
|
340
|
+
constructor(items) {
|
|
341
|
+
this.items = items;
|
|
342
|
+
}
|
|
343
|
+
/** Value of the unprefixed attribute `local`. */
|
|
344
|
+
get(local) {
|
|
345
|
+
const items = this.items;
|
|
346
|
+
for (let i = 0; i < items.length; i += 2) if (items[i] === local) return items[i + 1];
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Value of a prefixed attribute with local name `local` (e.g. `r:id` for
|
|
350
|
+
* "id"), whatever the prefix; `xml:` and `xmlns:` are skipped.
|
|
351
|
+
*/
|
|
352
|
+
getPrefixed(local) {
|
|
353
|
+
const items = this.items;
|
|
354
|
+
for (let i = 0; i < items.length; i += 2) {
|
|
355
|
+
const q = items[i];
|
|
356
|
+
const colon = q.indexOf(":");
|
|
357
|
+
if (colon <= 0 || q.slice(colon + 1) !== local) continue;
|
|
358
|
+
const prefix = q.slice(0, colon);
|
|
359
|
+
if (prefix === "xml" || prefix === "xmlns") continue;
|
|
360
|
+
return items[i + 1];
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/** Value of the attribute with exactly this qualified name (e.g. `xml:space`, `xmlns`). */
|
|
364
|
+
getQualified(qname) {
|
|
365
|
+
return this.get(qname);
|
|
366
|
+
}
|
|
367
|
+
/** Every [qualified name, value] pair, in document order. */
|
|
368
|
+
*entries() {
|
|
369
|
+
for (let i = 0; i < this.items.length; i += 2) yield [this.items[i], this.items[i + 1]];
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
function malformed(message) {
|
|
373
|
+
return new FormatError("XML_MALFORMED", message);
|
|
374
|
+
}
|
|
375
|
+
const EMPTY_ATTRS = new XmlAttrs([]);
|
|
376
|
+
var XmlTokenizer = class {
|
|
377
|
+
handler;
|
|
378
|
+
maxDepth;
|
|
379
|
+
buf = "";
|
|
380
|
+
stack = [];
|
|
381
|
+
rootSeen = false;
|
|
382
|
+
rootClosed = false;
|
|
383
|
+
pendingCR = false;
|
|
384
|
+
constructor(handler, maxDepth) {
|
|
385
|
+
this.handler = handler;
|
|
386
|
+
this.maxDepth = maxDepth;
|
|
387
|
+
}
|
|
388
|
+
feed(chunk) {
|
|
389
|
+
this.buf = this.buf.length === 0 ? chunk : this.buf + chunk;
|
|
390
|
+
this.pump(false);
|
|
391
|
+
}
|
|
392
|
+
end() {
|
|
393
|
+
this.pump(true);
|
|
394
|
+
if (this.buf.trim() !== "") throw malformed("Unexpected end of XML data.");
|
|
395
|
+
if (this.stack.length > 0) throw malformed(`Element <${this.stack.at(-1)}> is not closed.`);
|
|
396
|
+
if (!this.rootSeen) throw malformed("XML part has no root element.");
|
|
397
|
+
}
|
|
398
|
+
pump(final) {
|
|
399
|
+
const buf = this.buf;
|
|
400
|
+
const len = buf.length;
|
|
401
|
+
let i = 0;
|
|
402
|
+
while (i < len) {
|
|
403
|
+
if (buf.charCodeAt(i) !== 60) {
|
|
404
|
+
let j = buf.indexOf("<", i);
|
|
405
|
+
if (j === -1) {
|
|
406
|
+
if (!final) {
|
|
407
|
+
const amp = buf.lastIndexOf("&");
|
|
408
|
+
j = amp >= i && buf.indexOf(";", amp) === -1 ? amp : len;
|
|
409
|
+
if (j > i) this.chars(buf.slice(i, j));
|
|
410
|
+
i = j;
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
j = len;
|
|
414
|
+
}
|
|
415
|
+
this.chars(buf.slice(i, j));
|
|
416
|
+
i = j;
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (len - i < 9 && !final && buf.startsWith("<!", i)) break;
|
|
420
|
+
const c1 = buf.charCodeAt(i + 1);
|
|
421
|
+
if (c1 === 63) {
|
|
422
|
+
const e = buf.indexOf("?>", i + 2);
|
|
423
|
+
if (e === -1) {
|
|
424
|
+
if (final) throw malformed("Unterminated processing instruction.");
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
i = e + 2;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
if (c1 === 33) {
|
|
431
|
+
if (buf.startsWith("<!--", i)) {
|
|
432
|
+
const e = buf.indexOf("-->", i + 4);
|
|
433
|
+
if (e === -1) {
|
|
434
|
+
if (final) throw malformed("Unterminated comment.");
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
i = e + 3;
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (buf.startsWith("<![CDATA[", i)) {
|
|
441
|
+
const e = buf.indexOf("]]>", i + 9);
|
|
442
|
+
if (e === -1) {
|
|
443
|
+
if (final) throw malformed("Unterminated CDATA section.");
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
if (this.stack.length === 0) throw malformed("CDATA outside the root element.");
|
|
447
|
+
this.handler.text(normaliseNewlines(buf.slice(i + 9, e)));
|
|
448
|
+
i = e + 3;
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
if (/^<!DOCTYPE/i.test(buf.slice(i, i + 9))) throw new FormatError("XML_DTD_FORBIDDEN", "XML parts must not contain a document type declaration (<!DOCTYPE).");
|
|
452
|
+
throw malformed("Unexpected markup declaration.");
|
|
453
|
+
}
|
|
454
|
+
if (c1 === 47) {
|
|
455
|
+
const e = buf.indexOf(">", i + 2);
|
|
456
|
+
if (e === -1) {
|
|
457
|
+
if (final) throw malformed("Unterminated end tag.");
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
const qname = buf.slice(i + 2, e).trim();
|
|
461
|
+
const open = this.stack.pop();
|
|
462
|
+
if (open === void 0 || open !== qname) throw malformed(open === void 0 ? `Unexpected end tag </${qname}>.` : `End tag </${qname}> does not match <${open}>.`);
|
|
463
|
+
if (this.stack.length === 0) this.rootClosed = true;
|
|
464
|
+
this.handler.close(localName(qname));
|
|
465
|
+
i = e + 1;
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
const e = findTagEnd(buf, i + 1);
|
|
469
|
+
if (e === -1) {
|
|
470
|
+
if (final) throw malformed("Unterminated start tag.");
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
this.startTag(buf, i + 1, e);
|
|
474
|
+
i = e + 1;
|
|
475
|
+
}
|
|
476
|
+
this.buf = i >= len ? "" : buf.slice(i);
|
|
477
|
+
}
|
|
478
|
+
chars(raw) {
|
|
479
|
+
if (this.stack.length === 0) {
|
|
480
|
+
if (raw.trim() !== "") throw malformed("Text outside the root element.");
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
let s = raw.indexOf("&") === -1 ? raw : decodeReferences(raw);
|
|
484
|
+
if (this.pendingCR) {
|
|
485
|
+
if (s.charCodeAt(0) === 10) s = s.slice(1);
|
|
486
|
+
this.pendingCR = false;
|
|
487
|
+
}
|
|
488
|
+
if (s.length > 0 && s.charCodeAt(s.length - 1) === 13) this.pendingCR = true;
|
|
489
|
+
if (s.indexOf("\r") !== -1) s = s.replace(/\r\n?/g, "\n");
|
|
490
|
+
if (s.length > 0) this.handler.text(s);
|
|
491
|
+
}
|
|
492
|
+
startTag(buf, start, end) {
|
|
493
|
+
let selfClosing = false;
|
|
494
|
+
let stop = end;
|
|
495
|
+
if (buf.charCodeAt(end - 1) === 47) {
|
|
496
|
+
selfClosing = true;
|
|
497
|
+
stop = end - 1;
|
|
498
|
+
}
|
|
499
|
+
let p = start;
|
|
500
|
+
while (p < stop && !isSpace(buf.charCodeAt(p))) p++;
|
|
501
|
+
const qname = buf.slice(start, p);
|
|
502
|
+
if (qname.length === 0) throw malformed("Start tag without a name.");
|
|
503
|
+
if (this.rootClosed) throw malformed("Content after the root element.");
|
|
504
|
+
const items = [];
|
|
505
|
+
for (;;) {
|
|
506
|
+
while (p < stop && isSpace(buf.charCodeAt(p))) p++;
|
|
507
|
+
if (p >= stop) break;
|
|
508
|
+
const nameStart = p;
|
|
509
|
+
while (p < stop && buf.charCodeAt(p) !== 61 && !isSpace(buf.charCodeAt(p))) p++;
|
|
510
|
+
const aname = buf.slice(nameStart, p);
|
|
511
|
+
while (p < stop && isSpace(buf.charCodeAt(p))) p++;
|
|
512
|
+
if (buf.charCodeAt(p) !== 61 || aname.length === 0) throw malformed(`Malformed attribute in <${qname}>.`);
|
|
513
|
+
p++;
|
|
514
|
+
while (p < stop && isSpace(buf.charCodeAt(p))) p++;
|
|
515
|
+
const q = buf.charCodeAt(p);
|
|
516
|
+
if (q !== 34 && q !== 39) throw malformed(`Unquoted attribute value in <${qname}>.`);
|
|
517
|
+
const close = buf.indexOf(q === 34 ? "\"" : "'", p + 1);
|
|
518
|
+
if (close === -1 || close >= stop) throw malformed(`Unterminated attribute value in <${qname}>.`);
|
|
519
|
+
const raw = buf.slice(p + 1, close);
|
|
520
|
+
if (raw.indexOf("<") !== -1) throw malformed(`'<' in an attribute value of <${qname}>.`);
|
|
521
|
+
items.push(aname, normaliseAttr(raw));
|
|
522
|
+
p = close + 1;
|
|
523
|
+
}
|
|
524
|
+
this.rootSeen = true;
|
|
525
|
+
const attrs = items.length ? new XmlAttrs(items) : EMPTY_ATTRS;
|
|
526
|
+
if (!selfClosing) {
|
|
527
|
+
this.stack.push(qname);
|
|
528
|
+
if (this.stack.length > this.maxDepth) throw new LimitError("LIMIT_EXCEEDED", `XML nesting is deeper than maxXmlDepth (${this.maxDepth}).`, { details: {
|
|
529
|
+
limit: "maxXmlDepth",
|
|
530
|
+
value: this.stack.length,
|
|
531
|
+
max: this.maxDepth
|
|
532
|
+
} });
|
|
533
|
+
} else if (this.stack.length === 0) this.rootClosed = true;
|
|
534
|
+
this.handler.open(localName(qname), attrs, selfClosing);
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
function isSpace(c) {
|
|
538
|
+
return c === 32 || c === 9 || c === 10 || c === 13;
|
|
539
|
+
}
|
|
540
|
+
function localName(qname) {
|
|
541
|
+
const colon = qname.indexOf(":");
|
|
542
|
+
return colon === -1 ? qname : qname.slice(colon + 1);
|
|
543
|
+
}
|
|
544
|
+
/** Index of the '>' that ends the tag starting before `from`, skipping quoted values; -1 if not in `buf`. */
|
|
545
|
+
function findTagEnd(buf, from) {
|
|
546
|
+
let quote = 0;
|
|
547
|
+
for (let i = from; i < buf.length; i++) {
|
|
548
|
+
const c = buf.charCodeAt(i);
|
|
549
|
+
if (quote !== 0) {
|
|
550
|
+
if (c === quote) quote = 0;
|
|
551
|
+
} else if (c === 34 || c === 39) quote = c;
|
|
552
|
+
else if (c === 62) return i;
|
|
553
|
+
else if (c === 60) throw malformed("'<' inside a tag.");
|
|
554
|
+
}
|
|
555
|
+
return -1;
|
|
556
|
+
}
|
|
557
|
+
function normaliseNewlines(s) {
|
|
558
|
+
return s.indexOf("\r") === -1 ? s : s.replace(/\r\n?/g, "\n");
|
|
559
|
+
}
|
|
560
|
+
/** Attribute-value normalisation (XML 1.0 §3.3.3): literal TAB, CR, LF become spaces; references are decoded after. */
|
|
561
|
+
function normaliseAttr(raw) {
|
|
562
|
+
let s = raw;
|
|
563
|
+
if (/[\t\n\r]/.test(s)) s = s.replace(/\r\n|[\t\n\r]/g, " ");
|
|
564
|
+
return s.indexOf("&") === -1 ? s : decodeReferences(s);
|
|
565
|
+
}
|
|
566
|
+
/** Decodes the five predefined entities and numeric character references. */
|
|
567
|
+
function decodeReferences(s) {
|
|
568
|
+
let out = "";
|
|
569
|
+
let last = 0;
|
|
570
|
+
for (let i = s.indexOf("&"); i !== -1; i = s.indexOf("&", last)) {
|
|
571
|
+
const semi = s.indexOf(";", i + 1);
|
|
572
|
+
if (semi === -1 || semi - i > 12) throw malformed("Unterminated character or entity reference.");
|
|
573
|
+
const ref = s.slice(i + 1, semi);
|
|
574
|
+
let ch;
|
|
575
|
+
switch (ref) {
|
|
576
|
+
case "lt":
|
|
577
|
+
ch = "<";
|
|
578
|
+
break;
|
|
579
|
+
case "gt":
|
|
580
|
+
ch = ">";
|
|
581
|
+
break;
|
|
582
|
+
case "amp":
|
|
583
|
+
ch = "&";
|
|
584
|
+
break;
|
|
585
|
+
case "quot":
|
|
586
|
+
ch = "\"";
|
|
587
|
+
break;
|
|
588
|
+
case "apos":
|
|
589
|
+
ch = "'";
|
|
590
|
+
break;
|
|
591
|
+
default: {
|
|
592
|
+
let cp;
|
|
593
|
+
if (/^#x[0-9A-Fa-f]{1,6}$/.test(ref)) cp = parseInt(ref.slice(2), 16);
|
|
594
|
+
else if (/^#[0-9]{1,7}$/.test(ref)) cp = parseInt(ref.slice(1), 10);
|
|
595
|
+
else throw malformed(`Unknown entity &${ref}; (only the five predefined entities are allowed).`);
|
|
596
|
+
if (!isXmlChar(cp)) throw malformed(`Character reference &${ref}; is not a valid XML character.`);
|
|
597
|
+
ch = String.fromCodePoint(cp);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
out += s.slice(last, i) + ch;
|
|
601
|
+
last = semi + 1;
|
|
602
|
+
}
|
|
603
|
+
return out + s.slice(last);
|
|
604
|
+
}
|
|
605
|
+
/** XML 1.0 Char production. */
|
|
606
|
+
function isXmlChar(cp) {
|
|
607
|
+
return cp === 9 || cp === 10 || cp === 13 || cp >= 32 && cp <= 55295 || cp >= 57344 && cp <= 65533 || cp >= 65536 && cp <= 1114111;
|
|
608
|
+
}
|
|
609
|
+
// src/internal/read/context.ts
|
|
610
|
+
/**
|
|
611
|
+
* Per-read state shared by the part parsers: the zip, the limits, the
|
|
612
|
+
* warning collector, the abort signal and progress reporting. Internal.
|
|
613
|
+
*/
|
|
614
|
+
var ReadContext = class {
|
|
615
|
+
zip;
|
|
616
|
+
limits;
|
|
617
|
+
signal;
|
|
618
|
+
onWarning;
|
|
619
|
+
warnings = [];
|
|
620
|
+
/** Names of the parts read so far (for keeping the others, see InternalReadOptions). */
|
|
621
|
+
consumed = /* @__PURE__ */ new Set();
|
|
622
|
+
dropped = 0;
|
|
623
|
+
cells = 0;
|
|
624
|
+
constructor(zip, limits, signal, onWarning, onProgress) {
|
|
625
|
+
this.zip = zip;
|
|
626
|
+
this.limits = limits;
|
|
627
|
+
this.signal = signal;
|
|
628
|
+
this.onWarning = onWarning;
|
|
629
|
+
this.onProgress = throttleProgress(onProgress);
|
|
630
|
+
}
|
|
631
|
+
onProgress;
|
|
632
|
+
warn(code, message, where) {
|
|
633
|
+
if (this.warnings.length >= this.limits.maxWarnings) {
|
|
634
|
+
if (this.dropped++ === 0) {
|
|
635
|
+
const w = {
|
|
636
|
+
code: "WARNINGS_TRUNCATED",
|
|
637
|
+
message: `More than maxWarnings (${this.limits.maxWarnings}) warnings; later ones were dropped.`
|
|
638
|
+
};
|
|
639
|
+
this.warnings.push(w);
|
|
640
|
+
this.onWarning?.(w);
|
|
641
|
+
}
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const w = {
|
|
645
|
+
code,
|
|
646
|
+
message
|
|
647
|
+
};
|
|
648
|
+
if (where?.part !== void 0) w.part = where.part;
|
|
649
|
+
if (where?.sheet !== void 0) w.sheet = where.sheet;
|
|
650
|
+
if (where?.ref !== void 0) w.ref = where.ref;
|
|
651
|
+
this.warnings.push(w);
|
|
652
|
+
this.onWarning?.(w);
|
|
653
|
+
}
|
|
654
|
+
/** Counts one cell against maxCells. */
|
|
655
|
+
countCell() {
|
|
656
|
+
if (++this.cells > this.limits.maxCells) throw new LimitError("LIMIT_EXCEEDED", `The workbook has more than maxCells (${this.limits.maxCells}) cells.`, { details: {
|
|
657
|
+
limit: "maxCells",
|
|
658
|
+
value: this.cells,
|
|
659
|
+
max: this.limits.maxCells
|
|
660
|
+
} });
|
|
661
|
+
}
|
|
662
|
+
checkAbort() {
|
|
663
|
+
throwIfAborted$1(this.signal);
|
|
664
|
+
}
|
|
665
|
+
progress(p) {
|
|
666
|
+
this.onProgress?.(p);
|
|
667
|
+
}
|
|
668
|
+
/** Reads a whole part as text (for small parts: rels, content types, workbook). */
|
|
669
|
+
async text(entry) {
|
|
670
|
+
this.consumed.add(entry.name);
|
|
671
|
+
const bytes = await this.zip.read(entry, this.signal);
|
|
672
|
+
return newDecoder(bytes).decode(stripBom(bytes));
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Streams a part through the XML tokenizer. Errors from the tokenizer are
|
|
676
|
+
* re-thrown with the part name in the message and `details.part`.
|
|
677
|
+
*/
|
|
678
|
+
async parse(entry, handler, onChunk) {
|
|
679
|
+
this.consumed.add(entry.name);
|
|
680
|
+
const tok = new XmlTokenizer(handler, this.limits.maxXmlDepth);
|
|
681
|
+
let decoder;
|
|
682
|
+
try {
|
|
683
|
+
for await (const chunk of this.zip.stream(entry, this.signal)) {
|
|
684
|
+
if (!decoder) {
|
|
685
|
+
decoder = newDecoder(chunk);
|
|
686
|
+
tok.feed(decoder.decode(stripBom(chunk), { stream: true }));
|
|
687
|
+
} else tok.feed(decoder.decode(chunk, { stream: true }));
|
|
688
|
+
onChunk?.(chunk.length);
|
|
689
|
+
this.checkAbort();
|
|
690
|
+
}
|
|
691
|
+
if (decoder) tok.feed(decoder.decode());
|
|
692
|
+
tok.end();
|
|
693
|
+
} catch (err) {
|
|
694
|
+
throw withPart(err, entry.name);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
function withPart(err, part) {
|
|
699
|
+
if (err instanceof FormatError && (err.code === "XML_MALFORMED" || err.code === "XML_DTD_FORBIDDEN") && !err.details?.["part"]) return new FormatError(err.code, `${part}: ${err.message}`, {
|
|
700
|
+
details: {
|
|
701
|
+
...err.details,
|
|
702
|
+
part
|
|
703
|
+
},
|
|
704
|
+
cause: err
|
|
705
|
+
});
|
|
706
|
+
if (err instanceof LimitError && err.details?.["limit"] === "maxXmlDepth" && !err.details["part"]) return new LimitError(err.code, `${part}: ${err.message}`, {
|
|
707
|
+
details: {
|
|
708
|
+
...err.details,
|
|
709
|
+
part
|
|
710
|
+
},
|
|
711
|
+
cause: err
|
|
712
|
+
});
|
|
713
|
+
return err;
|
|
714
|
+
}
|
|
715
|
+
function newDecoder(first) {
|
|
716
|
+
const Ctor = globalThis.TextDecoder;
|
|
717
|
+
if (first[0] === 255 && first[1] === 254) return new Ctor("utf-16le");
|
|
718
|
+
if (first[0] === 254 && first[1] === 255) return new Ctor("utf-16be");
|
|
719
|
+
return new Ctor("utf-8");
|
|
720
|
+
}
|
|
721
|
+
function stripBom(b) {
|
|
722
|
+
if (b[0] === 239 && b[1] === 187 && b[2] === 191) return b.subarray(3);
|
|
723
|
+
if (b[0] === 255 && b[1] === 254 || b[0] === 254 && b[1] === 255) return b.subarray(2);
|
|
724
|
+
return b;
|
|
725
|
+
}
|
|
726
|
+
// src/internal/read/formats.ts
|
|
727
|
+
/** Container signatures, checked in order. */
|
|
728
|
+
const CONTAINERS = [
|
|
729
|
+
{
|
|
730
|
+
kind: "cfb",
|
|
731
|
+
magic: [
|
|
732
|
+
208,
|
|
733
|
+
207,
|
|
734
|
+
17,
|
|
735
|
+
224,
|
|
736
|
+
161,
|
|
737
|
+
177,
|
|
738
|
+
26,
|
|
739
|
+
225
|
|
740
|
+
]
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
kind: "zip",
|
|
744
|
+
magic: [
|
|
745
|
+
80,
|
|
746
|
+
75,
|
|
747
|
+
3,
|
|
748
|
+
4
|
|
749
|
+
]
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
kind: "zip",
|
|
753
|
+
magic: [
|
|
754
|
+
80,
|
|
755
|
+
75,
|
|
756
|
+
5,
|
|
757
|
+
6
|
|
758
|
+
]
|
|
759
|
+
}
|
|
760
|
+
];
|
|
761
|
+
/** OPC workbook formats by the content type of their workbook part. */
|
|
762
|
+
const WORKBOOK_FORMATS = [
|
|
763
|
+
{
|
|
764
|
+
format: "xlsx",
|
|
765
|
+
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
|
|
766
|
+
decoder: "spreadsheetml",
|
|
767
|
+
label: "Excel workbook (.xlsx)"
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
format: "xltx",
|
|
771
|
+
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml",
|
|
772
|
+
decoder: "spreadsheetml",
|
|
773
|
+
label: "Excel template (.xltx)"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
format: "xlsm",
|
|
777
|
+
contentType: "application/vnd.ms-excel.sheet.macroEnabled.main+xml",
|
|
778
|
+
decoder: "spreadsheetml",
|
|
779
|
+
macros: true,
|
|
780
|
+
label: "macro-enabled workbook (.xlsm)"
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
format: "xltm",
|
|
784
|
+
contentType: "application/vnd.ms-excel.template.macroEnabled.main+xml",
|
|
785
|
+
decoder: "spreadsheetml",
|
|
786
|
+
macros: true,
|
|
787
|
+
label: "macro-enabled template (.xltm)"
|
|
788
|
+
},
|
|
789
|
+
{
|
|
790
|
+
format: "xlsb",
|
|
791
|
+
contentType: "application/vnd.ms-excel.sheet.binary.macroEnabled.main",
|
|
792
|
+
macros: true,
|
|
793
|
+
label: "binary workbook (.xlsb)"
|
|
794
|
+
}
|
|
795
|
+
];
|
|
796
|
+
/** Formats recognised by something other than a workbook content type. */
|
|
797
|
+
const OTHER_FORMATS = {
|
|
798
|
+
ods: { label: "OpenDocument spreadsheet (.ods)" },
|
|
799
|
+
cfb: { label: "legacy .xls file or a password-protected (encrypted) workbook" },
|
|
800
|
+
unknown: { label: "file that is not a spreadsheet package" }
|
|
801
|
+
};
|
|
802
|
+
function sniffContainer(b) {
|
|
803
|
+
for (const c of CONTAINERS) if (c.magic.every((x, i) => b[i] === x)) return c.kind;
|
|
804
|
+
return "unknown";
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* The workbook format for a workbook part, from its content type; when the
|
|
808
|
+
* content type is missing or unknown, from the part's extension (.bin is
|
|
809
|
+
* binary, anything else is read as SpreadsheetML).
|
|
810
|
+
*/
|
|
811
|
+
function workbookFormat(contentType, partName) {
|
|
812
|
+
const ct = (contentType ?? "").toLowerCase();
|
|
813
|
+
const known = WORKBOOK_FORMATS.find((f) => f.contentType.toLowerCase() === ct);
|
|
814
|
+
if (known) return known;
|
|
815
|
+
if (partName.toLowerCase().endsWith(".bin")) return WORKBOOK_FORMATS.find((f) => f.format === "xlsb");
|
|
816
|
+
return WORKBOOK_FORMATS[0];
|
|
817
|
+
}
|
|
818
|
+
// src/internal/read/opc.ts
|
|
819
|
+
/**
|
|
820
|
+
* Open Packaging Conventions for the reader: part lookup (case-insensitive,
|
|
821
|
+
* as OPC requires), [Content_Types].xml and relationship parts. Internal.
|
|
822
|
+
*/
|
|
823
|
+
var Package = class {
|
|
824
|
+
ctx;
|
|
825
|
+
parts = /* @__PURE__ */ new Map();
|
|
826
|
+
/** Part name (lower case, no leading '/') -> content type. */
|
|
827
|
+
overrides = /* @__PURE__ */ new Map();
|
|
828
|
+
/** Extension (lower case) -> content type. */
|
|
829
|
+
defaults = /* @__PURE__ */ new Map();
|
|
830
|
+
constructor(ctx) {
|
|
831
|
+
this.ctx = ctx;
|
|
832
|
+
for (const e of ctx.zip.entries) {
|
|
833
|
+
if (e.name.endsWith("/")) continue;
|
|
834
|
+
const key = e.name.toLowerCase();
|
|
835
|
+
if (this.parts.has(key)) throw new FormatError("ZIP_INVALID", `Part names ${this.parts.get(key).name} and ${e.name} differ only in case.`, { details: { entry: e.name } });
|
|
836
|
+
this.parts.set(key, e);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
part(name) {
|
|
840
|
+
return this.parts.get(stripSlash(name).toLowerCase());
|
|
841
|
+
}
|
|
842
|
+
get partNames() {
|
|
843
|
+
return [...this.parts.values()].map((e) => e.name);
|
|
844
|
+
}
|
|
845
|
+
async loadContentTypes() {
|
|
846
|
+
const entry = this.part("[Content_Types].xml");
|
|
847
|
+
if (!entry) return;
|
|
848
|
+
await this.ctx.parse(entry, {
|
|
849
|
+
open: (name, a) => {
|
|
850
|
+
if (name === "Default") {
|
|
851
|
+
const ext = a.get("Extension");
|
|
852
|
+
const type = a.get("ContentType");
|
|
853
|
+
if (ext && type) this.defaults.set(ext.toLowerCase(), type);
|
|
854
|
+
} else if (name === "Override") {
|
|
855
|
+
const part = a.get("PartName");
|
|
856
|
+
const type = a.get("ContentType");
|
|
857
|
+
if (part && type) this.overrides.set(stripSlash(part).toLowerCase(), type);
|
|
858
|
+
}
|
|
859
|
+
},
|
|
860
|
+
close: () => {},
|
|
861
|
+
text: () => {}
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
contentType(name) {
|
|
865
|
+
const key = stripSlash(name).toLowerCase();
|
|
866
|
+
const o = this.overrides.get(key);
|
|
867
|
+
if (o) return o;
|
|
868
|
+
const dot = key.lastIndexOf(".");
|
|
869
|
+
return dot === -1 ? void 0 : this.defaults.get(key.slice(dot + 1));
|
|
870
|
+
}
|
|
871
|
+
/** Content types of all overrides (for format detection). */
|
|
872
|
+
get overrideTypes() {
|
|
873
|
+
return [...this.overrides.values()];
|
|
874
|
+
}
|
|
875
|
+
/** Relationships of `source` ('' for the package). Missing rels part: []. */
|
|
876
|
+
async rels(source) {
|
|
877
|
+
const src = stripSlash(source);
|
|
878
|
+
const slash = src.lastIndexOf("/");
|
|
879
|
+
const dir = slash === -1 ? "" : src.slice(0, slash + 1);
|
|
880
|
+
const relsName = `${dir}_rels/${slash === -1 ? src : src.slice(slash + 1)}.rels`;
|
|
881
|
+
const entry = this.part(relsName);
|
|
882
|
+
if (!entry) return [];
|
|
883
|
+
const out = [];
|
|
884
|
+
await this.ctx.parse(entry, {
|
|
885
|
+
open: (name, a) => {
|
|
886
|
+
if (name !== "Relationship") return;
|
|
887
|
+
const id = a.get("Id");
|
|
888
|
+
const type = a.get("Type");
|
|
889
|
+
const target = a.get("Target");
|
|
890
|
+
if (!id || !type || target === void 0) return;
|
|
891
|
+
const external = (a.get("TargetMode") ?? "").toLowerCase() === "external";
|
|
892
|
+
out.push({
|
|
893
|
+
id,
|
|
894
|
+
type,
|
|
895
|
+
kind: type.slice(type.lastIndexOf("/") + 1),
|
|
896
|
+
target: external ? target : resolveTarget(dir, target),
|
|
897
|
+
external
|
|
898
|
+
});
|
|
899
|
+
},
|
|
900
|
+
close: () => {},
|
|
901
|
+
text: () => {}
|
|
902
|
+
});
|
|
903
|
+
return out;
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
function stripSlash(name) {
|
|
907
|
+
return name.startsWith("/") ? name.slice(1) : name;
|
|
908
|
+
}
|
|
909
|
+
/** Resolves a relationship target against the source part's folder (RFC 3986 dot segments, '%xx' decoded). */
|
|
910
|
+
function resolveTarget(baseDir, target) {
|
|
911
|
+
let t = target;
|
|
912
|
+
const hash = t.indexOf("#");
|
|
913
|
+
if (hash !== -1) t = t.slice(0, hash);
|
|
914
|
+
try {
|
|
915
|
+
t = decodeURIComponent(t);
|
|
916
|
+
} catch {}
|
|
917
|
+
t = t.replace(/\\/g, "/");
|
|
918
|
+
const segments = t.startsWith("/") ? [] : baseDir.split("/").filter((s) => s !== "");
|
|
919
|
+
for (const seg of t.split("/")) {
|
|
920
|
+
if (seg === "" || seg === ".") continue;
|
|
921
|
+
if (seg === "..") segments.pop();
|
|
922
|
+
else segments.push(seg);
|
|
923
|
+
}
|
|
924
|
+
return segments.join("/");
|
|
925
|
+
}
|
|
926
|
+
// src/internal/read/formula.ts
|
|
927
|
+
/**
|
|
928
|
+
* A1 reference shifter for shared formulas (docs/api.md §12 Q6). Internal.
|
|
929
|
+
*
|
|
930
|
+
* Shifts relative cell references, `$` anchors stay; handles ranges, whole
|
|
931
|
+
* column (`A:C`) and whole row (`1:3`) ranges and sheet-qualified references.
|
|
932
|
+
* String literals, quoted sheet names and bracketed parts (structured
|
|
933
|
+
* references, external workbook indexes) are copied unchanged. Returns
|
|
934
|
+
* undefined when a shifted reference would leave the sheet, so the caller
|
|
935
|
+
* keeps the cached value only.
|
|
936
|
+
*/
|
|
937
|
+
const MAX_ROW = 1048576;
|
|
938
|
+
const MAX_COL = 16384;
|
|
939
|
+
const CELL = /\$?([A-Za-z]{1,3})\$?(\d{1,7})/y;
|
|
940
|
+
const CELL_PARTS = /^(\$?)([A-Za-z]{1,3})(\$?)(\d{1,7})$/;
|
|
941
|
+
const COLS = /(\$?)([A-Za-z]{1,3}):(\$?)([A-Za-z]{1,3})/y;
|
|
942
|
+
const ROWS = /(\$?)(\d{1,7}):(\$?)(\d{1,7})/y;
|
|
943
|
+
function colNumber(letters) {
|
|
944
|
+
let n = 0;
|
|
945
|
+
for (let i = 0; i < letters.length; i++) n = n * 26 + (letters.toUpperCase().charCodeAt(i) - 64);
|
|
946
|
+
return n;
|
|
947
|
+
}
|
|
948
|
+
function colLetters(n) {
|
|
949
|
+
let s = "";
|
|
950
|
+
while (n > 0) {
|
|
951
|
+
const r = (n - 1) % 26;
|
|
952
|
+
s = String.fromCharCode(65 + r) + s;
|
|
953
|
+
n = Math.floor((n - 1) / 26);
|
|
954
|
+
}
|
|
955
|
+
return s;
|
|
956
|
+
}
|
|
957
|
+
function isWordChar(c) {
|
|
958
|
+
return c !== void 0 && /[A-Za-z0-9_.\\]/.test(c);
|
|
959
|
+
}
|
|
960
|
+
function shiftFormula(formula, dRow, dCol) {
|
|
961
|
+
if (dRow === 0 && dCol === 0) return formula;
|
|
962
|
+
let out = "";
|
|
963
|
+
let i = 0;
|
|
964
|
+
const n = formula.length;
|
|
965
|
+
while (i < n) {
|
|
966
|
+
const ch = formula[i];
|
|
967
|
+
if (ch === "\"") {
|
|
968
|
+
let j = i + 1;
|
|
969
|
+
for (; j < n; j++) if (formula[j] === "\"") {
|
|
970
|
+
if (formula[j + 1] === "\"") j++;
|
|
971
|
+
else break;
|
|
972
|
+
}
|
|
973
|
+
out += formula.slice(i, j + 1);
|
|
974
|
+
i = j + 1;
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
977
|
+
if (ch === "'") {
|
|
978
|
+
let j = i + 1;
|
|
979
|
+
for (; j < n; j++) if (formula[j] === "'") {
|
|
980
|
+
if (formula[j + 1] === "'") j++;
|
|
981
|
+
else break;
|
|
982
|
+
}
|
|
983
|
+
out += formula.slice(i, j + 1);
|
|
984
|
+
i = j + 1;
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
if (ch === "[") {
|
|
988
|
+
let depth = 0;
|
|
989
|
+
let j = i;
|
|
990
|
+
for (; j < n; j++) if (formula[j] === "[") depth++;
|
|
991
|
+
else if (formula[j] === "]" && --depth === 0) break;
|
|
992
|
+
out += formula.slice(i, j + 1);
|
|
993
|
+
i = j + 1;
|
|
994
|
+
continue;
|
|
995
|
+
}
|
|
996
|
+
const prev = i > 0 ? formula[i - 1] : void 0;
|
|
997
|
+
if ((ch === "$" || /[A-Za-z0-9]/.test(ch)) && !isWordChar(prev) && prev !== "$") {
|
|
998
|
+
const shifted = tryRef(formula, i, dRow, dCol);
|
|
999
|
+
if (shifted === null) return void 0;
|
|
1000
|
+
if (shifted !== void 0) {
|
|
1001
|
+
out += shifted.text;
|
|
1002
|
+
i = shifted.end;
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
let j = i + 1;
|
|
1006
|
+
while (j < n && isWordChar(formula[j])) j++;
|
|
1007
|
+
out += formula.slice(i, j);
|
|
1008
|
+
i = j;
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
out += ch;
|
|
1012
|
+
i++;
|
|
1013
|
+
}
|
|
1014
|
+
return out;
|
|
1015
|
+
}
|
|
1016
|
+
/** A reference at `i`: { text, end }, undefined if there is none, null if shifting fails. */
|
|
1017
|
+
function tryRef(f, i, dRow, dCol) {
|
|
1018
|
+
const after = (end) => f[end];
|
|
1019
|
+
const isEnd = (end) => {
|
|
1020
|
+
const c = after(end);
|
|
1021
|
+
return c === void 0 || !(isWordChar(c) || c === "(" || c === "!" || c === "$");
|
|
1022
|
+
};
|
|
1023
|
+
COLS.lastIndex = i;
|
|
1024
|
+
let m = COLS.exec(f);
|
|
1025
|
+
if (m && isEnd(COLS.lastIndex)) {
|
|
1026
|
+
const a = shiftPart(m[1], colNumber(m[2]), dCol, MAX_COL);
|
|
1027
|
+
const b = shiftPart(m[3], colNumber(m[4]), dCol, MAX_COL);
|
|
1028
|
+
if (colNumber(m[2]) > MAX_COL || colNumber(m[4]) > MAX_COL) return void 0;
|
|
1029
|
+
if (a === void 0 || b === void 0) return null;
|
|
1030
|
+
return {
|
|
1031
|
+
text: `${m[1]}${colLetters(a)}:${m[3]}${colLetters(b)}`,
|
|
1032
|
+
end: COLS.lastIndex
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
ROWS.lastIndex = i;
|
|
1036
|
+
m = ROWS.exec(f);
|
|
1037
|
+
if (m && isEnd(ROWS.lastIndex)) {
|
|
1038
|
+
const a = shiftPart(m[1], Number(m[2]), dRow, MAX_ROW);
|
|
1039
|
+
const b = shiftPart(m[3], Number(m[4]), dRow, MAX_ROW);
|
|
1040
|
+
if (a === void 0 || b === void 0) return null;
|
|
1041
|
+
return {
|
|
1042
|
+
text: `${m[1]}${a}:${m[3]}${b}`,
|
|
1043
|
+
end: ROWS.lastIndex
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
CELL.lastIndex = i;
|
|
1047
|
+
m = CELL.exec(f);
|
|
1048
|
+
if (m && isEnd(CELL.lastIndex)) {
|
|
1049
|
+
const parts = CELL_PARTS.exec(m[0]);
|
|
1050
|
+
const col = colNumber(parts[2]);
|
|
1051
|
+
if (col > MAX_COL) return void 0;
|
|
1052
|
+
const c = shiftPart(parts[1], col, dCol, MAX_COL);
|
|
1053
|
+
const r = shiftPart(parts[3], Number(parts[4]), dRow, MAX_ROW);
|
|
1054
|
+
if (c === void 0 || r === void 0) return null;
|
|
1055
|
+
return {
|
|
1056
|
+
text: `${parts[1]}${colLetters(c)}${parts[3]}${r}`,
|
|
1057
|
+
end: CELL.lastIndex
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function shiftPart(anchor, value, delta, max) {
|
|
1062
|
+
if (anchor === "$") return value;
|
|
1063
|
+
const v = value + delta;
|
|
1064
|
+
return v >= 1 && v <= max ? v : void 0;
|
|
1065
|
+
}
|
|
1066
|
+
// src/internal/read/styles.ts
|
|
1067
|
+
const EMPTY_STYLES = {
|
|
1068
|
+
style: () => void 0,
|
|
1069
|
+
numFmt: () => void 0,
|
|
1070
|
+
size: 0,
|
|
1071
|
+
indexedColors: void 0
|
|
1072
|
+
};
|
|
1073
|
+
const BORDER_STYLES = /* @__PURE__ */ new Set([
|
|
1074
|
+
"none",
|
|
1075
|
+
"thin",
|
|
1076
|
+
"medium",
|
|
1077
|
+
"thick",
|
|
1078
|
+
"double",
|
|
1079
|
+
"hair",
|
|
1080
|
+
"dotted",
|
|
1081
|
+
"dashed",
|
|
1082
|
+
"dashDot",
|
|
1083
|
+
"dashDotDot",
|
|
1084
|
+
"mediumDashed",
|
|
1085
|
+
"mediumDashDot",
|
|
1086
|
+
"mediumDashDotDot",
|
|
1087
|
+
"slantDashDot"
|
|
1088
|
+
]);
|
|
1089
|
+
const PATTERNS = /* @__PURE__ */ new Set([
|
|
1090
|
+
"none",
|
|
1091
|
+
"solid",
|
|
1092
|
+
"mediumGray",
|
|
1093
|
+
"darkGray",
|
|
1094
|
+
"lightGray",
|
|
1095
|
+
"darkHorizontal",
|
|
1096
|
+
"darkVertical",
|
|
1097
|
+
"darkDown",
|
|
1098
|
+
"darkUp",
|
|
1099
|
+
"darkGrid",
|
|
1100
|
+
"darkTrellis",
|
|
1101
|
+
"lightHorizontal",
|
|
1102
|
+
"lightVertical",
|
|
1103
|
+
"lightDown",
|
|
1104
|
+
"lightUp",
|
|
1105
|
+
"lightGrid",
|
|
1106
|
+
"lightTrellis",
|
|
1107
|
+
"gray125",
|
|
1108
|
+
"gray0625"
|
|
1109
|
+
]);
|
|
1110
|
+
const H_ALIGN = /* @__PURE__ */ new Set([
|
|
1111
|
+
"general",
|
|
1112
|
+
"left",
|
|
1113
|
+
"center",
|
|
1114
|
+
"right",
|
|
1115
|
+
"fill",
|
|
1116
|
+
"justify",
|
|
1117
|
+
"centerContinuous",
|
|
1118
|
+
"distributed"
|
|
1119
|
+
]);
|
|
1120
|
+
const V_ALIGN = /* @__PURE__ */ new Set([
|
|
1121
|
+
"top",
|
|
1122
|
+
"center",
|
|
1123
|
+
"bottom",
|
|
1124
|
+
"justify",
|
|
1125
|
+
"distributed"
|
|
1126
|
+
]);
|
|
1127
|
+
const UNDERLINE = /* @__PURE__ */ new Set([
|
|
1128
|
+
"single",
|
|
1129
|
+
"double",
|
|
1130
|
+
"singleAccounting",
|
|
1131
|
+
"doubleAccounting"
|
|
1132
|
+
]);
|
|
1133
|
+
function bool(v, dflt = true) {
|
|
1134
|
+
if (v === void 0) return dflt;
|
|
1135
|
+
return v === "1" || v === "true" || v === "on";
|
|
1136
|
+
}
|
|
1137
|
+
function num(v) {
|
|
1138
|
+
if (v === void 0 || v === "") return void 0;
|
|
1139
|
+
const n = Number(v);
|
|
1140
|
+
return Number.isFinite(n) ? n : void 0;
|
|
1141
|
+
}
|
|
1142
|
+
function int(v) {
|
|
1143
|
+
const n = num(v);
|
|
1144
|
+
return n === void 0 ? void 0 : Math.trunc(n);
|
|
1145
|
+
}
|
|
1146
|
+
/** CT_Color -> model colour (object forms only, §3.5.6). */
|
|
1147
|
+
function color(a) {
|
|
1148
|
+
const rgb = a.get("rgb");
|
|
1149
|
+
if (rgb !== void 0 && /^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$/.test(rgb)) return { rgb: (rgb.length === 6 ? `FF${rgb}` : rgb).toUpperCase() };
|
|
1150
|
+
const theme = int(a.get("theme"));
|
|
1151
|
+
if (theme !== void 0 && theme >= 0) {
|
|
1152
|
+
const tint = num(a.get("tint"));
|
|
1153
|
+
return tint === void 0 || tint === 0 ? { theme } : {
|
|
1154
|
+
theme,
|
|
1155
|
+
tint
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
const indexed = int(a.get("indexed"));
|
|
1159
|
+
if (indexed !== void 0 && indexed >= 0) return { indexed };
|
|
1160
|
+
if (bool(a.get("auto"), false)) return { auto: true };
|
|
1161
|
+
}
|
|
1162
|
+
/** Parser for font properties: <font> in styles.xml and <rPr> in rich text. */
|
|
1163
|
+
var FontBuilder = class {
|
|
1164
|
+
font = {};
|
|
1165
|
+
/** Handles one child element of <font>/<rPr>. */
|
|
1166
|
+
child(name, a) {
|
|
1167
|
+
const f = this.font;
|
|
1168
|
+
const val = a.get("val");
|
|
1169
|
+
switch (name) {
|
|
1170
|
+
case "name":
|
|
1171
|
+
case "rFont":
|
|
1172
|
+
if (val !== void 0) f.name = val;
|
|
1173
|
+
break;
|
|
1174
|
+
case "sz": {
|
|
1175
|
+
const n = num(val);
|
|
1176
|
+
if (n !== void 0) f.size = n;
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
case "color": {
|
|
1180
|
+
const c = color(a);
|
|
1181
|
+
if (c) f.color = c;
|
|
1182
|
+
break;
|
|
1183
|
+
}
|
|
1184
|
+
case "b":
|
|
1185
|
+
f.bold = bool(val);
|
|
1186
|
+
break;
|
|
1187
|
+
case "i":
|
|
1188
|
+
f.italic = bool(val);
|
|
1189
|
+
break;
|
|
1190
|
+
case "strike":
|
|
1191
|
+
f.strike = bool(val);
|
|
1192
|
+
break;
|
|
1193
|
+
case "outline":
|
|
1194
|
+
f.outline = bool(val);
|
|
1195
|
+
break;
|
|
1196
|
+
case "shadow":
|
|
1197
|
+
f.shadow = bool(val);
|
|
1198
|
+
break;
|
|
1199
|
+
case "condense":
|
|
1200
|
+
f.condense = bool(val);
|
|
1201
|
+
break;
|
|
1202
|
+
case "extend":
|
|
1203
|
+
f.extend = bool(val);
|
|
1204
|
+
break;
|
|
1205
|
+
case "u":
|
|
1206
|
+
if (val === void 0 || val === "single") f.underline = true;
|
|
1207
|
+
else if (UNDERLINE.has(val)) f.underline = val;
|
|
1208
|
+
else if (val === "none") f.underline = false;
|
|
1209
|
+
break;
|
|
1210
|
+
case "vertAlign":
|
|
1211
|
+
if (val === "superscript" || val === "subscript" || val === "baseline") f.vertAlign = val;
|
|
1212
|
+
break;
|
|
1213
|
+
case "family": {
|
|
1214
|
+
const n = int(val);
|
|
1215
|
+
if (n !== void 0) f.family = n;
|
|
1216
|
+
break;
|
|
1217
|
+
}
|
|
1218
|
+
case "charset": {
|
|
1219
|
+
const n = int(val);
|
|
1220
|
+
if (n !== void 0) f.charset = n;
|
|
1221
|
+
break;
|
|
1222
|
+
}
|
|
1223
|
+
case "scheme": if (val === "major" || val === "minor" || val === "none") f.scheme = val;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
/** Streaming handler state for styles.xml. */
|
|
1228
|
+
var StylesParser = class {
|
|
1229
|
+
full;
|
|
1230
|
+
numFmts = /* @__PURE__ */ new Map();
|
|
1231
|
+
fonts = [];
|
|
1232
|
+
fills = [];
|
|
1233
|
+
borders = [];
|
|
1234
|
+
xfs = [];
|
|
1235
|
+
indexed;
|
|
1236
|
+
section = "";
|
|
1237
|
+
font;
|
|
1238
|
+
fill;
|
|
1239
|
+
fillColorTarget;
|
|
1240
|
+
border;
|
|
1241
|
+
xf;
|
|
1242
|
+
constructor(full) {
|
|
1243
|
+
this.full = full;
|
|
1244
|
+
}
|
|
1245
|
+
open(name, a, empty) {
|
|
1246
|
+
switch (name) {
|
|
1247
|
+
case "numFmts":
|
|
1248
|
+
case "fonts":
|
|
1249
|
+
case "fills":
|
|
1250
|
+
case "borders":
|
|
1251
|
+
case "cellXfs":
|
|
1252
|
+
case "cellStyleXfs":
|
|
1253
|
+
case "dxfs":
|
|
1254
|
+
case "indexedColors":
|
|
1255
|
+
case "colors":
|
|
1256
|
+
case "cellStyles":
|
|
1257
|
+
case "tableStyles":
|
|
1258
|
+
case "extLst":
|
|
1259
|
+
if (!empty) this.section = name;
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
const sec = this.section;
|
|
1263
|
+
if (sec === "numFmts" && name === "numFmt") {
|
|
1264
|
+
const id = int(a.get("numFmtId"));
|
|
1265
|
+
const code = a.get("formatCode");
|
|
1266
|
+
if (id !== void 0 && code !== void 0) this.numFmts.set(id, code);
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
if (sec === "cellXfs" && name === "xf") {
|
|
1270
|
+
this.xf = {
|
|
1271
|
+
numFmtId: int(a.get("numFmtId")) ?? 0,
|
|
1272
|
+
fontId: int(a.get("fontId")) ?? 0,
|
|
1273
|
+
fillId: int(a.get("fillId")) ?? 0,
|
|
1274
|
+
borderId: int(a.get("borderId")) ?? 0
|
|
1275
|
+
};
|
|
1276
|
+
this.xfs.push(this.xf);
|
|
1277
|
+
if (empty) this.xf = void 0;
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
if (sec === "indexedColors" && name === "rgbColor") {
|
|
1281
|
+
const rgb = a.get("rgb");
|
|
1282
|
+
if (rgb && /^[0-9A-Fa-f]{8}$/.test(rgb)) (this.indexed ??= []).push(rgb.toUpperCase());
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
if (!this.full) return;
|
|
1286
|
+
if (sec === "cellXfs" && this.xf) {
|
|
1287
|
+
if (name === "alignment") this.xf.alignment = alignment(a);
|
|
1288
|
+
else if (name === "protection") {
|
|
1289
|
+
const p = {};
|
|
1290
|
+
if (a.get("locked") !== void 0) p.locked = bool(a.get("locked"));
|
|
1291
|
+
if (a.get("hidden") !== void 0) p.hidden = bool(a.get("hidden"));
|
|
1292
|
+
this.xf.protection = p;
|
|
1293
|
+
}
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
if (sec === "fonts") {
|
|
1297
|
+
if (name === "font") {
|
|
1298
|
+
this.font = new FontBuilder();
|
|
1299
|
+
if (empty) this.endFont();
|
|
1300
|
+
} else this.font?.child(name, a);
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
if (sec === "fills") {
|
|
1304
|
+
if (name === "fill") {
|
|
1305
|
+
this.fill = {};
|
|
1306
|
+
if (empty) this.endFill();
|
|
1307
|
+
} else if (name === "patternFill" && this.fill) {
|
|
1308
|
+
const t = a.get("patternType") ?? "none";
|
|
1309
|
+
this.fill.pattern = {
|
|
1310
|
+
type: "pattern",
|
|
1311
|
+
pattern: PATTERNS.has(t) ? t : "none"
|
|
1312
|
+
};
|
|
1313
|
+
} else if (name === "gradientFill" && this.fill) {
|
|
1314
|
+
const g = {
|
|
1315
|
+
type: "gradient",
|
|
1316
|
+
gradient: a.get("type") === "path" ? "path" : "linear",
|
|
1317
|
+
stops: []
|
|
1318
|
+
};
|
|
1319
|
+
for (const k of [
|
|
1320
|
+
"degree",
|
|
1321
|
+
"left",
|
|
1322
|
+
"right",
|
|
1323
|
+
"top",
|
|
1324
|
+
"bottom"
|
|
1325
|
+
]) {
|
|
1326
|
+
const n = num(a.get(k));
|
|
1327
|
+
if (n !== void 0) g[k] = n;
|
|
1328
|
+
}
|
|
1329
|
+
this.fill.gradient = g;
|
|
1330
|
+
} else if (name === "stop" && this.fill?.gradient) {
|
|
1331
|
+
this.fill.stop = num(a.get("position")) ?? 0;
|
|
1332
|
+
this.fillColorTarget = "stop";
|
|
1333
|
+
} else if ((name === "fgColor" || name === "bgColor") && this.fill?.pattern) {
|
|
1334
|
+
const c = color(a);
|
|
1335
|
+
if (c) this.fill.pattern[name] = c;
|
|
1336
|
+
} else if (name === "color" && this.fillColorTarget === "stop" && this.fill?.gradient) {
|
|
1337
|
+
const c = color(a);
|
|
1338
|
+
if (c) this.fill.gradient.stops.push({
|
|
1339
|
+
position: this.fill.stop ?? 0,
|
|
1340
|
+
color: c
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
if (sec === "borders") {
|
|
1346
|
+
if (name === "border") {
|
|
1347
|
+
const b = {};
|
|
1348
|
+
if (a.get("diagonalUp") !== void 0) b.diagonalUp = bool(a.get("diagonalUp"));
|
|
1349
|
+
if (a.get("diagonalDown") !== void 0) b.diagonalDown = bool(a.get("diagonalDown"));
|
|
1350
|
+
this.border = { b };
|
|
1351
|
+
if (empty) this.endBorder();
|
|
1352
|
+
} else if (this.border && (name === "left" || name === "right" || name === "top" || name === "bottom" || name === "diagonal" || name === "start" || name === "end")) {
|
|
1353
|
+
const side = name === "start" ? "left" : name === "end" ? "right" : name;
|
|
1354
|
+
const st = a.get("style");
|
|
1355
|
+
if (st !== void 0 && st !== "none" && BORDER_STYLES.has(st)) {
|
|
1356
|
+
this.border.b[side] = { style: st };
|
|
1357
|
+
this.border.side = empty ? void 0 : side;
|
|
1358
|
+
} else this.border.side = void 0;
|
|
1359
|
+
} else if (name === "color" && this.border?.side) {
|
|
1360
|
+
const c = color(a);
|
|
1361
|
+
const s = this.border.b[this.border.side];
|
|
1362
|
+
if (c && s) s.color = c;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
close(name) {
|
|
1367
|
+
switch (name) {
|
|
1368
|
+
case "numFmts":
|
|
1369
|
+
case "fonts":
|
|
1370
|
+
case "fills":
|
|
1371
|
+
case "borders":
|
|
1372
|
+
case "cellXfs":
|
|
1373
|
+
case "cellStyleXfs":
|
|
1374
|
+
case "dxfs":
|
|
1375
|
+
case "indexedColors":
|
|
1376
|
+
case "colors":
|
|
1377
|
+
case "cellStyles":
|
|
1378
|
+
case "tableStyles":
|
|
1379
|
+
case "extLst":
|
|
1380
|
+
this.section = name === "indexedColors" ? "colors" : "";
|
|
1381
|
+
return;
|
|
1382
|
+
case "font":
|
|
1383
|
+
if (this.section === "fonts") this.endFont();
|
|
1384
|
+
return;
|
|
1385
|
+
case "fill":
|
|
1386
|
+
if (this.section === "fills") this.endFill();
|
|
1387
|
+
return;
|
|
1388
|
+
case "stop":
|
|
1389
|
+
this.fillColorTarget = void 0;
|
|
1390
|
+
return;
|
|
1391
|
+
case "border":
|
|
1392
|
+
if (this.section === "borders") this.endBorder();
|
|
1393
|
+
return;
|
|
1394
|
+
case "left":
|
|
1395
|
+
case "right":
|
|
1396
|
+
case "top":
|
|
1397
|
+
case "bottom":
|
|
1398
|
+
case "diagonal":
|
|
1399
|
+
case "start":
|
|
1400
|
+
case "end":
|
|
1401
|
+
if (this.border) this.border.side = void 0;
|
|
1402
|
+
return;
|
|
1403
|
+
case "xf":
|
|
1404
|
+
this.xf = void 0;
|
|
1405
|
+
return;
|
|
1406
|
+
default: return;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
text() {}
|
|
1410
|
+
endFont() {
|
|
1411
|
+
if (this.font) this.fonts.push(this.font.font);
|
|
1412
|
+
this.font = void 0;
|
|
1413
|
+
}
|
|
1414
|
+
endFill() {
|
|
1415
|
+
const f = this.fill;
|
|
1416
|
+
let out;
|
|
1417
|
+
if (f?.gradient) out = f.gradient;
|
|
1418
|
+
else if (f?.pattern && f.pattern.pattern !== "none") out = f.pattern;
|
|
1419
|
+
this.fills.push(out);
|
|
1420
|
+
this.fill = void 0;
|
|
1421
|
+
}
|
|
1422
|
+
endBorder() {
|
|
1423
|
+
if (this.border) {
|
|
1424
|
+
const b = this.border.b;
|
|
1425
|
+
this.borders.push(Object.keys(b).length ? b : void 0);
|
|
1426
|
+
}
|
|
1427
|
+
this.border = void 0;
|
|
1428
|
+
}
|
|
1429
|
+
/** Builds the shared, frozen styles. */
|
|
1430
|
+
result() {
|
|
1431
|
+
const xfs = this.xfs;
|
|
1432
|
+
const numFmts = this.numFmts;
|
|
1433
|
+
const full = this.full;
|
|
1434
|
+
const fmtOf = (x) => {
|
|
1435
|
+
const custom = numFmts.get(x.numFmtId);
|
|
1436
|
+
if (custom !== void 0) return custom === "General" ? void 0 : custom;
|
|
1437
|
+
return x.numFmtId === 0 ? void 0 : x.numFmtId;
|
|
1438
|
+
};
|
|
1439
|
+
const styles = new Array(xfs.length);
|
|
1440
|
+
const built = new Array(xfs.length).fill(false);
|
|
1441
|
+
const fonts = this.fonts;
|
|
1442
|
+
const fills = this.fills;
|
|
1443
|
+
const borders = this.borders;
|
|
1444
|
+
const make = (i) => {
|
|
1445
|
+
const x = xfs[i];
|
|
1446
|
+
const s = {};
|
|
1447
|
+
const font = fonts[x.fontId];
|
|
1448
|
+
if (font && x.fontId !== 0 && Object.keys(font).length) s.font = font;
|
|
1449
|
+
const fill = fills[x.fillId];
|
|
1450
|
+
if (fill && x.fillId > 1) s.fill = fill;
|
|
1451
|
+
const border = borders[x.borderId];
|
|
1452
|
+
if (border && x.borderId !== 0) s.border = border;
|
|
1453
|
+
if (x.alignment && Object.keys(x.alignment).length) s.alignment = x.alignment;
|
|
1454
|
+
const nf = fmtOf(x);
|
|
1455
|
+
if (nf !== void 0) s.numFmt = nf;
|
|
1456
|
+
if (x.protection && Object.keys(x.protection).length) s.protection = x.protection;
|
|
1457
|
+
return Object.keys(s).length ? deepFreeze(s) : void 0;
|
|
1458
|
+
};
|
|
1459
|
+
return {
|
|
1460
|
+
size: xfs.length,
|
|
1461
|
+
indexedColors: this.indexed,
|
|
1462
|
+
numFmt: (i) => {
|
|
1463
|
+
const x = xfs[i];
|
|
1464
|
+
return x ? fmtOf(x) : void 0;
|
|
1465
|
+
},
|
|
1466
|
+
style: (i) => {
|
|
1467
|
+
if (!full || i <= 0 || i >= xfs.length) return void 0;
|
|
1468
|
+
if (!built[i]) {
|
|
1469
|
+
styles[i] = make(i);
|
|
1470
|
+
built[i] = true;
|
|
1471
|
+
}
|
|
1472
|
+
return styles[i];
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
function alignment(a) {
|
|
1478
|
+
const al = {};
|
|
1479
|
+
const h = a.get("horizontal");
|
|
1480
|
+
if (h !== void 0 && H_ALIGN.has(h)) al.horizontal = h;
|
|
1481
|
+
const v = a.get("vertical");
|
|
1482
|
+
if (v !== void 0 && V_ALIGN.has(v)) al.vertical = v;
|
|
1483
|
+
if (a.get("wrapText") !== void 0) al.wrapText = bool(a.get("wrapText"));
|
|
1484
|
+
if (a.get("shrinkToFit") !== void 0) al.shrinkToFit = bool(a.get("shrinkToFit"));
|
|
1485
|
+
if (a.get("justifyLastLine") !== void 0) al.justifyLastLine = bool(a.get("justifyLastLine"));
|
|
1486
|
+
const indent = int(a.get("indent"));
|
|
1487
|
+
if (indent !== void 0 && indent > 0) al.indent = indent;
|
|
1488
|
+
const rot = int(a.get("textRotation"));
|
|
1489
|
+
if (rot !== void 0 && rot !== 0) {
|
|
1490
|
+
if (rot === 255) al.rotation = "vertical";
|
|
1491
|
+
else if (rot >= 1 && rot <= 90) al.rotation = rot;
|
|
1492
|
+
else if (rot > 90 && rot <= 180) al.rotation = -(rot - 90);
|
|
1493
|
+
}
|
|
1494
|
+
const ro = int(a.get("readingOrder"));
|
|
1495
|
+
if (ro === 1) al.readingOrder = "ltr";
|
|
1496
|
+
else if (ro === 2) al.readingOrder = "rtl";
|
|
1497
|
+
return al;
|
|
1498
|
+
}
|
|
1499
|
+
function deepFreeze(o) {
|
|
1500
|
+
if (o && typeof o === "object" && !Object.isFrozen(o)) {
|
|
1501
|
+
Object.freeze(o);
|
|
1502
|
+
for (const v of Object.values(o)) deepFreeze(v);
|
|
1503
|
+
}
|
|
1504
|
+
return o;
|
|
1505
|
+
}
|
|
1506
|
+
// src/internal/read/strings.ts
|
|
1507
|
+
/**
|
|
1508
|
+
* Shared strings (xl/sharedStrings.xml) and inline strings (<is>). Internal.
|
|
1509
|
+
*
|
|
1510
|
+
* `<si>`/`<is>` hold either one `<t>` (plain text) or `<r>` runs with optional
|
|
1511
|
+
* `<rPr>` fonts. Phonetic runs (`<rPh>`) are not part of the cell text and are
|
|
1512
|
+
* skipped. Text is ST_Xstring: `_xHHHH_` escapes are decoded.
|
|
1513
|
+
*/
|
|
1514
|
+
/** Decodes ST_Xstring `_xHHHH_` escapes (`_x005F_` is a literal underscore). */
|
|
1515
|
+
function decodeXstring(s) {
|
|
1516
|
+
if (s.indexOf("_x") === -1) return s;
|
|
1517
|
+
return s.replace(/_x([0-9A-Fa-f]{4})_/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Collects one string item (<si> or <is>). Feed it the events between the
|
|
1521
|
+
* item's open and close; `value()` gives the string or rich text.
|
|
1522
|
+
*/
|
|
1523
|
+
var StringItem = class {
|
|
1524
|
+
runs = [];
|
|
1525
|
+
plain = "";
|
|
1526
|
+
hasRuns = false;
|
|
1527
|
+
inT = false;
|
|
1528
|
+
inRun = false;
|
|
1529
|
+
inRPh = 0;
|
|
1530
|
+
runText = "";
|
|
1531
|
+
font;
|
|
1532
|
+
inRPr = false;
|
|
1533
|
+
open(name, a) {
|
|
1534
|
+
if (this.inRPh > 0) {
|
|
1535
|
+
this.inRPh++;
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
switch (name) {
|
|
1539
|
+
case "rPh":
|
|
1540
|
+
this.inRPh = 1;
|
|
1541
|
+
return;
|
|
1542
|
+
case "r":
|
|
1543
|
+
this.inRun = true;
|
|
1544
|
+
this.hasRuns = true;
|
|
1545
|
+
this.runText = "";
|
|
1546
|
+
this.font = void 0;
|
|
1547
|
+
return;
|
|
1548
|
+
case "rPr":
|
|
1549
|
+
this.inRPr = true;
|
|
1550
|
+
this.font = new FontBuilder();
|
|
1551
|
+
return;
|
|
1552
|
+
case "t":
|
|
1553
|
+
this.inT = true;
|
|
1554
|
+
return;
|
|
1555
|
+
default: if (this.inRPr) this.font?.child(name, a);
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
close(name) {
|
|
1559
|
+
if (this.inRPh > 0) {
|
|
1560
|
+
this.inRPh--;
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
switch (name) {
|
|
1564
|
+
case "t":
|
|
1565
|
+
this.inT = false;
|
|
1566
|
+
return;
|
|
1567
|
+
case "rPr":
|
|
1568
|
+
this.inRPr = false;
|
|
1569
|
+
return;
|
|
1570
|
+
case "r": {
|
|
1571
|
+
const run = { text: decodeXstring(this.runText) };
|
|
1572
|
+
if (this.font && Object.keys(this.font.font).length) run.font = this.font.font;
|
|
1573
|
+
this.runs.push(run);
|
|
1574
|
+
this.inRun = false;
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
default: return;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
text(s) {
|
|
1581
|
+
if (!this.inT || this.inRPh > 0) return;
|
|
1582
|
+
if (this.inRun) this.runText += s;
|
|
1583
|
+
else this.plain += s;
|
|
1584
|
+
}
|
|
1585
|
+
value(mode) {
|
|
1586
|
+
if (!this.hasRuns) return decodeXstring(this.plain);
|
|
1587
|
+
if (mode === "plain") return this.runs.map((r) => r.text).join("");
|
|
1588
|
+
return { richText: this.runs };
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
/** Handler for sharedStrings.xml. */
|
|
1592
|
+
var SharedStringsParser = class {
|
|
1593
|
+
mode;
|
|
1594
|
+
max;
|
|
1595
|
+
strings = [];
|
|
1596
|
+
item;
|
|
1597
|
+
depth = 0;
|
|
1598
|
+
constructor(mode, max) {
|
|
1599
|
+
this.mode = mode;
|
|
1600
|
+
this.max = max;
|
|
1601
|
+
}
|
|
1602
|
+
open(name, a, empty) {
|
|
1603
|
+
if (this.item) {
|
|
1604
|
+
if (!empty) this.depth++;
|
|
1605
|
+
this.item.open(name, a);
|
|
1606
|
+
if (empty) this.item.close(name);
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
if (name === "si") {
|
|
1610
|
+
if (this.strings.length >= this.max) throw new LimitError("LIMIT_EXCEEDED", `More than maxSharedStrings (${this.max}) shared strings.`, { details: {
|
|
1611
|
+
limit: "maxSharedStrings",
|
|
1612
|
+
value: this.strings.length + 1,
|
|
1613
|
+
max: this.max
|
|
1614
|
+
} });
|
|
1615
|
+
if (empty) this.strings.push("");
|
|
1616
|
+
else {
|
|
1617
|
+
this.item = new StringItem();
|
|
1618
|
+
this.depth = 0;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
close(name) {
|
|
1623
|
+
if (!this.item) return;
|
|
1624
|
+
if (this.depth === 0 && name === "si") {
|
|
1625
|
+
this.strings.push(this.item.value(this.mode));
|
|
1626
|
+
this.item = void 0;
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
this.depth--;
|
|
1630
|
+
this.item.close(name);
|
|
1631
|
+
}
|
|
1632
|
+
text(s) {
|
|
1633
|
+
this.item?.text(s);
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
// src/internal/read/sheet.ts
|
|
1637
|
+
const MAX_ROWS = 1048576;
|
|
1638
|
+
const MAX_COLS = 16384;
|
|
1639
|
+
const ERROR_CODES = /* @__PURE__ */ new Set([
|
|
1640
|
+
"#NULL!",
|
|
1641
|
+
"#DIV/0!",
|
|
1642
|
+
"#VALUE!",
|
|
1643
|
+
"#REF!",
|
|
1644
|
+
"#NAME?",
|
|
1645
|
+
"#NUM!",
|
|
1646
|
+
"#N/A",
|
|
1647
|
+
"#GETTING_DATA",
|
|
1648
|
+
"#SPILL!",
|
|
1649
|
+
"#CALC!",
|
|
1650
|
+
"#FIELD!",
|
|
1651
|
+
"#BLOCKED!",
|
|
1652
|
+
"#CONNECT!",
|
|
1653
|
+
"#UNKNOWN!",
|
|
1654
|
+
"#BUSY!",
|
|
1655
|
+
"#PYTHON!",
|
|
1656
|
+
"#EXTERNAL!"
|
|
1657
|
+
]);
|
|
1658
|
+
/** Maximum digit width of Calibri 11 in pixels; the writer uses the same value (internal/write/sheet-features.ts). */
|
|
1659
|
+
const MAX_DIGIT_WIDTH = 7;
|
|
1660
|
+
/**
|
|
1661
|
+
* A column width as stored in the file (characters plus padding, ECMA-376
|
|
1662
|
+
* §18.3.1.13) to the width Excel's UI shows, which the model uses (§3.3).
|
|
1663
|
+
* The inverse of the writer's conversion: 20 is written as 20.7109375 and
|
|
1664
|
+
* reads back as 20.
|
|
1665
|
+
*/
|
|
1666
|
+
function fileWidthToChars(width) {
|
|
1667
|
+
if (width <= 0) return 0;
|
|
1668
|
+
const px = Math.trunc((256 * width + Math.trunc(128 / MAX_DIGIT_WIDTH)) / 256 * MAX_DIGIT_WIDTH);
|
|
1669
|
+
return Math.max(0, Math.trunc((px - 5) / MAX_DIGIT_WIDTH * 100 + .5) / 100);
|
|
1670
|
+
}
|
|
1671
|
+
/** Parses "B12" -> [row 11, col 1]; undefined if not an A1 cell reference. */
|
|
1672
|
+
function parseRef(ref) {
|
|
1673
|
+
const n = ref.length;
|
|
1674
|
+
let i = 0;
|
|
1675
|
+
if (ref.charCodeAt(0) === 36) i++;
|
|
1676
|
+
let col = 0;
|
|
1677
|
+
const colStart = i;
|
|
1678
|
+
for (; i < n; i++) {
|
|
1679
|
+
let c = ref.charCodeAt(i);
|
|
1680
|
+
if (c >= 97 && c <= 122) c -= 32;
|
|
1681
|
+
if (c < 65 || c > 90) break;
|
|
1682
|
+
col = col * 26 + (c - 64);
|
|
1683
|
+
}
|
|
1684
|
+
const letters = i - colStart;
|
|
1685
|
+
if (letters < 1 || letters > 3) return void 0;
|
|
1686
|
+
if (ref.charCodeAt(i) === 36) i++;
|
|
1687
|
+
let row = 0;
|
|
1688
|
+
const rowStart = i;
|
|
1689
|
+
for (; i < n; i++) {
|
|
1690
|
+
const c = ref.charCodeAt(i);
|
|
1691
|
+
if (c < 48 || c > 57) return void 0;
|
|
1692
|
+
row = row * 10 + (c - 48);
|
|
1693
|
+
}
|
|
1694
|
+
const digits = i - rowStart;
|
|
1695
|
+
if (digits < 1 || digits > 7) return void 0;
|
|
1696
|
+
return [row - 1, col - 1];
|
|
1697
|
+
}
|
|
1698
|
+
/** "A1:B2" -> A1 with the dollar signs removed (sheet qualification stripped). */
|
|
1699
|
+
function cleanRange(ref) {
|
|
1700
|
+
const bang = ref.lastIndexOf("!");
|
|
1701
|
+
return (bang === -1 ? ref : ref.slice(bang + 1)).replace(/\$/g, "");
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* A date-formatted number as a Date, or undefined when it is not a valid
|
|
1705
|
+
* serial: negative, beyond 9999-12-31, or the 1900 system's fictitious
|
|
1706
|
+
* 1900-02-29 (serial 60), which `serialToDate` maps to 1900-03-01.
|
|
1707
|
+
*/
|
|
1708
|
+
function dateOf(serial, date1904, dateZone) {
|
|
1709
|
+
if (!date1904 && Math.floor(serial) === 60) return void 0;
|
|
1710
|
+
try {
|
|
1711
|
+
return serialToDate(serial, {
|
|
1712
|
+
date1904,
|
|
1713
|
+
dateZone
|
|
1714
|
+
});
|
|
1715
|
+
} catch {
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
var SheetParser = class {
|
|
1720
|
+
ctx;
|
|
1721
|
+
styles;
|
|
1722
|
+
opts;
|
|
1723
|
+
part;
|
|
1724
|
+
sheet;
|
|
1725
|
+
rows = [];
|
|
1726
|
+
rowProps = [];
|
|
1727
|
+
colProps = [];
|
|
1728
|
+
merges = [];
|
|
1729
|
+
hyperlinks = [];
|
|
1730
|
+
shared = /* @__PURE__ */ new Map();
|
|
1731
|
+
view;
|
|
1732
|
+
print;
|
|
1733
|
+
fitToPage = false;
|
|
1734
|
+
fitTo;
|
|
1735
|
+
path = [];
|
|
1736
|
+
curRow = -1;
|
|
1737
|
+
nextCol = 0;
|
|
1738
|
+
cell;
|
|
1739
|
+
textTarget;
|
|
1740
|
+
buf = "";
|
|
1741
|
+
inline;
|
|
1742
|
+
inlineDepth = 0;
|
|
1743
|
+
viewCount = 0;
|
|
1744
|
+
activePane;
|
|
1745
|
+
selections = [];
|
|
1746
|
+
headerKey;
|
|
1747
|
+
minRow = 1e400;
|
|
1748
|
+
minCol = 1e400;
|
|
1749
|
+
maxRow = -1;
|
|
1750
|
+
maxCol = -1;
|
|
1751
|
+
constructor(name, state, ctx, styles, opts, part) {
|
|
1752
|
+
this.ctx = ctx;
|
|
1753
|
+
this.styles = styles;
|
|
1754
|
+
this.opts = opts;
|
|
1755
|
+
this.part = part;
|
|
1756
|
+
this.sheet = {
|
|
1757
|
+
name,
|
|
1758
|
+
rows: this.rows
|
|
1759
|
+
};
|
|
1760
|
+
if (state && state !== "visible") this.sheet.state = state;
|
|
1761
|
+
}
|
|
1762
|
+
open(name, a, empty) {
|
|
1763
|
+
if (this.inline) {
|
|
1764
|
+
if (!empty) this.inlineDepth++;
|
|
1765
|
+
this.inline.open(name, a);
|
|
1766
|
+
if (empty) this.inline.close(name);
|
|
1767
|
+
return;
|
|
1768
|
+
}
|
|
1769
|
+
const parent = this.path.at(-1);
|
|
1770
|
+
if (!empty) this.path.push(name);
|
|
1771
|
+
switch (name) {
|
|
1772
|
+
case "c":
|
|
1773
|
+
if (parent === "row") this.openCell(a, empty);
|
|
1774
|
+
return;
|
|
1775
|
+
case "v":
|
|
1776
|
+
if (this.cell) this.startText("v");
|
|
1777
|
+
return;
|
|
1778
|
+
case "f":
|
|
1779
|
+
if (this.cell) {
|
|
1780
|
+
this.cell.fType = a.get("t");
|
|
1781
|
+
this.cell.fRef = a.get("ref");
|
|
1782
|
+
this.cell.fSi = a.get("si");
|
|
1783
|
+
this.cell.f = "";
|
|
1784
|
+
if (!empty) this.startText("f");
|
|
1785
|
+
}
|
|
1786
|
+
return;
|
|
1787
|
+
case "is":
|
|
1788
|
+
if (this.cell && !empty) {
|
|
1789
|
+
this.inline = new StringItem();
|
|
1790
|
+
this.inlineDepth = 0;
|
|
1791
|
+
}
|
|
1792
|
+
return;
|
|
1793
|
+
case "row":
|
|
1794
|
+
if (parent === "sheetData") this.openRow(a);
|
|
1795
|
+
return;
|
|
1796
|
+
case "col":
|
|
1797
|
+
if (parent === "cols") this.openCol(a);
|
|
1798
|
+
return;
|
|
1799
|
+
case "mergeCell": {
|
|
1800
|
+
const ref = a.get("ref");
|
|
1801
|
+
if (ref) this.merges.push(cleanRange(ref));
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
case "hyperlink":
|
|
1805
|
+
if (parent === "hyperlinks") {
|
|
1806
|
+
const ref = a.get("ref");
|
|
1807
|
+
if (ref) this.hyperlinks.push({
|
|
1808
|
+
ref: cleanRange(ref),
|
|
1809
|
+
relId: a.getPrefixed("id"),
|
|
1810
|
+
location: a.get("location"),
|
|
1811
|
+
tooltip: a.get("tooltip")
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
return;
|
|
1815
|
+
case "sheetView":
|
|
1816
|
+
this.openView(a);
|
|
1817
|
+
return;
|
|
1818
|
+
case "pane":
|
|
1819
|
+
if (parent === "sheetView" && this.viewCount === 1) this.openPane(a);
|
|
1820
|
+
return;
|
|
1821
|
+
case "selection":
|
|
1822
|
+
if (parent === "sheetView" && this.viewCount === 1) this.selections.push({
|
|
1823
|
+
pane: a.get("pane"),
|
|
1824
|
+
activeCell: a.get("activeCell"),
|
|
1825
|
+
sqref: a.get("sqref")
|
|
1826
|
+
});
|
|
1827
|
+
return;
|
|
1828
|
+
case "sheetFormatPr": {
|
|
1829
|
+
const w = num(a.get("defaultColWidth"));
|
|
1830
|
+
if (w !== void 0) this.sheet.defaultColWidth = fileWidthToChars(w);
|
|
1831
|
+
const h = num(a.get("defaultRowHeight"));
|
|
1832
|
+
if (h !== void 0) this.sheet.defaultRowHeight = h;
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
case "tabColor":
|
|
1836
|
+
if (parent === "sheetPr") {
|
|
1837
|
+
const c = color(a);
|
|
1838
|
+
if (c) this.sheet.tabColor = c;
|
|
1839
|
+
}
|
|
1840
|
+
return;
|
|
1841
|
+
case "pageSetUpPr":
|
|
1842
|
+
if (parent === "sheetPr") this.fitToPage = bool(a.get("fitToPage"), false);
|
|
1843
|
+
return;
|
|
1844
|
+
case "autoFilter":
|
|
1845
|
+
if (parent === "worksheet") {
|
|
1846
|
+
const ref = a.get("ref");
|
|
1847
|
+
if (ref) this.sheet.autoFilter = cleanRange(ref);
|
|
1848
|
+
}
|
|
1849
|
+
return;
|
|
1850
|
+
case "printOptions":
|
|
1851
|
+
this.openPrintOptions(a);
|
|
1852
|
+
return;
|
|
1853
|
+
case "pageMargins":
|
|
1854
|
+
this.openMargins(a);
|
|
1855
|
+
return;
|
|
1856
|
+
case "pageSetup":
|
|
1857
|
+
if (parent === "worksheet") this.openPageSetup(a);
|
|
1858
|
+
return;
|
|
1859
|
+
case "oddHeader":
|
|
1860
|
+
case "oddFooter":
|
|
1861
|
+
case "evenHeader":
|
|
1862
|
+
case "evenFooter":
|
|
1863
|
+
case "firstHeader":
|
|
1864
|
+
case "firstFooter":
|
|
1865
|
+
if (parent === "headerFooter" && !empty) {
|
|
1866
|
+
this.headerKey = name;
|
|
1867
|
+
this.startText("hf");
|
|
1868
|
+
}
|
|
1869
|
+
return;
|
|
1870
|
+
default: return;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
close(name) {
|
|
1874
|
+
if (this.inline) {
|
|
1875
|
+
if (this.inlineDepth === 0 && name === "is") {
|
|
1876
|
+
if (this.cell) this.cell.inline = this.inline.value(this.opts.richText);
|
|
1877
|
+
this.inline = void 0;
|
|
1878
|
+
this.path.pop();
|
|
1879
|
+
return;
|
|
1880
|
+
}
|
|
1881
|
+
this.inlineDepth--;
|
|
1882
|
+
this.inline.close(name);
|
|
1883
|
+
return;
|
|
1884
|
+
}
|
|
1885
|
+
this.path.pop();
|
|
1886
|
+
switch (name) {
|
|
1887
|
+
case "v":
|
|
1888
|
+
if (this.cell && this.textTarget === "v") this.cell.v = this.buf;
|
|
1889
|
+
this.textTarget = void 0;
|
|
1890
|
+
return;
|
|
1891
|
+
case "f":
|
|
1892
|
+
if (this.cell && this.textTarget === "f") this.cell.f = decodeXstring(this.buf);
|
|
1893
|
+
this.textTarget = void 0;
|
|
1894
|
+
return;
|
|
1895
|
+
case "c":
|
|
1896
|
+
if (this.cell) this.finishCell();
|
|
1897
|
+
return;
|
|
1898
|
+
case "sheetView": return;
|
|
1899
|
+
case "oddHeader":
|
|
1900
|
+
case "oddFooter":
|
|
1901
|
+
case "evenHeader":
|
|
1902
|
+
case "evenFooter":
|
|
1903
|
+
case "firstHeader":
|
|
1904
|
+
case "firstFooter":
|
|
1905
|
+
if (this.textTarget === "hf" && this.headerKey) this.setHeaderFooter(this.headerKey, this.buf);
|
|
1906
|
+
this.textTarget = void 0;
|
|
1907
|
+
this.headerKey = void 0;
|
|
1908
|
+
return;
|
|
1909
|
+
default: return;
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
text(s) {
|
|
1913
|
+
if (this.inline) {
|
|
1914
|
+
this.inline.text(s);
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1917
|
+
if (this.textTarget) this.buf += s;
|
|
1918
|
+
}
|
|
1919
|
+
startText(target) {
|
|
1920
|
+
this.textTarget = target;
|
|
1921
|
+
this.buf = "";
|
|
1922
|
+
}
|
|
1923
|
+
openRow(a) {
|
|
1924
|
+
const r = int(a.get("r"));
|
|
1925
|
+
if (r !== void 0 && r >= 1) {
|
|
1926
|
+
if (r > 1048576) {
|
|
1927
|
+
this.curRow = MAX_ROWS;
|
|
1928
|
+
this.ctx.warn("CELL_OUT_OF_BOUNDS", `Row ${r} is beyond the format limit (${MAX_ROWS}); its cells were skipped.`, {
|
|
1929
|
+
part: this.part,
|
|
1930
|
+
sheet: this.sheet.name
|
|
1931
|
+
});
|
|
1932
|
+
} else this.curRow = r - 1;
|
|
1933
|
+
} else this.curRow++;
|
|
1934
|
+
this.nextCol = 0;
|
|
1935
|
+
if (this.curRow >= 1048576) return;
|
|
1936
|
+
const p = {};
|
|
1937
|
+
const ht = num(a.get("ht"));
|
|
1938
|
+
if (ht !== void 0 && bool(a.get("customHeight"), false)) p.height = ht;
|
|
1939
|
+
if (bool(a.get("hidden"), false)) p.hidden = true;
|
|
1940
|
+
const ol = int(a.get("outlineLevel"));
|
|
1941
|
+
if (ol !== void 0 && ol > 0) p.outlineLevel = ol;
|
|
1942
|
+
if (bool(a.get("collapsed"), false)) p.collapsed = true;
|
|
1943
|
+
const s = int(a.get("s"));
|
|
1944
|
+
if (s !== void 0 && bool(a.get("customFormat"), false)) {
|
|
1945
|
+
const st = this.styles.style(s);
|
|
1946
|
+
if (st) p.style = st;
|
|
1947
|
+
}
|
|
1948
|
+
if (Object.keys(p).length) this.rowProps[this.curRow] = p;
|
|
1949
|
+
}
|
|
1950
|
+
openCol(a) {
|
|
1951
|
+
const min = int(a.get("min"));
|
|
1952
|
+
const max = int(a.get("max"));
|
|
1953
|
+
if (min === void 0 || max === void 0 || min < 1 || max < min) return;
|
|
1954
|
+
const p = {};
|
|
1955
|
+
const w = num(a.get("width"));
|
|
1956
|
+
if (w !== void 0 && (bool(a.get("customWidth"), false) || a.get("customWidth") === void 0)) p.width = fileWidthToChars(w);
|
|
1957
|
+
if (bool(a.get("hidden"), false)) p.hidden = true;
|
|
1958
|
+
const ol = int(a.get("outlineLevel"));
|
|
1959
|
+
if (ol !== void 0 && ol > 0) p.outlineLevel = ol;
|
|
1960
|
+
if (bool(a.get("collapsed"), false)) p.collapsed = true;
|
|
1961
|
+
const s = int(a.get("style"));
|
|
1962
|
+
if (s !== void 0) {
|
|
1963
|
+
const st = this.styles.style(s);
|
|
1964
|
+
if (st) p.style = st;
|
|
1965
|
+
}
|
|
1966
|
+
if (!Object.keys(p).length) return;
|
|
1967
|
+
const last = Math.min(max, MAX_COLS);
|
|
1968
|
+
for (let c = min - 1; c < last; c++) this.colProps[c] = { ...p };
|
|
1969
|
+
}
|
|
1970
|
+
openCell(a, empty) {
|
|
1971
|
+
let row = this.curRow;
|
|
1972
|
+
let col = this.nextCol;
|
|
1973
|
+
const r = a.get("r");
|
|
1974
|
+
if (r !== void 0) {
|
|
1975
|
+
const pos = parseRef(r);
|
|
1976
|
+
if (!pos) {
|
|
1977
|
+
this.ctx.warn("INVALID_CELL_REF", `Cell reference "${r}" is not valid; the cell was skipped.`, {
|
|
1978
|
+
part: this.part,
|
|
1979
|
+
sheet: this.sheet.name
|
|
1980
|
+
});
|
|
1981
|
+
this.skipCell(empty);
|
|
1982
|
+
return;
|
|
1983
|
+
}
|
|
1984
|
+
[row, col] = pos;
|
|
1985
|
+
}
|
|
1986
|
+
if (row < 0) row = 0;
|
|
1987
|
+
this.nextCol = col + 1;
|
|
1988
|
+
if (row >= 1048576 || col >= 16384) {
|
|
1989
|
+
this.ctx.warn("CELL_OUT_OF_BOUNDS", `Cell ${r ?? `${colLetters(col + 1)}${row + 1}`} is beyond the format limits; it was skipped.`, {
|
|
1990
|
+
part: this.part,
|
|
1991
|
+
sheet: this.sheet.name
|
|
1992
|
+
});
|
|
1993
|
+
this.skipCell(empty);
|
|
1994
|
+
return;
|
|
1995
|
+
}
|
|
1996
|
+
this.cell = {
|
|
1997
|
+
row,
|
|
1998
|
+
col,
|
|
1999
|
+
ref: `${colLetters(col + 1)}${row + 1}`,
|
|
2000
|
+
t: a.get("t") ?? "n",
|
|
2001
|
+
s: int(a.get("s")) ?? 0,
|
|
2002
|
+
v: void 0,
|
|
2003
|
+
f: void 0,
|
|
2004
|
+
fType: void 0,
|
|
2005
|
+
fRef: void 0,
|
|
2006
|
+
fSi: void 0,
|
|
2007
|
+
inline: void 0
|
|
2008
|
+
};
|
|
2009
|
+
if (empty) this.finishCell();
|
|
2010
|
+
}
|
|
2011
|
+
skipCell(empty) {
|
|
2012
|
+
this.cell = void 0;
|
|
2013
|
+
if (!empty) this.cell = {
|
|
2014
|
+
row: -1,
|
|
2015
|
+
col: -1,
|
|
2016
|
+
ref: "",
|
|
2017
|
+
t: "n",
|
|
2018
|
+
s: 0,
|
|
2019
|
+
v: void 0,
|
|
2020
|
+
f: void 0,
|
|
2021
|
+
fType: void 0,
|
|
2022
|
+
fRef: void 0,
|
|
2023
|
+
fSi: void 0,
|
|
2024
|
+
inline: void 0
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
finishCell() {
|
|
2028
|
+
const p = this.cell;
|
|
2029
|
+
this.cell = void 0;
|
|
2030
|
+
if (p.row < 0) return;
|
|
2031
|
+
const cell = this.convert(p);
|
|
2032
|
+
if (!cell) return;
|
|
2033
|
+
this.ctx.countCell();
|
|
2034
|
+
let row = this.rows[p.row];
|
|
2035
|
+
if (!row) row = this.rows[p.row] = [];
|
|
2036
|
+
if (row[p.col] !== void 0) this.ctx.warn("DUPLICATE_CELL", `Cell ${p.ref} appears more than once; the last one was kept.`, {
|
|
2037
|
+
part: this.part,
|
|
2038
|
+
sheet: this.sheet.name,
|
|
2039
|
+
ref: p.ref
|
|
2040
|
+
});
|
|
2041
|
+
row[p.col] = cell;
|
|
2042
|
+
if (p.row < this.minRow) this.minRow = p.row;
|
|
2043
|
+
if (p.row > this.maxRow) this.maxRow = p.row;
|
|
2044
|
+
if (p.col < this.minCol) this.minCol = p.col;
|
|
2045
|
+
if (p.col > this.maxCol) this.maxCol = p.col;
|
|
2046
|
+
}
|
|
2047
|
+
convert(p) {
|
|
2048
|
+
const style = this.styles.style(p.s);
|
|
2049
|
+
let value;
|
|
2050
|
+
let type = "empty";
|
|
2051
|
+
const v = p.v;
|
|
2052
|
+
switch (p.t) {
|
|
2053
|
+
case "s": {
|
|
2054
|
+
if (v === void 0) break;
|
|
2055
|
+
const idx = Number(v);
|
|
2056
|
+
const sst = this.sharedStrings;
|
|
2057
|
+
const str = Number.isInteger(idx) && idx >= 0 ? sst[idx] : void 0;
|
|
2058
|
+
if (str === void 0) {
|
|
2059
|
+
this.ctx.warn("INVALID_SHARED_STRING", `Cell ${p.ref} refers to shared string ${v}, which does not exist; the cell was left empty.`, {
|
|
2060
|
+
part: this.part,
|
|
2061
|
+
sheet: this.sheet.name,
|
|
2062
|
+
ref: p.ref
|
|
2063
|
+
});
|
|
2064
|
+
break;
|
|
2065
|
+
}
|
|
2066
|
+
value = str;
|
|
2067
|
+
type = typeof str === "string" ? "string" : "richText";
|
|
2068
|
+
break;
|
|
2069
|
+
}
|
|
2070
|
+
case "inlineStr":
|
|
2071
|
+
if (p.inline !== void 0) {
|
|
2072
|
+
value = p.inline;
|
|
2073
|
+
type = typeof p.inline === "string" ? "string" : "richText";
|
|
2074
|
+
} else if (v !== void 0) {
|
|
2075
|
+
value = decodeXstring(v);
|
|
2076
|
+
type = "string";
|
|
2077
|
+
}
|
|
2078
|
+
break;
|
|
2079
|
+
case "str":
|
|
2080
|
+
if (v !== void 0) {
|
|
2081
|
+
value = decodeXstring(v);
|
|
2082
|
+
type = "string";
|
|
2083
|
+
}
|
|
2084
|
+
break;
|
|
2085
|
+
case "b":
|
|
2086
|
+
if (v !== void 0) {
|
|
2087
|
+
value = v.trim() === "1" || v.trim().toLowerCase() === "true";
|
|
2088
|
+
type = "boolean";
|
|
2089
|
+
}
|
|
2090
|
+
break;
|
|
2091
|
+
case "e":
|
|
2092
|
+
if (v !== void 0) {
|
|
2093
|
+
const code = v.trim();
|
|
2094
|
+
if (ERROR_CODES.has(code)) {
|
|
2095
|
+
value = { error: code };
|
|
2096
|
+
type = "error";
|
|
2097
|
+
} else {
|
|
2098
|
+
value = code;
|
|
2099
|
+
type = "string";
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
break;
|
|
2103
|
+
case "d":
|
|
2104
|
+
if (v !== void 0) {
|
|
2105
|
+
const d = parseIsoDate(v.trim().replace(/(\.\d{3})\d+/, "$1"), this.opts.dateZone);
|
|
2106
|
+
if (d) {
|
|
2107
|
+
value = d;
|
|
2108
|
+
type = "date";
|
|
2109
|
+
} else {
|
|
2110
|
+
value = v;
|
|
2111
|
+
type = "string";
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
break;
|
|
2115
|
+
default: {
|
|
2116
|
+
if (v === void 0 || v.trim() === "") break;
|
|
2117
|
+
const n = Number(v);
|
|
2118
|
+
if (!Number.isFinite(n)) {
|
|
2119
|
+
value = v;
|
|
2120
|
+
type = "string";
|
|
2121
|
+
break;
|
|
2122
|
+
}
|
|
2123
|
+
value = n;
|
|
2124
|
+
type = "number";
|
|
2125
|
+
if (this.opts.dates === "date" && isDateFormat(this.styles.numFmt(p.s))) {
|
|
2126
|
+
const d = dateOf(n, this.opts.date1904, this.opts.dateZone);
|
|
2127
|
+
if (d) {
|
|
2128
|
+
value = d;
|
|
2129
|
+
type = "date";
|
|
2130
|
+
} else this.ctx.warn("INVALID_DATE_SERIAL", `Cell ${p.ref} has a date format but ${n} is not a valid date serial; it was returned as a number.`, {
|
|
2131
|
+
part: this.part,
|
|
2132
|
+
sheet: this.sheet.name,
|
|
2133
|
+
ref: p.ref
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
const formula = this.formula(p);
|
|
2139
|
+
if (value === void 0 && formula === void 0 && !style) return void 0;
|
|
2140
|
+
const cell = { type };
|
|
2141
|
+
if (value !== void 0) cell.value = value;
|
|
2142
|
+
if (formula !== void 0) {
|
|
2143
|
+
cell.formula = formula.text;
|
|
2144
|
+
if (formula.arrayRef) cell.arrayRef = formula.arrayRef;
|
|
2145
|
+
}
|
|
2146
|
+
if (style) cell.style = style;
|
|
2147
|
+
return cell;
|
|
2148
|
+
}
|
|
2149
|
+
formula(p) {
|
|
2150
|
+
if (p.f === void 0 || !this.opts.formulas) return void 0;
|
|
2151
|
+
if (p.fType === "shared" && p.fSi !== void 0) {
|
|
2152
|
+
if (p.f !== "") {
|
|
2153
|
+
this.shared.set(p.fSi, {
|
|
2154
|
+
formula: p.f,
|
|
2155
|
+
row: p.row,
|
|
2156
|
+
col: p.col
|
|
2157
|
+
});
|
|
2158
|
+
return { text: p.f };
|
|
2159
|
+
}
|
|
2160
|
+
const master = this.shared.get(p.fSi);
|
|
2161
|
+
const shifted = master ? shiftFormula(master.formula, p.row - master.row, p.col - master.col) : void 0;
|
|
2162
|
+
if (shifted === void 0) {
|
|
2163
|
+
this.ctx.warn("SHARED_FORMULA_UNRESOLVED", `The shared formula of cell ${p.ref} could not be resolved; only its cached value was read.`, {
|
|
2164
|
+
part: this.part,
|
|
2165
|
+
sheet: this.sheet.name,
|
|
2166
|
+
ref: p.ref
|
|
2167
|
+
});
|
|
2168
|
+
return;
|
|
2169
|
+
}
|
|
2170
|
+
return { text: shifted };
|
|
2171
|
+
}
|
|
2172
|
+
if (p.fType === "dataTable") return void 0;
|
|
2173
|
+
if (p.f === "") return void 0;
|
|
2174
|
+
if (p.fType === "array" && p.fRef) return {
|
|
2175
|
+
text: p.f,
|
|
2176
|
+
arrayRef: cleanRange(p.fRef)
|
|
2177
|
+
};
|
|
2178
|
+
return { text: p.f };
|
|
2179
|
+
}
|
|
2180
|
+
/** Set before parsing; the shared strings table. */
|
|
2181
|
+
sharedStrings = [];
|
|
2182
|
+
openView(a) {
|
|
2183
|
+
this.viewCount++;
|
|
2184
|
+
if (this.viewCount !== 1) return;
|
|
2185
|
+
const v = {};
|
|
2186
|
+
if (bool(a.get("rightToLeft"), false)) v.rightToLeft = true;
|
|
2187
|
+
if (a.get("showGridLines") !== void 0 && !bool(a.get("showGridLines"))) v.showGridLines = false;
|
|
2188
|
+
if (a.get("showRowColHeaders") !== void 0 && !bool(a.get("showRowColHeaders"))) v.showRowColHeaders = false;
|
|
2189
|
+
const zoom = int(a.get("zoomScale"));
|
|
2190
|
+
if (zoom !== void 0 && zoom !== 100 && zoom >= 10 && zoom <= 400) v.zoom = zoom;
|
|
2191
|
+
this.view = v;
|
|
2192
|
+
}
|
|
2193
|
+
openPane(a) {
|
|
2194
|
+
const state = a.get("state") ?? "split";
|
|
2195
|
+
this.activePane = a.get("activePane");
|
|
2196
|
+
if (state === "frozen" || state === "frozenSplit") {
|
|
2197
|
+
const freeze = {};
|
|
2198
|
+
const ys = int(a.get("ySplit"));
|
|
2199
|
+
const xs = int(a.get("xSplit"));
|
|
2200
|
+
if (ys !== void 0 && ys > 0) freeze.rows = ys;
|
|
2201
|
+
if (xs !== void 0 && xs > 0) freeze.cols = xs;
|
|
2202
|
+
if (Object.keys(freeze).length && this.view) this.view.freeze = freeze;
|
|
2203
|
+
} else this.ctx.warn("SPLIT_PANE_IGNORED", "The sheet has a split (not frozen) pane, which the model does not represent; it was ignored.", {
|
|
2204
|
+
part: this.part,
|
|
2205
|
+
sheet: this.sheet.name
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
printSetup() {
|
|
2209
|
+
return this.print ??= {};
|
|
2210
|
+
}
|
|
2211
|
+
openPrintOptions(a) {
|
|
2212
|
+
const p = this.printSetup();
|
|
2213
|
+
if (bool(a.get("gridLines"), false)) p.gridLines = true;
|
|
2214
|
+
if (bool(a.get("headings"), false)) p.headings = true;
|
|
2215
|
+
const h = bool(a.get("horizontalCentered"), false);
|
|
2216
|
+
const v = bool(a.get("verticalCentered"), false);
|
|
2217
|
+
if (h || v) {
|
|
2218
|
+
p.center = {};
|
|
2219
|
+
if (h) p.center.horizontal = true;
|
|
2220
|
+
if (v) p.center.vertical = true;
|
|
2221
|
+
}
|
|
2222
|
+
if (!Object.keys(p).length) this.print = void 0;
|
|
2223
|
+
}
|
|
2224
|
+
openMargins(a) {
|
|
2225
|
+
const m = {};
|
|
2226
|
+
for (const k of [
|
|
2227
|
+
"left",
|
|
2228
|
+
"right",
|
|
2229
|
+
"top",
|
|
2230
|
+
"bottom",
|
|
2231
|
+
"header",
|
|
2232
|
+
"footer"
|
|
2233
|
+
]) {
|
|
2234
|
+
const n = num(a.get(k));
|
|
2235
|
+
if (n !== void 0) m[k] = n;
|
|
2236
|
+
}
|
|
2237
|
+
if (Object.keys(m).length) this.printSetup().margins = m;
|
|
2238
|
+
}
|
|
2239
|
+
openPageSetup(a) {
|
|
2240
|
+
const p = this.printSetup();
|
|
2241
|
+
const o = a.get("orientation");
|
|
2242
|
+
if (o === "portrait" || o === "landscape") p.orientation = o;
|
|
2243
|
+
const paper = int(a.get("paperSize"));
|
|
2244
|
+
if (paper !== void 0) p.paperSize = paper;
|
|
2245
|
+
const scale = int(a.get("scale"));
|
|
2246
|
+
if (scale !== void 0 && scale !== 100) p.scale = scale;
|
|
2247
|
+
const fw = int(a.get("fitToWidth"));
|
|
2248
|
+
const fh = int(a.get("fitToHeight"));
|
|
2249
|
+
this.fitTo = {
|
|
2250
|
+
width: fw ?? 1,
|
|
2251
|
+
height: fh ?? 1
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
setHeaderFooter(key, text) {
|
|
2255
|
+
const p = this.printSetup();
|
|
2256
|
+
const kind = key.endsWith("Header") ? "header" : "footer";
|
|
2257
|
+
const which = key.startsWith("odd") ? "odd" : key.startsWith("even") ? "even" : "first";
|
|
2258
|
+
(p[kind] ??= {})[which] = text;
|
|
2259
|
+
}
|
|
2260
|
+
/** Applies hyperlinks, merges and layout once the part is parsed. */
|
|
2261
|
+
finish(rels) {
|
|
2262
|
+
const sheet = this.sheet;
|
|
2263
|
+
if (this.rowProps.length) sheet.rowProps = this.rowProps;
|
|
2264
|
+
if (this.colProps.length) sheet.colProps = this.colProps;
|
|
2265
|
+
if (this.merges.length) sheet.merges = this.merges;
|
|
2266
|
+
if (this.view) {
|
|
2267
|
+
const sel = this.selections.find((s) => s.pane === this.activePane) ?? this.selections[0];
|
|
2268
|
+
if (sel?.activeCell && sel.activeCell !== "A1") this.view.activeCell = sel.activeCell;
|
|
2269
|
+
if (sel?.sqref && sel.sqref !== "A1" && sel.sqref !== sel.activeCell) this.view.selection = sel.sqref.split(" ")[0];
|
|
2270
|
+
if (Object.keys(this.view).length) sheet.view = this.view;
|
|
2271
|
+
}
|
|
2272
|
+
if (this.fitToPage && this.fitTo) this.printSetup().fitTo = this.fitTo;
|
|
2273
|
+
if (this.print && Object.keys(this.print).length) sheet.print = this.print;
|
|
2274
|
+
for (const h of this.hyperlinks) this.attachHyperlink(h, rels);
|
|
2275
|
+
if (this.maxRow >= 0) {
|
|
2276
|
+
const tl = `${colLetters(this.minCol + 1)}${this.minRow + 1}`;
|
|
2277
|
+
const br = `${colLetters(this.maxCol + 1)}${this.maxRow + 1}`;
|
|
2278
|
+
sheet.dimension = tl === br ? tl : `${tl}:${br}`;
|
|
2279
|
+
}
|
|
2280
|
+
return sheet;
|
|
2281
|
+
}
|
|
2282
|
+
attachHyperlink(h, rels) {
|
|
2283
|
+
const first = h.ref.split(":")[0];
|
|
2284
|
+
const pos = parseRef(first);
|
|
2285
|
+
if (!pos) return;
|
|
2286
|
+
if (h.ref.includes(":") && h.ref.split(":")[1] !== first) this.ctx.warn("HYPERLINK_RANGE_REDUCED", `The hyperlink on ${h.ref} was attached to its top-left cell ${first}.`, {
|
|
2287
|
+
part: this.part,
|
|
2288
|
+
sheet: this.sheet.name,
|
|
2289
|
+
ref: h.ref
|
|
2290
|
+
});
|
|
2291
|
+
let link;
|
|
2292
|
+
if (h.relId) {
|
|
2293
|
+
const rel = rels.find((r) => r.id === h.relId);
|
|
2294
|
+
if (rel) {
|
|
2295
|
+
const target = h.location ? `${rel.target}#${h.location}` : rel.target;
|
|
2296
|
+
link = h.tooltip !== void 0 ? {
|
|
2297
|
+
target,
|
|
2298
|
+
tooltip: h.tooltip
|
|
2299
|
+
} : { target };
|
|
2300
|
+
}
|
|
2301
|
+
} else if (h.location !== void 0) link = h.tooltip !== void 0 ? {
|
|
2302
|
+
location: h.location,
|
|
2303
|
+
tooltip: h.tooltip
|
|
2304
|
+
} : { location: h.location };
|
|
2305
|
+
if (!link) return;
|
|
2306
|
+
const [r, c] = pos;
|
|
2307
|
+
if (r >= 1048576 || c >= 16384) return;
|
|
2308
|
+
let row = this.rows[r];
|
|
2309
|
+
if (!row) row = this.rows[r] = [];
|
|
2310
|
+
const cell = row[c] ?? (row[c] = { type: "empty" });
|
|
2311
|
+
cell.hyperlink = link;
|
|
2312
|
+
}
|
|
2313
|
+
};
|
|
2314
|
+
// src/internal/read/workbook.ts
|
|
2315
|
+
var WorkbookParser = class {
|
|
2316
|
+
sheets = [];
|
|
2317
|
+
definedNames = [];
|
|
2318
|
+
date1904 = false;
|
|
2319
|
+
activeTab;
|
|
2320
|
+
fullCalcOnLoad;
|
|
2321
|
+
/** The root element's namespace, to tell Strict from transitional. */
|
|
2322
|
+
rootNamespace;
|
|
2323
|
+
name;
|
|
2324
|
+
nameText = "";
|
|
2325
|
+
seenView = false;
|
|
2326
|
+
open(name, a, empty) {
|
|
2327
|
+
switch (name) {
|
|
2328
|
+
case "workbook":
|
|
2329
|
+
this.rootNamespace = a.get("xmlns") ?? [...a.entries()].find(([k]) => k.startsWith("xmlns:"))?.[1];
|
|
2330
|
+
return;
|
|
2331
|
+
case "workbookPr":
|
|
2332
|
+
this.date1904 = bool(a.get("date1904"), false);
|
|
2333
|
+
return;
|
|
2334
|
+
case "workbookView":
|
|
2335
|
+
if (!this.seenView) {
|
|
2336
|
+
this.seenView = true;
|
|
2337
|
+
this.activeTab = int(a.get("activeTab"));
|
|
2338
|
+
}
|
|
2339
|
+
return;
|
|
2340
|
+
case "sheet": {
|
|
2341
|
+
const n = a.get("name");
|
|
2342
|
+
if (n === void 0) return;
|
|
2343
|
+
const st = a.get("state");
|
|
2344
|
+
this.sheets.push({
|
|
2345
|
+
name: n,
|
|
2346
|
+
relId: a.getPrefixed("id"),
|
|
2347
|
+
state: st === "hidden" || st === "veryHidden" ? st : "visible"
|
|
2348
|
+
});
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2351
|
+
case "definedName": {
|
|
2352
|
+
const n = a.get("name");
|
|
2353
|
+
if (n === void 0) return;
|
|
2354
|
+
const d = {
|
|
2355
|
+
name: n,
|
|
2356
|
+
ref: ""
|
|
2357
|
+
};
|
|
2358
|
+
const local = int(a.get("localSheetId"));
|
|
2359
|
+
if (local !== void 0) d.sheet = local;
|
|
2360
|
+
if (a.get("hidden") !== void 0) d.hidden = bool(a.get("hidden"));
|
|
2361
|
+
const comment = a.get("comment");
|
|
2362
|
+
if (comment !== void 0) d.comment = comment;
|
|
2363
|
+
this.nameText = "";
|
|
2364
|
+
if (empty) this.definedNames.push(d);
|
|
2365
|
+
else this.name = d;
|
|
2366
|
+
return;
|
|
2367
|
+
}
|
|
2368
|
+
case "calcPr":
|
|
2369
|
+
if (a.get("fullCalcOnLoad") !== void 0) this.fullCalcOnLoad = bool(a.get("fullCalcOnLoad"));
|
|
2370
|
+
return;
|
|
2371
|
+
default: return;
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
close(name) {
|
|
2375
|
+
if (name === "definedName" && this.name) {
|
|
2376
|
+
this.name.ref = this.nameText;
|
|
2377
|
+
this.definedNames.push(this.name);
|
|
2378
|
+
this.name = void 0;
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
text(s) {
|
|
2382
|
+
if (this.name) this.nameText += s;
|
|
2383
|
+
}
|
|
2384
|
+
};
|
|
2385
|
+
const SCHEME_ORDER = [
|
|
2386
|
+
"dk1",
|
|
2387
|
+
"lt1",
|
|
2388
|
+
"dk2",
|
|
2389
|
+
"lt2",
|
|
2390
|
+
"accent1",
|
|
2391
|
+
"accent2",
|
|
2392
|
+
"accent3",
|
|
2393
|
+
"accent4",
|
|
2394
|
+
"accent5",
|
|
2395
|
+
"accent6",
|
|
2396
|
+
"hlink",
|
|
2397
|
+
"folHlink"
|
|
2398
|
+
];
|
|
2399
|
+
var ThemeParser = class {
|
|
2400
|
+
colors = /* @__PURE__ */ new Map();
|
|
2401
|
+
slot;
|
|
2402
|
+
fontGroup;
|
|
2403
|
+
major;
|
|
2404
|
+
minor;
|
|
2405
|
+
inScheme = false;
|
|
2406
|
+
open(name, a) {
|
|
2407
|
+
if (name === "clrScheme") this.inScheme = true;
|
|
2408
|
+
else if (this.inScheme && SCHEME_ORDER.includes(name)) this.slot = name;
|
|
2409
|
+
else if (this.slot && (name === "srgbClr" || name === "sysClr")) {
|
|
2410
|
+
const v = name === "srgbClr" ? a.get("val") : a.get("lastClr") ?? a.get("val");
|
|
2411
|
+
if (v && /^[0-9A-Fa-f]{6}$/.test(v) && !this.colors.has(this.slot)) this.colors.set(this.slot, `FF${v.toUpperCase()}`);
|
|
2412
|
+
} else if (name === "majorFont") this.fontGroup = "major";
|
|
2413
|
+
else if (name === "minorFont") this.fontGroup = "minor";
|
|
2414
|
+
else if (name === "latin" && this.fontGroup) {
|
|
2415
|
+
const tf = a.get("typeface");
|
|
2416
|
+
if (tf !== void 0) this[this.fontGroup] = tf;
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
close(name) {
|
|
2420
|
+
if (name === "clrScheme") this.inScheme = false;
|
|
2421
|
+
else if (name === this.slot) this.slot = void 0;
|
|
2422
|
+
else if (name === "majorFont" || name === "minorFont") this.fontGroup = void 0;
|
|
2423
|
+
}
|
|
2424
|
+
text() {}
|
|
2425
|
+
result() {
|
|
2426
|
+
if (this.colors.size === 0 && this.major === void 0 && this.minor === void 0) return void 0;
|
|
2427
|
+
const t = { colors: SCHEME_ORDER.map((k) => this.colors.get(k) ?? "") };
|
|
2428
|
+
if (this.major !== void 0) t.majorFont = this.major;
|
|
2429
|
+
if (this.minor !== void 0) t.minorFont = this.minor;
|
|
2430
|
+
return t;
|
|
2431
|
+
}
|
|
2432
|
+
};
|
|
2433
|
+
const CORE_FIELDS = {
|
|
2434
|
+
title: "title",
|
|
2435
|
+
subject: "subject",
|
|
2436
|
+
creator: "creator",
|
|
2437
|
+
keywords: "keywords",
|
|
2438
|
+
description: "description",
|
|
2439
|
+
lastModifiedBy: "lastModifiedBy",
|
|
2440
|
+
category: "category",
|
|
2441
|
+
created: "created",
|
|
2442
|
+
modified: "modified",
|
|
2443
|
+
Company: "company",
|
|
2444
|
+
Manager: "manager",
|
|
2445
|
+
Application: "application"
|
|
2446
|
+
};
|
|
2447
|
+
/** docProps/core.xml and docProps/app.xml: simple elements with text. */
|
|
2448
|
+
var PropsParser = class {
|
|
2449
|
+
props;
|
|
2450
|
+
field;
|
|
2451
|
+
value = "";
|
|
2452
|
+
depth = 0;
|
|
2453
|
+
constructor(props) {
|
|
2454
|
+
this.props = props;
|
|
2455
|
+
}
|
|
2456
|
+
open(name, _a, empty) {
|
|
2457
|
+
if (empty) return;
|
|
2458
|
+
this.depth++;
|
|
2459
|
+
if (this.depth === 2 && Object.prototype.hasOwnProperty.call(CORE_FIELDS, name)) {
|
|
2460
|
+
this.field = CORE_FIELDS[name];
|
|
2461
|
+
this.value = "";
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
close() {
|
|
2465
|
+
if (this.depth === 2 && this.field) {
|
|
2466
|
+
const f = this.field;
|
|
2467
|
+
const v = this.value;
|
|
2468
|
+
if (f === "created" || f === "modified") {
|
|
2469
|
+
const d = parseIsoDate(v.trim().replace(/(\.\d{3})\d+/, "$1"), "utc");
|
|
2470
|
+
if (d) this.props[f] = d;
|
|
2471
|
+
} else if (v !== "" && f !== "custom") this.props[f] = v;
|
|
2472
|
+
this.field = void 0;
|
|
2473
|
+
}
|
|
2474
|
+
this.depth--;
|
|
2475
|
+
}
|
|
2476
|
+
text(s) {
|
|
2477
|
+
if (this.field) this.value += s;
|
|
2478
|
+
}
|
|
2479
|
+
};
|
|
2480
|
+
/** docProps/custom.xml. */
|
|
2481
|
+
var CustomPropsParser = class {
|
|
2482
|
+
items = [];
|
|
2483
|
+
name;
|
|
2484
|
+
kind;
|
|
2485
|
+
value = "";
|
|
2486
|
+
open(name, a) {
|
|
2487
|
+
if (name === "property") {
|
|
2488
|
+
this.name = a.get("name");
|
|
2489
|
+
this.kind = void 0;
|
|
2490
|
+
} else if (this.name !== void 0 && this.kind === void 0) {
|
|
2491
|
+
this.kind = name;
|
|
2492
|
+
this.value = "";
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
close(name) {
|
|
2496
|
+
if (name === "property") {
|
|
2497
|
+
this.name = void 0;
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
if (this.name === void 0 || name !== this.kind) return;
|
|
2501
|
+
const v = this.value;
|
|
2502
|
+
let out;
|
|
2503
|
+
switch (name) {
|
|
2504
|
+
case "lpwstr":
|
|
2505
|
+
case "lpstr":
|
|
2506
|
+
case "bstr":
|
|
2507
|
+
out = v;
|
|
2508
|
+
break;
|
|
2509
|
+
case "bool":
|
|
2510
|
+
out = v === "true" || v === "1";
|
|
2511
|
+
break;
|
|
2512
|
+
case "filetime":
|
|
2513
|
+
case "date":
|
|
2514
|
+
out = parseIsoDate(v.trim(), "utc");
|
|
2515
|
+
break;
|
|
2516
|
+
default: if (/^(i[1248]|ui[1248]|int|uint|r4|r8|decimal)$/.test(name)) {
|
|
2517
|
+
const n = Number(v);
|
|
2518
|
+
if (Number.isFinite(n)) out = n;
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
if (out !== void 0) this.items.push({
|
|
2522
|
+
name: this.name,
|
|
2523
|
+
value: out
|
|
2524
|
+
});
|
|
2525
|
+
this.kind = "";
|
|
2526
|
+
}
|
|
2527
|
+
text(s) {
|
|
2528
|
+
if (this.kind) this.value += s;
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
// src/internal/read/reader.ts
|
|
2532
|
+
/** Friendly names for parts the model does not represent, keyed by relationship kind. */
|
|
2533
|
+
const UNSUPPORTED = /* @__PURE__ */ new Map([
|
|
2534
|
+
["drawing", "drawings (charts, images, shapes)"],
|
|
2535
|
+
["vmlDrawing", "legacy drawings (VML)"],
|
|
2536
|
+
["comments", "comments"],
|
|
2537
|
+
["threadedComment", "threaded comments"],
|
|
2538
|
+
["pivotTable", "pivot tables"],
|
|
2539
|
+
["pivotCacheDefinition", "pivot caches"],
|
|
2540
|
+
["table", "tables (ListObjects)"],
|
|
2541
|
+
["oleObject", "embedded OLE objects"],
|
|
2542
|
+
["ctrlProp", "form controls"],
|
|
2543
|
+
["image", "images"],
|
|
2544
|
+
["vbaProject", "VBA macros"],
|
|
2545
|
+
["externalLink", "external links"],
|
|
2546
|
+
["connections", "data connections"],
|
|
2547
|
+
["queryTable", "query tables"],
|
|
2548
|
+
["slicer", "slicers"],
|
|
2549
|
+
["slicerCache", "slicer caches"],
|
|
2550
|
+
["timeline", "timelines"],
|
|
2551
|
+
["chartsheet", "chart sheets"],
|
|
2552
|
+
["dialogsheet", "dialog sheets"],
|
|
2553
|
+
["macrosheet", "macro sheets"]
|
|
2554
|
+
]);
|
|
2555
|
+
function unsupported(format, message) {
|
|
2556
|
+
return new FormatError("UNSUPPORTED_FORMAT", message, { details: { format } });
|
|
2557
|
+
}
|
|
2558
|
+
function limitsOf(options) {
|
|
2559
|
+
const l = { ...DEFAULT_LIMITS };
|
|
2560
|
+
const given = options?.limits;
|
|
2561
|
+
if (given) for (const k of Object.keys(DEFAULT_LIMITS)) {
|
|
2562
|
+
const v = given[k];
|
|
2563
|
+
if (v === void 0) continue;
|
|
2564
|
+
if (typeof v !== "number" || !(v > 0)) throw new TypeError(`limits.${k} must be a positive number`);
|
|
2565
|
+
l[k] = v;
|
|
2566
|
+
}
|
|
2567
|
+
return l;
|
|
2568
|
+
}
|
|
2569
|
+
function throwIfAborted(signal) {
|
|
2570
|
+
if (signal?.aborted) {
|
|
2571
|
+
if (signal.reason !== void 0) throw signal.reason;
|
|
2572
|
+
const err = /* @__PURE__ */ new Error("The operation was aborted.");
|
|
2573
|
+
err.name = "AbortError";
|
|
2574
|
+
throw err;
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
/** Opens the package and finds the workbook part, rejecting formats the reader has no decoder for. */
|
|
2578
|
+
async function openPackage(bytes, limits, ctxOf) {
|
|
2579
|
+
const container = sniffContainer(bytes);
|
|
2580
|
+
if (container === "cfb") throw unsupported("cfb", `This is a ${OTHER_FORMATS.cfb.label}. Only .xlsx-family files can be read.`);
|
|
2581
|
+
if (container !== "zip") throw unsupported("unknown", "The input is not an .xlsx file (no zip signature).");
|
|
2582
|
+
const ctx = ctxOf(openZipChecked(bytes, limits));
|
|
2583
|
+
const pkg = new Package(ctx);
|
|
2584
|
+
const mimetype = pkg.part("mimetype");
|
|
2585
|
+
if (mimetype && (await ctx.text(mimetype)).trim().startsWith("application/vnd.oasis.opendocument.spreadsheet")) throw unsupported("ods", `This is an ${OTHER_FORMATS.ods.label}. Only .xlsx-family files can be read.`);
|
|
2586
|
+
await pkg.loadContentTypes();
|
|
2587
|
+
const office = (await pkg.rels("")).find((r) => r.kind === "officeDocument" && !r.external && pkg.part(r.target));
|
|
2588
|
+
if (!office) throw new FormatError("NOT_XLSX", "The zip has no workbook part (no officeDocument relationship).");
|
|
2589
|
+
const format = workbookFormat(pkg.contentType(office.target), office.target);
|
|
2590
|
+
if (!format.decoder) throw unsupported(format.format, `This is a ${format.label}, which this version cannot read.`);
|
|
2591
|
+
return {
|
|
2592
|
+
pkg,
|
|
2593
|
+
workbookPart: office.target,
|
|
2594
|
+
format
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
function openZipChecked(bytes, limits) {
|
|
2598
|
+
return openZip(bytes, { limits: {
|
|
2599
|
+
maxInputBytes: limits.maxInputBytes,
|
|
2600
|
+
maxEntries: limits.maxEntries,
|
|
2601
|
+
maxEntryBytes: limits.maxEntryBytes,
|
|
2602
|
+
maxTotalBytes: limits.maxTotalBytes,
|
|
2603
|
+
maxRatio: limits.maxRatio
|
|
2604
|
+
} });
|
|
2605
|
+
}
|
|
2606
|
+
async function parseWorkbook(pkg, part) {
|
|
2607
|
+
const wb = new WorkbookParser();
|
|
2608
|
+
await pkg.ctx.parse(pkg.part(part), wb);
|
|
2609
|
+
return wb;
|
|
2610
|
+
}
|
|
2611
|
+
/** Detects the file format from the bytes. Never throws for unreadable input. */
|
|
2612
|
+
async function detectFormatImpl(bytes) {
|
|
2613
|
+
const container = sniffContainer(bytes);
|
|
2614
|
+
if (container !== "zip") return container;
|
|
2615
|
+
try {
|
|
2616
|
+
const ctx = new ReadContext(openZipChecked(bytes, DEFAULT_LIMITS), DEFAULT_LIMITS, void 0, void 0, void 0);
|
|
2617
|
+
const pkg = new Package(ctx);
|
|
2618
|
+
const mimetype = pkg.part("mimetype");
|
|
2619
|
+
if (mimetype && (await ctx.text(mimetype)).trim().startsWith("application/vnd.oasis.opendocument.spreadsheet")) return "ods";
|
|
2620
|
+
if (!pkg.part("[Content_Types].xml")) return "zip";
|
|
2621
|
+
await pkg.loadContentTypes();
|
|
2622
|
+
const office = (await pkg.rels("")).find((r) => r.kind === "officeDocument" && !r.external && pkg.part(r.target));
|
|
2623
|
+
if (office) return workbookFormat(pkg.contentType(office.target), office.target).format;
|
|
2624
|
+
for (const t of pkg.overrideTypes) {
|
|
2625
|
+
const f = WORKBOOK_FORMATS.find((w) => w.contentType === t);
|
|
2626
|
+
if (f) return f.format;
|
|
2627
|
+
}
|
|
2628
|
+
return "zip";
|
|
2629
|
+
} catch {
|
|
2630
|
+
return "zip";
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
/** Lists the worksheets (name, index, visibility) without parsing any sheet. */
|
|
2634
|
+
async function readSheetNamesImpl(bytes, options) {
|
|
2635
|
+
const limits = limitsOf(options);
|
|
2636
|
+
throwIfAborted(options?.signal);
|
|
2637
|
+
const { pkg, workbookPart } = await openPackage(bytes, limits, (zip) => new ReadContext(zip, limits, options?.signal, void 0, void 0));
|
|
2638
|
+
const wb = await parseWorkbook(pkg, workbookPart);
|
|
2639
|
+
const rels = await pkg.rels(workbookPart);
|
|
2640
|
+
return worksheetsOf(wb.sheets, rels).map((s, index) => ({
|
|
2641
|
+
name: s.entry.name,
|
|
2642
|
+
index,
|
|
2643
|
+
state: s.entry.state
|
|
2644
|
+
}));
|
|
2645
|
+
}
|
|
2646
|
+
function worksheetsOf(sheets, rels) {
|
|
2647
|
+
const out = [];
|
|
2648
|
+
sheets.forEach((entry, bookIndex) => {
|
|
2649
|
+
const rel = entry.relId ? rels.find((r) => r.id === entry.relId) : void 0;
|
|
2650
|
+
if (rel && rel.kind !== "worksheet") return;
|
|
2651
|
+
out.push({
|
|
2652
|
+
entry,
|
|
2653
|
+
rel,
|
|
2654
|
+
bookIndex
|
|
2655
|
+
});
|
|
2656
|
+
});
|
|
2657
|
+
return out;
|
|
2658
|
+
}
|
|
2659
|
+
/** Reads an .xlsx-family file into the model. */
|
|
2660
|
+
async function readImpl(input, options, internal) {
|
|
2661
|
+
const o = options ?? {};
|
|
2662
|
+
const limits = limitsOf(o);
|
|
2663
|
+
checkEnum("dates", o.dates, ["date", "serial"]);
|
|
2664
|
+
checkEnum("dateZone", o.dateZone, ["local", "utc"]);
|
|
2665
|
+
checkEnum("richText", o.richText, ["runs", "plain"]);
|
|
2666
|
+
throwIfAborted(o.signal);
|
|
2667
|
+
const bytes = await toBytes(input, "read");
|
|
2668
|
+
throwIfAborted(o.signal);
|
|
2669
|
+
let ctx;
|
|
2670
|
+
const { pkg, workbookPart, format } = await openPackage(bytes, limits, (zip) => {
|
|
2671
|
+
ctx = new ReadContext(zip, limits, o.signal, o.onWarning, o.onProgress);
|
|
2672
|
+
return ctx;
|
|
2673
|
+
});
|
|
2674
|
+
ctx.progress({
|
|
2675
|
+
phase: "unzip",
|
|
2676
|
+
ratio: .02
|
|
2677
|
+
});
|
|
2678
|
+
const wbp = await parseWorkbook(pkg, workbookPart);
|
|
2679
|
+
const wbRels = await pkg.rels(workbookPart);
|
|
2680
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2681
|
+
const warnUnsupported = (rels, part) => {
|
|
2682
|
+
for (const r of rels) {
|
|
2683
|
+
const what = UNSUPPORTED.get(r.kind);
|
|
2684
|
+
if (what && !seen.has(r.kind)) {
|
|
2685
|
+
seen.add(r.kind);
|
|
2686
|
+
ctx.warn("UNSUPPORTED_PART", `The workbook contains ${what}, which are not read.`, { part: r.external ? part : r.target });
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
};
|
|
2690
|
+
if (format.macros) {
|
|
2691
|
+
seen.add("vbaProject");
|
|
2692
|
+
ctx.warn("UNSUPPORTED_PART", `The workbook is a ${format.label}; its VBA macros are not read or run.`, { part: workbookPart });
|
|
2693
|
+
}
|
|
2694
|
+
warnUnsupported(wbRels, workbookPart);
|
|
2695
|
+
const relOf = (kind) => wbRels.find((r) => r.kind === kind && !r.external);
|
|
2696
|
+
let styles = EMPTY_STYLES;
|
|
2697
|
+
const stylesRel = relOf("styles");
|
|
2698
|
+
if (stylesRel) {
|
|
2699
|
+
const entry = pkg.part(stylesRel.target);
|
|
2700
|
+
if (!entry) ctx.warn("MISSING_PART", `The styles part ${stylesRel.target} is missing; default styles were used.`, { part: stylesRel.target });
|
|
2701
|
+
else {
|
|
2702
|
+
const sp = new StylesParser(o.styles !== false);
|
|
2703
|
+
await ctx.parse(entry, sp);
|
|
2704
|
+
styles = sp.result();
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
ctx.progress({
|
|
2708
|
+
phase: "styles",
|
|
2709
|
+
ratio: .05
|
|
2710
|
+
});
|
|
2711
|
+
let theme;
|
|
2712
|
+
const themeRel = relOf("theme");
|
|
2713
|
+
if (themeRel && o.styles !== false) {
|
|
2714
|
+
const entry = pkg.part(themeRel.target);
|
|
2715
|
+
if (!entry) ctx.warn("MISSING_PART", `The theme part ${themeRel.target} is missing; the default theme applies.`, { part: themeRel.target });
|
|
2716
|
+
else {
|
|
2717
|
+
const tp = new ThemeParser();
|
|
2718
|
+
if (await optional(ctx, entry.name, () => ctx.parse(entry, tp))) theme = tp.result();
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
let sst = [];
|
|
2722
|
+
const sstRel = relOf("sharedStrings");
|
|
2723
|
+
if (sstRel) {
|
|
2724
|
+
const entry = pkg.part(sstRel.target);
|
|
2725
|
+
if (!entry) ctx.warn("MISSING_PART", `The shared strings part ${sstRel.target} is missing; cells that use it are empty.`, { part: sstRel.target });
|
|
2726
|
+
else {
|
|
2727
|
+
const sp = new SharedStringsParser(o.richText ?? "runs", limits.maxSharedStrings);
|
|
2728
|
+
await ctx.parse(entry, sp);
|
|
2729
|
+
sst = sp.strings;
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
const properties = await readProperties(pkg, ctx);
|
|
2733
|
+
const listed = worksheetsOf(wbp.sheets, wbRels);
|
|
2734
|
+
for (const s of wbp.sheets) {
|
|
2735
|
+
const rel = s.relId ? wbRels.find((r) => r.id === s.relId) : void 0;
|
|
2736
|
+
if (rel && rel.kind !== "worksheet") warnUnsupported([rel], workbookPart);
|
|
2737
|
+
}
|
|
2738
|
+
const wanted = selector(o.sheets);
|
|
2739
|
+
const totalBytes = listed.reduce((n, s) => n + (s.rel && wanted(s.entry.name, listed.indexOf(s)) ? pkg.part(s.rel.target)?.size ?? 0 : 0), 0) || 1;
|
|
2740
|
+
let doneBytes = 0;
|
|
2741
|
+
const sheets = [];
|
|
2742
|
+
for (let i = 0; i < listed.length; i++) {
|
|
2743
|
+
const { entry, rel } = listed[i];
|
|
2744
|
+
const parser = new SheetParser(entry.name, entry.state, ctx, styles, {
|
|
2745
|
+
formulas: o.formulas !== false,
|
|
2746
|
+
dates: o.dates ?? "date",
|
|
2747
|
+
dateZone: o.dateZone ?? "local",
|
|
2748
|
+
richText: o.richText ?? "runs",
|
|
2749
|
+
date1904: wbp.date1904
|
|
2750
|
+
}, rel?.target ?? workbookPart);
|
|
2751
|
+
parser.sharedStrings = sst;
|
|
2752
|
+
const part = rel ? pkg.part(rel.target) : void 0;
|
|
2753
|
+
if (!part) {
|
|
2754
|
+
ctx.warn("MISSING_PART", `The part for sheet "${entry.name}" is missing; the sheet is empty.`, { sheet: entry.name });
|
|
2755
|
+
sheets.push(parser.finish([]));
|
|
2756
|
+
continue;
|
|
2757
|
+
}
|
|
2758
|
+
if (!wanted(entry.name, i)) {
|
|
2759
|
+
sheets.push(parser.finish([]));
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
const sheetRels = await pkg.rels(part.name);
|
|
2763
|
+
warnUnsupported(sheetRels, part.name);
|
|
2764
|
+
const base = doneBytes;
|
|
2765
|
+
ctx.progress({
|
|
2766
|
+
phase: "parse",
|
|
2767
|
+
sheet: entry.name,
|
|
2768
|
+
ratio: .1 + .9 * (base / totalBytes)
|
|
2769
|
+
});
|
|
2770
|
+
let read = 0;
|
|
2771
|
+
await ctx.parse(part, parser, (n) => {
|
|
2772
|
+
read += n;
|
|
2773
|
+
ctx.progress({
|
|
2774
|
+
phase: "parse",
|
|
2775
|
+
sheet: entry.name,
|
|
2776
|
+
ratio: .1 + .9 * (Math.min(base + read, totalBytes) / totalBytes)
|
|
2777
|
+
});
|
|
2778
|
+
});
|
|
2779
|
+
doneBytes += part.size;
|
|
2780
|
+
sheets.push(parser.finish(sheetRels));
|
|
2781
|
+
}
|
|
2782
|
+
const bookToSheet = /* @__PURE__ */ new Map();
|
|
2783
|
+
listed.forEach((s, i) => bookToSheet.set(s.bookIndex, i));
|
|
2784
|
+
const definedNames = [];
|
|
2785
|
+
for (const d of wbp.definedNames) {
|
|
2786
|
+
const local = d.sheet === void 0 ? void 0 : bookToSheet.get(d.sheet);
|
|
2787
|
+
if (d.sheet !== void 0 && local === void 0) continue;
|
|
2788
|
+
const sheet = local === void 0 ? void 0 : sheets[local];
|
|
2789
|
+
if (d.name === "_xlnm._FilterDatabase") continue;
|
|
2790
|
+
if (sheet && d.name === "_xlnm.Print_Area") {
|
|
2791
|
+
(sheet.print ??= {}).printArea = refsOnly(d.ref);
|
|
2792
|
+
continue;
|
|
2793
|
+
}
|
|
2794
|
+
if (sheet && d.name === "_xlnm.Print_Titles") {
|
|
2795
|
+
const titles = {};
|
|
2796
|
+
for (const part of refsOnly(d.ref).split(",")) if (/^\d+:\d+$/.test(part)) titles.rows = part;
|
|
2797
|
+
else if (/^[A-Za-z]+:[A-Za-z]+$/.test(part)) titles.cols = part;
|
|
2798
|
+
if (Object.keys(titles).length) (sheet.print ??= {}).printTitles = titles;
|
|
2799
|
+
continue;
|
|
2800
|
+
}
|
|
2801
|
+
const out = { ...d };
|
|
2802
|
+
if (local === void 0) delete out.sheet;
|
|
2803
|
+
else out.sheet = local;
|
|
2804
|
+
definedNames.push(out);
|
|
2805
|
+
}
|
|
2806
|
+
const workbook = { sheets };
|
|
2807
|
+
if (wbp.activeTab !== void 0) {
|
|
2808
|
+
const active = bookToSheet.get(wbp.activeTab);
|
|
2809
|
+
if (active !== void 0 && active !== 0) workbook.activeSheet = active;
|
|
2810
|
+
}
|
|
2811
|
+
if (wbp.date1904) workbook.date1904 = true;
|
|
2812
|
+
if (properties) workbook.properties = properties;
|
|
2813
|
+
if (definedNames.length) workbook.definedNames = definedNames;
|
|
2814
|
+
if (theme) workbook.theme = theme;
|
|
2815
|
+
if (styles.indexedColors) workbook.indexedColors = styles.indexedColors;
|
|
2816
|
+
if (wbp.fullCalcOnLoad !== void 0) workbook.calc = { fullCalcOnLoad: wbp.fullCalcOnLoad };
|
|
2817
|
+
const result = {
|
|
2818
|
+
workbook,
|
|
2819
|
+
warnings: ctx.warnings
|
|
2820
|
+
};
|
|
2821
|
+
if (internal?.retainParts) {
|
|
2822
|
+
const parts = /* @__PURE__ */ new Map();
|
|
2823
|
+
for (const name of pkg.partNames) {
|
|
2824
|
+
if (ctx.consumed.has(name)) continue;
|
|
2825
|
+
parts.set(name, await ctx.zip.read(name, o.signal));
|
|
2826
|
+
}
|
|
2827
|
+
result.parts = parts;
|
|
2828
|
+
}
|
|
2829
|
+
ctx.progress({
|
|
2830
|
+
phase: "parse",
|
|
2831
|
+
ratio: 1
|
|
2832
|
+
});
|
|
2833
|
+
return result;
|
|
2834
|
+
}
|
|
2835
|
+
function checkEnum(name, v, allowed) {
|
|
2836
|
+
if (v !== void 0 && !allowed.includes(v)) throw new TypeError(`${name} must be one of ${allowed.map((a) => `'${a}'`).join(", ")}`);
|
|
2837
|
+
}
|
|
2838
|
+
function selector(sheets) {
|
|
2839
|
+
if (!sheets) return () => true;
|
|
2840
|
+
if (!Array.isArray(sheets)) throw new TypeError("sheets must be an array of names or indices");
|
|
2841
|
+
const byName = /* @__PURE__ */ new Set();
|
|
2842
|
+
const byIndex = /* @__PURE__ */ new Set();
|
|
2843
|
+
for (const s of sheets) if (typeof s === "number") byIndex.add(s);
|
|
2844
|
+
else if (typeof s === "string") byName.add(s.toLowerCase());
|
|
2845
|
+
else throw new TypeError("sheets must contain names or indices");
|
|
2846
|
+
return (name, index) => byIndex.has(index) || byName.has(name.toLowerCase());
|
|
2847
|
+
}
|
|
2848
|
+
/** "'My Sheet'!$A$1:$F$40" -> "A1:F40"; several areas keep their commas. */
|
|
2849
|
+
function refsOnly(ref) {
|
|
2850
|
+
return ref.split(",").map((p) => {
|
|
2851
|
+
const bang = p.lastIndexOf("!");
|
|
2852
|
+
return (bang === -1 ? p : p.slice(bang + 1)).replace(/\$/g, "").trim();
|
|
2853
|
+
}).join(",");
|
|
2854
|
+
}
|
|
2855
|
+
/** Parses an optional part; on a format problem, warns BROKEN_OPTIONAL_PART and returns false. */
|
|
2856
|
+
async function optional(ctx, part, fn) {
|
|
2857
|
+
try {
|
|
2858
|
+
await fn();
|
|
2859
|
+
return true;
|
|
2860
|
+
} catch (err) {
|
|
2861
|
+
if (err instanceof FormatError && err.code === "XML_MALFORMED") {
|
|
2862
|
+
ctx.warn("BROKEN_OPTIONAL_PART", `${part} is not well-formed XML and was skipped.`, { part });
|
|
2863
|
+
return false;
|
|
2864
|
+
}
|
|
2865
|
+
throw err;
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
async function readProperties(pkg, ctx) {
|
|
2869
|
+
const rels = await pkg.rels("");
|
|
2870
|
+
const props = {};
|
|
2871
|
+
for (const kind of [
|
|
2872
|
+
"core-properties",
|
|
2873
|
+
"metadata/core-properties",
|
|
2874
|
+
"extended-properties"
|
|
2875
|
+
]) {
|
|
2876
|
+
const rel = rels.find((r) => (r.kind === kind || r.type.endsWith(`/${kind}`)) && !r.external);
|
|
2877
|
+
const entry = rel ? pkg.part(rel.target) : void 0;
|
|
2878
|
+
if (!entry) continue;
|
|
2879
|
+
const handler = new PropsParser(props);
|
|
2880
|
+
await optional(ctx, entry.name, () => ctx.parse(entry, handler));
|
|
2881
|
+
}
|
|
2882
|
+
const customRel = rels.find((r) => r.kind === "custom-properties" && !r.external);
|
|
2883
|
+
const custom = customRel ? pkg.part(customRel.target) : void 0;
|
|
2884
|
+
if (custom) {
|
|
2885
|
+
const cp = new CustomPropsParser();
|
|
2886
|
+
if (await optional(ctx, custom.name, () => ctx.parse(custom, cp)) && cp.items.length) props.custom = cp.items;
|
|
2887
|
+
}
|
|
2888
|
+
return Object.keys(props).length ? props : void 0;
|
|
2889
|
+
}
|
|
2890
|
+
// src/read.ts
|
|
2891
|
+
/** Default limits (docs/api.md §5.2; the measurements behind each value are listed there). */
|
|
2892
|
+
const DEFAULT_READ_LIMITS = DEFAULT_LIMITS;
|
|
2893
|
+
/** Detects the file format from the bytes. Never throws for unreadable input; returns `'unknown'` or `'zip'` instead. */
|
|
2894
|
+
async function detectFormat(input) {
|
|
2895
|
+
return detectFormatImpl(await toBytes(input, "detectFormat"));
|
|
2896
|
+
}
|
|
2897
|
+
/** Lists the worksheets (name, index, visibility) without parsing any sheet. */
|
|
2898
|
+
async function readSheetNames(input, options) {
|
|
2899
|
+
return readSheetNamesImpl(await toBytes(input, "readSheetNames"), options);
|
|
2900
|
+
}
|
|
2901
|
+
/** Reads an .xlsx, .xlsm, .xltx or .xltm file into the model. */
|
|
2902
|
+
async function read(input, options) {
|
|
2903
|
+
const { workbook, warnings } = await readImpl(input, options);
|
|
2904
|
+
return {
|
|
2905
|
+
workbook,
|
|
2906
|
+
warnings
|
|
2907
|
+
};
|
|
2908
|
+
}
|
|
2909
|
+
export { readSheetNames as i, detectFormat as n, read as r, DEFAULT_READ_LIMITS as t };
|