@office-open/xlsx 0.9.0 → 0.9.1

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.
@@ -1,2251 +0,0 @@
1
- import { attr, attrNum, attrs, escapeXml, findChild, selfCloseElement, textOf } from "@office-open/xml";
2
- import { ChartCollection, Relationships, derivePasswordHash } from "@office-open/core";
3
- //#region src/parts/shared-strings.ts
4
- /**
5
- * Build rich text run properties XML (CT_RPrElt).
6
- * Exported for reuse by Comments and other components.
7
- */
8
- function buildRPrXml(pr) {
9
- if (!pr) return "";
10
- const parts = [];
11
- if (pr.font) parts.push(`<rFont val="${escapeXml(pr.font)}"/>`);
12
- if (pr.charset !== void 0) parts.push(`<charset val="${pr.charset}"/>`);
13
- if (pr.family !== void 0) parts.push(`<family val="${pr.family}"/>`);
14
- if (pr.bold) parts.push("<b/>");
15
- if (pr.italic) parts.push("<i/>");
16
- if (pr.strike) parts.push("<strike/>");
17
- if (pr.outline) parts.push("<outline/>");
18
- if (pr.shadow) parts.push("<shadow/>");
19
- if (pr.condense) parts.push("<condense/>");
20
- if (pr.extend) parts.push("<extend/>");
21
- if (pr.color) {
22
- const rgb = pr.color.length === 6 ? `FF${pr.color}` : pr.color;
23
- parts.push(`<color rgb="${escapeXml(rgb)}"/>`);
24
- }
25
- if (pr.size !== void 0) parts.push(`<sz val="${pr.size}"/>`);
26
- if (pr.underline) if (pr.underline === "none") parts.push("<u/>");
27
- else parts.push(`<u val="${pr.underline}"/>`);
28
- if (pr.vertAlign) parts.push(`<vertAlign val="${pr.vertAlign}"/>`);
29
- if (pr.scheme) parts.push(`<scheme val="${pr.scheme}"/>`);
30
- return parts.length > 0 ? `<rPr>${parts.join("")}</rPr>` : "";
31
- }
32
- /** Build a CT_Rst XML string from RichTextOptions. */
33
- function buildRstXml(rst) {
34
- const parts = [];
35
- if (rst.runs && rst.runs.length > 0) for (const run of rst.runs) {
36
- const rPr = buildRPrXml(run.properties);
37
- parts.push(`<r>${rPr}<t>${escapeXml(run.text)}</t></r>`);
38
- }
39
- else if (rst.text !== void 0) parts.push(`<t>${escapeXml(rst.text)}</t>`);
40
- if (rst.phonetics) for (const ph of rst.phonetics) parts.push(`<rPh sb="${ph.sb}" eb="${ph.eb}"><t>${escapeXml(ph.text)}</t></rPh>`);
41
- return parts.join("");
42
- }
43
- var SharedStrings = class {
44
- entries = [];
45
- /** Dedup map for plain strings only. Rich text is not deduped. */
46
- indexMap = /* @__PURE__ */ new Map();
47
- /**
48
- * Register a plain string and return its index.
49
- * Returns existing index if the string is already registered.
50
- */
51
- register(s) {
52
- const existing = this.indexMap.get(s);
53
- if (existing !== void 0) return existing;
54
- const idx = this.entries.length;
55
- this.entries.push(s);
56
- this.indexMap.set(s, idx);
57
- return idx;
58
- }
59
- /**
60
- * Register a rich text entry and return its index.
61
- * Rich text is not deduped (each call creates a new entry).
62
- */
63
- registerRich(rst) {
64
- const idx = this.entries.length;
65
- this.entries.push(rst);
66
- return idx;
67
- }
68
- get count() {
69
- return this.entries.length;
70
- }
71
- /** Return a serializable snapshot for the descriptor. */
72
- toDescriptorOptions() {
73
- return {
74
- entries: this.entries,
75
- uniqueCount: this.indexMap.size
76
- };
77
- }
78
- /** Serialize to xl/sharedStrings.xml content (without XML declaration). */
79
- serialize() {
80
- const p = ["<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"", ` count="${this.entries.length}" uniqueCount="${this.indexMap.size}">`];
81
- for (const entry of this.entries) if (typeof entry === "string") p.push(`<si><t>${escapeXml(entry)}</t></si>`);
82
- else p.push(`<si>${buildRstXml(entry)}</si>`);
83
- p.push("</sst>");
84
- return p.join("");
85
- }
86
- };
87
- const sharedStringsDesc = {
88
- kind: "custom",
89
- stringify(opts, _ctx) {
90
- if (opts.entries.length === 0) return void 0;
91
- const p = ["<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"", ` count="${opts.entries.length}" uniqueCount="${opts.uniqueCount}">`];
92
- for (const entry of opts.entries) if (typeof entry === "string") p.push(`<si><t>${escapeXml(entry)}</t></si>`);
93
- else p.push(`<si>${buildRstXml(entry)}</si>`);
94
- p.push("</sst>");
95
- return p.join("");
96
- },
97
- parse(el, _ctx) {
98
- const entries = [];
99
- for (const si of el.elements ?? []) {
100
- if (si.name !== "si") continue;
101
- const t = findChild(si, "t");
102
- if (t) {
103
- entries.push(textOf(t) ?? "");
104
- continue;
105
- }
106
- const runs = [];
107
- for (const r of si.elements ?? []) {
108
- if (r.name !== "r") continue;
109
- const rt = findChild(r, "t");
110
- if (rt) runs.push({ text: textOf(rt) ?? "" });
111
- }
112
- if (runs.length > 0) entries.push({ runs });
113
- }
114
- return {
115
- entries,
116
- uniqueCount: entries.length
117
- };
118
- }
119
- };
120
- //#endregion
121
- //#region src/parts/styles.ts
122
- function fontKey(f) {
123
- return `b${f.bold ? 1 : 0}i${f.italic ? 1 : 0}u${f.underline ? 1 : 0}s${f.strike ? 1 : 0}z${f.size ?? 0}c${f.color ?? ""}n${f.font ?? ""}cs${f.charset ?? ""}fm${f.family ?? ""}co${f.condense ? 1 : 0}ex${f.extend ? 1 : 0}va${f.vertAlign ?? ""}sc${f.scheme ?? ""}sh${f.shadow ? 1 : 0}ol${f.outline ? 1 : 0}`;
124
- }
125
- function fillKey(f) {
126
- return `t${f.type ?? ""}c${f.color ?? ""}p${f.patternType ?? ""}bg${f.bgColor ?? ""}g${f.stops?.map((s) => `${s.position}_${s.color}`).join("|") ?? ""}`;
127
- }
128
- function borderKey(b) {
129
- const sk = (o) => `${o?.style ?? ""}_${o?.color ?? ""}`;
130
- return `t${sk(b.top)}b${sk(b.bottom)}l${sk(b.left)}r${sk(b.right)}d${sk(b.diagonal)}du${b.diagonalUp ? 1 : 0}dd${b.diagonalDown ? 1 : 0}st${sk(b.start)}en${sk(b.end)}v${sk(b.vertical)}h${sk(b.horizontal)}`;
131
- }
132
- const BUILTIN_NUMFMTS = {
133
- General: 0,
134
- "0": 1,
135
- "0.00": 2,
136
- "#,##0": 3,
137
- "#,##0.00": 4,
138
- "0%": 9,
139
- "0.00%": 10,
140
- "0.00E+00": 11,
141
- "mm-dd-yy": 14,
142
- "d-mmm-yy": 15,
143
- "d-mmm": 16,
144
- "mmm-yy": 17,
145
- "h:mm AM/PM": 18,
146
- "h:mm:ss AM/PM": 19,
147
- "h:mm": 20,
148
- "h:mm:ss": 21,
149
- "m/d/yy h:mm": 22,
150
- "#,##0 ;(#,##0)": 37,
151
- "#,##0 ;[Red](#,##0)": 38,
152
- "#,##0.00;(#,##0.00)": 39,
153
- "#,##0.00;[Red](#,##0.00)": 40,
154
- "mm:ss": 45,
155
- "[h]:mm:ss": 46,
156
- "mmss.0": 47,
157
- "##0.0E+0": 48,
158
- "@": 49
159
- };
160
- var Styles = class {
161
- fonts = [{
162
- size: 11,
163
- font: "Calibri"
164
- }];
165
- fontKeys = /* @__PURE__ */ new Map();
166
- fills = [{ patternType: "none" }, { patternType: "gray125" }];
167
- fillKeys = /* @__PURE__ */ new Map();
168
- borders = [{}];
169
- borderKeys = /* @__PURE__ */ new Map();
170
- customNumFmts = /* @__PURE__ */ new Map();
171
- nextCustomNumFmtId = 164;
172
- cellXfs = [{
173
- fontId: 0,
174
- fillId: 0,
175
- borderId: 0,
176
- numFmtId: 0
177
- }];
178
- cellXfKeys = /* @__PURE__ */ new Map();
179
- dxfs = [];
180
- colors;
181
- tableStyles;
182
- /** Custom cell styles (CT_CellStyles) */
183
- customCellStyles;
184
- /** Style sheet extensions (CT_ExtensionList) */
185
- styleExtensions;
186
- constructor() {
187
- this.fontKeys.set(fontKey(this.fonts[0]), 0);
188
- this.fillKeys.set(fillKey(this.fills[0]), 0);
189
- this.fillKeys.set(fillKey(this.fills[1]), 1);
190
- this.borderKeys.set(borderKey(this.borders[0]), 0);
191
- this.cellXfKeys.set(this.cellXfKey(this.cellXfs[0]), 0);
192
- }
193
- /**
194
- * Register a style and return its index (for the cell `s` attribute).
195
- * Deduplicates across fonts, fills, borders, numFmts, and cellXfs.
196
- */
197
- register(opts) {
198
- const xf = {
199
- fontId: this.registerFont(opts.font),
200
- fillId: this.registerFill(opts.fill),
201
- borderId: this.registerBorder(opts.border),
202
- numFmtId: this.registerNumFmt(opts.numFmt),
203
- alignment: opts.alignment,
204
- quotePrefix: opts.quotePrefix,
205
- pivotButton: opts.pivotButton,
206
- applyProtection: opts.applyProtection,
207
- protection: opts.protection
208
- };
209
- const key = this.cellXfKey(xf);
210
- const existing = this.cellXfKeys.get(key);
211
- if (existing !== void 0) return existing;
212
- const idx = this.cellXfs.length;
213
- this.cellXfs.push(xf);
214
- this.cellXfKeys.set(key, idx);
215
- return idx;
216
- }
217
- /**
218
- * Register a differential format and return its index (dxfId).
219
- * Used by conditional formatting rules.
220
- */
221
- registerDxf(opts) {
222
- const idx = this.dxfs.length;
223
- this.dxfs.push(opts);
224
- return idx;
225
- }
226
- /**
227
- * Set color palette (indexed colors and MRU colors).
228
- */
229
- setColors(opts) {
230
- this.colors = opts;
231
- }
232
- setTableStyles(styles) {
233
- this.tableStyles = styles;
234
- }
235
- setExtensions(extensions) {
236
- this.styleExtensions = extensions;
237
- }
238
- setCustomCellStyles(styles) {
239
- this.customCellStyles = styles;
240
- }
241
- /**
242
- * Expose internal state for descriptor-based XML generation.
243
- * The descriptor reads this snapshot to produce xl/styles.xml.
244
- */
245
- toDescriptorOptions() {
246
- return {
247
- customNumFmts: new Map(this.customNumFmts),
248
- fonts: [...this.fonts],
249
- fills: [...this.fills],
250
- borders: [...this.borders],
251
- cellXfs: [...this.cellXfs],
252
- dxfs: [...this.dxfs],
253
- colors: this.colors,
254
- tableStyles: this.tableStyles,
255
- customCellStyles: this.customCellStyles,
256
- styleExtensions: this.styleExtensions
257
- };
258
- }
259
- registerFont(opts) {
260
- if (!opts) return 0;
261
- const key = fontKey(opts);
262
- const existing = this.fontKeys.get(key);
263
- if (existing !== void 0) return existing;
264
- const idx = this.fonts.length;
265
- this.fonts.push(opts);
266
- this.fontKeys.set(key, idx);
267
- return idx;
268
- }
269
- registerFill(opts) {
270
- if (!opts) return 0;
271
- const key = fillKey(opts);
272
- const existing = this.fillKeys.get(key);
273
- if (existing !== void 0) return existing;
274
- const idx = this.fills.length;
275
- this.fills.push(opts);
276
- this.fillKeys.set(key, idx);
277
- return idx;
278
- }
279
- registerBorder(opts) {
280
- if (!opts) return 0;
281
- const key = borderKey(opts);
282
- const existing = this.borderKeys.get(key);
283
- if (existing !== void 0) return existing;
284
- const idx = this.borders.length;
285
- this.borders.push(opts);
286
- this.borderKeys.set(key, idx);
287
- return idx;
288
- }
289
- registerNumFmt(fmt) {
290
- if (!fmt) return 0;
291
- const builtin = BUILTIN_NUMFMTS[fmt];
292
- if (builtin !== void 0) return builtin;
293
- const existing = this.customNumFmts.get(fmt);
294
- if (existing !== void 0) return existing;
295
- const id = this.nextCustomNumFmtId++;
296
- this.customNumFmts.set(fmt, id);
297
- return id;
298
- }
299
- cellXfKey(xf) {
300
- const a = xf.alignment;
301
- const ak = a ? `h${a.horizontal ?? ""}v${a.vertical ?? ""}w${a.wrapText ? 1 : 0}r${a.textRotation ?? ""}i${a.indent ?? ""}ri${a.relativeIndent ?? ""}jl${a.justifyLastLine ? 1 : 0}st${a.shrinkToFit ? 1 : 0}ro${a.readingOrder ?? ""}` : "";
302
- const pr = xf.protection;
303
- const pk = pr ? `l${pr.locked ?? ""}h${pr.hidden ?? ""}` : "";
304
- return `${xf.fontId}|${xf.fillId}|${xf.borderId}|${xf.numFmtId}|${ak}|qp${xf.quotePrefix ? 1 : 0}|pb${xf.pivotButton ? 1 : 0}|${pk}`;
305
- }
306
- /**
307
- * Zero-allocation fast path: directly concatenate XML string.
308
- * Bypasses the IXmlableObject intermediate tree entirely.
309
- */
310
- /** Serialize to xl/styles.xml content (without XML declaration). */
311
- serialize() {
312
- const p = ["<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"];
313
- if (this.customNumFmts.size > 0) {
314
- p.push(`<numFmts count="${this.customNumFmts.size}">`);
315
- for (const [fmt, id] of this.customNumFmts) p.push(`<numFmt numFmtId="${id}" formatCode="${escapeXml(fmt)}"/>`);
316
- p.push("</numFmts>");
317
- }
318
- p.push(`<fonts count="${this.fonts.length}">`);
319
- for (const f of this.fonts) p.push(`<font>${this.fontXmlStr(f)}</font>`);
320
- p.push("</fonts>");
321
- p.push(`<fills count="${this.fills.length}">`);
322
- for (const f of this.fills) if (f.type === "gradient" && f.stops && f.stops.length > 0) {
323
- const gfAttrs = {};
324
- if (f.gradientType && f.gradientType !== "linear") gfAttrs.type = f.gradientType;
325
- if (f.gradientDegree !== void 0) gfAttrs.degree = f.gradientDegree;
326
- if (f.gradientLeft !== void 0) gfAttrs.left = f.gradientLeft;
327
- if (f.gradientRight !== void 0) gfAttrs.right = f.gradientRight;
328
- if (f.gradientTop !== void 0) gfAttrs.top = f.gradientTop;
329
- if (f.gradientBottom !== void 0) gfAttrs.bottom = f.gradientBottom;
330
- const stopParts = f.stops.map((s) => `<stop position="${s.position}"><color rgb="FF${s.color}"/></stop>`).join("");
331
- p.push(`<fill><gradientFill${attrs(gfAttrs)}>${stopParts}</gradientFill></fill>`);
332
- } else {
333
- const patternAttrs = attrs({ patternType: f.patternType ?? "solid" });
334
- const colorContent = (f.color ? `<fgColor rgb="FF${f.color}"/>` : f.colorIndexed !== void 0 ? `<fgColor indexed="${f.colorIndexed}"/>` : "") + (f.bgColor ? `<bgColor rgb="FF${f.bgColor}"/>` : "");
335
- p.push(colorContent ? `<fill><patternFill${patternAttrs}>${colorContent}</patternFill></fill>` : `<fill><patternFill${patternAttrs}/></fill>`);
336
- }
337
- p.push("</fills>");
338
- p.push(`<borders count="${this.borders.length}">`);
339
- for (const b of this.borders) {
340
- const bAttrs = [];
341
- if (b.diagonalUp) bAttrs.push("diagonalUp=\"1\"");
342
- if (b.diagonalDown) bAttrs.push("diagonalDown=\"1\"");
343
- const bAttr = bAttrs.length ? ` ${bAttrs.join(" ")}` : "";
344
- p.push(`<border${bAttr}>${this.borderXmlStr(b)}</border>`);
345
- }
346
- p.push("</borders>");
347
- p.push("<cellStyleXfs count=\"1\"><xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\"/></cellStyleXfs>");
348
- p.push(`<cellXfs count="${this.cellXfs.length}">`);
349
- for (const xf of this.cellXfs) {
350
- const xAttrs = {
351
- numFmtId: xf.numFmtId,
352
- fontId: xf.fontId,
353
- fillId: xf.fillId,
354
- borderId: xf.borderId,
355
- xfId: 0
356
- };
357
- if (xf.alignment) xAttrs.applyAlignment = 1;
358
- if (xf.fontId > 0) xAttrs.applyFont = 1;
359
- if (xf.fillId > 0) xAttrs.applyFill = 1;
360
- if (xf.borderId > 0) xAttrs.applyBorder = 1;
361
- if (xf.numFmtId > 0) xAttrs.applyNumberFormat = 1;
362
- if (xf.quotePrefix) xAttrs.quotePrefix = 1;
363
- if (xf.pivotButton) xAttrs.pivotButton = 1;
364
- if (xf.applyProtection) xAttrs.applyProtection = 1;
365
- if (xf.protection) xAttrs.applyProtection = xAttrs.applyProtection ?? 1;
366
- const inner = (xf.alignment ? this.alignmentXmlStr(xf.alignment) : "") + (xf.protection ? this.protectionXmlStr(xf.protection) : "");
367
- p.push(inner ? `<xf${attrs(xAttrs)}>${inner}</xf>` : `<xf${attrs(xAttrs)}/>`);
368
- }
369
- p.push("</cellXfs>");
370
- if (this.customCellStyles && this.customCellStyles.length > 0) {
371
- const csParts = [`<cellStyles ${[`count="${this.customCellStyles.length + 1}"`].join(" ")}>`];
372
- csParts.push("<cellStyle name=\"Normal\" xfId=\"0\" builtinId=\"0\"/>");
373
- for (const cs of this.customCellStyles) {
374
- const attrs = [`name="${escapeXml(cs.name)}"`, `xfId="${cs.xfId}"`];
375
- if (cs.builtinId !== void 0) attrs.push(`builtinId="${cs.builtinId}"`);
376
- if (cs.customBuiltin) attrs.push("customBuiltin=\"1\"");
377
- if (cs.iLevel !== void 0) attrs.push(`iLevel="${cs.iLevel}"`);
378
- if (cs.hidden) attrs.push("hidden=\"1\"");
379
- csParts.push(`<cellStyle ${attrs.join(" ")}/>`);
380
- }
381
- csParts.push("</cellStyles>");
382
- p.push(csParts.join(""));
383
- } else p.push("<cellStyles count=\"1\"><cellStyle name=\"Normal\" xfId=\"0\" builtinId=\"0\"/></cellStyles>");
384
- if (this.dxfs.length > 0) {
385
- p.push(`<dxfs count="${this.dxfs.length}">`);
386
- for (const dxf of this.dxfs) {
387
- const dParts = [];
388
- if (dxf.font) dParts.push(`<font>${this.fontXmlStr(dxf.font)}</font>`);
389
- if (dxf.fill) {
390
- const bgColor = dxf.fill.color ? `<bgColor rgb="FF${dxf.fill.color}"/>` : "";
391
- const patAttrs = attrs({ patternType: dxf.fill.patternType ?? "solid" });
392
- dParts.push(`<fill><patternFill${patAttrs}>${bgColor}</patternFill></fill>`);
393
- }
394
- if (dxf.numFmt) dParts.push(`<numFmt formatCode="${escapeXml(dxf.numFmt)}"/>`);
395
- if (dxf.border) dParts.push(`<border>${this.borderXmlStr(dxf.border)}</border>`);
396
- if (dParts.length > 0) p.push(`<dxf>${dParts.join("")}</dxf>`);
397
- else p.push("<dxf/>");
398
- }
399
- p.push("</dxfs>");
400
- } else p.push("<dxfs count=\"0\"/>");
401
- if (this.tableStyles && this.tableStyles.length > 0) {
402
- const tsParts = [`<tableStyles count="${this.tableStyles.length}" defaultTableStyle="TableStyleMedium2" defaultPivotStyle="PivotStyleLight16">`];
403
- for (const ts of this.tableStyles) {
404
- const tsAttrs = [`name="${escapeXml(ts.name)}"`];
405
- if (ts.pivot) tsAttrs.push("pivot=\"1\"");
406
- if (ts.elements && ts.elements.length > 0) {
407
- tsParts.push(`<tableStyle ${tsAttrs.join(" ")}>`);
408
- for (const el of ts.elements) {
409
- const elAttrs = [`type="${el.type}"`];
410
- if (el.dxfId !== void 0) elAttrs.push(`dxfId="${el.dxfId}"`);
411
- if (el.button) elAttrs.push("button=\"1\"");
412
- tsParts.push(`<tableStyleElement ${elAttrs.join(" ")}/>`);
413
- }
414
- tsParts.push("</tableStyle>");
415
- } else tsParts.push(`<tableStyle ${tsAttrs.join(" ")}/>`);
416
- }
417
- tsParts.push("</tableStyles>");
418
- p.push(tsParts.join(""));
419
- } else p.push("<tableStyles count=\"0\" defaultTableStyle=\"TableStyleMedium2\" defaultPivotStyle=\"PivotStyleLight16\"/>");
420
- if (this.colors) {
421
- const c = this.colors;
422
- const colorParts = ["<colors>"];
423
- if (c.indexedColors && c.indexedColors.length > 0) {
424
- colorParts.push("<indexedColors>");
425
- for (const ic of c.indexedColors) colorParts.push(`<rgbColor rgb="${ic.rgb}"/>`);
426
- colorParts.push("</indexedColors>");
427
- }
428
- if (c.mruColors && c.mruColors.length > 0) {
429
- colorParts.push("<mruColors>");
430
- for (const mc of c.mruColors) colorParts.push(`<color rgb="FF${mc}"/>`);
431
- colorParts.push("</mruColors>");
432
- }
433
- colorParts.push("</colors>");
434
- p.push(colorParts.join(""));
435
- }
436
- if (this.styleExtensions && this.styleExtensions.length > 0) {
437
- const extParts = ["<extLst>"];
438
- for (const ext of this.styleExtensions) if (ext.content) extParts.push(`<ext uri="${ext.uri}">${ext.content}</ext>`);
439
- else extParts.push(`<ext uri="${ext.uri}"/>`);
440
- extParts.push("</extLst>");
441
- p.push(extParts.join(""));
442
- } else p.push("<extLst/>");
443
- p.push("</styleSheet>");
444
- return p.join("");
445
- }
446
- fontXmlStr(f) {
447
- const parts = [];
448
- if (f.bold) parts.push("<b/>");
449
- if (f.italic) parts.push("<i/>");
450
- if (f.underline) parts.push("<u/>");
451
- if (f.strike) parts.push("<strike/>");
452
- if (f.outline) parts.push("<outline/>");
453
- if (f.shadow) parts.push("<shadow/>");
454
- if (f.condense) parts.push("<condense/>");
455
- if (f.extend) parts.push("<extend/>");
456
- if (f.size) parts.push(`<sz val="${f.size}"/>`);
457
- if (f.color) parts.push(`<color rgb="FF${f.color}"/>`);
458
- if (f.font) parts.push(`<name val="${escapeXml(f.font)}"/>`);
459
- if (f.charset !== void 0) parts.push(`<charset val="${f.charset}"/>`);
460
- if (f.family !== void 0) parts.push(`<family val="${f.family}"/>`);
461
- if (f.vertAlign) parts.push(`<vertAlign val="${f.vertAlign}"/>`);
462
- if (f.scheme) parts.push(`<scheme val="${f.scheme}"/>`);
463
- return parts.join("");
464
- }
465
- borderXmlStr(b) {
466
- const parts = [];
467
- const renderSide = (name, opts, required = true) => {
468
- if (opts && opts.style && opts.style !== "none") {
469
- const colorStr = opts.color ? `<color rgb="FF${opts.color}"/>` : "";
470
- parts.push(`<${name} style="${opts.style}">${colorStr}</${name}>`);
471
- } else if (required) parts.push(`<${name}/>`);
472
- };
473
- for (const side of [
474
- "left",
475
- "right",
476
- "top",
477
- "bottom",
478
- "diagonal",
479
- "vertical",
480
- "horizontal"
481
- ]) renderSide(side, b[side]);
482
- renderSide("start", b.start, false);
483
- renderSide("end", b.end, false);
484
- return parts.join("");
485
- }
486
- alignmentXmlStr(a) {
487
- const aAttrs = {};
488
- if (a.horizontal) aAttrs.horizontal = a.horizontal;
489
- if (a.vertical) aAttrs.vertical = a.vertical;
490
- if (a.wrapText) aAttrs.wrapText = 1;
491
- if (a.textRotation !== void 0) aAttrs.textRotation = a.textRotation;
492
- if (a.indent !== void 0) aAttrs.indent = a.indent;
493
- if (a.relativeIndent !== void 0) aAttrs.relativeIndent = a.relativeIndent;
494
- if (a.justifyLastLine) aAttrs.justifyLastLine = 1;
495
- if (a.shrinkToFit) aAttrs.shrinkToFit = 1;
496
- if (a.readingOrder !== void 0) aAttrs.readingOrder = a.readingOrder;
497
- return `<alignment${attrs(aAttrs)}/>`;
498
- }
499
- protectionXmlStr(pr) {
500
- const prAttrs = {};
501
- if (pr.locked !== void 0) prAttrs.locked = pr.locked ? 1 : 0;
502
- if (pr.hidden !== void 0) prAttrs.hidden = pr.hidden ? 1 : 0;
503
- return `<protection${attrs(prAttrs)}/>`;
504
- }
505
- };
506
- const stylesDesc = {
507
- kind: "custom",
508
- stringify(opts, _ctx) {
509
- return opts.styles.serialize();
510
- },
511
- parse(el, _ctx) {
512
- const result = {};
513
- const numFmtsEl = findChild(el, "numFmts");
514
- if (numFmtsEl) {
515
- const numFmts = {};
516
- for (const nf of numFmtsEl.elements ?? []) {
517
- if (nf.name !== "numFmt") continue;
518
- const id = attrNum(nf, "numFmtId");
519
- const code = attr(nf, "formatCode");
520
- if (id !== void 0 && code) numFmts[code] = id;
521
- }
522
- result.customNumFmts = numFmts;
523
- }
524
- const fontsEl = findChild(el, "fonts");
525
- if (fontsEl) {
526
- const fonts = [];
527
- for (const f of fontsEl.elements ?? []) {
528
- if (f.name !== "font") continue;
529
- fonts.push(parseFont(f));
530
- }
531
- result.fonts = fonts;
532
- }
533
- const fillsEl = findChild(el, "fills");
534
- if (fillsEl) {
535
- const fills = [];
536
- for (const f of fillsEl.elements ?? []) {
537
- if (f.name !== "fill") continue;
538
- fills.push(parseFill(f));
539
- }
540
- result.fills = fills;
541
- }
542
- const bordersEl = findChild(el, "borders");
543
- if (bordersEl) {
544
- const borders = [];
545
- for (const b of bordersEl.elements ?? []) {
546
- if (b.name !== "border") continue;
547
- borders.push(parseBorder(b));
548
- }
549
- result.borders = borders;
550
- }
551
- const cellXfsEl = findChild(el, "cellXfs");
552
- if (cellXfsEl) {
553
- const xfs = [];
554
- for (const xf of cellXfsEl.elements ?? []) {
555
- if (xf.name !== "xf") continue;
556
- const fontId = attrNum(xf, "fontId") ?? 0;
557
- const fillId = attrNum(xf, "fillId") ?? 0;
558
- const borderId = attrNum(xf, "borderId") ?? 0;
559
- const numFmtId = attrNum(xf, "numFmtId") ?? 0;
560
- const alignmentEl = findChild(xf, "alignment");
561
- const alignment = alignmentEl ? parseAlignment(alignmentEl) : void 0;
562
- const protectionEl = findChild(xf, "protection");
563
- const protection = protectionEl ? parseProtection(protectionEl) : void 0;
564
- const style = {};
565
- if (fontId > 0) style.fontIdx = fontId;
566
- if (fillId > 0) style.fillIdx = fillId;
567
- if (borderId > 0) style.borderIdx = borderId;
568
- if (numFmtId > 0) style.numFmtIdx = numFmtId;
569
- if (alignment) style.alignment = alignment;
570
- if (protection) style.protection = protection;
571
- if (attr(xf, "quotePrefix") === "1") style.quotePrefix = true;
572
- if (attr(xf, "pivotButton") === "1") style.pivotButton = true;
573
- xfs.push(style);
574
- }
575
- result.cellXfs = xfs;
576
- }
577
- return result;
578
- }
579
- };
580
- function parseFont(el) {
581
- const result = {};
582
- for (const child of el.elements ?? []) switch (child.name) {
583
- case "b":
584
- result.bold = true;
585
- break;
586
- case "i":
587
- result.italic = true;
588
- break;
589
- case "u":
590
- result.underline = true;
591
- break;
592
- case "strike":
593
- result.strike = true;
594
- break;
595
- case "outline":
596
- result.outline = true;
597
- break;
598
- case "shadow":
599
- result.shadow = true;
600
- break;
601
- case "condense":
602
- result.condense = true;
603
- break;
604
- case "extend":
605
- result.extend = true;
606
- break;
607
- case "sz":
608
- result.size = attrNum(child, "val");
609
- break;
610
- case "color":
611
- result.color = parseColorHex(child);
612
- break;
613
- case "name":
614
- result.font = attr(child, "val") ?? void 0;
615
- break;
616
- case "charset":
617
- result.charset = attrNum(child, "val");
618
- break;
619
- case "family":
620
- result.family = attrNum(child, "val");
621
- break;
622
- case "vertAlign":
623
- result.vertAlign = attr(child, "val") ?? void 0;
624
- break;
625
- case "scheme":
626
- result.scheme = attr(child, "val") ?? void 0;
627
- break;
628
- }
629
- return result;
630
- }
631
- function parseFill(el) {
632
- const patternFill = findChild(el, "patternFill");
633
- if (patternFill) {
634
- const result = {};
635
- result.patternType = attr(patternFill, "patternType") ?? void 0;
636
- const fg = findChild(patternFill, "fgColor");
637
- if (fg) result.color = parseColorHex(fg);
638
- const bg = findChild(patternFill, "bgColor");
639
- if (bg) result.bgColor = parseColorHex(bg);
640
- const indexed = fg ? attrNum(fg, "indexed") : void 0;
641
- if (indexed !== void 0) result.colorIndexed = indexed;
642
- return result;
643
- }
644
- const gradientFill = findChild(el, "gradientFill");
645
- if (gradientFill) {
646
- const result = { type: "gradient" };
647
- const gType = attr(gradientFill, "type");
648
- if (gType) result.gradientType = gType;
649
- const degree = attrNum(gradientFill, "degree");
650
- if (degree !== void 0) result.gradientDegree = degree;
651
- const stops = [];
652
- for (const s of gradientFill.elements ?? []) {
653
- if (s.name !== "stop") continue;
654
- const pos = attrNum(s, "position");
655
- const color = findChild(s, "color");
656
- if (pos !== void 0 && color) stops.push({
657
- position: pos,
658
- color: parseColorHex(color) ?? ""
659
- });
660
- }
661
- if (stops.length > 0) result.stops = stops;
662
- return result;
663
- }
664
- return {};
665
- }
666
- function parseBorder(el) {
667
- const result = {};
668
- if (attr(el, "diagonalUp") === "1") result.diagonalUp = true;
669
- if (attr(el, "diagonalDown") === "1") result.diagonalDown = true;
670
- for (const side of [
671
- "left",
672
- "right",
673
- "top",
674
- "bottom",
675
- "diagonal"
676
- ]) {
677
- const sideEl = findChild(el, side);
678
- if (sideEl) {
679
- const opts = {};
680
- const style = attr(sideEl, "style");
681
- if (style) opts.style = style;
682
- const color = findChild(sideEl, "color");
683
- if (color) opts.color = parseColorHex(color);
684
- if (Object.keys(opts).length > 0) result[side] = opts;
685
- }
686
- }
687
- return result;
688
- }
689
- function parseAlignment(el) {
690
- const result = {};
691
- const h = attr(el, "horizontal");
692
- if (h) result.horizontal = h;
693
- const v = attr(el, "vertical");
694
- if (v) result.vertical = v;
695
- if (attr(el, "wrapText") === "1") result.wrapText = true;
696
- const rotation = attrNum(el, "textRotation");
697
- if (rotation !== void 0) result.textRotation = rotation;
698
- const indent = attrNum(el, "indent");
699
- if (indent !== void 0) result.indent = indent;
700
- return result;
701
- }
702
- function parseProtection(el) {
703
- const result = {};
704
- const locked = attr(el, "locked");
705
- if (locked !== void 0) result.locked = locked !== "0";
706
- const hidden = attr(el, "hidden");
707
- if (hidden !== void 0) result.hidden = hidden !== "0";
708
- return result;
709
- }
710
- function parseColorHex(el) {
711
- const rgb = attr(el, "rgb");
712
- if (rgb) return rgb.length === 8 ? rgb.slice(2) : rgb;
713
- }
714
- //#endregion
715
- //#region src/parts/worksheet.ts
716
- /**
717
- * Worksheet XML generation — pure functions for xl/worksheets/sheet{n}.xml.
718
- *
719
- * All interfaces and the zero-allocation string concatenation fast path
720
- * are preserved. The `Worksheet` class has been replaced by `buildWorksheetXml()`.
721
- *
722
- * @module
723
- */
724
- /** Cell formula type (maps to ST_CellFormulaType). */
725
- const FormulaType = {
726
- NORMAL: "normal",
727
- ARRAY: "array",
728
- SHARED: "shared"
729
- };
730
- const worksheetDesc = {
731
- kind: "custom",
732
- /**
733
- * NOT intended for direct use by the compiler.
734
- * The compiler calls `stringifyWorksheet(opts, ctx)` instead, which has
735
- * access to the SharedStrings and Styles accumulators.
736
- * This method exists to satisfy the CustomDescriptor interface for the read path.
737
- */
738
- stringify(_opts, _ctx) {
739
- throw new Error("Use stringifyWorksheet(opts, ctx) for the write path. worksheetDesc.stringify() is not supported.");
740
- },
741
- parse(el, ctx) {
742
- const result = {};
743
- const strings = ctx && "sharedStrings" in ctx ? ctx.sharedStrings : [];
744
- const sheetPrEl = findChild(el, "sheetPr");
745
- if (sheetPrEl) {
746
- const sp = {};
747
- if (attr(sheetPrEl, "syncHorizontal") === "1") sp.syncHorizontal = true;
748
- if (attr(sheetPrEl, "syncVertical") === "1") sp.syncVertical = true;
749
- if (attr(sheetPrEl, "syncRef")) sp.syncRef = attr(sheetPrEl, "syncRef");
750
- if (attr(sheetPrEl, "transitionEvaluation") === "1") sp.transitionEvaluation = true;
751
- if (attr(sheetPrEl, "transitionEntry") === "1") sp.transitionEntry = true;
752
- if (attr(sheetPrEl, "published") === "1") sp.published = true;
753
- if (attr(sheetPrEl, "filterMode") === "1") sp.filterMode = true;
754
- if (attr(sheetPrEl, "enableFormatConditionsCalculation") === "1") sp.enableFormatConditionsCalculation = true;
755
- const outlinePr = findChild(sheetPrEl, "outlinePr");
756
- if (outlinePr) {
757
- if (attr(outlinePr, "applyStyles") === "1") sp.outlineApplyStyles = true;
758
- if (attr(outlinePr, "showOutlineSymbols") === "0") sp.outlineShowSymbols = false;
759
- }
760
- if (Object.keys(sp).length > 0) result.sheetPr = sp;
761
- const tabColorEl = findChild(sheetPrEl, "tabColor");
762
- if (tabColorEl) {
763
- const tc = {};
764
- if (attr(tabColorEl, "rgb")) tc.rgb = attr(tabColorEl, "rgb");
765
- if (attrNum(tabColorEl, "theme") !== void 0) tc.theme = attrNum(tabColorEl, "theme");
766
- if (attrNum(tabColorEl, "tint") !== void 0) tc.tint = attrNum(tabColorEl, "tint");
767
- if (attrNum(tabColorEl, "indexed") !== void 0) tc.indexed = attrNum(tabColorEl, "indexed");
768
- result.tabColor = tc;
769
- }
770
- }
771
- const sheetViewsEl = findChild(el, "sheetViews");
772
- if (sheetViewsEl) {
773
- const svEl = findChild(sheetViewsEl, "sheetView");
774
- if (svEl) {
775
- const sv = {};
776
- if (attr(svEl, "showGridLines") === "0") sv.showGridLines = false;
777
- if (attr(svEl, "showRowColHeaders") === "0") sv.showRowColHeaders = false;
778
- if (attr(svEl, "showZeros") === "0") sv.showZeros = false;
779
- const zs = attrNum(svEl, "zoomScale");
780
- if (zs !== void 0) sv.zoomScale = zs;
781
- if (attr(svEl, "tabSelected") !== void 0) sv.tabSelected = attr(svEl, "tabSelected") !== "0";
782
- if (attr(svEl, "rightToLeft") === "1") sv.rightToLeft = true;
783
- if (attr(svEl, "view")) sv.view = attr(svEl, "view");
784
- result.sheetView = sv;
785
- const paneEl = findChild(svEl, "pane");
786
- if (paneEl && attr(paneEl, "state") === "frozen") {
787
- const fp = {};
788
- const ys = attrNum(paneEl, "ySplit");
789
- if (ys && ys > 0) fp.row = ys;
790
- const xs = attrNum(paneEl, "xSplit");
791
- if (xs && xs > 0) fp.col = xs;
792
- if (Object.keys(fp).length > 0) result.freezePanes = fp;
793
- }
794
- }
795
- }
796
- const sfpEl = findChild(el, "sheetFormatPr");
797
- if (sfpEl) {
798
- const sfp = {};
799
- const bcw = attrNum(sfpEl, "baseColWidth");
800
- if (bcw !== void 0) sfp.baseColWidth = bcw;
801
- const dcw = attrNum(sfpEl, "defaultColWidth");
802
- if (dcw !== void 0) sfp.defaultColWidth = dcw;
803
- const drh = attrNum(sfpEl, "defaultRowHeight");
804
- if (drh !== void 0) sfp.defaultRowHeight = drh;
805
- if (attr(sfpEl, "zeroHeight") === "1") sfp.zeroHeight = true;
806
- if (attr(sfpEl, "thickTop") === "1") sfp.thickTop = true;
807
- if (attr(sfpEl, "thickBottom") === "1") sfp.thickBottom = true;
808
- const olr = attrNum(sfpEl, "outlineLevelRow");
809
- if (olr !== void 0) sfp.outlineLevelRow = olr;
810
- const olc = attrNum(sfpEl, "outlineLevelCol");
811
- if (olc !== void 0) sfp.outlineLevelCol = olc;
812
- result.sheetFormatPr = sfp;
813
- }
814
- const colsEl = findChild(el, "cols");
815
- if (colsEl) {
816
- const columns = [];
817
- for (const colEl of colsEl.elements ?? []) {
818
- if (colEl.name !== "col") continue;
819
- const col = {};
820
- col.min = attrNum(colEl, "min") ?? 0;
821
- col.max = attrNum(colEl, "max") ?? 0;
822
- const w = attrNum(colEl, "width");
823
- if (w !== void 0) col.width = w;
824
- if (attr(colEl, "hidden") === "1") col.hidden = true;
825
- if (attr(colEl, "customWidth") === "1") col.customWidth = true;
826
- const ol = attrNum(colEl, "outlineLevel");
827
- if (ol !== void 0) col.outlineLevel = ol;
828
- if (attr(colEl, "collapsed") === "1") col.collapsed = true;
829
- if (attr(colEl, "bestFit") === "1") col.bestFit = true;
830
- if (attr(colEl, "phonetic") === "1") col.phonetic = true;
831
- columns.push(col);
832
- }
833
- if (columns.length > 0) result.columns = columns;
834
- }
835
- const protEl = findChild(el, "sheetProtection");
836
- if (protEl?.attributes) {
837
- const prot = {};
838
- if (attr(protEl, "password")) prot.password = attr(protEl, "password");
839
- if (attr(protEl, "algorithmName")) prot.algorithmName = attr(protEl, "algorithmName");
840
- if (attr(protEl, "hashValue")) prot.hashValue = attr(protEl, "hashValue");
841
- if (attr(protEl, "saltValue")) prot.saltValue = attr(protEl, "saltValue");
842
- if (attrNum(protEl, "spinCount") !== void 0) prot.spinCount = attrNum(protEl, "spinCount");
843
- if (attr(protEl, "sheet") === "1") prot.sheet = true;
844
- if (attr(protEl, "objects") === "1") prot.objects = true;
845
- if (attr(protEl, "scenarios") === "1") prot.scenarios = true;
846
- if (attr(protEl, "formatCells") === "0") prot.formatCells = false;
847
- if (attr(protEl, "formatColumns") === "0") prot.formatColumns = false;
848
- if (attr(protEl, "formatRows") === "0") prot.formatRows = false;
849
- if (attr(protEl, "insertColumns") === "0") prot.insertColumns = false;
850
- if (attr(protEl, "insertRows") === "0") prot.insertRows = false;
851
- if (attr(protEl, "insertHyperlinks") === "0") prot.insertHyperlinks = false;
852
- if (attr(protEl, "deleteColumns") === "0") prot.deleteColumns = false;
853
- if (attr(protEl, "deleteRows") === "0") prot.deleteRows = false;
854
- if (attr(protEl, "selectLockedCells") === "1") prot.selectLockedCells = true;
855
- if (attr(protEl, "sort") === "0") prot.sort = false;
856
- if (attr(protEl, "autoFilter") === "0") prot.autoFilter = false;
857
- if (attr(protEl, "pivotTables") === "0") prot.pivotTables = false;
858
- if (attr(protEl, "selectUnlockedCells") === "1") prot.selectUnlockedCells = true;
859
- result.protection = prot;
860
- }
861
- const prEl = findChild(el, "protectedRanges");
862
- if (prEl) {
863
- const ranges = [];
864
- for (const rEl of prEl.elements ?? []) {
865
- if (rEl.name !== "protectedRange") continue;
866
- const r = {};
867
- r.sqref = attr(rEl, "sqref") ?? "";
868
- r.name = attr(rEl, "name") ?? "";
869
- if (attr(rEl, "password")) r.password = attr(rEl, "password");
870
- if (attr(rEl, "algorithmName")) r.algorithmName = attr(rEl, "algorithmName");
871
- if (attr(rEl, "hashValue")) r.hashValue = attr(rEl, "hashValue");
872
- if (attr(rEl, "saltValue")) r.saltValue = attr(rEl, "saltValue");
873
- if (attrNum(rEl, "spinCount") !== void 0) r.spinCount = attrNum(rEl, "spinCount");
874
- const sdEl = findChild(rEl, "securityDescriptor");
875
- if (sdEl) r.securityDescriptor = textOf(sdEl);
876
- ranges.push(r);
877
- }
878
- if (ranges.length > 0) result.protectedRanges = ranges;
879
- }
880
- const afEl = findChild(el, "autoFilter");
881
- if (afEl) result.autoFilter = attr(afEl, "ref") ?? "";
882
- const mcEl = findChild(el, "mergeCells");
883
- if (mcEl) {
884
- const merges = [];
885
- for (const mEl of mcEl.elements ?? []) {
886
- if (mEl.name !== "mergeCell") continue;
887
- const parts = (attr(mEl, "ref") ?? "").split(":");
888
- if (parts.length === 2) {
889
- const from = parseCellRef(parts[0]);
890
- const to = parseCellRef(parts[1]);
891
- if (from && to) merges.push({
892
- from,
893
- to
894
- });
895
- }
896
- }
897
- if (merges.length > 0) result.mergeCells = merges;
898
- }
899
- const cfEls = el.elements?.filter((e) => e.name === "conditionalFormatting") ?? [];
900
- if (cfEls.length > 0) {
901
- const cfs = [];
902
- for (const cfEl of cfEls) {
903
- const sqref = attr(cfEl, "sqref") ?? "";
904
- const rules = [];
905
- for (const ruleEl of cfEl.elements ?? []) {
906
- if (ruleEl.name !== "cfRule") continue;
907
- const rule = {};
908
- rule.type = attr(ruleEl, "type");
909
- rule.priority = attrNum(ruleEl, "priority") ?? 1;
910
- if (attr(ruleEl, "operator")) rule.operator = attr(ruleEl, "operator");
911
- const dxfId = attrNum(ruleEl, "dxfId");
912
- if (dxfId !== void 0) rule.dxfId = dxfId;
913
- if (attr(ruleEl, "stopIfTrue") === "1") rule.stopIfTrue = true;
914
- if (attr(ruleEl, "timePeriod")) rule.timePeriod = attr(ruleEl, "timePeriod");
915
- const rank = attrNum(ruleEl, "rank");
916
- if (rank !== void 0) rule.rank = rank;
917
- if (attr(ruleEl, "equalAverage") === "1") rule.equalAverage = true;
918
- const csEl = findChild(ruleEl, "colorScale");
919
- if (csEl) {
920
- const cfvo = [];
921
- const colors = [];
922
- for (const child of csEl.elements ?? []) {
923
- if (child.name === "cfvo") cfvo.push(parseCfvo(child));
924
- if (child.name === "color") {
925
- const rgb = attr(child, "rgb");
926
- if (rgb) colors.push(rgb.length === 8 ? rgb.slice(2) : rgb);
927
- }
928
- }
929
- rule.colorScale = {
930
- cfvo,
931
- colors
932
- };
933
- }
934
- const dbEl = findChild(ruleEl, "dataBar");
935
- if (dbEl) {
936
- const cfvo = [];
937
- let color = "";
938
- for (const child of dbEl.elements ?? []) {
939
- if (child.name === "cfvo") cfvo.push(parseCfvo(child));
940
- if (child.name === "color") {
941
- const rgb = attr(child, "rgb");
942
- if (rgb) color = rgb.length === 8 ? rgb.slice(2) : rgb;
943
- }
944
- }
945
- rule.dataBar = {
946
- cfvo,
947
- color
948
- };
949
- }
950
- const isEl = findChild(ruleEl, "iconSet");
951
- if (isEl) {
952
- const cfvo = [];
953
- for (const child of isEl.elements ?? []) if (child.name === "cfvo") cfvo.push(parseCfvo(child));
954
- const iconSet = { cfvo };
955
- if (attr(isEl, "iconSet")) iconSet.iconSet = attr(isEl, "iconSet");
956
- if (attr(isEl, "showValue") === "0") iconSet.showValue = false;
957
- if (attr(isEl, "percent") === "0") iconSet.percent = false;
958
- if (attr(isEl, "reverse") === "1") iconSet.reverse = true;
959
- rule.iconSet = iconSet;
960
- }
961
- const formulas = [];
962
- for (const child of ruleEl.elements ?? []) if (child.name === "formula") formulas.push(textOf(child) ?? "");
963
- if (formulas.length > 0) rule.formulas = formulas;
964
- rules.push(rule);
965
- }
966
- cfs.push({
967
- sqref,
968
- rules
969
- });
970
- }
971
- result.conditionalFormats = cfs;
972
- }
973
- const dvEl = findChild(el, "dataValidations");
974
- if (dvEl) {
975
- const dvs = [];
976
- for (const dEl of dvEl.elements ?? []) {
977
- if (dEl.name !== "dataValidation") continue;
978
- const dv = {};
979
- dv.sqref = attr(dEl, "sqref") ?? "";
980
- if (attr(dEl, "type")) dv.type = attr(dEl, "type");
981
- if (attr(dEl, "operator")) dv.operator = attr(dEl, "operator");
982
- if (attr(dEl, "allowBlank") === "1") dv.allowBlank = true;
983
- if (attr(dEl, "showErrorMessage") === "1") dv.showErrorMessage = true;
984
- if (attr(dEl, "showInputMessage") === "1") dv.showInputMessage = true;
985
- if (attr(dEl, "errorTitle")) dv.errorTitle = attr(dEl, "errorTitle");
986
- if (attr(dEl, "error")) dv.error = attr(dEl, "error");
987
- if (attr(dEl, "promptTitle")) dv.promptTitle = attr(dEl, "promptTitle");
988
- if (attr(dEl, "prompt")) dv.prompt = attr(dEl, "prompt");
989
- if (attr(dEl, "errorStyle")) dv.errorStyle = attr(dEl, "errorStyle");
990
- if (attr(dEl, "imeMode")) dv.imeMode = attr(dEl, "imeMode");
991
- if (attr(dEl, "showDropDown") === "1") dv.showDropDown = true;
992
- const f1El = findChild(dEl, "formula1");
993
- if (f1El) dv.formula1 = textOf(f1El);
994
- const f2El = findChild(dEl, "formula2");
995
- if (f2El) dv.formula2 = textOf(f2El);
996
- dvs.push(dv);
997
- }
998
- result.dataValidations = dvs;
999
- }
1000
- const hlEl = findChild(el, "hyperlinks");
1001
- if (hlEl) {
1002
- const hyperlinks = [];
1003
- for (const hEl of hlEl.elements ?? []) {
1004
- if (hEl.name !== "hyperlink") continue;
1005
- const hl = {};
1006
- hl.cell = attr(hEl, "ref") ?? "";
1007
- const rId = hEl.attributes?.["r:id"];
1008
- const location = attr(hEl, "location");
1009
- if (rId) hl.target = {
1010
- type: "external",
1011
- url: rId
1012
- };
1013
- else if (location) hl.target = {
1014
- type: "internal",
1015
- location
1016
- };
1017
- if (attr(hEl, "tooltip")) hl.tooltip = attr(hEl, "tooltip");
1018
- if (attr(hEl, "display")) hl.display = attr(hEl, "display");
1019
- hyperlinks.push(hl);
1020
- }
1021
- result.hyperlinks = hyperlinks;
1022
- }
1023
- const poEl = findChild(el, "printOptions");
1024
- if (poEl) {
1025
- const po = {};
1026
- if (attr(poEl, "horizontalCentered") === "1") po.horizontalCentered = true;
1027
- if (attr(poEl, "verticalCentered") === "1") po.verticalCentered = true;
1028
- if (attr(poEl, "headings") === "1") po.headings = true;
1029
- if (attr(poEl, "gridLines") === "1") po.gridLines = true;
1030
- if (attr(poEl, "gridLinesSet") === "0") po.gridLinesSet = false;
1031
- result.printOptions = po;
1032
- }
1033
- const psEl = findChild(el, "pageSetup");
1034
- if (psEl) {
1035
- const ps = {};
1036
- const pz = attrNum(psEl, "paperSize");
1037
- if (pz !== void 0) ps.paperSize = pz;
1038
- if (attr(psEl, "orientation")) ps.orientation = attr(psEl, "orientation");
1039
- const sc = attrNum(psEl, "scale");
1040
- if (sc !== void 0) ps.scale = sc;
1041
- const ftw = attrNum(psEl, "fitToWidth");
1042
- if (ftw !== void 0) ps.fitToWidth = ftw;
1043
- const fth = attrNum(psEl, "fitToHeight");
1044
- if (fth !== void 0) ps.fitToHeight = fth;
1045
- if (attr(psEl, "pageOrder")) ps.pageOrder = attr(psEl, "pageOrder");
1046
- if (attr(psEl, "useFirstPageNumber") === "1") ps.useFirstPageNumber = true;
1047
- const fpn = attrNum(psEl, "firstPageNumber");
1048
- if (fpn !== void 0) ps.firstPageNumber = fpn;
1049
- result.pageSetup = ps;
1050
- }
1051
- const hfEl = findChild(el, "headerFooter");
1052
- if (hfEl) {
1053
- const hf = {};
1054
- if (attr(hfEl, "differentOddEven") === "1") hf.differentOddEven = true;
1055
- if (attr(hfEl, "differentFirst") === "1") hf.differentFirst = true;
1056
- if (attr(hfEl, "scaleWithDoc") === "0") hf.scaleWithDoc = false;
1057
- if (attr(hfEl, "alignWithMargins") === "0") hf.alignWithMargins = false;
1058
- const oh = findChild(hfEl, "oddHeader");
1059
- if (oh) hf.oddHeader = textOf(oh);
1060
- const of2 = findChild(hfEl, "oddFooter");
1061
- if (of2) hf.oddFooter = textOf(of2);
1062
- const eh = findChild(hfEl, "evenHeader");
1063
- if (eh) hf.evenHeader = textOf(eh);
1064
- const ef = findChild(hfEl, "evenFooter");
1065
- if (ef) hf.evenFooter = textOf(ef);
1066
- const fh = findChild(hfEl, "firstHeader");
1067
- if (fh) hf.firstHeader = textOf(fh);
1068
- const ff = findChild(hfEl, "firstFooter");
1069
- if (ff) hf.firstFooter = textOf(ff);
1070
- result.headerFooter = hf;
1071
- }
1072
- const ieEl = findChild(el, "ignoredErrors");
1073
- if (ieEl) {
1074
- const errors = [];
1075
- for (const eEl of ieEl.elements ?? []) {
1076
- if (eEl.name !== "ignoredError") continue;
1077
- const ie = {};
1078
- ie.sqref = attr(eEl, "sqref") ?? "";
1079
- if (attr(eEl, "evalError") === "1") ie.evalError = true;
1080
- if (attr(eEl, "twoDigitTextYear") === "1") ie.twoDigitTextYear = true;
1081
- if (attr(eEl, "numberStoredAsText") === "1") ie.numberStoredAsText = true;
1082
- if (attr(eEl, "formula") === "1") ie.formula = true;
1083
- if (attr(eEl, "formulaRange") === "1") ie.formulaRange = true;
1084
- if (attr(eEl, "unlockedFormula") === "1") ie.unlockedFormula = true;
1085
- if (attr(eEl, "emptyCellReference") === "1") ie.emptyCellReference = true;
1086
- if (attr(eEl, "listDataValidation") === "1") ie.listDataValidation = true;
1087
- if (attr(eEl, "calculatedColumn") === "1") ie.calculatedColumn = true;
1088
- errors.push(ie);
1089
- }
1090
- result.ignoredErrors = errors;
1091
- }
1092
- const ppEl = findChild(el, "phoneticPr");
1093
- if (ppEl) {
1094
- const pp = {};
1095
- pp.fontId = attrNum(ppEl, "fontId") ?? 0;
1096
- if (attr(ppEl, "type")) pp.type = attr(ppEl, "type");
1097
- if (attr(ppEl, "alignment")) pp.alignment = attr(ppEl, "alignment");
1098
- result.phoneticPr = pp;
1099
- }
1100
- const scEl = findChild(el, "sheetCalcPr");
1101
- if (scEl) {
1102
- const sc = {};
1103
- if (attr(scEl, "fullCalcOnLoad") === "1") sc.fullCalcOnLoad = true;
1104
- result.sheetCalcPr = sc;
1105
- }
1106
- const sheetDataEl = findChild(el, "sheetData");
1107
- if (sheetDataEl) {
1108
- const rows = [];
1109
- for (const rowEl of sheetDataEl.elements ?? []) {
1110
- if (rowEl.name !== "row") continue;
1111
- const row = {};
1112
- const rowNumber = attrNum(rowEl, "r");
1113
- if (rowNumber !== void 0) row.rowNumber = rowNumber;
1114
- const ht = attrNum(rowEl, "ht");
1115
- if (ht !== void 0) row.height = ht;
1116
- if (attr(rowEl, "hidden") === "1") row.hidden = true;
1117
- if (attr(rowEl, "spans")) row.spans = attr(rowEl, "spans");
1118
- if (attr(rowEl, "customFormat") === "1") row.customFormat = true;
1119
- if (attr(rowEl, "thickTop") === "1") row.thickTop = true;
1120
- if (attr(rowEl, "thickBot") === "1") row.thickBot = true;
1121
- if (attr(rowEl, "ph") === "1") row.ph = true;
1122
- const cells = [];
1123
- for (const cellEl of rowEl.elements ?? []) {
1124
- if (cellEl.name !== "c") continue;
1125
- const cell = {};
1126
- const ref = attr(cellEl, "r");
1127
- if (ref) cell.reference = ref;
1128
- const type = attr(cellEl, "t");
1129
- const styleIdx = attrNum(cellEl, "s");
1130
- if (styleIdx !== void 0) cell.styleIndex = styleIdx;
1131
- const vEl = findChild(cellEl, "v");
1132
- const isEl = findChild(cellEl, "is");
1133
- if (type === "s" && vEl) cell.value = strings[parseInt(textOf(vEl) ?? "", 10)] ?? "";
1134
- else if (type === "b" && vEl) cell.value = textOf(vEl) === "1";
1135
- else if (type === "inlineStr" && isEl) cell.value = textOf(findChild(isEl, "t")) ?? "";
1136
- else if (vEl) {
1137
- const raw = textOf(vEl) ?? "";
1138
- const num = Number(raw);
1139
- cell.value = isNaN(num) ? raw : num;
1140
- }
1141
- cells.push(cell);
1142
- }
1143
- row.cells = cells;
1144
- rows.push(row);
1145
- }
1146
- if (rows.length > 0) result.rows = rows;
1147
- }
1148
- return result;
1149
- }
1150
- };
1151
- /**
1152
- * Build the complete worksheet XML string.
1153
- *
1154
- * Zero-allocation fast path: directly concatenates XML string,
1155
- * bypassing the IXmlableObject intermediate tree entirely.
1156
- */
1157
- function stringifyWorksheet(opts, ctx) {
1158
- const sharedStrings = ctx.sharedStrings;
1159
- const styles = ctx.styles;
1160
- const rows = opts.rows ?? [];
1161
- const columns = opts.columns ?? [];
1162
- const mergeCells = opts.mergeCells ?? [];
1163
- const protectedRanges = opts.protectedRanges ?? [];
1164
- const ignoredErrors = opts.ignoredErrors ?? [];
1165
- const rowBreaks = opts.rowBreaks ?? [];
1166
- const colBreaks = opts.colBreaks ?? [];
1167
- const customSheetViews = opts.customSheetViews ?? [];
1168
- const cellWatches = opts.cellWatches ?? [];
1169
- const controls = opts.controls ?? [];
1170
- const customProperties = opts.customProperties ?? [];
1171
- const oleObjects = opts.oleObjects ?? [];
1172
- const webPublishItems = opts.webPublishItems ?? [];
1173
- const p = ["<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"x14ac xr xr2 xr3\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" xmlns:xr=\"http://schemas.microsoft.com/office/spreadsheetml/2014/revision\" xmlns:xr2=\"http://schemas.microsoft.com/office/spreadsheetml/2015/revision2\" xmlns:xr3=\"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3\">"];
1174
- const hasTabColor = !!opts.tabColor;
1175
- const hasOutline = columns.some((c) => c.outlineLevel !== void 0);
1176
- const sp = opts.sheetPr;
1177
- const hasSheetPrAttrs = sp && (sp.syncHorizontal || sp.syncVertical || sp.syncRef || sp.transitionEvaluation || sp.transitionEntry || sp.published || sp.filterMode || sp.enableFormatConditionsCalculation);
1178
- if (hasTabColor || hasOutline || hasSheetPrAttrs) {
1179
- const prParts = [];
1180
- const prAttrs = {};
1181
- if (sp?.syncHorizontal) prAttrs.syncHorizontal = 1;
1182
- if (sp?.syncVertical) prAttrs.syncVertical = 1;
1183
- if (sp?.syncRef) prAttrs.syncRef = sp.syncRef;
1184
- if (sp?.transitionEvaluation) prAttrs.transitionEvaluation = 1;
1185
- if (sp?.transitionEntry) prAttrs.transitionEntry = 1;
1186
- if (sp?.published) prAttrs.published = 1;
1187
- if (sp?.filterMode) prAttrs.filterMode = 1;
1188
- if (sp?.enableFormatConditionsCalculation) prAttrs.enableFormatConditionsCalculation = 1;
1189
- if (opts.tabColor) {
1190
- const tc = opts.tabColor;
1191
- const tcAttrs = {};
1192
- if (tc.rgb) tcAttrs.rgb = tc.rgb;
1193
- if (tc.theme !== void 0) tcAttrs.theme = tc.theme;
1194
- if (tc.tint !== void 0) tcAttrs.tint = tc.tint;
1195
- if (tc.indexed !== void 0) tcAttrs.indexed = tc.indexed;
1196
- prParts.push(`<tabColor${attrs(tcAttrs)}/>`);
1197
- }
1198
- if (hasOutline) {
1199
- const outAttrs = {
1200
- summaryBelow: 1,
1201
- summaryRight: 1
1202
- };
1203
- if (sp?.outlineApplyStyles) outAttrs.applyStyles = 1;
1204
- if (sp?.outlineShowSymbols === false) outAttrs.showOutlineSymbols = 0;
1205
- prParts.push(`<outlinePr${attrs(outAttrs)}/>`);
1206
- }
1207
- if (opts.pageSetup?.fitToWidth || opts.pageSetup?.fitToHeight || opts.pageSetup?.autoPageBreaks) {
1208
- const psupAttrs = {};
1209
- if (opts.pageSetup?.fitToWidth || opts.pageSetup?.fitToHeight) psupAttrs.fitToPage = 1;
1210
- if (opts.pageSetup?.autoPageBreaks) psupAttrs.autoPageBreaks = 1;
1211
- prParts.push(`<pageSetUpPr${attrs(psupAttrs)}/>`);
1212
- }
1213
- const prAttrStr = Object.keys(prAttrs).length > 0 ? attrs(prAttrs) : "";
1214
- p.push(`<sheetPr${prAttrStr}>${prParts.join("")}</sheetPr>`);
1215
- }
1216
- const maxRow = rows.length;
1217
- let maxCol = 0;
1218
- for (const row of rows) if (row.cells && row.cells.length > maxCol) maxCol = row.cells.length;
1219
- if (maxRow > 0 && maxCol > 0) {
1220
- const dimRef = `A1:${defaultCellRef(maxRow, maxCol)}`;
1221
- p.push(`<dimension ref="${dimRef}"/>`);
1222
- }
1223
- const pivotSelXml = opts.sheetView?.pivotSelections ? opts.sheetView.pivotSelections.map((ps) => buildPivotSelectionXml(ps)).join("") : "";
1224
- if (opts.freezePanes) {
1225
- const fp = opts.freezePanes;
1226
- const ySplit = fp.row ? fp.row : 0;
1227
- const xSplit = fp.col ? fp.col : 0;
1228
- const topLeftCell = defaultCellRef(fp.row ? fp.row + 1 : 1, fp.col ? fp.col + 1 : 1);
1229
- const activePane = ySplit > 0 && xSplit > 0 ? "bottomRight" : ySplit > 0 ? "bottomLeft" : "topRight";
1230
- const svAttrs = buildSheetViewAttrs(opts.sheetView);
1231
- p.push(`<sheetViews><sheetView${svAttrs}>`, `<pane ySplit="${ySplit}" xSplit="${xSplit}" topLeftCell="${topLeftCell}" activePane="${activePane}" state="frozen"/>`, opts.selection ? buildSelectionXml(opts.selection) : "", pivotSelXml, "</sheetView></sheetViews>");
1232
- } else {
1233
- const svAttrs = buildSheetViewAttrs(opts.sheetView);
1234
- const innerXml = (opts.selection ? buildSelectionXml(opts.selection) : "") + pivotSelXml;
1235
- if (innerXml) p.push(`<sheetViews><sheetView${svAttrs}>${innerXml}</sheetView></sheetViews>`);
1236
- else p.push(`<sheetViews><sheetView${svAttrs}/></sheetViews>`);
1237
- }
1238
- if (opts.sheetFormatPr) {
1239
- const sfp = opts.sheetFormatPr;
1240
- const sfpAttrs = {};
1241
- if (sfp.baseColWidth !== void 0) sfpAttrs.baseColWidth = sfp.baseColWidth;
1242
- if (sfp.defaultColWidth !== void 0) sfpAttrs.defaultColWidth = sfp.defaultColWidth;
1243
- sfpAttrs.defaultRowHeight = sfp.defaultRowHeight ?? 15;
1244
- if (sfp.zeroHeight) sfpAttrs.zeroHeight = 1;
1245
- if (sfp.thickTop) sfpAttrs.thickTop = 1;
1246
- if (sfp.thickBottom) sfpAttrs.thickBottom = 1;
1247
- if (sfp.outlineLevelRow !== void 0) sfpAttrs.outlineLevelRow = sfp.outlineLevelRow;
1248
- if (sfp.outlineLevelCol !== void 0) sfpAttrs.outlineLevelCol = sfp.outlineLevelCol;
1249
- p.push(`<sheetFormatPr${attrs(sfpAttrs)}/>`);
1250
- } else p.push("<sheetFormatPr defaultRowHeight=\"15\"/>");
1251
- if (columns.length > 0) {
1252
- p.push("<cols>");
1253
- for (const col of columns) {
1254
- const colAttrs = {
1255
- min: col.min,
1256
- max: col.max
1257
- };
1258
- if (col.width !== void 0) {
1259
- colAttrs.width = col.width;
1260
- colAttrs.customWidth = 1;
1261
- }
1262
- if (col.hidden) colAttrs.hidden = 1;
1263
- if (col.outlineLevel !== void 0) colAttrs.outlineLevel = col.outlineLevel;
1264
- if (col.collapsed) colAttrs.collapsed = 1;
1265
- if (col.bestFit) colAttrs.bestFit = 1;
1266
- if (col.phonetic) colAttrs.phonetic = 1;
1267
- p.push(selfCloseElement("col", attrs(colAttrs)));
1268
- }
1269
- p.push("</cols>");
1270
- }
1271
- p.push("<sheetData>");
1272
- for (let i = 0; i < rows.length; i++) {
1273
- const rowOpts = rows[i];
1274
- const rowNumber = rowOpts.rowNumber ?? i + 1;
1275
- const rowAttrs = { r: rowNumber };
1276
- if (rowOpts.height !== void 0) {
1277
- rowAttrs.ht = rowOpts.height;
1278
- rowAttrs.customHeight = 1;
1279
- }
1280
- if (rowOpts.hidden) rowAttrs.hidden = 1;
1281
- if (rowOpts.spans) rowAttrs.spans = rowOpts.spans;
1282
- if (rowOpts.customFormat) rowAttrs.customFormat = 1;
1283
- if (rowOpts.thickTop) rowAttrs.thickTop = 1;
1284
- if (rowOpts.thickBot) rowAttrs.thickBot = 1;
1285
- if (rowOpts.ph) rowAttrs.ph = 1;
1286
- if (rowOpts.cells) {
1287
- const rowParts = [];
1288
- for (let j = 0; j < rowOpts.cells.length; j++) {
1289
- const cell = rowOpts.cells[j];
1290
- const cellStr = buildCellString(cell.reference ?? defaultCellRef(rowNumber, j + 1), cell, sharedStrings, styles);
1291
- if (cellStr) rowParts.push(cellStr);
1292
- }
1293
- p.push(`<row${attrs(rowAttrs)}>`, ...rowParts, "</row>");
1294
- } else p.push(`<row${attrs(rowAttrs)}/>`);
1295
- }
1296
- p.push("</sheetData>");
1297
- if (opts.sheetCalcPr) {
1298
- const scAttrs = [];
1299
- if (opts.sheetCalcPr.fullCalcOnLoad) scAttrs.push("fullCalcOnLoad=\"1\"");
1300
- p.push(`<sheetCalcPr${scAttrs.length ? " " + scAttrs.join(" ") : ""}/>`);
1301
- }
1302
- if (rowBreaks.length > 0) {
1303
- const brkParts = rowBreaks.map((b) => {
1304
- const bAttrs = { id: b.id };
1305
- if (b.min !== void 0) bAttrs.min = b.min;
1306
- if (b.max !== void 0) bAttrs.max = b.max;
1307
- if (b.manual) bAttrs.man = 1;
1308
- if (b.pivot) bAttrs.pt = 1;
1309
- return `<brk${attrs(bAttrs)}/>`;
1310
- });
1311
- p.push(`<rowBreaks count="${rowBreaks.length}" manualBreakCount="${rowBreaks.filter((b) => b.manual).length}">${brkParts.join("")}</rowBreaks>`);
1312
- }
1313
- if (colBreaks.length > 0) {
1314
- const brkParts = colBreaks.map((b) => {
1315
- const bAttrs = { id: b.id };
1316
- if (b.min !== void 0) bAttrs.min = b.min;
1317
- if (b.max !== void 0) bAttrs.max = b.max;
1318
- if (b.manual) bAttrs.man = 1;
1319
- if (b.pivot) bAttrs.pt = 1;
1320
- return `<brk${attrs(bAttrs)}/>`;
1321
- });
1322
- p.push(`<colBreaks count="${colBreaks.length}" manualBreakCount="${colBreaks.filter((b) => b.manual).length}">${brkParts.join("")}</colBreaks>`);
1323
- }
1324
- if (customProperties.length > 0) {
1325
- const cpParts = ["<customProperties>"];
1326
- for (const cp of customProperties) cpParts.push(`<customPr name="${escapeXml(cp.name)}" r:id="${escapeXml(cp.rId)}"/>`);
1327
- cpParts.push("</customProperties>");
1328
- p.push(cpParts.join(""));
1329
- }
1330
- if (opts.oleSize) p.push(`<oleSize ref="${escapeXml(opts.oleSize)}"/>`);
1331
- if (customSheetViews.length > 0) {
1332
- p.push("<customSheetViews>");
1333
- for (const csv of customSheetViews) {
1334
- const csvAttrs = { guid: csv.guid };
1335
- if (csv.scale !== void 0) csvAttrs.scale = csv.scale;
1336
- if (csv.showPageBreaks) csvAttrs.showPageBreaks = 1;
1337
- if (csv.showFormulas) csvAttrs.showFormulas = 1;
1338
- if (csv.showGridLines === false) csvAttrs.showGridLines = 0;
1339
- if (csv.showRowColHeaders === false) csvAttrs.showRowCol = 0;
1340
- if (csv.outlineSymbols === false) csvAttrs.outlineSymbols = 0;
1341
- if (csv.zeroValues === false) csvAttrs.zeroValues = 0;
1342
- if (csv.fitToPage) csvAttrs.fitToPage = 1;
1343
- if (csv.printArea) csvAttrs.printArea = 1;
1344
- if (csv.filter) csvAttrs.filter = 1;
1345
- if (csv.showAutoFilter) csvAttrs.showAutoFilter = 1;
1346
- if (csv.hiddenRows) csvAttrs.hiddenRows = 1;
1347
- if (csv.hiddenColumns) csvAttrs.hiddenColumns = 1;
1348
- if (csv.state && csv.state !== "visible") csvAttrs.state = csv.state;
1349
- if (csv.filterUnique) csvAttrs.filterUnique = 1;
1350
- if (csv.view && csv.view !== "normal") csvAttrs.view = csv.view;
1351
- p.push(`<customSheetView${attrs(csvAttrs)}/>`);
1352
- }
1353
- p.push("</customSheetViews>");
1354
- }
1355
- if (cellWatches.length > 0) {
1356
- p.push("<cellWatches>");
1357
- for (const cw of cellWatches) p.push(`<cellWatch r="${escapeXml(cw.r)}"/>`);
1358
- p.push("</cellWatches>");
1359
- }
1360
- if (opts.dataConsolidate) {
1361
- const dc = opts.dataConsolidate;
1362
- const dcAttrs = {};
1363
- if (dc.function && dc.function !== "sum") dcAttrs.function = dc.function;
1364
- if (dc.topLabels) dcAttrs.topLabels = 1;
1365
- if (dc.leftLabels) dcAttrs.leftLabels = 1;
1366
- if (dc.startLabels) dcAttrs.startLabels = 1;
1367
- if (dc.link) dcAttrs.link = 1;
1368
- const refsInner = dc.refs?.map((r) => `<dataRef ref="${escapeXml(r)}"/>`).join("") ?? "";
1369
- const refsXml = refsInner ? `<dataRefs>${refsInner}</dataRefs>` : "";
1370
- if (refsXml || Object.keys(dcAttrs).length > 0) p.push(`<dataConsolidate${attrs(dcAttrs)}>${refsXml}</dataConsolidate>`);
1371
- }
1372
- if (opts.protection) {
1373
- const prot = opts.protection;
1374
- const protAttrs = {};
1375
- if (prot.password) protAttrs.password = hashPassword(prot.password);
1376
- let derived;
1377
- if (prot.password !== void 0 && prot.hashValue === void 0) derived = derivePasswordHash(prot.password);
1378
- protAttrs.algorithmName = prot.algorithmName ?? derived?.algorithmName;
1379
- protAttrs.hashValue = prot.hashValue ?? derived?.hashValue;
1380
- protAttrs.saltValue = prot.saltValue ?? derived?.saltValue;
1381
- if (prot.spinCount !== void 0) protAttrs.spinCount = prot.spinCount;
1382
- else if (derived) protAttrs.spinCount = derived.spinCount;
1383
- if (prot.sheet) protAttrs.sheet = 1;
1384
- if (prot.objects) protAttrs.objects = 1;
1385
- if (prot.scenarios) protAttrs.scenarios = 1;
1386
- if (prot.formatCells === false) protAttrs.formatCells = 0;
1387
- if (prot.formatColumns === false) protAttrs.formatColumns = 0;
1388
- if (prot.formatRows === false) protAttrs.formatRows = 0;
1389
- if (prot.insertColumns === false) protAttrs.insertColumns = 0;
1390
- if (prot.insertRows === false) protAttrs.insertRows = 0;
1391
- if (prot.insertHyperlinks === false) protAttrs.insertHyperlinks = 0;
1392
- if (prot.deleteColumns === false) protAttrs.deleteColumns = 0;
1393
- if (prot.deleteRows === false) protAttrs.deleteRows = 0;
1394
- if (prot.selectLockedCells) protAttrs.selectLockedCells = 1;
1395
- if (prot.sort === false) protAttrs.sort = 0;
1396
- if (prot.autoFilter === false) protAttrs.autoFilter = 0;
1397
- if (prot.pivotTables === false) protAttrs.pivotTables = 0;
1398
- if (prot.selectUnlockedCells) protAttrs.selectUnlockedCells = 1;
1399
- p.push(selfCloseElement("sheetProtection", attrs(protAttrs)));
1400
- }
1401
- if (protectedRanges.length > 0) {
1402
- const prParts = ["<protectedRanges>"];
1403
- for (const pr of protectedRanges) {
1404
- const prAttrs = {
1405
- name: pr.name,
1406
- sqref: pr.sqref
1407
- };
1408
- if (pr.password) prAttrs.password = hashPassword(pr.password);
1409
- let prDerived;
1410
- if (pr.password !== void 0 && pr.hashValue === void 0) prDerived = derivePasswordHash(pr.password);
1411
- prAttrs.algorithmName = pr.algorithmName ?? prDerived?.algorithmName;
1412
- prAttrs.hashValue = pr.hashValue ?? prDerived?.hashValue;
1413
- prAttrs.saltValue = pr.saltValue ?? prDerived?.saltValue;
1414
- if (pr.spinCount !== void 0) prAttrs.spinCount = pr.spinCount;
1415
- else if (prDerived) prAttrs.spinCount = prDerived.spinCount;
1416
- if (!!pr.securityDescriptor) prParts.push(`<protectedRange${attrs(prAttrs)}><securityDescriptor>${escapeXml(pr.securityDescriptor)}</securityDescriptor></protectedRange>`);
1417
- else prParts.push(selfCloseElement("protectedRange", attrs(prAttrs)));
1418
- }
1419
- prParts.push("</protectedRanges>");
1420
- p.push(prParts.join(""));
1421
- }
1422
- if (opts.scenarios) {
1423
- const scParts = ["<scenarios"];
1424
- const scAttrs = {};
1425
- if (opts.scenarios.current !== void 0) scAttrs.current = opts.scenarios.current;
1426
- if (opts.scenarios.show !== void 0) scAttrs.show = opts.scenarios.show;
1427
- scParts[0] = `<scenarios${attrs(scAttrs)}>`;
1428
- for (const scenario of opts.scenarios.scenarios) {
1429
- const sAttrs = { name: scenario.name };
1430
- if (scenario.count !== void 0) sAttrs.count = scenario.count;
1431
- if (scenario.user) sAttrs.user = scenario.user;
1432
- if (scenario.comment) sAttrs.comment = scenario.comment;
1433
- if (scenario.hidden) sAttrs.hidden = true;
1434
- if (scenario.locked) sAttrs.locked = true;
1435
- const sParts = [`<scenario${attrs(sAttrs)}>`];
1436
- for (const cell of scenario.inputCells) {
1437
- const icAttrs = {
1438
- r: cell.r,
1439
- val: String(cell.val)
1440
- };
1441
- if (cell.deleted) icAttrs.deleted = true;
1442
- if (cell.undone) icAttrs.undone = true;
1443
- sParts.push(`<inputCells${attrs(icAttrs)}/>`);
1444
- }
1445
- sParts.push("</scenario>");
1446
- scParts.push(sParts.join(""));
1447
- }
1448
- scParts.push("</scenarios>");
1449
- p.push(scParts.join(""));
1450
- }
1451
- if (opts.autoFilter) if (typeof opts.autoFilter === "string") p.push(selfCloseElement("autoFilter", attrs({ ref: opts.autoFilter })));
1452
- else {
1453
- const af = opts.autoFilter;
1454
- const inner = [];
1455
- for (const t10 of af.top10 ?? []) {
1456
- const fcAttrs = { colId: t10.colId };
1457
- if (t10.hiddenButton) fcAttrs.hiddenButton = 1;
1458
- if (t10.showButton === false) fcAttrs.showButton = 0;
1459
- const t10Attrs = { val: t10.val };
1460
- if (t10.top === false) t10Attrs.top = 0;
1461
- if (t10.percent) t10Attrs.percent = 1;
1462
- if (t10.filterVal !== void 0) t10Attrs.filterVal = t10.filterVal;
1463
- inner.push(`<filterColumn${attrs(fcAttrs)}><top10${attrs(t10Attrs)}/></filterColumn>`);
1464
- }
1465
- for (const cf of af.customFilters ?? []) {
1466
- const fcAttrs = { colId: cf.colId };
1467
- if (cf.hiddenButton) fcAttrs.hiddenButton = 1;
1468
- if (cf.showButton === false) fcAttrs.showButton = 0;
1469
- const cfAttrs = {};
1470
- if (cf.and) cfAttrs.and = 1;
1471
- const filters = [];
1472
- if (cf.val !== void 0) {
1473
- const fAttrs = { val: cf.val };
1474
- if (cf.operator) fAttrs.operator = cf.operator;
1475
- filters.push(selfCloseElement("customFilter", attrs(fAttrs)));
1476
- }
1477
- if (cf.val2 !== void 0) filters.push(selfCloseElement("customFilter", attrs({ val: cf.val2 })));
1478
- if (filters.length > 0) inner.push(`<filterColumn${attrs(fcAttrs)}><customFilters${attrs(cfAttrs)}>${filters.join("")}</customFilters></filterColumn>`);
1479
- }
1480
- for (const fi of af.filters ?? []) {
1481
- const fcAttrs = { colId: fi.colId };
1482
- const filtersAttrs = {};
1483
- if (fi.blank) filtersAttrs.blank = 1;
1484
- if (fi.calendarType) filtersAttrs.calendarType = fi.calendarType;
1485
- const valParts = (fi.values ?? []).map((v) => `<filter val="${escapeXml(v)}"/>`);
1486
- inner.push(`<filterColumn${attrs(fcAttrs)}><filters${attrs(filtersAttrs)}>${valParts.join("")}</filters></filterColumn>`);
1487
- }
1488
- if (af.sort && af.sort.length > 0) {
1489
- const sortParts = [];
1490
- for (const sc of af.sort) {
1491
- const scAttrs = { ref: sc.ref };
1492
- if (sc.descending) scAttrs.descending = 1;
1493
- if (sc.sortBy) scAttrs.sortBy = sc.sortBy;
1494
- if (sc.customList) scAttrs.customList = sc.customList;
1495
- if (sc.iconId !== void 0) scAttrs.iconId = sc.iconId;
1496
- sortParts.push(selfCloseElement("sortCondition", attrs(scAttrs)));
1497
- }
1498
- const ssAttrs = { ref: af.ref };
1499
- if (af.sortState?.columnSort) ssAttrs.columnSort = 1;
1500
- if (af.sortState?.caseSensitive) ssAttrs.caseSensitive = 1;
1501
- if (af.sortState?.sortMethod) ssAttrs.sortMethod = af.sortState.sortMethod;
1502
- inner.push(`<sortState${attrs(ssAttrs)}>${sortParts.join("")}</sortState>`);
1503
- }
1504
- for (const cf of af.colorFilters ?? []) {
1505
- const cfAttrs = {};
1506
- if (cf.dxfId !== void 0) cfAttrs.dxfId = cf.dxfId;
1507
- if (cf.cellColor === false) cfAttrs.cellColor = 0;
1508
- inner.push(`<filterColumn colId="${cf.colId}"><colorFilter${attrs(cfAttrs)}/></filterColumn>`);
1509
- }
1510
- for (const if_ of af.iconFilters ?? []) {
1511
- const ifAttrs = { iconSet: if_.iconSet };
1512
- if (if_.iconId !== void 0) ifAttrs.iconId = if_.iconId;
1513
- inner.push(`<filterColumn colId="${if_.colId}"><iconFilter${attrs(ifAttrs)}/></filterColumn>`);
1514
- }
1515
- for (const df of af.dynamicFilters ?? []) {
1516
- const dfAttrs = { type: df.type };
1517
- if (df.val !== void 0) dfAttrs.val = df.val;
1518
- if (df.maxVal !== void 0) dfAttrs.maxVal = df.maxVal;
1519
- if (df.valIso !== void 0) dfAttrs.valIso = df.valIso;
1520
- if (df.maxValIso !== void 0) dfAttrs.maxValIso = df.maxValIso;
1521
- inner.push(`<filterColumn colId="${df.colId}"><dynamicFilter${attrs(dfAttrs)}/></filterColumn>`);
1522
- }
1523
- for (const dg of af.dateGroupItems ?? []) {
1524
- const dgAttrs = { dateTimeGrouping: dg.dateTimeGrouping };
1525
- if (dg.year !== void 0) dgAttrs.year = dg.year;
1526
- if (dg.month !== void 0) dgAttrs.month = dg.month;
1527
- if (dg.day !== void 0) dgAttrs.day = dg.day;
1528
- if (dg.hour !== void 0) dgAttrs.hour = dg.hour;
1529
- if (dg.minute !== void 0) dgAttrs.minute = dg.minute;
1530
- if (dg.second !== void 0) dgAttrs.second = dg.second;
1531
- inner.push(`<filterColumn colId="${dg.colId}"><dateGroupItem${attrs(dgAttrs)}/></filterColumn>`);
1532
- }
1533
- if (inner.length > 0) p.push(`<autoFilter ref="${af.ref}">`, ...inner, "</autoFilter>");
1534
- else p.push(selfCloseElement("autoFilter", attrs({ ref: af.ref })));
1535
- }
1536
- if (mergeCells.length > 0) {
1537
- p.push(`<mergeCells count="${mergeCells.length}">`);
1538
- for (const mc of mergeCells) {
1539
- const fromRef = defaultCellRef(mc.from.row, mc.from.col);
1540
- const toRef = defaultCellRef(mc.to.row, mc.to.col);
1541
- p.push(selfCloseElement("mergeCell", attrs({ ref: `${fromRef}:${toRef}` })));
1542
- }
1543
- p.push("</mergeCells>");
1544
- }
1545
- if (opts.phoneticPr) {
1546
- const pp = opts.phoneticPr;
1547
- const ppAttrs = { fontId: pp.fontId };
1548
- if (pp.type && pp.type !== "fullwidthKatakana") ppAttrs.type = pp.type;
1549
- if (pp.alignment && pp.alignment !== "left") ppAttrs.alignment = pp.alignment;
1550
- p.push(selfCloseElement("phoneticPr", attrs(ppAttrs)));
1551
- }
1552
- const conditionalFormats = opts.conditionalFormats ?? [];
1553
- if (conditionalFormats.length > 0) for (const cf of conditionalFormats) {
1554
- p.push(`<conditionalFormatting sqref="${cf.sqref}">`);
1555
- for (let ri = 0; ri < cf.rules.length; ri++) {
1556
- const rule = cf.rules[ri];
1557
- const ruleAttrs = {
1558
- type: rule.type,
1559
- priority: rule.priority ?? ri + 1
1560
- };
1561
- if (rule.operator) ruleAttrs.operator = rule.operator;
1562
- if (rule.dxfId !== void 0) ruleAttrs.dxfId = rule.dxfId;
1563
- if (rule.stopIfTrue) ruleAttrs.stopIfTrue = 1;
1564
- if (rule.timePeriod) ruleAttrs.timePeriod = rule.timePeriod;
1565
- if (rule.rank !== void 0) ruleAttrs.rank = rule.rank;
1566
- if (rule.equalAverage) ruleAttrs.equalAverage = 1;
1567
- if (rule.type === "colorScale" && rule.colorScale) {
1568
- const cs = rule.colorScale;
1569
- const inner = [];
1570
- for (const v of cs.cfvo) inner.push(buildCfvoXml(v));
1571
- for (const c of cs.colors) inner.push(`<color rgb="FF${c}"/>`);
1572
- p.push(`<cfRule${attrs(ruleAttrs)}><colorScale>${inner.join("")}</colorScale></cfRule>`);
1573
- } else if (rule.type === "dataBar" && rule.dataBar) {
1574
- const db = rule.dataBar;
1575
- const inner = [];
1576
- for (const v of db.cfvo) inner.push(buildCfvoXml(v));
1577
- inner.push(`<color rgb="FF${db.color}"/>`);
1578
- const dbAttrs = {};
1579
- if (db.minLength !== void 0 && db.minLength !== 10) dbAttrs.minLength = db.minLength;
1580
- if (db.maxLength !== void 0 && db.maxLength !== 90) dbAttrs.maxLength = db.maxLength;
1581
- if (db.showValue === false) dbAttrs.showValue = 0;
1582
- const attrStr = Object.keys(dbAttrs).length > 0 ? attrs(dbAttrs) : "";
1583
- p.push(`<cfRule${attrs(ruleAttrs)}><dataBar${attrStr}>${inner.join("")}</dataBar></cfRule>`);
1584
- } else if (rule.type === "iconSet" && rule.iconSet) {
1585
- const is = rule.iconSet;
1586
- const inner = [];
1587
- for (const v of is.cfvo) inner.push(buildCfvoXml(v));
1588
- const isAttrs = {};
1589
- if (is.iconSet !== void 0 && is.iconSet !== "3TrafficLights1") isAttrs.iconSet = is.iconSet;
1590
- if (is.showValue === false) isAttrs.showValue = 0;
1591
- if (is.percent === false) isAttrs.percent = 0;
1592
- if (is.reverse) isAttrs.reverse = 1;
1593
- const attrStr = Object.keys(isAttrs).length > 0 ? attrs(isAttrs) : "";
1594
- p.push(`<cfRule${attrs(ruleAttrs)}><iconSet${attrStr}>${inner.join("")}</iconSet></cfRule>`);
1595
- } else if (rule.formulas && rule.formulas.length > 0) {
1596
- const formulaParts = rule.formulas.map((f) => `<formula>${escapeXml(f)}</formula>`);
1597
- p.push(`<cfRule${attrs(ruleAttrs)}>`, ...formulaParts, "</cfRule>");
1598
- } else p.push(selfCloseElement("cfRule", attrs(ruleAttrs)));
1599
- }
1600
- p.push("</conditionalFormatting>");
1601
- }
1602
- const dataValidations = opts.dataValidations ?? [];
1603
- if (dataValidations.length > 0) {
1604
- const dvContainerAttrs = { count: dataValidations.length };
1605
- if (opts.dataValidationsDisablePrompts) dvContainerAttrs.disablePrompts = 1;
1606
- p.push(`<dataValidations${attrs(dvContainerAttrs)}>`);
1607
- for (const dv of dataValidations) {
1608
- const dvAttrs = { sqref: dv.sqref };
1609
- if (dv.type && dv.type !== "none") dvAttrs.type = dv.type;
1610
- if (dv.operator) dvAttrs.operator = dv.operator;
1611
- if (dv.allowBlank) dvAttrs.allowBlank = 1;
1612
- if (dv.showErrorMessage) dvAttrs.showErrorMessage = 1;
1613
- if (dv.showInputMessage) dvAttrs.showInputMessage = 1;
1614
- if (dv.errorTitle) dvAttrs.errorTitle = dv.errorTitle;
1615
- if (dv.error) dvAttrs.error = dv.error;
1616
- if (dv.promptTitle) dvAttrs.promptTitle = dv.promptTitle;
1617
- if (dv.prompt) dvAttrs.prompt = dv.prompt;
1618
- if (dv.errorStyle) dvAttrs.errorStyle = dv.errorStyle;
1619
- if (dv.imeMode) dvAttrs.imeMode = dv.imeMode;
1620
- if (dv.showDropDown) dvAttrs.showDropDown = 1;
1621
- const inner = [];
1622
- if (dv.formula1 !== void 0) inner.push(`<formula1>${escapeXml(dv.formula1)}</formula1>`);
1623
- if (dv.formula2 !== void 0) inner.push(`<formula2>${escapeXml(dv.formula2)}</formula2>`);
1624
- if (inner.length > 0) p.push(`<dataValidation${attrs(dvAttrs)}>`, ...inner, "</dataValidation>");
1625
- else p.push(selfCloseElement("dataValidation", attrs(dvAttrs)));
1626
- }
1627
- p.push("</dataValidations>");
1628
- }
1629
- const hyperlinks = opts.hyperlinks ?? [];
1630
- if (hyperlinks.length > 0) {
1631
- p.push("<hyperlinks>");
1632
- let hlIdx = 0;
1633
- for (const hl of hyperlinks) {
1634
- const hlAttrs = { ref: hl.cell };
1635
- if (hl.target.type === "external") {
1636
- hlIdx++;
1637
- hlAttrs["r:id"] = `rId${hlIdx}`;
1638
- } else hlAttrs.location = hl.target.location;
1639
- if (hl.tooltip) hlAttrs.tooltip = hl.tooltip;
1640
- if (hl.display) hlAttrs.display = hl.display;
1641
- p.push(selfCloseElement("hyperlink", attrs(hlAttrs)));
1642
- }
1643
- p.push("</hyperlinks>");
1644
- }
1645
- if (opts.printOptions) {
1646
- const po = opts.printOptions;
1647
- const poAttrs = {};
1648
- if (po.horizontalCentered) poAttrs.horizontalCentered = 1;
1649
- if (po.verticalCentered) poAttrs.verticalCentered = 1;
1650
- if (po.headings) poAttrs.headings = 1;
1651
- if (po.gridLines) poAttrs.gridLines = 1;
1652
- if (po.gridLinesSet === false) poAttrs.gridLinesSet = 0;
1653
- p.push(selfCloseElement("printOptions", attrs(poAttrs)));
1654
- }
1655
- p.push("<pageMargins left=\"0.75\" right=\"0.75\" top=\"1\" bottom=\"1\" header=\"0.5\" footer=\"0.5\"/>");
1656
- if (opts.pageSetup) {
1657
- const ps = opts.pageSetup;
1658
- const psAttrs = {};
1659
- if (ps.paperSize !== void 0) psAttrs.paperSize = ps.paperSize;
1660
- if (ps.orientation && ps.orientation !== "default") psAttrs.orientation = ps.orientation;
1661
- if (ps.scale !== void 0) psAttrs.scale = ps.scale;
1662
- if (ps.fitToWidth !== void 0) psAttrs.fitToWidth = ps.fitToWidth;
1663
- if (ps.fitToHeight !== void 0) psAttrs.fitToHeight = ps.fitToHeight;
1664
- if (ps.pageOrder && ps.pageOrder !== "downThenOver") psAttrs.pageOrder = ps.pageOrder;
1665
- if (ps.useFirstPageNumber) psAttrs.useFirstPageNumber = 1;
1666
- if (ps.firstPageNumber !== void 0) psAttrs.firstPageNumber = ps.firstPageNumber;
1667
- if (ps.paperHeight !== void 0) psAttrs.paperHeight = ps.paperHeight;
1668
- if (ps.paperWidth !== void 0) psAttrs.paperWidth = ps.paperWidth;
1669
- if (ps.usePrinterDefaults) psAttrs.usePrinterDefaults = 1;
1670
- if (ps.blackAndWhite) psAttrs.blackAndWhite = 1;
1671
- if (ps.draft) psAttrs.draft = 1;
1672
- if (ps.cellComments && ps.cellComments !== "none") psAttrs.cellComments = ps.cellComments;
1673
- if (ps.errors && ps.errors !== "displayed") psAttrs.errors = ps.errors;
1674
- p.push(selfCloseElement("pageSetup", attrs(psAttrs)));
1675
- }
1676
- if (opts.headerFooter) {
1677
- const hf = opts.headerFooter;
1678
- const hfAttrs = {};
1679
- if (hf.differentOddEven) hfAttrs.differentOddEven = 1;
1680
- if (hf.differentFirst) hfAttrs.differentFirst = 1;
1681
- if (hf.scaleWithDoc === false) hfAttrs.scaleWithDoc = 0;
1682
- if (hf.alignWithMargins === false) hfAttrs.alignWithMargins = 0;
1683
- const inner = [];
1684
- if (hf.oddHeader) inner.push(`<oddHeader>${escapeXml(hf.oddHeader)}</oddHeader>`);
1685
- if (hf.oddFooter) inner.push(`<oddFooter>${escapeXml(hf.oddFooter)}</oddFooter>`);
1686
- if (hf.evenHeader) inner.push(`<evenHeader>${escapeXml(hf.evenHeader)}</evenHeader>`);
1687
- if (hf.evenFooter) inner.push(`<evenFooter>${escapeXml(hf.evenFooter)}</evenFooter>`);
1688
- if (hf.firstHeader) inner.push(`<firstHeader>${escapeXml(hf.firstHeader)}</firstHeader>`);
1689
- if (hf.firstFooter) inner.push(`<firstFooter>${escapeXml(hf.firstFooter)}</firstFooter>`);
1690
- if (inner.length > 0) p.push(`<headerFooter${attrs(hfAttrs)}>`, ...inner, "</headerFooter>");
1691
- else if (hfAttrs.differentOddEven || hfAttrs.differentFirst) p.push(selfCloseElement("headerFooter", attrs(hfAttrs)));
1692
- }
1693
- if (opts.drawingHF) {
1694
- const dhf = opts.drawingHF;
1695
- const dhfAttrs = { "r:id": dhf.rId };
1696
- if (dhf.lho !== void 0) dhfAttrs.lho = dhf.lho;
1697
- if (dhf.lhe !== void 0) dhfAttrs.lhe = dhf.lhe;
1698
- if (dhf.lhf !== void 0) dhfAttrs.lhf = dhf.lhf;
1699
- if (dhf.cho !== void 0) dhfAttrs.cho = dhf.cho;
1700
- if (dhf.che !== void 0) dhfAttrs.che = dhf.che;
1701
- if (dhf.chf !== void 0) dhfAttrs.chf = dhf.chf;
1702
- if (dhf.rho !== void 0) dhfAttrs.rho = dhf.rho;
1703
- if (dhf.rhe !== void 0) dhfAttrs.rhe = dhf.rhe;
1704
- if (dhf.rhf !== void 0) dhfAttrs.rhf = dhf.rhf;
1705
- if (dhf.lfo !== void 0) dhfAttrs.lfo = dhf.lfo;
1706
- if (dhf.lfe !== void 0) dhfAttrs.lfe = dhf.lfe;
1707
- if (dhf.lff !== void 0) dhfAttrs.lff = dhf.lff;
1708
- if (dhf.cfo !== void 0) dhfAttrs.cfo = dhf.cfo;
1709
- if (dhf.cfe !== void 0) dhfAttrs.cfe = dhf.cfe;
1710
- if (dhf.cff !== void 0) dhfAttrs.cff = dhf.cff;
1711
- if (dhf.rfo !== void 0) dhfAttrs.rfo = dhf.rfo;
1712
- if (dhf.rfe !== void 0) dhfAttrs.rfe = dhf.rfe;
1713
- if (dhf.rff !== void 0) dhfAttrs.rff = dhf.rff;
1714
- p.push(selfCloseElement("drawingHF", attrs(dhfAttrs)));
1715
- }
1716
- if (opts.legacyDrawingHF) p.push(`<legacyDrawingHF r:id="${escapeXml(opts.legacyDrawingHF)}"/>`);
1717
- if (ignoredErrors.length > 0) {
1718
- const ieParts = ["<ignoredErrors>"];
1719
- for (const ie of ignoredErrors) {
1720
- const ieAttrs = { sqref: ie.sqref };
1721
- if (ie.evalError) ieAttrs.evalError = 1;
1722
- if (ie.twoDigitTextYear) ieAttrs.twoDigitTextYear = 1;
1723
- if (ie.numberStoredAsText) ieAttrs.numberStoredAsText = 1;
1724
- if (ie.formula) ieAttrs.formula = 1;
1725
- if (ie.formulaRange) ieAttrs.formulaRange = 1;
1726
- if (ie.unlockedFormula) ieAttrs.unlockedFormula = 1;
1727
- if (ie.emptyCellReference) ieAttrs.emptyCellReference = 1;
1728
- if (ie.listDataValidation) ieAttrs.listDataValidation = 1;
1729
- if (ie.calculatedColumn) ieAttrs.calculatedColumn = 1;
1730
- ieParts.push(selfCloseElement("ignoredError", attrs(ieAttrs)));
1731
- }
1732
- ieParts.push("</ignoredErrors>");
1733
- p.push(ieParts.join(""));
1734
- }
1735
- if (opts.backgroundImage) p.push("<!--BACKGROUND_PICTURE-->");
1736
- if (oleObjects.length > 0) {
1737
- const oleParts = ["<oleObjects>"];
1738
- for (const ole of oleObjects) {
1739
- const oleAttrs = [`shapeId="${ole.shapeId}"`];
1740
- if (ole.progId) oleAttrs.push(`progId="${escapeXml(ole.progId)}"`);
1741
- if (ole.dvAspect && ole.dvAspect !== "DVASPECT_CONTENT") oleAttrs.push(`dvAspect="${ole.dvAspect}"`);
1742
- if (ole.link) oleAttrs.push(`link="${escapeXml(ole.link)}"`);
1743
- if (ole.oleUpdate) oleAttrs.push(`oleUpdate="${ole.oleUpdate}"`);
1744
- if (ole.autoLoad) oleAttrs.push("autoLoad=\"1\"");
1745
- if (ole.rId) oleAttrs.push(`r:id="${escapeXml(ole.rId)}"`);
1746
- if (ole.objectPr) {
1747
- const opr = ole.objectPr;
1748
- const oprAttrs = [];
1749
- if (opr.locked === false) oprAttrs.push("locked=\"0\"");
1750
- if (opr.defaultSize === false) oprAttrs.push("defaultSize=\"0\"");
1751
- if (opr.print === false) oprAttrs.push("print=\"0\"");
1752
- if (opr.disabled) oprAttrs.push("disabled=\"1\"");
1753
- if (opr.uiObject) oprAttrs.push("uiObject=\"1\"");
1754
- if (opr.autoFill === false) oprAttrs.push("autoFill=\"0\"");
1755
- if (opr.autoLine === false) oprAttrs.push("autoLine=\"0\"");
1756
- if (opr.autoPict === false) oprAttrs.push("autoPict=\"0\"");
1757
- if (opr.macro) oprAttrs.push(`macro="${escapeXml(opr.macro)}"`);
1758
- if (opr.altText) oprAttrs.push(`altText="${escapeXml(opr.altText)}"`);
1759
- if (opr.dde) oprAttrs.push("dde=\"1\"");
1760
- if (opr.rId) oprAttrs.push(`r:id="${escapeXml(opr.rId)}"`);
1761
- oleParts.push(`<oleObject ${oleAttrs.join(" ")}><objectPr${oprAttrs.length ? " " + oprAttrs.join(" ") : ""}/></oleObject>`);
1762
- } else oleParts.push(`<oleObject ${oleAttrs.join(" ")}/>`);
1763
- }
1764
- oleParts.push("</oleObjects>");
1765
- p.push(oleParts.join(""));
1766
- }
1767
- if (controls.length > 0) {
1768
- const ctrlParts = ["<controls>"];
1769
- for (const c of controls) {
1770
- const cAttrs = [`shapeId="${c.shapeId}"`, `r:id="${escapeXml(c.rId)}"`];
1771
- if (c.name) cAttrs.push(`name="${escapeXml(c.name)}"`);
1772
- const prAttrs = [];
1773
- if (c.locked === false) prAttrs.push("locked=\"0\"");
1774
- if (c.uiObject) prAttrs.push("uiObject=\"1\"");
1775
- if (c.recalcAlways) prAttrs.push("recalcAlways=\"1\"");
1776
- if (c.linkedCell) prAttrs.push(`linkedCell="${escapeXml(c.linkedCell)}"`);
1777
- if (c.listFillRange) prAttrs.push(`listFillRange="${escapeXml(c.listFillRange)}"`);
1778
- if (c.cf) prAttrs.push(`cf="${escapeXml(c.cf)}"`);
1779
- if (prAttrs.length > 0) ctrlParts.push(`<control ${cAttrs.join(" ")}><controlPr${prAttrs.length ? " " + prAttrs.join(" ") : ""}/></control>`);
1780
- else ctrlParts.push(`<control ${cAttrs.join(" ")}/>`);
1781
- }
1782
- ctrlParts.push("</controls>");
1783
- p.push(ctrlParts.join(""));
1784
- }
1785
- if (webPublishItems.length > 0) {
1786
- const wpParts = [`<webPublishItems count="${webPublishItems.length}">`];
1787
- for (const wpi of webPublishItems) {
1788
- const wpiAttrs = [
1789
- `id="${wpi.id}"`,
1790
- `divId="${escapeXml(wpi.divId)}"`,
1791
- `sourceType="${wpi.sourceType}"`,
1792
- `destinationFile="${escapeXml(wpi.destinationFile)}"`
1793
- ];
1794
- if (wpi.sourceRef) wpiAttrs.push(`sourceRef="${escapeXml(wpi.sourceRef)}"`);
1795
- if (wpi.sourceObject) wpiAttrs.push(`sourceObject="${escapeXml(wpi.sourceObject)}"`);
1796
- if (wpi.title) wpiAttrs.push(`title="${escapeXml(wpi.title)}"`);
1797
- if (wpi.autoRepublish) wpiAttrs.push("autoRepublish=\"1\"");
1798
- wpParts.push(`<webPublishItem ${wpiAttrs.join(" ")}/>`);
1799
- }
1800
- wpParts.push("</webPublishItems>");
1801
- p.push(wpParts.join(""));
1802
- }
1803
- if (opts.ext) p.push(`<extLst>${opts.ext}</extLst>`);
1804
- p.push("</worksheet>");
1805
- return p.join("");
1806
- }
1807
- function buildCfvoXml(cfvo) {
1808
- const a = { type: cfvo.type };
1809
- if (cfvo.val !== void 0) a.val = cfvo.val;
1810
- if (cfvo.gte === false) a.gte = 0;
1811
- return `<cfvo${attrs(a)}/>`;
1812
- }
1813
- function buildSheetViewAttrs(sv) {
1814
- const svMap = { workbookViewId: 0 };
1815
- if (sv?.tabSelected !== void 0) svMap.tabSelected = sv.tabSelected ? 1 : 0;
1816
- else svMap.tabSelected = 1;
1817
- if (sv?.showGridLines === false) svMap.showGridLines = 0;
1818
- if (sv?.showRowColHeaders === false) svMap.showRowColHeaders = 0;
1819
- if (sv?.showZeros === false) svMap.showZeros = 0;
1820
- if (sv?.zoomScale !== void 0) svMap.zoomScale = sv.zoomScale;
1821
- if (sv?.rightToLeft) svMap.rightToLeft = 1;
1822
- if (sv?.windowProtection) svMap.windowProtection = 1;
1823
- if (sv?.showFormulas) svMap.showFormulas = 1;
1824
- if (sv?.showRuler === false) svMap.showRuler = 0;
1825
- if (sv?.showOutlineSymbols === false) svMap.showOutlineSymbols = 0;
1826
- if (sv?.defaultGridColor === false) svMap.defaultGridColor = 0;
1827
- if (sv?.showWhiteSpace === false) svMap.showWhiteSpace = 0;
1828
- if (sv?.view) svMap.view = sv.view;
1829
- if (sv?.colorId !== void 0) svMap.colorId = sv.colorId;
1830
- if (sv?.zoomScaleNormal !== void 0) svMap.zoomScaleNormal = sv.zoomScaleNormal;
1831
- if (sv?.zoomScaleSheetLayoutView !== void 0) svMap.zoomScaleSheetLayoutView = sv.zoomScaleSheetLayoutView;
1832
- if (sv?.zoomScalePageLayoutView !== void 0) svMap.zoomScalePageLayoutView = sv.zoomScalePageLayoutView;
1833
- return attrs(svMap);
1834
- }
1835
- function buildSelectionXml(sel) {
1836
- const selAttrs = {};
1837
- if (sel.pane) selAttrs.pane = sel.pane;
1838
- if (sel.activeCell) selAttrs.activeCell = sel.activeCell;
1839
- if (sel.activeCellId !== void 0) selAttrs.activeCellId = sel.activeCellId;
1840
- if (sel.sqref) selAttrs.sqref = sel.sqref;
1841
- return `<selection${attrs(selAttrs)}/>`;
1842
- }
1843
- function buildPivotSelectionXml(_ps) {
1844
- return "";
1845
- }
1846
- function hashPassword(password) {
1847
- let hash = 0;
1848
- for (let i = 0; i < password.length; i++) {
1849
- const c = password.charCodeAt(i);
1850
- hash = (hash >> 14 & 1) + (hash << 1 & 32767);
1851
- hash ^= c;
1852
- hash = hash & 16384 ? hash ^ 1 : hash;
1853
- }
1854
- hash = (hash >> 14 & 1) + (hash << 1 & 32767);
1855
- hash = (hash >> 14 & 1) + (hash << 1 & 32767);
1856
- hash ^= password.length;
1857
- return hash.toString(16).toUpperCase().padStart(4, "0");
1858
- }
1859
- function buildFormulaString(fOpts) {
1860
- const fAttrs = {};
1861
- if (fOpts.type && fOpts.type !== FormulaType.NORMAL) fAttrs.t = fOpts.type;
1862
- if (fOpts.reference) fAttrs.ref = fOpts.reference;
1863
- if (fOpts.sharedIndex !== void 0) fAttrs.si = fOpts.sharedIndex;
1864
- if (fOpts.aca) fAttrs.aca = 1;
1865
- if (fOpts.dt2D) fAttrs.dt2D = 1;
1866
- if (fOpts.dtr) fAttrs.dtr = 1;
1867
- if (fOpts.del1) fAttrs.del1 = 1;
1868
- if (fOpts.del2) fAttrs.del2 = 1;
1869
- if (fOpts.r1) fAttrs.r1 = fOpts.r1;
1870
- if (fOpts.r2) fAttrs.r2 = fOpts.r2;
1871
- if (fOpts.ca) fAttrs.ca = 1;
1872
- if (fOpts.bx) fAttrs.bx = 1;
1873
- if (fOpts.formula !== void 0 && fOpts.formula !== "") return `<f${attrs(fAttrs)}>${escapeXml(fOpts.formula)}</f>`;
1874
- if (Object.keys(fAttrs).length > 0) return selfCloseElement("f", attrs(fAttrs));
1875
- return "";
1876
- }
1877
- function buildCellString(ref, cell, sharedStrings, styles) {
1878
- const cellAttrs = { r: ref };
1879
- if (cell.style !== void 0 && styles) cellAttrs.s = styles.register(cell.style);
1880
- else if (cell.styleIndex !== void 0) cellAttrs.s = cell.styleIndex;
1881
- const value = cell.value;
1882
- if (cell.formula) {
1883
- const fStr = buildFormulaString(cell.formula);
1884
- let vStr = "";
1885
- if (value === null || value === void 0) return `<c${attrs(cellAttrs)}>${fStr}</c>`;
1886
- if (typeof value === "number") vStr = `<v>${value}</v>`;
1887
- else if (typeof value === "boolean") {
1888
- cellAttrs.t = "b";
1889
- vStr = `<v>${value ? 1 : 0}</v>`;
1890
- } else if (typeof value === "string") {
1891
- cellAttrs.t = "str";
1892
- vStr = `<v>${escapeXml(value)}</v>`;
1893
- } else if (value instanceof Date) vStr = `<v>${dateToSerialNumber(value)}</v>`;
1894
- if (vStr) return `<c${attrs(cellAttrs)}>${fStr}${vStr}</c>`;
1895
- return `<c${attrs(cellAttrs)}>${fStr}</c>`;
1896
- }
1897
- if (value === null || value === void 0) {
1898
- if (cell.styleIndex !== void 0) return selfCloseElement("c", attrs(cellAttrs));
1899
- return "";
1900
- }
1901
- if (typeof value === "object" && !(value instanceof Date)) {
1902
- if (sharedStrings) {
1903
- cellAttrs.t = "s";
1904
- const idx = sharedStrings.registerRich(value);
1905
- return `<c${attrs(cellAttrs)}><v>${idx}</v></c>`;
1906
- }
1907
- cellAttrs.t = "inlineStr";
1908
- return `<c${attrs(cellAttrs)}><is>${buildRstXml(value)}</is></c>`;
1909
- }
1910
- if (typeof value === "string") {
1911
- if (sharedStrings) {
1912
- cellAttrs.t = "s";
1913
- const idx = sharedStrings.register(value);
1914
- return `<c${attrs(cellAttrs)}><v>${idx}</v></c>`;
1915
- }
1916
- cellAttrs.t = "inlineStr";
1917
- return `<c${attrs(cellAttrs)}><is><t>${escapeXml(value)}</t></is></c>`;
1918
- }
1919
- if (typeof value === "number") return `<c${attrs(cellAttrs)}><v>${value}</v></c>`;
1920
- if (typeof value === "boolean") {
1921
- cellAttrs.t = "b";
1922
- return `<c${attrs(cellAttrs)}><v>${value ? 1 : 0}</v></c>`;
1923
- }
1924
- if (value instanceof Date) {
1925
- const serial = dateToSerialNumber(value);
1926
- return `<c${attrs(cellAttrs)}><v>${serial}</v></c>`;
1927
- }
1928
- return "";
1929
- }
1930
- function defaultCellRef(row, col) {
1931
- return columnToLetter(col) + row;
1932
- }
1933
- function columnToLetter(col) {
1934
- let result = "";
1935
- let n = col;
1936
- while (n > 0) {
1937
- const remainder = (n - 1) % 26;
1938
- result = String.fromCharCode(65 + remainder) + result;
1939
- n = Math.floor((n - 1) / 26);
1940
- }
1941
- return result;
1942
- }
1943
- function dateToSerialNumber(date) {
1944
- const epoch = new Date(1899, 11, 30);
1945
- return (date.getTime() - epoch.getTime()) / 864e5;
1946
- }
1947
- function parseCfvo(el) {
1948
- const result = {};
1949
- result.type = attr(el, "type") ?? "num";
1950
- const val = attr(el, "val");
1951
- if (val !== void 0) result.val = isNaN(Number(val)) ? val : Number(val);
1952
- if (attr(el, "gte") === "0") result.gte = false;
1953
- return result;
1954
- }
1955
- function parseCellRef(ref) {
1956
- const match = ref.match(/^([A-Z]+)(\d+)$/);
1957
- if (!match) return void 0;
1958
- const colStr = match[1];
1959
- const row = parseInt(match[2], 10);
1960
- let col = 0;
1961
- for (let i = 0; i < colStr.length; i++) col = col * 26 + (colStr.charCodeAt(i) - 64);
1962
- return {
1963
- row,
1964
- col
1965
- };
1966
- }
1967
- //#endregion
1968
- //#region src/parts/content-types.ts
1969
- /**
1970
- * Content Types module for XLSX packages.
1971
- *
1972
- * @module
1973
- */
1974
- const XLSX_MAIN = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
1975
- const XLSX_WORKSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
1976
- const XLSX_CHARTSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml";
1977
- const XLSX_STYLES = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml";
1978
- const XLSX_SHARED_STRINGS = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml";
1979
- const XLSX_THEME = "application/vnd.openxmlformats-officedocument.theme+xml";
1980
- const XLSX_CHART = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml";
1981
- const STATIC_XML = [
1982
- {
1983
- type: "Default",
1984
- contentType: "application/vnd.openxmlformats-package.relationships+xml",
1985
- key: "rels"
1986
- },
1987
- {
1988
- type: "Default",
1989
- contentType: "application/xml",
1990
- key: "xml"
1991
- },
1992
- {
1993
- type: "Override",
1994
- contentType: XLSX_MAIN,
1995
- key: "/xl/workbook.xml"
1996
- },
1997
- {
1998
- type: "Override",
1999
- contentType: "application/vnd.openxmlformats-package.core-properties+xml",
2000
- key: "/docProps/core.xml"
2001
- },
2002
- {
2003
- type: "Override",
2004
- contentType: "application/vnd.openxmlformats-officedocument.extended-properties+xml",
2005
- key: "/docProps/app.xml"
2006
- }
2007
- ].map((e) => e.type === "Default" ? `<Default ContentType="${e.contentType}" Extension="${e.key}"/>` : `<Override ContentType="${e.contentType}" PartName="${e.key}"/>`).join("");
2008
- var ContentTypes = class {
2009
- dynamicEntries = [];
2010
- addWorksheet(index) {
2011
- this.dynamicEntries.push({
2012
- type: "Override",
2013
- contentType: XLSX_WORKSHEET,
2014
- key: `/xl/worksheets/sheet${index}.xml`
2015
- });
2016
- }
2017
- addChartsheet(index) {
2018
- this.dynamicEntries.push({
2019
- type: "Override",
2020
- contentType: XLSX_CHARTSHEET,
2021
- key: `/xl/chartsheets/sheet${index}.xml`
2022
- });
2023
- }
2024
- addStyles() {
2025
- this.dynamicEntries.push({
2026
- type: "Override",
2027
- contentType: XLSX_STYLES,
2028
- key: "/xl/styles.xml"
2029
- });
2030
- }
2031
- addSharedStrings() {
2032
- this.dynamicEntries.push({
2033
- type: "Override",
2034
- contentType: XLSX_SHARED_STRINGS,
2035
- key: "/xl/sharedStrings.xml"
2036
- });
2037
- }
2038
- addTheme(index = 1) {
2039
- this.dynamicEntries.push({
2040
- type: "Override",
2041
- contentType: XLSX_THEME,
2042
- key: `/xl/theme/theme${index}.xml`
2043
- });
2044
- }
2045
- addChart(index) {
2046
- this.dynamicEntries.push({
2047
- type: "Override",
2048
- contentType: XLSX_CHART,
2049
- key: `/xl/charts/chart${index}.xml`
2050
- });
2051
- }
2052
- addDrawing(index) {
2053
- this.dynamicEntries.push({
2054
- type: "Override",
2055
- contentType: "application/vnd.openxmlformats-officedocument.drawing+xml",
2056
- key: `/xl/drawings/drawing${index}.xml`
2057
- });
2058
- }
2059
- addComments(index) {
2060
- this.dynamicEntries.push({
2061
- type: "Override",
2062
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
2063
- key: `/xl/comments${index}.xml`
2064
- });
2065
- }
2066
- addVmlDrawing() {
2067
- if (this.dynamicEntries.some((e) => e.type === "Default" && e.key === "vml")) return;
2068
- this.dynamicEntries.push({
2069
- type: "Default",
2070
- contentType: "application/vnd.openxmlformats-officedocument.vmlDrawing",
2071
- key: "vml"
2072
- });
2073
- }
2074
- addImageType(extension) {
2075
- const contentType = extension === "png" ? "image/png" : "image/jpeg";
2076
- if (this.dynamicEntries.some((e) => e.type === "Default" && e.key === extension)) return;
2077
- this.dynamicEntries.push({
2078
- type: "Default",
2079
- contentType,
2080
- key: extension
2081
- });
2082
- }
2083
- addPivotTable(index) {
2084
- this.dynamicEntries.push({
2085
- type: "Override",
2086
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",
2087
- key: `/xl/pivotTables/pivotTable${index}.xml`
2088
- });
2089
- }
2090
- addPivotCacheDefinition(index) {
2091
- this.dynamicEntries.push({
2092
- type: "Override",
2093
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
2094
- key: `/xl/pivotCache/pivotCacheDefinition${index}.xml`
2095
- });
2096
- }
2097
- addPivotCacheRecords(index) {
2098
- this.dynamicEntries.push({
2099
- type: "Override",
2100
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml",
2101
- key: `/xl/pivotCache/pivotCacheRecords${index}.xml`
2102
- });
2103
- }
2104
- addTable(index) {
2105
- this.dynamicEntries.push({
2106
- type: "Override",
2107
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",
2108
- key: `/xl/tables/table${index}.xml`
2109
- });
2110
- }
2111
- addExternalLink(index) {
2112
- this.dynamicEntries.push({
2113
- type: "Override",
2114
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml",
2115
- key: `/xl/externalLinks/externalLink${index}.xml`
2116
- });
2117
- }
2118
- addCalcChain() {
2119
- this.dynamicEntries.push({
2120
- type: "Override",
2121
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml",
2122
- key: "/xl/calcChain.xml"
2123
- });
2124
- }
2125
- addDialogsheet(index) {
2126
- this.dynamicEntries.push({
2127
- type: "Override",
2128
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml",
2129
- key: `/xl/dialogsheets/sheet${index}.xml`
2130
- });
2131
- }
2132
- addRevisionHeaders() {
2133
- this.dynamicEntries.push({
2134
- type: "Override",
2135
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.revisionHeaders+xml",
2136
- key: "/xl/revisionHeaders.xml"
2137
- });
2138
- }
2139
- addRevisionLog(index) {
2140
- this.dynamicEntries.push({
2141
- type: "Override",
2142
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.revisionLog+xml",
2143
- key: `/xl/revisions/revision${index}.xml`
2144
- });
2145
- }
2146
- addQueryTable(index) {
2147
- this.dynamicEntries.push({
2148
- type: "Override",
2149
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.queryTable+xml",
2150
- key: `/xl/queryTables/queryTable${index}.xml`
2151
- });
2152
- }
2153
- addMetadata() {
2154
- this.dynamicEntries.push({
2155
- type: "Override",
2156
- contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",
2157
- key: "/xl/metadata.xml"
2158
- });
2159
- }
2160
- serialize() {
2161
- const p = ["<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">", STATIC_XML];
2162
- for (const e of this.dynamicEntries) if (e.type === "Default") p.push(`<Default ContentType="${e.contentType}" Extension="${e.key}"/>`);
2163
- else p.push(`<Override ContentType="${e.contentType}" PartName="${e.key}"/>`);
2164
- p.push("</Types>");
2165
- return p.join("");
2166
- }
2167
- };
2168
- //#endregion
2169
- //#region src/parts/media.ts
2170
- var Media = class {
2171
- map = /* @__PURE__ */ new Map();
2172
- addImage(key, data) {
2173
- this.map.set(key, data);
2174
- }
2175
- get array() {
2176
- return [...this.map.values()];
2177
- }
2178
- };
2179
- //#endregion
2180
- //#region src/context.ts
2181
- /**
2182
- * XLSX compile context — write and read contexts for the descriptor pipeline.
2183
- *
2184
- * @module
2185
- */
2186
- /**
2187
- * XLSX-specific write context.
2188
- *
2189
- * Holds mutable state that accumulates during the compile phase:
2190
- * shared strings, styles, media, charts, content types, and relationships.
2191
- */
2192
- var XlsxWriteContext = class {
2193
- sharedStrings = new SharedStrings();
2194
- styles = new Styles();
2195
- media = new Media();
2196
- charts = new ChartCollection();
2197
- contentTypes = new ContentTypes();
2198
- workbookRels = new Relationships();
2199
- pivotCacheRefs = [];
2200
- addRelationship(type, target, _mode) {
2201
- const id = this.workbookRels.relationshipCount + 1;
2202
- this.workbookRels.addRelationship(id, type, target);
2203
- return `rId${id}`;
2204
- }
2205
- addMedia(_data, _type) {
2206
- return "";
2207
- }
2208
- /**
2209
- * Register a differential format and return its dxfId.
2210
- */
2211
- registerDxf(opts) {
2212
- return this.styles.registerDxf(opts);
2213
- }
2214
- };
2215
- /**
2216
- * XLSX-specific read context.
2217
- *
2218
- * Wraps an {@link XlsxDocument} to implement the core {@link ReadContext}
2219
- * interface used by the descriptor parse pipeline.
2220
- */
2221
- var XlsxReadContext = class {
2222
- xlsx;
2223
- /** Parsed shared strings for resolving cell values. */
2224
- sharedStrings;
2225
- constructor(xlsx, sharedStrings) {
2226
- this.xlsx = xlsx;
2227
- this.sharedStrings = sharedStrings ?? [];
2228
- }
2229
- resolveRelationship(rId) {
2230
- const wbRels = this.xlsx.doc.get("xl/_rels/workbook.xml.rels");
2231
- if (!wbRels?.elements) return void 0;
2232
- for (const child of wbRels.elements) {
2233
- if (child.name !== "Relationship") continue;
2234
- if (child.attributes?.["Id"] === rId) {
2235
- const target = child.attributes["Target"];
2236
- if (!target) return void 0;
2237
- return target.startsWith("/") ? target.slice(1) : `xl/${target}`;
2238
- }
2239
- }
2240
- }
2241
- getPart(path) {
2242
- return this.xlsx.doc.get(path);
2243
- }
2244
- getRaw(path) {
2245
- return this.xlsx.doc.getRaw(path);
2246
- }
2247
- };
2248
- //#endregion
2249
- export { Styles as a, sharedStringsDesc as c, worksheetDesc as i, XlsxWriteContext as n, stylesDesc as o, stringifyWorksheet as r, SharedStrings as s, XlsxReadContext as t };
2250
-
2251
- //# sourceMappingURL=context-a1lzscdy.mjs.map