@office-open/xlsx 0.9.8 → 0.10.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.
- package/dist/comments-CIu-wLTT.mjs +1727 -0
- package/dist/comments-CIu-wLTT.mjs.map +1 -0
- package/dist/{context-D6f14vKV.mjs → context-Cru_79gz.mjs} +514 -1639
- package/dist/context-Cru_79gz.mjs.map +1 -0
- package/dist/file-ATgsKghI.d.mts +515 -0
- package/dist/file-ATgsKghI.d.mts.map +1 -0
- package/dist/{generate-DS-qtz9W.mjs → generate-CXy-A9Hp.mjs} +54 -10
- package/dist/generate-CXy-A9Hp.mjs.map +1 -0
- package/dist/generate.d.mts +1 -1
- package/dist/generate.mjs +1 -1
- package/dist/index.d.mts +7 -216
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -4
- package/dist/index.mjs.map +1 -1
- package/dist/parse.d.mts +2 -1
- package/dist/parse.d.mts.map +1 -1
- package/dist/parse.mjs +65 -4
- package/dist/parse.mjs.map +1 -1
- package/dist/patch.d.mts +20 -22
- package/dist/patch.d.mts.map +1 -1
- package/dist/patch.mjs +398 -23
- package/dist/patch.mjs.map +1 -1
- package/dist/{file-DDaqjg-B.d.mts → worksheet-DgjBJg_S.d.mts} +8 -313
- package/dist/worksheet-DgjBJg_S.d.mts.map +1 -0
- package/package.json +3 -3
- package/dist/context-D6f14vKV.mjs.map +0 -1
- package/dist/file-DDaqjg-B.d.mts.map +0 -1
- package/dist/generate-DS-qtz9W.mjs.map +0 -1
|
@@ -0,0 +1,1727 @@
|
|
|
1
|
+
import { attr, attrMeasure, attrNum, attrs, attrsRaw, escapeXml, findChild, selfCloseElement, textOf } from "@office-open/xml";
|
|
2
|
+
import { 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$1(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
|
+
/**
|
|
69
|
+
* Bulk-load parsed template entries, preserving their original indices so
|
|
70
|
+
* existing cell references stay valid. Plain strings populate the dedup map
|
|
71
|
+
* (first occurrence wins); rich-text entries are appended unchanged.
|
|
72
|
+
*
|
|
73
|
+
* Used by patch to extend an existing workbook's shared strings, so appended
|
|
74
|
+
* worksheets continue registering strings at the correct offset.
|
|
75
|
+
*/
|
|
76
|
+
loadEntries(entries) {
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
const idx = this.entries.length;
|
|
79
|
+
this.entries.push(entry);
|
|
80
|
+
if (typeof entry === "string" && !this.indexMap.has(entry)) this.indexMap.set(entry, idx);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
get count() {
|
|
84
|
+
return this.entries.length;
|
|
85
|
+
}
|
|
86
|
+
/** Return a serializable snapshot for the descriptor. */
|
|
87
|
+
toDescriptorOptions() {
|
|
88
|
+
return {
|
|
89
|
+
entries: this.entries,
|
|
90
|
+
uniqueCount: this.indexMap.size
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Serialize to xl/sharedStrings.xml content (without XML declaration). */
|
|
94
|
+
serialize() {
|
|
95
|
+
const p = ["<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"", ` count="${this.entries.length}" uniqueCount="${this.indexMap.size}">`];
|
|
96
|
+
for (const entry of this.entries) if (typeof entry === "string") p.push(`<si><t>${escapeXml(entry)}</t></si>`);
|
|
97
|
+
else p.push(`<si>${buildRstXml$1(entry)}</si>`);
|
|
98
|
+
p.push("</sst>");
|
|
99
|
+
return p.join("");
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const sharedStringsDesc = {
|
|
103
|
+
kind: "custom",
|
|
104
|
+
stringify(opts, _ctx) {
|
|
105
|
+
if (opts.entries.length === 0) return void 0;
|
|
106
|
+
const p = ["<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"", ` count="${opts.entries.length}" uniqueCount="${opts.uniqueCount}">`];
|
|
107
|
+
for (const entry of opts.entries) if (typeof entry === "string") p.push(`<si><t>${escapeXml(entry)}</t></si>`);
|
|
108
|
+
else p.push(`<si>${buildRstXml$1(entry)}</si>`);
|
|
109
|
+
p.push("</sst>");
|
|
110
|
+
return p.join("");
|
|
111
|
+
},
|
|
112
|
+
parse(el, _ctx) {
|
|
113
|
+
const entries = [];
|
|
114
|
+
for (const si of el.elements ?? []) {
|
|
115
|
+
if (si.name !== "si") continue;
|
|
116
|
+
const t = findChild(si, "t");
|
|
117
|
+
if (t) {
|
|
118
|
+
entries.push(textOf(t) ?? "");
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const runs = [];
|
|
122
|
+
for (const r of si.elements ?? []) {
|
|
123
|
+
if (r.name !== "r") continue;
|
|
124
|
+
const rt = findChild(r, "t");
|
|
125
|
+
if (rt) {
|
|
126
|
+
const rPrEl = findChild(r, "rPr");
|
|
127
|
+
const run = { text: textOf(rt) ?? "" };
|
|
128
|
+
if (rPrEl) run.properties = parseRPr(rPrEl);
|
|
129
|
+
runs.push(run);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const phonetics = [];
|
|
133
|
+
for (const rPh of si.elements ?? []) {
|
|
134
|
+
if (rPh.name !== "rPh") continue;
|
|
135
|
+
const sb = attrNum(rPh, "sb") ?? 0;
|
|
136
|
+
const eb = attrNum(rPh, "eb") ?? 0;
|
|
137
|
+
const rPhT = findChild(rPh, "t");
|
|
138
|
+
phonetics.push({
|
|
139
|
+
sb,
|
|
140
|
+
eb,
|
|
141
|
+
text: rPhT ? textOf(rPhT) ?? "" : ""
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (runs.length > 0) {
|
|
145
|
+
const entry = { runs };
|
|
146
|
+
if (phonetics.length > 0) entry.phonetics = phonetics;
|
|
147
|
+
entries.push(entry);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
entries,
|
|
152
|
+
uniqueCount: entries.length
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
/** Parse CT_RPrElt (run properties inside shared strings r element). */
|
|
157
|
+
function parseRPr(el) {
|
|
158
|
+
const result = {};
|
|
159
|
+
for (const child of el.elements ?? []) switch (child.name) {
|
|
160
|
+
case "rFont":
|
|
161
|
+
result.font = attr(child, "val") ?? void 0;
|
|
162
|
+
break;
|
|
163
|
+
case "charset":
|
|
164
|
+
result.charset = attrNum(child, "val");
|
|
165
|
+
break;
|
|
166
|
+
case "family":
|
|
167
|
+
result.family = attrNum(child, "val");
|
|
168
|
+
break;
|
|
169
|
+
case "b":
|
|
170
|
+
result.bold = attr(child, "val") !== "0";
|
|
171
|
+
break;
|
|
172
|
+
case "i":
|
|
173
|
+
result.italic = attr(child, "val") !== "0";
|
|
174
|
+
break;
|
|
175
|
+
case "strike":
|
|
176
|
+
result.strike = true;
|
|
177
|
+
break;
|
|
178
|
+
case "outline":
|
|
179
|
+
result.outline = true;
|
|
180
|
+
break;
|
|
181
|
+
case "shadow":
|
|
182
|
+
result.shadow = true;
|
|
183
|
+
break;
|
|
184
|
+
case "condense":
|
|
185
|
+
result.condense = true;
|
|
186
|
+
break;
|
|
187
|
+
case "extend":
|
|
188
|
+
result.extend = true;
|
|
189
|
+
break;
|
|
190
|
+
case "color": {
|
|
191
|
+
const rgb = attr(child, "rgb");
|
|
192
|
+
if (rgb) result.color = rgb.length === 8 ? rgb.slice(2) : rgb;
|
|
193
|
+
else {
|
|
194
|
+
const indexed = attrNum(child, "indexed");
|
|
195
|
+
if (indexed !== void 0) result.color = String(indexed);
|
|
196
|
+
else {
|
|
197
|
+
const theme = attr(child, "theme");
|
|
198
|
+
if (theme !== void 0) result.color = `theme:${theme}`;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case "sz":
|
|
204
|
+
result.size = attrNum(child, "val");
|
|
205
|
+
break;
|
|
206
|
+
case "u":
|
|
207
|
+
result.underline = attr(child, "val") ?? true;
|
|
208
|
+
break;
|
|
209
|
+
case "vertAlign":
|
|
210
|
+
result.vertAlign = attr(child, "val") ?? void 0;
|
|
211
|
+
break;
|
|
212
|
+
case "scheme":
|
|
213
|
+
result.scheme = attr(child, "val") ?? void 0;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/parts/worksheet.ts
|
|
220
|
+
/**
|
|
221
|
+
* Worksheet XML generation — pure functions for xl/worksheets/sheet{n}.xml.
|
|
222
|
+
*
|
|
223
|
+
* All interfaces and the zero-allocation string concatenation fast path
|
|
224
|
+
* are preserved. The `Worksheet` class has been replaced by `buildWorksheetXml()`.
|
|
225
|
+
*
|
|
226
|
+
* @module
|
|
227
|
+
*/
|
|
228
|
+
/** Cell formula type (maps to ST_CellFormulaType). */
|
|
229
|
+
const FormulaType = {
|
|
230
|
+
NORMAL: "normal",
|
|
231
|
+
ARRAY: "array",
|
|
232
|
+
SHARED: "shared"
|
|
233
|
+
};
|
|
234
|
+
const worksheetDesc = {
|
|
235
|
+
kind: "custom",
|
|
236
|
+
/**
|
|
237
|
+
* NOT intended for direct use by the compiler.
|
|
238
|
+
* The compiler calls `stringifyWorksheet(opts, ctx)` instead, which has
|
|
239
|
+
* access to the SharedStrings and Styles accumulators.
|
|
240
|
+
* This method exists to satisfy the CustomDescriptor interface for the read path.
|
|
241
|
+
*/
|
|
242
|
+
stringify(_opts, _ctx) {
|
|
243
|
+
throw new Error("Use stringifyWorksheet(opts, ctx) for the write path. worksheetDesc.stringify() is not supported.");
|
|
244
|
+
},
|
|
245
|
+
parse(el, ctx) {
|
|
246
|
+
const result = {};
|
|
247
|
+
let pageSetUpPrCache;
|
|
248
|
+
const strings = ctx && "sharedStrings" in ctx ? ctx.sharedStrings : [];
|
|
249
|
+
const sheetPrEl = findChild(el, "sheetPr");
|
|
250
|
+
if (sheetPrEl) {
|
|
251
|
+
const sp = {};
|
|
252
|
+
if (attr(sheetPrEl, "syncHorizontal") === "1") sp.syncHorizontal = true;
|
|
253
|
+
if (attr(sheetPrEl, "syncVertical") === "1") sp.syncVertical = true;
|
|
254
|
+
if (attr(sheetPrEl, "syncRef")) sp.syncRef = attr(sheetPrEl, "syncRef");
|
|
255
|
+
if (attr(sheetPrEl, "transitionEvaluation") === "1") sp.transitionEvaluation = true;
|
|
256
|
+
if (attr(sheetPrEl, "transitionEntry") === "1") sp.transitionEntry = true;
|
|
257
|
+
if (attr(sheetPrEl, "published") === "1") sp.published = true;
|
|
258
|
+
if (attr(sheetPrEl, "filterMode") === "1") sp.filterMode = true;
|
|
259
|
+
if (attr(sheetPrEl, "enableFormatConditionsCalculation") === "1") sp.enableFormatConditionsCalculation = true;
|
|
260
|
+
const outlinePr = findChild(sheetPrEl, "outlinePr");
|
|
261
|
+
if (outlinePr) {
|
|
262
|
+
if (attr(outlinePr, "applyStyles") === "1") sp.outlineApplyStyles = true;
|
|
263
|
+
if (attr(outlinePr, "showOutlineSymbols") === "0") sp.outlineShowSymbols = false;
|
|
264
|
+
if (attr(outlinePr, "summaryBelow") === "0") sp.outlineSummaryBelow = false;
|
|
265
|
+
if (attr(outlinePr, "summaryRight") === "0") sp.outlineSummaryRight = false;
|
|
266
|
+
}
|
|
267
|
+
const pageSetUpPr = findChild(sheetPrEl, "pageSetUpPr");
|
|
268
|
+
if (pageSetUpPr) {
|
|
269
|
+
const psup = {};
|
|
270
|
+
if (attr(pageSetUpPr, "fitToPage") === "1") psup.fitToPage = true;
|
|
271
|
+
if (attr(pageSetUpPr, "autoPageBreaks") === "1") psup.autoPageBreaks = true;
|
|
272
|
+
if (Object.keys(psup).length > 0) pageSetUpPrCache = psup;
|
|
273
|
+
}
|
|
274
|
+
if (Object.keys(sp).length > 0) result.sheetPr = sp;
|
|
275
|
+
const tabColorEl = findChild(sheetPrEl, "tabColor");
|
|
276
|
+
if (tabColorEl) {
|
|
277
|
+
const tc = {};
|
|
278
|
+
if (attr(tabColorEl, "rgb")) tc.rgb = attr(tabColorEl, "rgb");
|
|
279
|
+
if (attrNum(tabColorEl, "theme") !== void 0) tc.theme = attrNum(tabColorEl, "theme");
|
|
280
|
+
if (attrNum(tabColorEl, "tint") !== void 0) tc.tint = attrNum(tabColorEl, "tint");
|
|
281
|
+
if (attrNum(tabColorEl, "indexed") !== void 0) tc.indexed = attrNum(tabColorEl, "indexed");
|
|
282
|
+
result.tabColor = tc;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const sheetViewsEl = findChild(el, "sheetViews");
|
|
286
|
+
if (sheetViewsEl) {
|
|
287
|
+
const svEl = findChild(sheetViewsEl, "sheetView");
|
|
288
|
+
if (svEl) {
|
|
289
|
+
const sv = {};
|
|
290
|
+
if (attr(svEl, "showGridLines") === "0") sv.showGridLines = false;
|
|
291
|
+
if (attr(svEl, "showRowColHeaders") === "0") sv.showRowColHeaders = false;
|
|
292
|
+
if (attr(svEl, "showZeros") === "0") sv.showZeros = false;
|
|
293
|
+
const zs = attrNum(svEl, "zoomScale");
|
|
294
|
+
if (zs !== void 0) sv.zoomScale = zs;
|
|
295
|
+
if (attr(svEl, "tabSelected") !== void 0) sv.tabSelected = attr(svEl, "tabSelected") !== "0";
|
|
296
|
+
if (attr(svEl, "rightToLeft") === "1") sv.rightToLeft = true;
|
|
297
|
+
if (attr(svEl, "windowProtection") === "1") sv.windowProtection = true;
|
|
298
|
+
if (attr(svEl, "showFormulas") === "1") sv.showFormulas = true;
|
|
299
|
+
if (attr(svEl, "showRuler") === "0") sv.showRuler = false;
|
|
300
|
+
if (attr(svEl, "showOutlineSymbols") === "0") sv.showOutlineSymbols = false;
|
|
301
|
+
if (attr(svEl, "defaultGridColor") === "0") sv.defaultGridColor = false;
|
|
302
|
+
if (attr(svEl, "showWhiteSpace") === "0") sv.showWhiteSpace = false;
|
|
303
|
+
if (attr(svEl, "view")) sv.view = attr(svEl, "view");
|
|
304
|
+
const colorId = attrNum(svEl, "colorId");
|
|
305
|
+
if (colorId !== void 0) sv.colorId = colorId;
|
|
306
|
+
const zsn = attrNum(svEl, "zoomScaleNormal");
|
|
307
|
+
if (zsn !== void 0) sv.zoomScaleNormal = zsn;
|
|
308
|
+
const zssl = attrNum(svEl, "zoomScaleSheetLayoutView");
|
|
309
|
+
if (zssl !== void 0) sv.zoomScaleSheetLayoutView = zssl;
|
|
310
|
+
const zspl = attrNum(svEl, "zoomScalePageLayoutView");
|
|
311
|
+
if (zspl !== void 0) sv.zoomScalePageLayoutView = zspl;
|
|
312
|
+
result.sheetView = sv;
|
|
313
|
+
const paneEl = findChild(svEl, "pane");
|
|
314
|
+
if (paneEl && attr(paneEl, "state") === "frozen") {
|
|
315
|
+
const fp = {};
|
|
316
|
+
const ys = attrNum(paneEl, "ySplit");
|
|
317
|
+
if (ys && ys > 0) fp.row = ys;
|
|
318
|
+
const xs = attrNum(paneEl, "xSplit");
|
|
319
|
+
if (xs && xs > 0) fp.col = xs;
|
|
320
|
+
if (Object.keys(fp).length > 0) result.freezePanes = fp;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const sfpEl = findChild(el, "sheetFormatPr");
|
|
325
|
+
if (sfpEl) {
|
|
326
|
+
const sfp = {};
|
|
327
|
+
const bcw = attrNum(sfpEl, "baseColWidth");
|
|
328
|
+
if (bcw !== void 0) sfp.baseColWidth = bcw;
|
|
329
|
+
const dcw = attrNum(sfpEl, "defaultColWidth");
|
|
330
|
+
if (dcw !== void 0) sfp.defaultColWidth = dcw;
|
|
331
|
+
const drh = attrNum(sfpEl, "defaultRowHeight");
|
|
332
|
+
if (drh !== void 0) sfp.defaultRowHeight = drh;
|
|
333
|
+
if (attr(sfpEl, "zeroHeight") === "1") sfp.zeroHeight = true;
|
|
334
|
+
if (attr(sfpEl, "thickTop") === "1") sfp.thickTop = true;
|
|
335
|
+
if (attr(sfpEl, "thickBottom") === "1") sfp.thickBottom = true;
|
|
336
|
+
const olr = attrNum(sfpEl, "outlineLevelRow");
|
|
337
|
+
if (olr !== void 0) sfp.outlineLevelRow = olr;
|
|
338
|
+
const olc = attrNum(sfpEl, "outlineLevelCol");
|
|
339
|
+
if (olc !== void 0) sfp.outlineLevelCol = olc;
|
|
340
|
+
result.sheetFormatPr = sfp;
|
|
341
|
+
}
|
|
342
|
+
const colsEl = findChild(el, "cols");
|
|
343
|
+
if (colsEl) {
|
|
344
|
+
const columns = [];
|
|
345
|
+
for (const colEl of colsEl.elements ?? []) {
|
|
346
|
+
if (colEl.name !== "col") continue;
|
|
347
|
+
const col = {};
|
|
348
|
+
col.min = attrNum(colEl, "min") ?? 0;
|
|
349
|
+
col.max = attrNum(colEl, "max") ?? 0;
|
|
350
|
+
const w = attrNum(colEl, "width");
|
|
351
|
+
if (w !== void 0) col.width = w;
|
|
352
|
+
if (attr(colEl, "hidden") === "1") col.hidden = true;
|
|
353
|
+
if (attr(colEl, "customWidth") === "1") col.customWidth = true;
|
|
354
|
+
const ol = attrNum(colEl, "outlineLevel");
|
|
355
|
+
if (ol !== void 0) col.outlineLevel = ol;
|
|
356
|
+
if (attr(colEl, "collapsed") === "1") col.collapsed = true;
|
|
357
|
+
if (attr(colEl, "bestFit") === "1") col.bestFit = true;
|
|
358
|
+
if (attr(colEl, "phonetic") === "1") col.phonetic = true;
|
|
359
|
+
columns.push(col);
|
|
360
|
+
}
|
|
361
|
+
if (columns.length > 0) result.columns = columns;
|
|
362
|
+
}
|
|
363
|
+
const protEl = findChild(el, "sheetProtection");
|
|
364
|
+
if (protEl?.attributes) {
|
|
365
|
+
const prot = {};
|
|
366
|
+
if (attr(protEl, "password")) prot.password = attr(protEl, "password");
|
|
367
|
+
if (attr(protEl, "algorithmName")) prot.algorithmName = attr(protEl, "algorithmName");
|
|
368
|
+
if (attr(protEl, "hashValue")) prot.hashValue = attr(protEl, "hashValue");
|
|
369
|
+
if (attr(protEl, "saltValue")) prot.saltValue = attr(protEl, "saltValue");
|
|
370
|
+
if (attrNum(protEl, "spinCount") !== void 0) prot.spinCount = attrNum(protEl, "spinCount");
|
|
371
|
+
if (attr(protEl, "sheet") === "1") prot.sheet = true;
|
|
372
|
+
if (attr(protEl, "objects") === "1") prot.objects = true;
|
|
373
|
+
if (attr(protEl, "scenarios") === "1") prot.scenarios = true;
|
|
374
|
+
if (attr(protEl, "formatCells") === "0") prot.formatCells = false;
|
|
375
|
+
if (attr(protEl, "formatColumns") === "0") prot.formatColumns = false;
|
|
376
|
+
if (attr(protEl, "formatRows") === "0") prot.formatRows = false;
|
|
377
|
+
if (attr(protEl, "insertColumns") === "0") prot.insertColumns = false;
|
|
378
|
+
if (attr(protEl, "insertRows") === "0") prot.insertRows = false;
|
|
379
|
+
if (attr(protEl, "insertHyperlinks") === "0") prot.insertHyperlinks = false;
|
|
380
|
+
if (attr(protEl, "deleteColumns") === "0") prot.deleteColumns = false;
|
|
381
|
+
if (attr(protEl, "deleteRows") === "0") prot.deleteRows = false;
|
|
382
|
+
if (attr(protEl, "selectLockedCells") === "1") prot.selectLockedCells = true;
|
|
383
|
+
if (attr(protEl, "sort") === "0") prot.sort = false;
|
|
384
|
+
if (attr(protEl, "autoFilter") === "0") prot.autoFilter = false;
|
|
385
|
+
if (attr(protEl, "pivotTables") === "0") prot.pivotTables = false;
|
|
386
|
+
if (attr(protEl, "selectUnlockedCells") === "1") prot.selectUnlockedCells = true;
|
|
387
|
+
result.protection = prot;
|
|
388
|
+
}
|
|
389
|
+
const prEl = findChild(el, "protectedRanges");
|
|
390
|
+
if (prEl) {
|
|
391
|
+
const ranges = [];
|
|
392
|
+
for (const rEl of prEl.elements ?? []) {
|
|
393
|
+
if (rEl.name !== "protectedRange") continue;
|
|
394
|
+
const r = {};
|
|
395
|
+
r.sqref = attr(rEl, "sqref") ?? "";
|
|
396
|
+
r.name = attr(rEl, "name") ?? "";
|
|
397
|
+
if (attr(rEl, "password")) r.password = attr(rEl, "password");
|
|
398
|
+
if (attr(rEl, "algorithmName")) r.algorithmName = attr(rEl, "algorithmName");
|
|
399
|
+
if (attr(rEl, "hashValue")) r.hashValue = attr(rEl, "hashValue");
|
|
400
|
+
if (attr(rEl, "saltValue")) r.saltValue = attr(rEl, "saltValue");
|
|
401
|
+
if (attrNum(rEl, "spinCount") !== void 0) r.spinCount = attrNum(rEl, "spinCount");
|
|
402
|
+
const sdEl = findChild(rEl, "securityDescriptor");
|
|
403
|
+
if (sdEl) r.securityDescriptor = textOf(sdEl);
|
|
404
|
+
ranges.push(r);
|
|
405
|
+
}
|
|
406
|
+
if (ranges.length > 0) result.protectedRanges = ranges;
|
|
407
|
+
}
|
|
408
|
+
const afEl = findChild(el, "autoFilter");
|
|
409
|
+
if (afEl) result.autoFilter = attr(afEl, "ref") ?? "";
|
|
410
|
+
const mcEl = findChild(el, "mergeCells");
|
|
411
|
+
if (mcEl) {
|
|
412
|
+
const merges = [];
|
|
413
|
+
for (const mEl of mcEl.elements ?? []) {
|
|
414
|
+
if (mEl.name !== "mergeCell") continue;
|
|
415
|
+
const parts = (attr(mEl, "ref") ?? "").split(":");
|
|
416
|
+
if (parts.length === 2) {
|
|
417
|
+
const from = parseCellRef(parts[0]);
|
|
418
|
+
const to = parseCellRef(parts[1]);
|
|
419
|
+
if (from && to) merges.push({
|
|
420
|
+
from,
|
|
421
|
+
to
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (merges.length > 0) result.mergeCells = merges;
|
|
426
|
+
}
|
|
427
|
+
const cfEls = el.elements?.filter((e) => e.name === "conditionalFormatting") ?? [];
|
|
428
|
+
if (cfEls.length > 0) {
|
|
429
|
+
const cfs = [];
|
|
430
|
+
for (const cfEl of cfEls) {
|
|
431
|
+
const sqref = attr(cfEl, "sqref") ?? "";
|
|
432
|
+
const rules = [];
|
|
433
|
+
for (const ruleEl of cfEl.elements ?? []) {
|
|
434
|
+
if (ruleEl.name !== "cfRule") continue;
|
|
435
|
+
const rule = {};
|
|
436
|
+
rule.type = attr(ruleEl, "type");
|
|
437
|
+
rule.priority = attrNum(ruleEl, "priority") ?? 1;
|
|
438
|
+
if (attr(ruleEl, "operator")) rule.operator = attr(ruleEl, "operator");
|
|
439
|
+
const dxfId = attrNum(ruleEl, "dxfId");
|
|
440
|
+
if (dxfId !== void 0) rule.dxfId = dxfId;
|
|
441
|
+
if (attr(ruleEl, "stopIfTrue") === "1") rule.stopIfTrue = true;
|
|
442
|
+
if (attr(ruleEl, "timePeriod")) rule.timePeriod = attr(ruleEl, "timePeriod");
|
|
443
|
+
const rank = attrNum(ruleEl, "rank");
|
|
444
|
+
if (rank !== void 0) rule.rank = rank;
|
|
445
|
+
if (attr(ruleEl, "equalAverage") === "1") rule.equalAverage = true;
|
|
446
|
+
const csEl = findChild(ruleEl, "colorScale");
|
|
447
|
+
if (csEl) {
|
|
448
|
+
const cfvo = [];
|
|
449
|
+
const colors = [];
|
|
450
|
+
for (const child of csEl.elements ?? []) {
|
|
451
|
+
if (child.name === "cfvo") cfvo.push(parseCfvo(child));
|
|
452
|
+
if (child.name === "color") {
|
|
453
|
+
const rgb = attr(child, "rgb");
|
|
454
|
+
if (rgb) colors.push(rgb.length === 8 ? rgb.slice(2) : rgb);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
rule.colorScale = {
|
|
458
|
+
cfvo,
|
|
459
|
+
colors
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
const dbEl = findChild(ruleEl, "dataBar");
|
|
463
|
+
if (dbEl) {
|
|
464
|
+
const cfvo = [];
|
|
465
|
+
let color = "";
|
|
466
|
+
for (const child of dbEl.elements ?? []) {
|
|
467
|
+
if (child.name === "cfvo") cfvo.push(parseCfvo(child));
|
|
468
|
+
if (child.name === "color") {
|
|
469
|
+
const rgb = attr(child, "rgb");
|
|
470
|
+
if (rgb) color = rgb.length === 8 ? rgb.slice(2) : rgb;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
rule.dataBar = {
|
|
474
|
+
cfvo,
|
|
475
|
+
color
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
const isEl = findChild(ruleEl, "iconSet");
|
|
479
|
+
if (isEl) {
|
|
480
|
+
const cfvo = [];
|
|
481
|
+
for (const child of isEl.elements ?? []) if (child.name === "cfvo") cfvo.push(parseCfvo(child));
|
|
482
|
+
const iconSet = { cfvo };
|
|
483
|
+
if (attr(isEl, "iconSet")) iconSet.iconSet = attr(isEl, "iconSet");
|
|
484
|
+
if (attr(isEl, "showValue") === "0") iconSet.showValue = false;
|
|
485
|
+
if (attr(isEl, "percent") === "0") iconSet.percent = false;
|
|
486
|
+
if (attr(isEl, "reverse") === "1") iconSet.reverse = true;
|
|
487
|
+
rule.iconSet = iconSet;
|
|
488
|
+
}
|
|
489
|
+
const formulas = [];
|
|
490
|
+
for (const child of ruleEl.elements ?? []) if (child.name === "formula") formulas.push(textOf(child) ?? "");
|
|
491
|
+
if (formulas.length > 0) rule.formulas = formulas;
|
|
492
|
+
rules.push(rule);
|
|
493
|
+
}
|
|
494
|
+
cfs.push({
|
|
495
|
+
sqref,
|
|
496
|
+
rules
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
result.conditionalFormats = cfs;
|
|
500
|
+
}
|
|
501
|
+
const dvEl = findChild(el, "dataValidations");
|
|
502
|
+
if (dvEl) {
|
|
503
|
+
const dvs = [];
|
|
504
|
+
for (const dEl of dvEl.elements ?? []) {
|
|
505
|
+
if (dEl.name !== "dataValidation") continue;
|
|
506
|
+
const dv = {};
|
|
507
|
+
dv.sqref = attr(dEl, "sqref") ?? "";
|
|
508
|
+
if (attr(dEl, "type")) dv.type = attr(dEl, "type");
|
|
509
|
+
if (attr(dEl, "operator")) dv.operator = attr(dEl, "operator");
|
|
510
|
+
if (attr(dEl, "allowBlank") === "1") dv.allowBlank = true;
|
|
511
|
+
if (attr(dEl, "showErrorMessage") === "1") dv.showErrorMessage = true;
|
|
512
|
+
if (attr(dEl, "showInputMessage") === "1") dv.showInputMessage = true;
|
|
513
|
+
if (attr(dEl, "errorTitle")) dv.errorTitle = attr(dEl, "errorTitle");
|
|
514
|
+
if (attr(dEl, "error")) dv.error = attr(dEl, "error");
|
|
515
|
+
if (attr(dEl, "promptTitle")) dv.promptTitle = attr(dEl, "promptTitle");
|
|
516
|
+
if (attr(dEl, "prompt")) dv.prompt = attr(dEl, "prompt");
|
|
517
|
+
if (attr(dEl, "errorStyle")) dv.errorStyle = attr(dEl, "errorStyle");
|
|
518
|
+
if (attr(dEl, "imeMode")) dv.imeMode = attr(dEl, "imeMode");
|
|
519
|
+
if (attr(dEl, "showDropDown") === "1") dv.showDropDown = true;
|
|
520
|
+
const f1El = findChild(dEl, "formula1");
|
|
521
|
+
if (f1El) dv.formula1 = textOf(f1El);
|
|
522
|
+
const f2El = findChild(dEl, "formula2");
|
|
523
|
+
if (f2El) dv.formula2 = textOf(f2El);
|
|
524
|
+
dvs.push(dv);
|
|
525
|
+
}
|
|
526
|
+
result.dataValidations = dvs;
|
|
527
|
+
}
|
|
528
|
+
const hlEl = findChild(el, "hyperlinks");
|
|
529
|
+
if (hlEl) {
|
|
530
|
+
const hyperlinks = [];
|
|
531
|
+
for (const hEl of hlEl.elements ?? []) {
|
|
532
|
+
if (hEl.name !== "hyperlink") continue;
|
|
533
|
+
const hl = {};
|
|
534
|
+
hl.cell = attr(hEl, "ref") ?? "";
|
|
535
|
+
const rId = hEl.attributes?.["r:id"];
|
|
536
|
+
const location = attr(hEl, "location");
|
|
537
|
+
if (rId) hl.target = {
|
|
538
|
+
type: "external",
|
|
539
|
+
url: rId
|
|
540
|
+
};
|
|
541
|
+
else if (location) hl.target = {
|
|
542
|
+
type: "internal",
|
|
543
|
+
location
|
|
544
|
+
};
|
|
545
|
+
if (attr(hEl, "tooltip")) hl.tooltip = attr(hEl, "tooltip");
|
|
546
|
+
if (attr(hEl, "display")) hl.display = attr(hEl, "display");
|
|
547
|
+
hyperlinks.push(hl);
|
|
548
|
+
}
|
|
549
|
+
result.hyperlinks = hyperlinks;
|
|
550
|
+
}
|
|
551
|
+
const poEl = findChild(el, "printOptions");
|
|
552
|
+
if (poEl) {
|
|
553
|
+
const po = {};
|
|
554
|
+
if (attr(poEl, "horizontalCentered") === "1") po.horizontalCentered = true;
|
|
555
|
+
if (attr(poEl, "verticalCentered") === "1") po.verticalCentered = true;
|
|
556
|
+
if (attr(poEl, "headings") === "1") po.headings = true;
|
|
557
|
+
if (attr(poEl, "gridLines") === "1") po.gridLines = true;
|
|
558
|
+
if (attr(poEl, "gridLinesSet") === "0") po.gridLinesSet = false;
|
|
559
|
+
result.printOptions = po;
|
|
560
|
+
}
|
|
561
|
+
const psEl = findChild(el, "pageSetup");
|
|
562
|
+
if (psEl) {
|
|
563
|
+
const ps = {};
|
|
564
|
+
const pz = attrNum(psEl, "paperSize");
|
|
565
|
+
if (pz !== void 0) ps.paperSize = pz;
|
|
566
|
+
const ph = attrMeasure(psEl, "paperHeight");
|
|
567
|
+
if (ph !== void 0) ps.paperHeight = ph;
|
|
568
|
+
const pw = attrMeasure(psEl, "paperWidth");
|
|
569
|
+
if (pw !== void 0) ps.paperWidth = pw;
|
|
570
|
+
if (attr(psEl, "orientation")) ps.orientation = attr(psEl, "orientation");
|
|
571
|
+
const sc = attrNum(psEl, "scale");
|
|
572
|
+
if (sc !== void 0) ps.scale = sc;
|
|
573
|
+
const ftw = attrNum(psEl, "fitToWidth");
|
|
574
|
+
if (ftw !== void 0) ps.fitToWidth = ftw;
|
|
575
|
+
const fth = attrNum(psEl, "fitToHeight");
|
|
576
|
+
if (fth !== void 0) ps.fitToHeight = fth;
|
|
577
|
+
if (attr(psEl, "pageOrder")) ps.pageOrder = attr(psEl, "pageOrder");
|
|
578
|
+
if (attr(psEl, "useFirstPageNumber") === "1") ps.useFirstPageNumber = true;
|
|
579
|
+
const fpn = attrNum(psEl, "firstPageNumber");
|
|
580
|
+
if (fpn !== void 0) ps.firstPageNumber = fpn;
|
|
581
|
+
if (pageSetUpPrCache) Object.assign(ps, pageSetUpPrCache);
|
|
582
|
+
result.pageSetup = ps;
|
|
583
|
+
} else if (pageSetUpPrCache) result.pageSetup = pageSetUpPrCache;
|
|
584
|
+
const hfEl = findChild(el, "headerFooter");
|
|
585
|
+
if (hfEl) {
|
|
586
|
+
const hf = {};
|
|
587
|
+
if (attr(hfEl, "differentOddEven") === "1") hf.differentOddEven = true;
|
|
588
|
+
if (attr(hfEl, "differentFirst") === "1") hf.differentFirst = true;
|
|
589
|
+
if (attr(hfEl, "scaleWithDoc") === "0") hf.scaleWithDoc = false;
|
|
590
|
+
if (attr(hfEl, "alignWithMargins") === "0") hf.alignWithMargins = false;
|
|
591
|
+
const oh = findChild(hfEl, "oddHeader");
|
|
592
|
+
if (oh) hf.oddHeader = textOf(oh);
|
|
593
|
+
const of2 = findChild(hfEl, "oddFooter");
|
|
594
|
+
if (of2) hf.oddFooter = textOf(of2);
|
|
595
|
+
const eh = findChild(hfEl, "evenHeader");
|
|
596
|
+
if (eh) hf.evenHeader = textOf(eh);
|
|
597
|
+
const ef = findChild(hfEl, "evenFooter");
|
|
598
|
+
if (ef) hf.evenFooter = textOf(ef);
|
|
599
|
+
const fh = findChild(hfEl, "firstHeader");
|
|
600
|
+
if (fh) hf.firstHeader = textOf(fh);
|
|
601
|
+
const ff = findChild(hfEl, "firstFooter");
|
|
602
|
+
if (ff) hf.firstFooter = textOf(ff);
|
|
603
|
+
result.headerFooter = hf;
|
|
604
|
+
}
|
|
605
|
+
const ieEl = findChild(el, "ignoredErrors");
|
|
606
|
+
if (ieEl) {
|
|
607
|
+
const errors = [];
|
|
608
|
+
for (const eEl of ieEl.elements ?? []) {
|
|
609
|
+
if (eEl.name !== "ignoredError") continue;
|
|
610
|
+
const ie = {};
|
|
611
|
+
ie.sqref = attr(eEl, "sqref") ?? "";
|
|
612
|
+
if (attr(eEl, "evalError") === "1") ie.evalError = true;
|
|
613
|
+
if (attr(eEl, "twoDigitTextYear") === "1") ie.twoDigitTextYear = true;
|
|
614
|
+
if (attr(eEl, "numberStoredAsText") === "1") ie.numberStoredAsText = true;
|
|
615
|
+
if (attr(eEl, "formula") === "1") ie.formula = true;
|
|
616
|
+
if (attr(eEl, "formulaRange") === "1") ie.formulaRange = true;
|
|
617
|
+
if (attr(eEl, "unlockedFormula") === "1") ie.unlockedFormula = true;
|
|
618
|
+
if (attr(eEl, "emptyCellReference") === "1") ie.emptyCellReference = true;
|
|
619
|
+
if (attr(eEl, "listDataValidation") === "1") ie.listDataValidation = true;
|
|
620
|
+
if (attr(eEl, "calculatedColumn") === "1") ie.calculatedColumn = true;
|
|
621
|
+
errors.push(ie);
|
|
622
|
+
}
|
|
623
|
+
result.ignoredErrors = errors;
|
|
624
|
+
}
|
|
625
|
+
const ppEl = findChild(el, "phoneticPr");
|
|
626
|
+
if (ppEl) {
|
|
627
|
+
const pp = {};
|
|
628
|
+
pp.fontId = attrNum(ppEl, "fontId") ?? 0;
|
|
629
|
+
if (attr(ppEl, "type")) pp.type = attr(ppEl, "type");
|
|
630
|
+
if (attr(ppEl, "alignment")) pp.alignment = attr(ppEl, "alignment");
|
|
631
|
+
result.phoneticPr = pp;
|
|
632
|
+
}
|
|
633
|
+
const scEl = findChild(el, "sheetCalcPr");
|
|
634
|
+
if (scEl) {
|
|
635
|
+
const sc = {};
|
|
636
|
+
if (attr(scEl, "fullCalcOnLoad") === "1") sc.fullCalcOnLoad = true;
|
|
637
|
+
result.sheetCalcPr = sc;
|
|
638
|
+
}
|
|
639
|
+
const sheetDataEl = findChild(el, "sheetData");
|
|
640
|
+
if (sheetDataEl) {
|
|
641
|
+
const rows = [];
|
|
642
|
+
for (const rowEl of sheetDataEl.elements ?? []) {
|
|
643
|
+
if (rowEl.name !== "row") continue;
|
|
644
|
+
const row = {};
|
|
645
|
+
const rowNumber = attrNum(rowEl, "r");
|
|
646
|
+
if (rowNumber !== void 0) row.rowNumber = rowNumber;
|
|
647
|
+
const ht = attrNum(rowEl, "ht");
|
|
648
|
+
if (ht !== void 0) row.height = ht;
|
|
649
|
+
if (attr(rowEl, "hidden") === "1") row.hidden = true;
|
|
650
|
+
if (attr(rowEl, "spans")) row.spans = attr(rowEl, "spans");
|
|
651
|
+
if (attr(rowEl, "customFormat") === "1") row.customFormat = true;
|
|
652
|
+
if (attr(rowEl, "thickTop") === "1") row.thickTop = true;
|
|
653
|
+
if (attr(rowEl, "thickBot") === "1") row.thickBot = true;
|
|
654
|
+
if (attr(rowEl, "ph") === "1") row.ph = true;
|
|
655
|
+
const cells = [];
|
|
656
|
+
for (const cellEl of rowEl.elements ?? []) {
|
|
657
|
+
if (cellEl.name !== "c") continue;
|
|
658
|
+
const cell = {};
|
|
659
|
+
const ref = attr(cellEl, "r");
|
|
660
|
+
if (ref) cell.reference = ref;
|
|
661
|
+
const type = attr(cellEl, "t");
|
|
662
|
+
const styleIdx = attrNum(cellEl, "s");
|
|
663
|
+
if (styleIdx !== void 0) {
|
|
664
|
+
const resolved = ctx && "resolveStyle" in ctx ? ctx.resolveStyle(styleIdx) : void 0;
|
|
665
|
+
if (resolved) cell.style = resolved;
|
|
666
|
+
else cell.styleIndex = styleIdx;
|
|
667
|
+
}
|
|
668
|
+
const vEl = findChild(cellEl, "v");
|
|
669
|
+
const isEl = findChild(cellEl, "is");
|
|
670
|
+
if (type === "s" && vEl) cell.value = strings[parseInt(textOf(vEl) ?? "", 10)] ?? "";
|
|
671
|
+
else if (type === "b" && vEl) cell.value = textOf(vEl) === "1";
|
|
672
|
+
else if (type === "inlineStr" && isEl) cell.value = textOf(findChild(isEl, "t")) ?? "";
|
|
673
|
+
else if (vEl) {
|
|
674
|
+
const raw = textOf(vEl) ?? "";
|
|
675
|
+
const num = Number(raw);
|
|
676
|
+
cell.value = isNaN(num) ? raw : num;
|
|
677
|
+
}
|
|
678
|
+
const fEl = findChild(cellEl, "f");
|
|
679
|
+
if (fEl) {
|
|
680
|
+
const formula = { formula: textOf(fEl) ?? "" };
|
|
681
|
+
const ft = attr(fEl, "t");
|
|
682
|
+
if (ft && ft !== "normal") formula.type = ft;
|
|
683
|
+
const fRef = attr(fEl, "ref");
|
|
684
|
+
if (fRef) formula.reference = fRef;
|
|
685
|
+
const fSi = attrNum(fEl, "si");
|
|
686
|
+
if (fSi !== void 0) formula.sharedIndex = fSi;
|
|
687
|
+
if (attr(fEl, "aca") === "1") formula.aca = true;
|
|
688
|
+
if (attr(fEl, "ca") === "1") formula.ca = true;
|
|
689
|
+
if (attr(fEl, "bx") === "1") formula.bx = true;
|
|
690
|
+
cell.formula = formula;
|
|
691
|
+
}
|
|
692
|
+
cells.push(cell);
|
|
693
|
+
}
|
|
694
|
+
row.cells = cells;
|
|
695
|
+
rows.push(row);
|
|
696
|
+
}
|
|
697
|
+
if (rows.length > 0) result.rows = rows;
|
|
698
|
+
}
|
|
699
|
+
return result;
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
/**
|
|
703
|
+
* Build the complete worksheet XML string.
|
|
704
|
+
*
|
|
705
|
+
* Zero-allocation fast path: directly concatenates XML string,
|
|
706
|
+
* bypassing the IXmlableObject intermediate tree entirely.
|
|
707
|
+
*/
|
|
708
|
+
function stringifyWorksheet(opts, ctx) {
|
|
709
|
+
const sharedStrings = ctx.sharedStrings;
|
|
710
|
+
const styles = ctx.styles;
|
|
711
|
+
const rows = opts.rows ?? [];
|
|
712
|
+
const columns = opts.columns ?? [];
|
|
713
|
+
const mergeCells = opts.mergeCells ?? [];
|
|
714
|
+
const protectedRanges = opts.protectedRanges ?? [];
|
|
715
|
+
const ignoredErrors = opts.ignoredErrors ?? [];
|
|
716
|
+
const rowBreaks = opts.rowBreaks ?? [];
|
|
717
|
+
const colBreaks = opts.colBreaks ?? [];
|
|
718
|
+
const customSheetViews = opts.customSheetViews ?? [];
|
|
719
|
+
const cellWatches = opts.cellWatches ?? [];
|
|
720
|
+
const controls = opts.controls ?? [];
|
|
721
|
+
const customProperties = opts.customProperties ?? [];
|
|
722
|
+
const oleObjects = opts.oleObjects ?? [];
|
|
723
|
+
const webPublishItems = opts.webPublishItems ?? [];
|
|
724
|
+
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\">"];
|
|
725
|
+
const hasTabColor = !!opts.tabColor;
|
|
726
|
+
const hasOutline = columns.some((c) => c.outlineLevel !== void 0);
|
|
727
|
+
const sp = opts.sheetPr;
|
|
728
|
+
const hasSheetPrAttrs = sp && (sp.syncHorizontal || sp.syncVertical || sp.syncRef || sp.transitionEvaluation || sp.transitionEntry || sp.published || sp.filterMode || sp.enableFormatConditionsCalculation);
|
|
729
|
+
const hasPageSetUpPr = !!opts.pageSetup?.fitToWidth || !!opts.pageSetup?.fitToHeight || !!opts.pageSetup?.autoPageBreaks;
|
|
730
|
+
if (hasTabColor || hasOutline || hasSheetPrAttrs || hasPageSetUpPr) {
|
|
731
|
+
const prParts = [];
|
|
732
|
+
const prAttrs = {};
|
|
733
|
+
if (sp?.syncHorizontal) prAttrs.syncHorizontal = 1;
|
|
734
|
+
if (sp?.syncVertical) prAttrs.syncVertical = 1;
|
|
735
|
+
if (sp?.syncRef) prAttrs.syncRef = sp.syncRef;
|
|
736
|
+
if (sp?.transitionEvaluation) prAttrs.transitionEvaluation = 1;
|
|
737
|
+
if (sp?.transitionEntry) prAttrs.transitionEntry = 1;
|
|
738
|
+
if (sp?.published) prAttrs.published = 1;
|
|
739
|
+
if (sp?.filterMode) prAttrs.filterMode = 1;
|
|
740
|
+
if (sp?.enableFormatConditionsCalculation) prAttrs.enableFormatConditionsCalculation = 1;
|
|
741
|
+
if (opts.tabColor) {
|
|
742
|
+
const tc = opts.tabColor;
|
|
743
|
+
const tcAttrs = {};
|
|
744
|
+
if (tc.rgb) tcAttrs.rgb = tc.rgb;
|
|
745
|
+
if (tc.theme !== void 0) tcAttrs.theme = tc.theme;
|
|
746
|
+
if (tc.tint !== void 0) tcAttrs.tint = tc.tint;
|
|
747
|
+
if (tc.indexed !== void 0) tcAttrs.indexed = tc.indexed;
|
|
748
|
+
prParts.push(`<tabColor${attrs(tcAttrs)}/>`);
|
|
749
|
+
}
|
|
750
|
+
if (hasOutline) {
|
|
751
|
+
const outAttrs = {
|
|
752
|
+
summaryBelow: 1,
|
|
753
|
+
summaryRight: 1
|
|
754
|
+
};
|
|
755
|
+
if (sp?.outlineSummaryBelow === false) outAttrs.summaryBelow = 0;
|
|
756
|
+
if (sp?.outlineSummaryRight === false) outAttrs.summaryRight = 0;
|
|
757
|
+
if (sp?.outlineApplyStyles) outAttrs.applyStyles = 1;
|
|
758
|
+
if (sp?.outlineShowSymbols === false) outAttrs.showOutlineSymbols = 0;
|
|
759
|
+
prParts.push(`<outlinePr${attrs(outAttrs)}/>`);
|
|
760
|
+
}
|
|
761
|
+
if (opts.pageSetup?.fitToWidth || opts.pageSetup?.fitToHeight || opts.pageSetup?.autoPageBreaks) {
|
|
762
|
+
const psupAttrs = {};
|
|
763
|
+
if (opts.pageSetup?.fitToWidth || opts.pageSetup?.fitToHeight) psupAttrs.fitToPage = 1;
|
|
764
|
+
if (opts.pageSetup?.autoPageBreaks) psupAttrs.autoPageBreaks = 1;
|
|
765
|
+
prParts.push(`<pageSetUpPr${attrs(psupAttrs)}/>`);
|
|
766
|
+
}
|
|
767
|
+
const prAttrStr = Object.keys(prAttrs).length > 0 ? attrs(prAttrs) : "";
|
|
768
|
+
p.push(`<sheetPr${prAttrStr}>${prParts.join("")}</sheetPr>`);
|
|
769
|
+
}
|
|
770
|
+
const maxRow = rows.length;
|
|
771
|
+
let maxCol = 0;
|
|
772
|
+
for (const row of rows) if (row.cells && row.cells.length > maxCol) maxCol = row.cells.length;
|
|
773
|
+
if (maxRow > 0 && maxCol > 0) {
|
|
774
|
+
const dimRef = `A1:${defaultCellRef(maxRow, maxCol)}`;
|
|
775
|
+
p.push(`<dimension ref="${dimRef}"/>`);
|
|
776
|
+
}
|
|
777
|
+
const pivotSelXml = opts.sheetView?.pivotSelections ? opts.sheetView.pivotSelections.map((ps) => buildPivotSelectionXml(ps)).join("") : "";
|
|
778
|
+
if (opts.freezePanes) {
|
|
779
|
+
const fp = opts.freezePanes;
|
|
780
|
+
const ySplit = fp.row ? fp.row : 0;
|
|
781
|
+
const xSplit = fp.col ? fp.col : 0;
|
|
782
|
+
const topLeftCell = defaultCellRef(fp.row ? fp.row + 1 : 1, fp.col ? fp.col + 1 : 1);
|
|
783
|
+
const activePane = ySplit > 0 && xSplit > 0 ? "bottomRight" : ySplit > 0 ? "bottomLeft" : "topRight";
|
|
784
|
+
const svAttrs = buildSheetViewAttrs(opts.sheetView);
|
|
785
|
+
p.push(`<sheetViews><sheetView${svAttrs}>`, `<pane ySplit="${ySplit}" xSplit="${xSplit}" topLeftCell="${topLeftCell}" activePane="${activePane}" state="frozen"/>`, opts.selection ? buildSelectionXml(opts.selection) : "", pivotSelXml, "</sheetView></sheetViews>");
|
|
786
|
+
} else {
|
|
787
|
+
const svAttrs = buildSheetViewAttrs(opts.sheetView);
|
|
788
|
+
const innerXml = (opts.selection ? buildSelectionXml(opts.selection) : "") + pivotSelXml;
|
|
789
|
+
if (innerXml) p.push(`<sheetViews><sheetView${svAttrs}>${innerXml}</sheetView></sheetViews>`);
|
|
790
|
+
else p.push(`<sheetViews><sheetView${svAttrs}/></sheetViews>`);
|
|
791
|
+
}
|
|
792
|
+
if (opts.sheetFormatPr) {
|
|
793
|
+
const sfp = opts.sheetFormatPr;
|
|
794
|
+
const sfpAttrs = {};
|
|
795
|
+
if (sfp.baseColWidth !== void 0) sfpAttrs.baseColWidth = sfp.baseColWidth;
|
|
796
|
+
if (sfp.defaultColWidth !== void 0) sfpAttrs.defaultColWidth = sfp.defaultColWidth;
|
|
797
|
+
sfpAttrs.defaultRowHeight = sfp.defaultRowHeight ?? 15;
|
|
798
|
+
if (sfp.zeroHeight) sfpAttrs.zeroHeight = 1;
|
|
799
|
+
if (sfp.thickTop) sfpAttrs.thickTop = 1;
|
|
800
|
+
if (sfp.thickBottom) sfpAttrs.thickBottom = 1;
|
|
801
|
+
if (sfp.outlineLevelRow !== void 0) sfpAttrs.outlineLevelRow = sfp.outlineLevelRow;
|
|
802
|
+
if (sfp.outlineLevelCol !== void 0) sfpAttrs.outlineLevelCol = sfp.outlineLevelCol;
|
|
803
|
+
p.push(`<sheetFormatPr${attrs(sfpAttrs)}/>`);
|
|
804
|
+
} else p.push("<sheetFormatPr defaultRowHeight=\"15\"/>");
|
|
805
|
+
if (columns.length > 0) {
|
|
806
|
+
p.push("<cols>");
|
|
807
|
+
for (const col of columns) {
|
|
808
|
+
const colAttrs = {
|
|
809
|
+
min: col.min,
|
|
810
|
+
max: col.max
|
|
811
|
+
};
|
|
812
|
+
if (col.width !== void 0) {
|
|
813
|
+
colAttrs.width = col.width;
|
|
814
|
+
colAttrs.customWidth = 1;
|
|
815
|
+
}
|
|
816
|
+
if (col.hidden) colAttrs.hidden = 1;
|
|
817
|
+
if (col.outlineLevel !== void 0) colAttrs.outlineLevel = col.outlineLevel;
|
|
818
|
+
if (col.collapsed) colAttrs.collapsed = 1;
|
|
819
|
+
if (col.bestFit) colAttrs.bestFit = 1;
|
|
820
|
+
if (col.phonetic) colAttrs.phonetic = 1;
|
|
821
|
+
p.push(selfCloseElement("col", attrs(colAttrs)));
|
|
822
|
+
}
|
|
823
|
+
p.push("</cols>");
|
|
824
|
+
}
|
|
825
|
+
p.push("<sheetData>");
|
|
826
|
+
for (let i = 0; i < rows.length; i++) {
|
|
827
|
+
const rowOpts = rows[i];
|
|
828
|
+
const rowNumber = rowOpts.rowNumber ?? i + 1;
|
|
829
|
+
const rowAttrs = { r: rowNumber };
|
|
830
|
+
if (rowOpts.height !== void 0) {
|
|
831
|
+
rowAttrs.ht = rowOpts.height;
|
|
832
|
+
rowAttrs.customHeight = 1;
|
|
833
|
+
}
|
|
834
|
+
if (rowOpts.hidden) rowAttrs.hidden = 1;
|
|
835
|
+
if (rowOpts.spans) rowAttrs.spans = rowOpts.spans;
|
|
836
|
+
if (rowOpts.customFormat) rowAttrs.customFormat = 1;
|
|
837
|
+
if (rowOpts.thickTop) rowAttrs.thickTop = 1;
|
|
838
|
+
if (rowOpts.thickBot) rowAttrs.thickBot = 1;
|
|
839
|
+
if (rowOpts.ph) rowAttrs.ph = 1;
|
|
840
|
+
if (rowOpts.cells) {
|
|
841
|
+
p.push(`<row${attrsRaw(rowAttrs)}>`);
|
|
842
|
+
for (let j = 0; j < rowOpts.cells.length; j++) {
|
|
843
|
+
const cell = rowOpts.cells[j];
|
|
844
|
+
const cellStr = buildCellString(cell.reference ?? defaultCellRef(rowNumber, j + 1), cell, sharedStrings, styles);
|
|
845
|
+
if (cellStr) p.push(cellStr);
|
|
846
|
+
}
|
|
847
|
+
p.push("</row>");
|
|
848
|
+
} else p.push(`<row${attrsRaw(rowAttrs)}/>`);
|
|
849
|
+
}
|
|
850
|
+
p.push("</sheetData>");
|
|
851
|
+
if (opts.sheetCalcPr) {
|
|
852
|
+
const scAttrs = [];
|
|
853
|
+
if (opts.sheetCalcPr.fullCalcOnLoad) scAttrs.push("fullCalcOnLoad=\"1\"");
|
|
854
|
+
p.push(`<sheetCalcPr${scAttrs.length ? " " + scAttrs.join(" ") : ""}/>`);
|
|
855
|
+
}
|
|
856
|
+
if (rowBreaks.length > 0) {
|
|
857
|
+
const brkParts = rowBreaks.map((b) => {
|
|
858
|
+
const bAttrs = { id: b.id };
|
|
859
|
+
if (b.min !== void 0) bAttrs.min = b.min;
|
|
860
|
+
if (b.max !== void 0) bAttrs.max = b.max;
|
|
861
|
+
if (b.manual) bAttrs.man = 1;
|
|
862
|
+
if (b.pivot) bAttrs.pt = 1;
|
|
863
|
+
return `<brk${attrs(bAttrs)}/>`;
|
|
864
|
+
});
|
|
865
|
+
p.push(`<rowBreaks count="${rowBreaks.length}" manualBreakCount="${rowBreaks.filter((b) => b.manual).length}">${brkParts.join("")}</rowBreaks>`);
|
|
866
|
+
}
|
|
867
|
+
if (colBreaks.length > 0) {
|
|
868
|
+
const brkParts = colBreaks.map((b) => {
|
|
869
|
+
const bAttrs = { id: b.id };
|
|
870
|
+
if (b.min !== void 0) bAttrs.min = b.min;
|
|
871
|
+
if (b.max !== void 0) bAttrs.max = b.max;
|
|
872
|
+
if (b.manual) bAttrs.man = 1;
|
|
873
|
+
if (b.pivot) bAttrs.pt = 1;
|
|
874
|
+
return `<brk${attrs(bAttrs)}/>`;
|
|
875
|
+
});
|
|
876
|
+
p.push(`<colBreaks count="${colBreaks.length}" manualBreakCount="${colBreaks.filter((b) => b.manual).length}">${brkParts.join("")}</colBreaks>`);
|
|
877
|
+
}
|
|
878
|
+
if (customProperties.length > 0) {
|
|
879
|
+
const cpParts = ["<customProperties>"];
|
|
880
|
+
for (const cp of customProperties) cpParts.push(`<customPr name="${escapeXml(cp.name)}" r:id="${escapeXml(cp.rId)}"/>`);
|
|
881
|
+
cpParts.push("</customProperties>");
|
|
882
|
+
p.push(cpParts.join(""));
|
|
883
|
+
}
|
|
884
|
+
if (opts.oleSize) p.push(`<oleSize ref="${escapeXml(opts.oleSize)}"/>`);
|
|
885
|
+
if (customSheetViews.length > 0) {
|
|
886
|
+
p.push("<customSheetViews>");
|
|
887
|
+
for (const csv of customSheetViews) {
|
|
888
|
+
const csvAttrs = { guid: csv.guid };
|
|
889
|
+
if (csv.scale !== void 0) csvAttrs.scale = csv.scale;
|
|
890
|
+
if (csv.showPageBreaks) csvAttrs.showPageBreaks = 1;
|
|
891
|
+
if (csv.showFormulas) csvAttrs.showFormulas = 1;
|
|
892
|
+
if (csv.showGridLines === false) csvAttrs.showGridLines = 0;
|
|
893
|
+
if (csv.showRowColHeaders === false) csvAttrs.showRowCol = 0;
|
|
894
|
+
if (csv.outlineSymbols === false) csvAttrs.outlineSymbols = 0;
|
|
895
|
+
if (csv.zeroValues === false) csvAttrs.zeroValues = 0;
|
|
896
|
+
if (csv.fitToPage) csvAttrs.fitToPage = 1;
|
|
897
|
+
if (csv.printArea) csvAttrs.printArea = 1;
|
|
898
|
+
if (csv.filter) csvAttrs.filter = 1;
|
|
899
|
+
if (csv.showAutoFilter) csvAttrs.showAutoFilter = 1;
|
|
900
|
+
if (csv.hiddenRows) csvAttrs.hiddenRows = 1;
|
|
901
|
+
if (csv.hiddenColumns) csvAttrs.hiddenColumns = 1;
|
|
902
|
+
if (csv.state && csv.state !== "visible") csvAttrs.state = csv.state;
|
|
903
|
+
if (csv.filterUnique) csvAttrs.filterUnique = 1;
|
|
904
|
+
if (csv.view && csv.view !== "normal") csvAttrs.view = csv.view;
|
|
905
|
+
p.push(`<customSheetView${attrs(csvAttrs)}/>`);
|
|
906
|
+
}
|
|
907
|
+
p.push("</customSheetViews>");
|
|
908
|
+
}
|
|
909
|
+
if (cellWatches.length > 0) {
|
|
910
|
+
p.push("<cellWatches>");
|
|
911
|
+
for (const cw of cellWatches) p.push(`<cellWatch r="${escapeXml(cw.r)}"/>`);
|
|
912
|
+
p.push("</cellWatches>");
|
|
913
|
+
}
|
|
914
|
+
if (opts.dataConsolidate) {
|
|
915
|
+
const dc = opts.dataConsolidate;
|
|
916
|
+
const dcAttrs = {};
|
|
917
|
+
if (dc.function && dc.function !== "sum") dcAttrs.function = dc.function;
|
|
918
|
+
if (dc.topLabels) dcAttrs.topLabels = 1;
|
|
919
|
+
if (dc.leftLabels) dcAttrs.leftLabels = 1;
|
|
920
|
+
if (dc.startLabels) dcAttrs.startLabels = 1;
|
|
921
|
+
if (dc.link) dcAttrs.link = 1;
|
|
922
|
+
const refsInner = dc.refs?.map((r) => `<dataRef ref="${escapeXml(r)}"/>`).join("") ?? "";
|
|
923
|
+
const refsXml = refsInner ? `<dataRefs>${refsInner}</dataRefs>` : "";
|
|
924
|
+
if (refsXml || Object.keys(dcAttrs).length > 0) p.push(`<dataConsolidate${attrs(dcAttrs)}>${refsXml}</dataConsolidate>`);
|
|
925
|
+
}
|
|
926
|
+
if (opts.protection) {
|
|
927
|
+
const prot = opts.protection;
|
|
928
|
+
const protAttrs = {};
|
|
929
|
+
if (prot.password) protAttrs.password = hashPassword(prot.password);
|
|
930
|
+
let derived;
|
|
931
|
+
if (prot.password !== void 0 && prot.hashValue === void 0) derived = derivePasswordHash(prot.password);
|
|
932
|
+
protAttrs.algorithmName = prot.algorithmName ?? derived?.algorithmName;
|
|
933
|
+
protAttrs.hashValue = prot.hashValue ?? derived?.hashValue;
|
|
934
|
+
protAttrs.saltValue = prot.saltValue ?? derived?.saltValue;
|
|
935
|
+
if (prot.spinCount !== void 0) protAttrs.spinCount = prot.spinCount;
|
|
936
|
+
else if (derived) protAttrs.spinCount = derived.spinCount;
|
|
937
|
+
if (prot.sheet) protAttrs.sheet = 1;
|
|
938
|
+
if (prot.objects) protAttrs.objects = 1;
|
|
939
|
+
if (prot.scenarios) protAttrs.scenarios = 1;
|
|
940
|
+
if (prot.formatCells === false) protAttrs.formatCells = 0;
|
|
941
|
+
if (prot.formatColumns === false) protAttrs.formatColumns = 0;
|
|
942
|
+
if (prot.formatRows === false) protAttrs.formatRows = 0;
|
|
943
|
+
if (prot.insertColumns === false) protAttrs.insertColumns = 0;
|
|
944
|
+
if (prot.insertRows === false) protAttrs.insertRows = 0;
|
|
945
|
+
if (prot.insertHyperlinks === false) protAttrs.insertHyperlinks = 0;
|
|
946
|
+
if (prot.deleteColumns === false) protAttrs.deleteColumns = 0;
|
|
947
|
+
if (prot.deleteRows === false) protAttrs.deleteRows = 0;
|
|
948
|
+
if (prot.selectLockedCells) protAttrs.selectLockedCells = 1;
|
|
949
|
+
if (prot.sort === false) protAttrs.sort = 0;
|
|
950
|
+
if (prot.autoFilter === false) protAttrs.autoFilter = 0;
|
|
951
|
+
if (prot.pivotTables === false) protAttrs.pivotTables = 0;
|
|
952
|
+
if (prot.selectUnlockedCells) protAttrs.selectUnlockedCells = 1;
|
|
953
|
+
p.push(selfCloseElement("sheetProtection", attrs(protAttrs)));
|
|
954
|
+
}
|
|
955
|
+
if (protectedRanges.length > 0) {
|
|
956
|
+
const prParts = ["<protectedRanges>"];
|
|
957
|
+
for (const pr of protectedRanges) {
|
|
958
|
+
const prAttrs = {
|
|
959
|
+
name: pr.name,
|
|
960
|
+
sqref: pr.sqref
|
|
961
|
+
};
|
|
962
|
+
if (pr.password) prAttrs.password = hashPassword(pr.password);
|
|
963
|
+
let prDerived;
|
|
964
|
+
if (pr.password !== void 0 && pr.hashValue === void 0) prDerived = derivePasswordHash(pr.password);
|
|
965
|
+
prAttrs.algorithmName = pr.algorithmName ?? prDerived?.algorithmName;
|
|
966
|
+
prAttrs.hashValue = pr.hashValue ?? prDerived?.hashValue;
|
|
967
|
+
prAttrs.saltValue = pr.saltValue ?? prDerived?.saltValue;
|
|
968
|
+
if (pr.spinCount !== void 0) prAttrs.spinCount = pr.spinCount;
|
|
969
|
+
else if (prDerived) prAttrs.spinCount = prDerived.spinCount;
|
|
970
|
+
if (!!pr.securityDescriptor) prParts.push(`<protectedRange${attrs(prAttrs)}><securityDescriptor>${escapeXml(pr.securityDescriptor)}</securityDescriptor></protectedRange>`);
|
|
971
|
+
else prParts.push(selfCloseElement("protectedRange", attrs(prAttrs)));
|
|
972
|
+
}
|
|
973
|
+
prParts.push("</protectedRanges>");
|
|
974
|
+
p.push(prParts.join(""));
|
|
975
|
+
}
|
|
976
|
+
if (opts.scenarios) {
|
|
977
|
+
const scParts = ["<scenarios"];
|
|
978
|
+
const scAttrs = {};
|
|
979
|
+
if (opts.scenarios.current !== void 0) scAttrs.current = opts.scenarios.current;
|
|
980
|
+
if (opts.scenarios.show !== void 0) scAttrs.show = opts.scenarios.show;
|
|
981
|
+
scParts[0] = `<scenarios${attrs(scAttrs)}>`;
|
|
982
|
+
for (const scenario of opts.scenarios.scenarios) {
|
|
983
|
+
const sAttrs = { name: scenario.name };
|
|
984
|
+
if (scenario.count !== void 0) sAttrs.count = scenario.count;
|
|
985
|
+
if (scenario.user) sAttrs.user = scenario.user;
|
|
986
|
+
if (scenario.comment) sAttrs.comment = scenario.comment;
|
|
987
|
+
if (scenario.hidden) sAttrs.hidden = true;
|
|
988
|
+
if (scenario.locked) sAttrs.locked = true;
|
|
989
|
+
const sParts = [`<scenario${attrs(sAttrs)}>`];
|
|
990
|
+
for (const cell of scenario.inputCells) {
|
|
991
|
+
const icAttrs = {
|
|
992
|
+
r: cell.r,
|
|
993
|
+
val: String(cell.val)
|
|
994
|
+
};
|
|
995
|
+
if (cell.deleted) icAttrs.deleted = true;
|
|
996
|
+
if (cell.undone) icAttrs.undone = true;
|
|
997
|
+
sParts.push(`<inputCells${attrs(icAttrs)}/>`);
|
|
998
|
+
}
|
|
999
|
+
sParts.push("</scenario>");
|
|
1000
|
+
scParts.push(sParts.join(""));
|
|
1001
|
+
}
|
|
1002
|
+
scParts.push("</scenarios>");
|
|
1003
|
+
p.push(scParts.join(""));
|
|
1004
|
+
}
|
|
1005
|
+
if (opts.autoFilter) if (typeof opts.autoFilter === "string") p.push(selfCloseElement("autoFilter", attrs({ ref: opts.autoFilter })));
|
|
1006
|
+
else {
|
|
1007
|
+
const af = opts.autoFilter;
|
|
1008
|
+
const inner = [];
|
|
1009
|
+
for (const t10 of af.top10 ?? []) {
|
|
1010
|
+
const fcAttrs = { colId: t10.colId };
|
|
1011
|
+
if (t10.hiddenButton) fcAttrs.hiddenButton = 1;
|
|
1012
|
+
if (t10.showButton === false) fcAttrs.showButton = 0;
|
|
1013
|
+
const t10Attrs = { val: t10.val };
|
|
1014
|
+
if (t10.top === false) t10Attrs.top = 0;
|
|
1015
|
+
if (t10.percent) t10Attrs.percent = 1;
|
|
1016
|
+
if (t10.filterVal !== void 0) t10Attrs.filterVal = t10.filterVal;
|
|
1017
|
+
inner.push(`<filterColumn${attrs(fcAttrs)}><top10${attrs(t10Attrs)}/></filterColumn>`);
|
|
1018
|
+
}
|
|
1019
|
+
for (const cf of af.customFilters ?? []) {
|
|
1020
|
+
const fcAttrs = { colId: cf.colId };
|
|
1021
|
+
if (cf.hiddenButton) fcAttrs.hiddenButton = 1;
|
|
1022
|
+
if (cf.showButton === false) fcAttrs.showButton = 0;
|
|
1023
|
+
const cfAttrs = {};
|
|
1024
|
+
if (cf.and) cfAttrs.and = 1;
|
|
1025
|
+
const filters = [];
|
|
1026
|
+
if (cf.val !== void 0) {
|
|
1027
|
+
const fAttrs = { val: cf.val };
|
|
1028
|
+
if (cf.operator) fAttrs.operator = cf.operator;
|
|
1029
|
+
filters.push(selfCloseElement("customFilter", attrs(fAttrs)));
|
|
1030
|
+
}
|
|
1031
|
+
if (cf.val2 !== void 0) filters.push(selfCloseElement("customFilter", attrs({ val: cf.val2 })));
|
|
1032
|
+
if (filters.length > 0) inner.push(`<filterColumn${attrs(fcAttrs)}><customFilters${attrs(cfAttrs)}>${filters.join("")}</customFilters></filterColumn>`);
|
|
1033
|
+
}
|
|
1034
|
+
for (const fi of af.filters ?? []) {
|
|
1035
|
+
const fcAttrs = { colId: fi.colId };
|
|
1036
|
+
const filtersAttrs = {};
|
|
1037
|
+
if (fi.blank) filtersAttrs.blank = 1;
|
|
1038
|
+
if (fi.calendarType) filtersAttrs.calendarType = fi.calendarType;
|
|
1039
|
+
const valParts = (fi.values ?? []).map((v) => `<filter val="${escapeXml(v)}"/>`);
|
|
1040
|
+
inner.push(`<filterColumn${attrs(fcAttrs)}><filters${attrs(filtersAttrs)}>${valParts.join("")}</filters></filterColumn>`);
|
|
1041
|
+
}
|
|
1042
|
+
if (af.sort && af.sort.length > 0) {
|
|
1043
|
+
const sortParts = [];
|
|
1044
|
+
for (const sc of af.sort) {
|
|
1045
|
+
const scAttrs = { ref: sc.ref };
|
|
1046
|
+
if (sc.descending) scAttrs.descending = 1;
|
|
1047
|
+
if (sc.sortBy) scAttrs.sortBy = sc.sortBy;
|
|
1048
|
+
if (sc.customList) scAttrs.customList = sc.customList;
|
|
1049
|
+
if (sc.iconId !== void 0) scAttrs.iconId = sc.iconId;
|
|
1050
|
+
sortParts.push(selfCloseElement("sortCondition", attrs(scAttrs)));
|
|
1051
|
+
}
|
|
1052
|
+
const ssAttrs = { ref: af.ref };
|
|
1053
|
+
if (af.sortState?.columnSort) ssAttrs.columnSort = 1;
|
|
1054
|
+
if (af.sortState?.caseSensitive) ssAttrs.caseSensitive = 1;
|
|
1055
|
+
if (af.sortState?.sortMethod) ssAttrs.sortMethod = af.sortState.sortMethod;
|
|
1056
|
+
inner.push(`<sortState${attrs(ssAttrs)}>${sortParts.join("")}</sortState>`);
|
|
1057
|
+
}
|
|
1058
|
+
for (const cf of af.colorFilters ?? []) {
|
|
1059
|
+
const cfAttrs = {};
|
|
1060
|
+
if (cf.dxfId !== void 0) cfAttrs.dxfId = cf.dxfId;
|
|
1061
|
+
if (cf.cellColor === false) cfAttrs.cellColor = 0;
|
|
1062
|
+
inner.push(`<filterColumn colId="${cf.colId}"><colorFilter${attrs(cfAttrs)}/></filterColumn>`);
|
|
1063
|
+
}
|
|
1064
|
+
for (const if_ of af.iconFilters ?? []) {
|
|
1065
|
+
const ifAttrs = { iconSet: if_.iconSet };
|
|
1066
|
+
if (if_.iconId !== void 0) ifAttrs.iconId = if_.iconId;
|
|
1067
|
+
inner.push(`<filterColumn colId="${if_.colId}"><iconFilter${attrs(ifAttrs)}/></filterColumn>`);
|
|
1068
|
+
}
|
|
1069
|
+
for (const df of af.dynamicFilters ?? []) {
|
|
1070
|
+
const dfAttrs = { type: df.type };
|
|
1071
|
+
if (df.val !== void 0) dfAttrs.val = df.val;
|
|
1072
|
+
if (df.maxVal !== void 0) dfAttrs.maxVal = df.maxVal;
|
|
1073
|
+
if (df.valIso !== void 0) dfAttrs.valIso = df.valIso;
|
|
1074
|
+
if (df.maxValIso !== void 0) dfAttrs.maxValIso = df.maxValIso;
|
|
1075
|
+
inner.push(`<filterColumn colId="${df.colId}"><dynamicFilter${attrs(dfAttrs)}/></filterColumn>`);
|
|
1076
|
+
}
|
|
1077
|
+
for (const dg of af.dateGroupItems ?? []) {
|
|
1078
|
+
const dgAttrs = { dateTimeGrouping: dg.dateTimeGrouping };
|
|
1079
|
+
if (dg.year !== void 0) dgAttrs.year = dg.year;
|
|
1080
|
+
if (dg.month !== void 0) dgAttrs.month = dg.month;
|
|
1081
|
+
if (dg.day !== void 0) dgAttrs.day = dg.day;
|
|
1082
|
+
if (dg.hour !== void 0) dgAttrs.hour = dg.hour;
|
|
1083
|
+
if (dg.minute !== void 0) dgAttrs.minute = dg.minute;
|
|
1084
|
+
if (dg.second !== void 0) dgAttrs.second = dg.second;
|
|
1085
|
+
inner.push(`<filterColumn colId="${dg.colId}"><dateGroupItem${attrs(dgAttrs)}/></filterColumn>`);
|
|
1086
|
+
}
|
|
1087
|
+
if (inner.length > 0) p.push(`<autoFilter ref="${af.ref}">`, ...inner, "</autoFilter>");
|
|
1088
|
+
else p.push(selfCloseElement("autoFilter", attrs({ ref: af.ref })));
|
|
1089
|
+
}
|
|
1090
|
+
if (mergeCells.length > 0) {
|
|
1091
|
+
p.push(`<mergeCells count="${mergeCells.length}">`);
|
|
1092
|
+
for (const mc of mergeCells) {
|
|
1093
|
+
const fromRef = defaultCellRef(mc.from.row, mc.from.col);
|
|
1094
|
+
const toRef = defaultCellRef(mc.to.row, mc.to.col);
|
|
1095
|
+
p.push(selfCloseElement("mergeCell", attrs({ ref: `${fromRef}:${toRef}` })));
|
|
1096
|
+
}
|
|
1097
|
+
p.push("</mergeCells>");
|
|
1098
|
+
}
|
|
1099
|
+
if (opts.phoneticPr) {
|
|
1100
|
+
const pp = opts.phoneticPr;
|
|
1101
|
+
const ppAttrs = { fontId: pp.fontId };
|
|
1102
|
+
if (pp.type && pp.type !== "fullwidthKatakana") ppAttrs.type = pp.type;
|
|
1103
|
+
if (pp.alignment && pp.alignment !== "left") ppAttrs.alignment = pp.alignment;
|
|
1104
|
+
p.push(selfCloseElement("phoneticPr", attrs(ppAttrs)));
|
|
1105
|
+
}
|
|
1106
|
+
const conditionalFormats = opts.conditionalFormats ?? [];
|
|
1107
|
+
if (conditionalFormats.length > 0) for (const cf of conditionalFormats) {
|
|
1108
|
+
p.push(`<conditionalFormatting sqref="${cf.sqref}">`);
|
|
1109
|
+
for (let ri = 0; ri < cf.rules.length; ri++) {
|
|
1110
|
+
const rule = cf.rules[ri];
|
|
1111
|
+
const ruleAttrs = {
|
|
1112
|
+
type: rule.type,
|
|
1113
|
+
priority: rule.priority ?? ri + 1
|
|
1114
|
+
};
|
|
1115
|
+
if (rule.operator) ruleAttrs.operator = rule.operator;
|
|
1116
|
+
if (rule.dxfId !== void 0) ruleAttrs.dxfId = rule.dxfId;
|
|
1117
|
+
if (rule.stopIfTrue) ruleAttrs.stopIfTrue = 1;
|
|
1118
|
+
if (rule.timePeriod) ruleAttrs.timePeriod = rule.timePeriod;
|
|
1119
|
+
if (rule.rank !== void 0) ruleAttrs.rank = rule.rank;
|
|
1120
|
+
if (rule.equalAverage) ruleAttrs.equalAverage = 1;
|
|
1121
|
+
if (rule.type === "colorScale" && rule.colorScale) {
|
|
1122
|
+
const cs = rule.colorScale;
|
|
1123
|
+
const inner = [];
|
|
1124
|
+
for (const v of cs.cfvo) inner.push(buildCfvoXml(v));
|
|
1125
|
+
for (const c of cs.colors) inner.push(`<color rgb="FF${c}"/>`);
|
|
1126
|
+
p.push(`<cfRule${attrs(ruleAttrs)}><colorScale>${inner.join("")}</colorScale></cfRule>`);
|
|
1127
|
+
} else if (rule.type === "dataBar" && rule.dataBar) {
|
|
1128
|
+
const db = rule.dataBar;
|
|
1129
|
+
const inner = [];
|
|
1130
|
+
for (const v of db.cfvo) inner.push(buildCfvoXml(v));
|
|
1131
|
+
inner.push(`<color rgb="FF${db.color}"/>`);
|
|
1132
|
+
const dbAttrs = {};
|
|
1133
|
+
if (db.minLength !== void 0 && db.minLength !== 10) dbAttrs.minLength = db.minLength;
|
|
1134
|
+
if (db.maxLength !== void 0 && db.maxLength !== 90) dbAttrs.maxLength = db.maxLength;
|
|
1135
|
+
if (db.showValue === false) dbAttrs.showValue = 0;
|
|
1136
|
+
const attrStr = Object.keys(dbAttrs).length > 0 ? attrs(dbAttrs) : "";
|
|
1137
|
+
p.push(`<cfRule${attrs(ruleAttrs)}><dataBar${attrStr}>${inner.join("")}</dataBar></cfRule>`);
|
|
1138
|
+
} else if (rule.type === "iconSet" && rule.iconSet) {
|
|
1139
|
+
const is = rule.iconSet;
|
|
1140
|
+
const inner = [];
|
|
1141
|
+
for (const v of is.cfvo) inner.push(buildCfvoXml(v));
|
|
1142
|
+
const isAttrs = {};
|
|
1143
|
+
if (is.iconSet !== void 0 && is.iconSet !== "3TrafficLights1") isAttrs.iconSet = is.iconSet;
|
|
1144
|
+
if (is.showValue === false) isAttrs.showValue = 0;
|
|
1145
|
+
if (is.percent === false) isAttrs.percent = 0;
|
|
1146
|
+
if (is.reverse) isAttrs.reverse = 1;
|
|
1147
|
+
const attrStr = Object.keys(isAttrs).length > 0 ? attrs(isAttrs) : "";
|
|
1148
|
+
p.push(`<cfRule${attrs(ruleAttrs)}><iconSet${attrStr}>${inner.join("")}</iconSet></cfRule>`);
|
|
1149
|
+
} else if (rule.formulas && rule.formulas.length > 0) {
|
|
1150
|
+
const formulaParts = rule.formulas.map((f) => `<formula>${escapeXml(f)}</formula>`);
|
|
1151
|
+
p.push(`<cfRule${attrs(ruleAttrs)}>`, ...formulaParts, "</cfRule>");
|
|
1152
|
+
} else p.push(selfCloseElement("cfRule", attrs(ruleAttrs)));
|
|
1153
|
+
}
|
|
1154
|
+
p.push("</conditionalFormatting>");
|
|
1155
|
+
}
|
|
1156
|
+
const dataValidations = opts.dataValidations ?? [];
|
|
1157
|
+
if (dataValidations.length > 0) {
|
|
1158
|
+
const dvContainerAttrs = { count: dataValidations.length };
|
|
1159
|
+
if (opts.dataValidationsDisablePrompts) dvContainerAttrs.disablePrompts = 1;
|
|
1160
|
+
p.push(`<dataValidations${attrs(dvContainerAttrs)}>`);
|
|
1161
|
+
for (const dv of dataValidations) {
|
|
1162
|
+
const dvAttrs = { sqref: dv.sqref };
|
|
1163
|
+
if (dv.type && dv.type !== "none") dvAttrs.type = dv.type;
|
|
1164
|
+
if (dv.operator) dvAttrs.operator = dv.operator;
|
|
1165
|
+
if (dv.allowBlank) dvAttrs.allowBlank = 1;
|
|
1166
|
+
if (dv.showErrorMessage) dvAttrs.showErrorMessage = 1;
|
|
1167
|
+
if (dv.showInputMessage) dvAttrs.showInputMessage = 1;
|
|
1168
|
+
if (dv.errorTitle) dvAttrs.errorTitle = dv.errorTitle;
|
|
1169
|
+
if (dv.error) dvAttrs.error = dv.error;
|
|
1170
|
+
if (dv.promptTitle) dvAttrs.promptTitle = dv.promptTitle;
|
|
1171
|
+
if (dv.prompt) dvAttrs.prompt = dv.prompt;
|
|
1172
|
+
if (dv.errorStyle) dvAttrs.errorStyle = dv.errorStyle;
|
|
1173
|
+
if (dv.imeMode) dvAttrs.imeMode = dv.imeMode;
|
|
1174
|
+
if (dv.showDropDown) dvAttrs.showDropDown = 1;
|
|
1175
|
+
const inner = [];
|
|
1176
|
+
if (dv.formula1 !== void 0) inner.push(`<formula1>${escapeXml(dv.formula1)}</formula1>`);
|
|
1177
|
+
if (dv.formula2 !== void 0) inner.push(`<formula2>${escapeXml(dv.formula2)}</formula2>`);
|
|
1178
|
+
if (inner.length > 0) p.push(`<dataValidation${attrs(dvAttrs)}>`, ...inner, "</dataValidation>");
|
|
1179
|
+
else p.push(selfCloseElement("dataValidation", attrs(dvAttrs)));
|
|
1180
|
+
}
|
|
1181
|
+
p.push("</dataValidations>");
|
|
1182
|
+
}
|
|
1183
|
+
const hyperlinks = opts.hyperlinks ?? [];
|
|
1184
|
+
if (hyperlinks.length > 0) {
|
|
1185
|
+
p.push("<hyperlinks>");
|
|
1186
|
+
let hlIdx = 0;
|
|
1187
|
+
for (const hl of hyperlinks) {
|
|
1188
|
+
const hlAttrs = { ref: hl.cell };
|
|
1189
|
+
if (hl.target.type === "external") {
|
|
1190
|
+
hlIdx++;
|
|
1191
|
+
hlAttrs["r:id"] = `rId${hlIdx}`;
|
|
1192
|
+
} else hlAttrs.location = hl.target.location;
|
|
1193
|
+
if (hl.tooltip) hlAttrs.tooltip = hl.tooltip;
|
|
1194
|
+
if (hl.display) hlAttrs.display = hl.display;
|
|
1195
|
+
p.push(selfCloseElement("hyperlink", attrs(hlAttrs)));
|
|
1196
|
+
}
|
|
1197
|
+
p.push("</hyperlinks>");
|
|
1198
|
+
}
|
|
1199
|
+
if (opts.printOptions) {
|
|
1200
|
+
const po = opts.printOptions;
|
|
1201
|
+
const poAttrs = {};
|
|
1202
|
+
if (po.horizontalCentered) poAttrs.horizontalCentered = 1;
|
|
1203
|
+
if (po.verticalCentered) poAttrs.verticalCentered = 1;
|
|
1204
|
+
if (po.headings) poAttrs.headings = 1;
|
|
1205
|
+
if (po.gridLines) poAttrs.gridLines = 1;
|
|
1206
|
+
if (po.gridLinesSet === false) poAttrs.gridLinesSet = 0;
|
|
1207
|
+
p.push(selfCloseElement("printOptions", attrs(poAttrs)));
|
|
1208
|
+
}
|
|
1209
|
+
p.push("<pageMargins left=\"0.75\" right=\"0.75\" top=\"1\" bottom=\"1\" header=\"0.5\" footer=\"0.5\"/>");
|
|
1210
|
+
if (opts.pageSetup) {
|
|
1211
|
+
const ps = opts.pageSetup;
|
|
1212
|
+
const psAttrs = {};
|
|
1213
|
+
if (ps.paperSize !== void 0) psAttrs.paperSize = ps.paperSize;
|
|
1214
|
+
if (ps.orientation && ps.orientation !== "default") psAttrs.orientation = ps.orientation;
|
|
1215
|
+
if (ps.scale !== void 0) psAttrs.scale = ps.scale;
|
|
1216
|
+
if (ps.fitToWidth !== void 0) psAttrs.fitToWidth = ps.fitToWidth;
|
|
1217
|
+
if (ps.fitToHeight !== void 0) psAttrs.fitToHeight = ps.fitToHeight;
|
|
1218
|
+
if (ps.pageOrder && ps.pageOrder !== "downThenOver") psAttrs.pageOrder = ps.pageOrder;
|
|
1219
|
+
if (ps.useFirstPageNumber) psAttrs.useFirstPageNumber = 1;
|
|
1220
|
+
if (ps.firstPageNumber !== void 0) psAttrs.firstPageNumber = ps.firstPageNumber;
|
|
1221
|
+
if (ps.paperHeight !== void 0) psAttrs.paperHeight = ps.paperHeight;
|
|
1222
|
+
if (ps.paperWidth !== void 0) psAttrs.paperWidth = ps.paperWidth;
|
|
1223
|
+
if (ps.usePrinterDefaults) psAttrs.usePrinterDefaults = 1;
|
|
1224
|
+
if (ps.blackAndWhite) psAttrs.blackAndWhite = 1;
|
|
1225
|
+
if (ps.draft) psAttrs.draft = 1;
|
|
1226
|
+
if (ps.cellComments && ps.cellComments !== "none") psAttrs.cellComments = ps.cellComments;
|
|
1227
|
+
if (ps.errors && ps.errors !== "displayed") psAttrs.errors = ps.errors;
|
|
1228
|
+
p.push(selfCloseElement("pageSetup", attrs(psAttrs)));
|
|
1229
|
+
}
|
|
1230
|
+
if (opts.headerFooter) {
|
|
1231
|
+
const hf = opts.headerFooter;
|
|
1232
|
+
const hfAttrs = {};
|
|
1233
|
+
if (hf.differentOddEven) hfAttrs.differentOddEven = 1;
|
|
1234
|
+
if (hf.differentFirst) hfAttrs.differentFirst = 1;
|
|
1235
|
+
if (hf.scaleWithDoc === false) hfAttrs.scaleWithDoc = 0;
|
|
1236
|
+
if (hf.alignWithMargins === false) hfAttrs.alignWithMargins = 0;
|
|
1237
|
+
const inner = [];
|
|
1238
|
+
if (hf.oddHeader) inner.push(`<oddHeader>${escapeXml(hf.oddHeader)}</oddHeader>`);
|
|
1239
|
+
if (hf.oddFooter) inner.push(`<oddFooter>${escapeXml(hf.oddFooter)}</oddFooter>`);
|
|
1240
|
+
if (hf.evenHeader) inner.push(`<evenHeader>${escapeXml(hf.evenHeader)}</evenHeader>`);
|
|
1241
|
+
if (hf.evenFooter) inner.push(`<evenFooter>${escapeXml(hf.evenFooter)}</evenFooter>`);
|
|
1242
|
+
if (hf.firstHeader) inner.push(`<firstHeader>${escapeXml(hf.firstHeader)}</firstHeader>`);
|
|
1243
|
+
if (hf.firstFooter) inner.push(`<firstFooter>${escapeXml(hf.firstFooter)}</firstFooter>`);
|
|
1244
|
+
if (inner.length > 0) p.push(`<headerFooter${attrs(hfAttrs)}>`, ...inner, "</headerFooter>");
|
|
1245
|
+
else if (hfAttrs.differentOddEven || hfAttrs.differentFirst) p.push(selfCloseElement("headerFooter", attrs(hfAttrs)));
|
|
1246
|
+
}
|
|
1247
|
+
if (opts.drawingHF) {
|
|
1248
|
+
const dhf = opts.drawingHF;
|
|
1249
|
+
const dhfAttrs = { "r:id": dhf.rId };
|
|
1250
|
+
if (dhf.lho !== void 0) dhfAttrs.lho = dhf.lho;
|
|
1251
|
+
if (dhf.lhe !== void 0) dhfAttrs.lhe = dhf.lhe;
|
|
1252
|
+
if (dhf.lhf !== void 0) dhfAttrs.lhf = dhf.lhf;
|
|
1253
|
+
if (dhf.cho !== void 0) dhfAttrs.cho = dhf.cho;
|
|
1254
|
+
if (dhf.che !== void 0) dhfAttrs.che = dhf.che;
|
|
1255
|
+
if (dhf.chf !== void 0) dhfAttrs.chf = dhf.chf;
|
|
1256
|
+
if (dhf.rho !== void 0) dhfAttrs.rho = dhf.rho;
|
|
1257
|
+
if (dhf.rhe !== void 0) dhfAttrs.rhe = dhf.rhe;
|
|
1258
|
+
if (dhf.rhf !== void 0) dhfAttrs.rhf = dhf.rhf;
|
|
1259
|
+
if (dhf.lfo !== void 0) dhfAttrs.lfo = dhf.lfo;
|
|
1260
|
+
if (dhf.lfe !== void 0) dhfAttrs.lfe = dhf.lfe;
|
|
1261
|
+
if (dhf.lff !== void 0) dhfAttrs.lff = dhf.lff;
|
|
1262
|
+
if (dhf.cfo !== void 0) dhfAttrs.cfo = dhf.cfo;
|
|
1263
|
+
if (dhf.cfe !== void 0) dhfAttrs.cfe = dhf.cfe;
|
|
1264
|
+
if (dhf.cff !== void 0) dhfAttrs.cff = dhf.cff;
|
|
1265
|
+
if (dhf.rfo !== void 0) dhfAttrs.rfo = dhf.rfo;
|
|
1266
|
+
if (dhf.rfe !== void 0) dhfAttrs.rfe = dhf.rfe;
|
|
1267
|
+
if (dhf.rff !== void 0) dhfAttrs.rff = dhf.rff;
|
|
1268
|
+
p.push(selfCloseElement("drawingHF", attrs(dhfAttrs)));
|
|
1269
|
+
}
|
|
1270
|
+
if (opts.legacyDrawingHF) p.push(`<legacyDrawingHF r:id="${escapeXml(opts.legacyDrawingHF)}"/>`);
|
|
1271
|
+
if (ignoredErrors.length > 0) {
|
|
1272
|
+
const ieParts = ["<ignoredErrors>"];
|
|
1273
|
+
for (const ie of ignoredErrors) {
|
|
1274
|
+
const ieAttrs = { sqref: ie.sqref };
|
|
1275
|
+
if (ie.evalError) ieAttrs.evalError = 1;
|
|
1276
|
+
if (ie.twoDigitTextYear) ieAttrs.twoDigitTextYear = 1;
|
|
1277
|
+
if (ie.numberStoredAsText) ieAttrs.numberStoredAsText = 1;
|
|
1278
|
+
if (ie.formula) ieAttrs.formula = 1;
|
|
1279
|
+
if (ie.formulaRange) ieAttrs.formulaRange = 1;
|
|
1280
|
+
if (ie.unlockedFormula) ieAttrs.unlockedFormula = 1;
|
|
1281
|
+
if (ie.emptyCellReference) ieAttrs.emptyCellReference = 1;
|
|
1282
|
+
if (ie.listDataValidation) ieAttrs.listDataValidation = 1;
|
|
1283
|
+
if (ie.calculatedColumn) ieAttrs.calculatedColumn = 1;
|
|
1284
|
+
ieParts.push(selfCloseElement("ignoredError", attrs(ieAttrs)));
|
|
1285
|
+
}
|
|
1286
|
+
ieParts.push("</ignoredErrors>");
|
|
1287
|
+
p.push(ieParts.join(""));
|
|
1288
|
+
}
|
|
1289
|
+
if (opts.backgroundImage) p.push("<!--BACKGROUND_PICTURE-->");
|
|
1290
|
+
if (oleObjects.length > 0) {
|
|
1291
|
+
const oleParts = ["<oleObjects>"];
|
|
1292
|
+
for (const ole of oleObjects) {
|
|
1293
|
+
const oleAttrs = [`shapeId="${ole.shapeId}"`];
|
|
1294
|
+
if (ole.progId) oleAttrs.push(`progId="${escapeXml(ole.progId)}"`);
|
|
1295
|
+
if (ole.dvAspect && ole.dvAspect !== "DVASPECT_CONTENT") oleAttrs.push(`dvAspect="${ole.dvAspect}"`);
|
|
1296
|
+
if (ole.link) oleAttrs.push(`link="${escapeXml(ole.link)}"`);
|
|
1297
|
+
if (ole.oleUpdate) oleAttrs.push(`oleUpdate="${ole.oleUpdate}"`);
|
|
1298
|
+
if (ole.autoLoad) oleAttrs.push("autoLoad=\"1\"");
|
|
1299
|
+
if (ole.rId) oleAttrs.push(`r:id="${escapeXml(ole.rId)}"`);
|
|
1300
|
+
if (ole.objectPr) {
|
|
1301
|
+
const opr = ole.objectPr;
|
|
1302
|
+
const oprAttrs = [];
|
|
1303
|
+
if (opr.locked === false) oprAttrs.push("locked=\"0\"");
|
|
1304
|
+
if (opr.defaultSize === false) oprAttrs.push("defaultSize=\"0\"");
|
|
1305
|
+
if (opr.print === false) oprAttrs.push("print=\"0\"");
|
|
1306
|
+
if (opr.disabled) oprAttrs.push("disabled=\"1\"");
|
|
1307
|
+
if (opr.uiObject) oprAttrs.push("uiObject=\"1\"");
|
|
1308
|
+
if (opr.autoFill === false) oprAttrs.push("autoFill=\"0\"");
|
|
1309
|
+
if (opr.autoLine === false) oprAttrs.push("autoLine=\"0\"");
|
|
1310
|
+
if (opr.autoPict === false) oprAttrs.push("autoPict=\"0\"");
|
|
1311
|
+
if (opr.macro) oprAttrs.push(`macro="${escapeXml(opr.macro)}"`);
|
|
1312
|
+
if (opr.altText) oprAttrs.push(`altText="${escapeXml(opr.altText)}"`);
|
|
1313
|
+
if (opr.dde) oprAttrs.push("dde=\"1\"");
|
|
1314
|
+
if (opr.rId) oprAttrs.push(`r:id="${escapeXml(opr.rId)}"`);
|
|
1315
|
+
oleParts.push(`<oleObject ${oleAttrs.join(" ")}><objectPr${oprAttrs.length ? " " + oprAttrs.join(" ") : ""}/></oleObject>`);
|
|
1316
|
+
} else oleParts.push(`<oleObject ${oleAttrs.join(" ")}/>`);
|
|
1317
|
+
}
|
|
1318
|
+
oleParts.push("</oleObjects>");
|
|
1319
|
+
p.push(oleParts.join(""));
|
|
1320
|
+
}
|
|
1321
|
+
if (controls.length > 0) {
|
|
1322
|
+
const ctrlParts = ["<controls>"];
|
|
1323
|
+
for (const c of controls) {
|
|
1324
|
+
const cAttrs = [`shapeId="${c.shapeId}"`, `r:id="${escapeXml(c.rId)}"`];
|
|
1325
|
+
if (c.name) cAttrs.push(`name="${escapeXml(c.name)}"`);
|
|
1326
|
+
const prAttrs = [];
|
|
1327
|
+
if (c.locked === false) prAttrs.push("locked=\"0\"");
|
|
1328
|
+
if (c.uiObject) prAttrs.push("uiObject=\"1\"");
|
|
1329
|
+
if (c.recalcAlways) prAttrs.push("recalcAlways=\"1\"");
|
|
1330
|
+
if (c.linkedCell) prAttrs.push(`linkedCell="${escapeXml(c.linkedCell)}"`);
|
|
1331
|
+
if (c.listFillRange) prAttrs.push(`listFillRange="${escapeXml(c.listFillRange)}"`);
|
|
1332
|
+
if (c.cf) prAttrs.push(`cf="${escapeXml(c.cf)}"`);
|
|
1333
|
+
if (prAttrs.length > 0) ctrlParts.push(`<control ${cAttrs.join(" ")}><controlPr${prAttrs.length ? " " + prAttrs.join(" ") : ""}/></control>`);
|
|
1334
|
+
else ctrlParts.push(`<control ${cAttrs.join(" ")}/>`);
|
|
1335
|
+
}
|
|
1336
|
+
ctrlParts.push("</controls>");
|
|
1337
|
+
p.push(ctrlParts.join(""));
|
|
1338
|
+
}
|
|
1339
|
+
if (webPublishItems.length > 0) {
|
|
1340
|
+
const wpParts = [`<webPublishItems count="${webPublishItems.length}">`];
|
|
1341
|
+
for (const wpi of webPublishItems) {
|
|
1342
|
+
const wpiAttrs = [
|
|
1343
|
+
`id="${wpi.id}"`,
|
|
1344
|
+
`divId="${escapeXml(wpi.divId)}"`,
|
|
1345
|
+
`sourceType="${wpi.sourceType}"`,
|
|
1346
|
+
`destinationFile="${escapeXml(wpi.destinationFile)}"`
|
|
1347
|
+
];
|
|
1348
|
+
if (wpi.sourceRef) wpiAttrs.push(`sourceRef="${escapeXml(wpi.sourceRef)}"`);
|
|
1349
|
+
if (wpi.sourceObject) wpiAttrs.push(`sourceObject="${escapeXml(wpi.sourceObject)}"`);
|
|
1350
|
+
if (wpi.title) wpiAttrs.push(`title="${escapeXml(wpi.title)}"`);
|
|
1351
|
+
if (wpi.autoRepublish) wpiAttrs.push("autoRepublish=\"1\"");
|
|
1352
|
+
wpParts.push(`<webPublishItem ${wpiAttrs.join(" ")}/>`);
|
|
1353
|
+
}
|
|
1354
|
+
wpParts.push("</webPublishItems>");
|
|
1355
|
+
p.push(wpParts.join(""));
|
|
1356
|
+
}
|
|
1357
|
+
if (opts.ext) p.push(`<extLst>${opts.ext}</extLst>`);
|
|
1358
|
+
p.push("</worksheet>");
|
|
1359
|
+
return p.join("");
|
|
1360
|
+
}
|
|
1361
|
+
function buildCfvoXml(cfvo) {
|
|
1362
|
+
const a = { type: cfvo.type };
|
|
1363
|
+
if (cfvo.val !== void 0) a.val = cfvo.val;
|
|
1364
|
+
if (cfvo.gte === false) a.gte = 0;
|
|
1365
|
+
return `<cfvo${attrs(a)}/>`;
|
|
1366
|
+
}
|
|
1367
|
+
function buildSheetViewAttrs(sv) {
|
|
1368
|
+
const svMap = { workbookViewId: 0 };
|
|
1369
|
+
if (sv?.tabSelected !== void 0) svMap.tabSelected = sv.tabSelected ? 1 : 0;
|
|
1370
|
+
else svMap.tabSelected = 1;
|
|
1371
|
+
if (sv?.showGridLines === false) svMap.showGridLines = 0;
|
|
1372
|
+
if (sv?.showRowColHeaders === false) svMap.showRowColHeaders = 0;
|
|
1373
|
+
if (sv?.showZeros === false) svMap.showZeros = 0;
|
|
1374
|
+
if (sv?.zoomScale !== void 0) svMap.zoomScale = sv.zoomScale;
|
|
1375
|
+
if (sv?.rightToLeft) svMap.rightToLeft = 1;
|
|
1376
|
+
if (sv?.windowProtection) svMap.windowProtection = 1;
|
|
1377
|
+
if (sv?.showFormulas) svMap.showFormulas = 1;
|
|
1378
|
+
if (sv?.showRuler === false) svMap.showRuler = 0;
|
|
1379
|
+
if (sv?.showOutlineSymbols === false) svMap.showOutlineSymbols = 0;
|
|
1380
|
+
if (sv?.defaultGridColor === false) svMap.defaultGridColor = 0;
|
|
1381
|
+
if (sv?.showWhiteSpace === false) svMap.showWhiteSpace = 0;
|
|
1382
|
+
if (sv?.view) svMap.view = sv.view;
|
|
1383
|
+
if (sv?.colorId !== void 0) svMap.colorId = sv.colorId;
|
|
1384
|
+
if (sv?.zoomScaleNormal !== void 0) svMap.zoomScaleNormal = sv.zoomScaleNormal;
|
|
1385
|
+
if (sv?.zoomScaleSheetLayoutView !== void 0) svMap.zoomScaleSheetLayoutView = sv.zoomScaleSheetLayoutView;
|
|
1386
|
+
if (sv?.zoomScalePageLayoutView !== void 0) svMap.zoomScalePageLayoutView = sv.zoomScalePageLayoutView;
|
|
1387
|
+
return attrs(svMap);
|
|
1388
|
+
}
|
|
1389
|
+
function buildSelectionXml(sel) {
|
|
1390
|
+
const selAttrs = {};
|
|
1391
|
+
if (sel.pane) selAttrs.pane = sel.pane;
|
|
1392
|
+
if (sel.activeCell) selAttrs.activeCell = sel.activeCell;
|
|
1393
|
+
if (sel.activeCellId !== void 0) selAttrs.activeCellId = sel.activeCellId;
|
|
1394
|
+
if (sel.sqref) selAttrs.sqref = sel.sqref;
|
|
1395
|
+
return `<selection${attrs(selAttrs)}/>`;
|
|
1396
|
+
}
|
|
1397
|
+
function buildPivotSelectionXml(_ps) {
|
|
1398
|
+
return "";
|
|
1399
|
+
}
|
|
1400
|
+
function hashPassword(password) {
|
|
1401
|
+
let hash = 0;
|
|
1402
|
+
for (let i = 0; i < password.length; i++) {
|
|
1403
|
+
const c = password.charCodeAt(i);
|
|
1404
|
+
hash = (hash >> 14 & 1) + (hash << 1 & 32767);
|
|
1405
|
+
hash ^= c;
|
|
1406
|
+
hash = hash & 16384 ? hash ^ 1 : hash;
|
|
1407
|
+
}
|
|
1408
|
+
hash = (hash >> 14 & 1) + (hash << 1 & 32767);
|
|
1409
|
+
hash = (hash >> 14 & 1) + (hash << 1 & 32767);
|
|
1410
|
+
hash ^= password.length;
|
|
1411
|
+
return hash.toString(16).toUpperCase().padStart(4, "0");
|
|
1412
|
+
}
|
|
1413
|
+
function buildFormulaString(fOpts) {
|
|
1414
|
+
const fAttrs = {};
|
|
1415
|
+
if (fOpts.type && fOpts.type !== FormulaType.NORMAL) fAttrs.t = fOpts.type;
|
|
1416
|
+
if (fOpts.reference) fAttrs.ref = fOpts.reference;
|
|
1417
|
+
if (fOpts.sharedIndex !== void 0) fAttrs.si = fOpts.sharedIndex;
|
|
1418
|
+
if (fOpts.aca) fAttrs.aca = 1;
|
|
1419
|
+
if (fOpts.dt2D) fAttrs.dt2D = 1;
|
|
1420
|
+
if (fOpts.dtr) fAttrs.dtr = 1;
|
|
1421
|
+
if (fOpts.del1) fAttrs.del1 = 1;
|
|
1422
|
+
if (fOpts.del2) fAttrs.del2 = 1;
|
|
1423
|
+
if (fOpts.r1) fAttrs.r1 = fOpts.r1;
|
|
1424
|
+
if (fOpts.r2) fAttrs.r2 = fOpts.r2;
|
|
1425
|
+
if (fOpts.ca) fAttrs.ca = 1;
|
|
1426
|
+
if (fOpts.bx) fAttrs.bx = 1;
|
|
1427
|
+
if (fOpts.formula !== void 0 && fOpts.formula !== "") return `<f${attrs(fAttrs)}>${escapeXml(fOpts.formula)}</f>`;
|
|
1428
|
+
if (Object.keys(fAttrs).length > 0) return selfCloseElement("f", attrs(fAttrs));
|
|
1429
|
+
return "";
|
|
1430
|
+
}
|
|
1431
|
+
function buildCellString(ref, cell, sharedStrings, styles) {
|
|
1432
|
+
const cellAttrs = { r: ref };
|
|
1433
|
+
if (cell.style !== void 0 && styles) cellAttrs.s = styles.register(cell.style);
|
|
1434
|
+
else if (cell.styleIndex !== void 0) cellAttrs.s = cell.styleIndex;
|
|
1435
|
+
const value = cell.value;
|
|
1436
|
+
if (cell.formula) {
|
|
1437
|
+
const fStr = buildFormulaString(cell.formula);
|
|
1438
|
+
let vStr = "";
|
|
1439
|
+
if (value === null || value === void 0) return `<c${attrsRaw(cellAttrs)}>${fStr}</c>`;
|
|
1440
|
+
if (typeof value === "number") vStr = `<v>${value}</v>`;
|
|
1441
|
+
else if (typeof value === "boolean") {
|
|
1442
|
+
cellAttrs.t = "b";
|
|
1443
|
+
vStr = `<v>${value ? 1 : 0}</v>`;
|
|
1444
|
+
} else if (typeof value === "string") {
|
|
1445
|
+
cellAttrs.t = "str";
|
|
1446
|
+
vStr = `<v>${escapeXml(value)}</v>`;
|
|
1447
|
+
} else if (value instanceof Date) vStr = `<v>${dateToSerialNumber(value)}</v>`;
|
|
1448
|
+
if (vStr) return `<c${attrsRaw(cellAttrs)}>${fStr}${vStr}</c>`;
|
|
1449
|
+
return `<c${attrsRaw(cellAttrs)}>${fStr}</c>`;
|
|
1450
|
+
}
|
|
1451
|
+
if (value === null || value === void 0) {
|
|
1452
|
+
if (cell.styleIndex !== void 0) return selfCloseElement("c", attrsRaw(cellAttrs));
|
|
1453
|
+
return "";
|
|
1454
|
+
}
|
|
1455
|
+
if (typeof value === "object" && !(value instanceof Date)) {
|
|
1456
|
+
if (sharedStrings) {
|
|
1457
|
+
cellAttrs.t = "s";
|
|
1458
|
+
const idx = sharedStrings.registerRich(value);
|
|
1459
|
+
return `<c${attrsRaw(cellAttrs)}><v>${idx}</v></c>`;
|
|
1460
|
+
}
|
|
1461
|
+
cellAttrs.t = "inlineStr";
|
|
1462
|
+
return `<c${attrsRaw(cellAttrs)}><is>${buildRstXml$1(value)}</is></c>`;
|
|
1463
|
+
}
|
|
1464
|
+
if (typeof value === "string") {
|
|
1465
|
+
if (sharedStrings) {
|
|
1466
|
+
cellAttrs.t = "s";
|
|
1467
|
+
const idx = sharedStrings.register(value);
|
|
1468
|
+
return `<c${attrsRaw(cellAttrs)}><v>${idx}</v></c>`;
|
|
1469
|
+
}
|
|
1470
|
+
cellAttrs.t = "inlineStr";
|
|
1471
|
+
return `<c${attrsRaw(cellAttrs)}><is><t>${escapeXml(value)}</t></is></c>`;
|
|
1472
|
+
}
|
|
1473
|
+
if (typeof value === "number") return `<c${attrsRaw(cellAttrs)}><v>${value}</v></c>`;
|
|
1474
|
+
if (typeof value === "boolean") {
|
|
1475
|
+
cellAttrs.t = "b";
|
|
1476
|
+
return `<c${attrsRaw(cellAttrs)}><v>${value ? 1 : 0}</v></c>`;
|
|
1477
|
+
}
|
|
1478
|
+
if (value instanceof Date) {
|
|
1479
|
+
const serial = dateToSerialNumber(value);
|
|
1480
|
+
return `<c${attrsRaw(cellAttrs)}><v>${serial}</v></c>`;
|
|
1481
|
+
}
|
|
1482
|
+
return "";
|
|
1483
|
+
}
|
|
1484
|
+
function defaultCellRef(row, col) {
|
|
1485
|
+
return columnToLetter(col) + row;
|
|
1486
|
+
}
|
|
1487
|
+
function columnToLetter(col) {
|
|
1488
|
+
let result = "";
|
|
1489
|
+
let n = col;
|
|
1490
|
+
while (n > 0) {
|
|
1491
|
+
const remainder = (n - 1) % 26;
|
|
1492
|
+
result = String.fromCharCode(65 + remainder) + result;
|
|
1493
|
+
n = Math.floor((n - 1) / 26);
|
|
1494
|
+
}
|
|
1495
|
+
return result;
|
|
1496
|
+
}
|
|
1497
|
+
function dateToSerialNumber(date) {
|
|
1498
|
+
const epoch = new Date(1899, 11, 30);
|
|
1499
|
+
return (date.getTime() - epoch.getTime()) / 864e5;
|
|
1500
|
+
}
|
|
1501
|
+
function parseCfvo(el) {
|
|
1502
|
+
const result = {};
|
|
1503
|
+
result.type = attr(el, "type") ?? "num";
|
|
1504
|
+
const val = attr(el, "val");
|
|
1505
|
+
if (val !== void 0) result.val = isNaN(Number(val)) ? val : Number(val);
|
|
1506
|
+
if (attr(el, "gte") === "0") result.gte = false;
|
|
1507
|
+
return result;
|
|
1508
|
+
}
|
|
1509
|
+
function parseCellRef(ref) {
|
|
1510
|
+
const match = ref.match(/^([A-Z]+)(\d+)$/);
|
|
1511
|
+
if (!match) return void 0;
|
|
1512
|
+
const colStr = match[1];
|
|
1513
|
+
const row = parseInt(match[2], 10);
|
|
1514
|
+
let col = 0;
|
|
1515
|
+
for (let i = 0; i < colStr.length; i++) col = col * 26 + (colStr.charCodeAt(i) - 64);
|
|
1516
|
+
return {
|
|
1517
|
+
row,
|
|
1518
|
+
col
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
//#endregion
|
|
1522
|
+
//#region src/parts/comments.ts
|
|
1523
|
+
const commentsDesc = {
|
|
1524
|
+
kind: "custom",
|
|
1525
|
+
stringify(opts, _ctx) {
|
|
1526
|
+
if (opts.comments.length === 0) return void 0;
|
|
1527
|
+
const authors = collectAuthors(opts.comments);
|
|
1528
|
+
const p = [`<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing">`, `<authors>`];
|
|
1529
|
+
for (const author of authors) p.push(`<author>${escapeXml(author)}</author>`);
|
|
1530
|
+
p.push("</authors><commentList>");
|
|
1531
|
+
for (const entry of opts.comments) {
|
|
1532
|
+
const authorId = authors.indexOf(entry.author);
|
|
1533
|
+
const textXml = typeof entry.text === "string" ? `<t>${escapeXml(entry.text)}</t>` : buildRstXml(entry.text);
|
|
1534
|
+
const commentPrXml = entry.commentPr ? buildCommentPrXml(entry.commentPr) : "";
|
|
1535
|
+
p.push(`<comment ref="${entry.cell}" authorId="${authorId}"><text>${textXml}</text>${commentPrXml}</comment>`);
|
|
1536
|
+
}
|
|
1537
|
+
p.push("</commentList></comments>");
|
|
1538
|
+
return p.join("");
|
|
1539
|
+
},
|
|
1540
|
+
parse(el, _ctx) {
|
|
1541
|
+
const comments = [];
|
|
1542
|
+
const authors = [];
|
|
1543
|
+
const authorsEl = findChild(el, "authors");
|
|
1544
|
+
if (authorsEl) {
|
|
1545
|
+
for (const a of authorsEl.elements ?? []) if (a.name === "author") authors.push(textOf(a) ?? "");
|
|
1546
|
+
}
|
|
1547
|
+
const listEl = findChild(el, "commentList");
|
|
1548
|
+
if (listEl) for (const c of listEl.elements ?? []) {
|
|
1549
|
+
if (c.name !== "comment") continue;
|
|
1550
|
+
const ref = attr(c, "ref") ?? "";
|
|
1551
|
+
const authorId = Number(attr(c, "authorId") ?? 0);
|
|
1552
|
+
const textEl = findChild(c, "text");
|
|
1553
|
+
const text = textEl ? parseRst(textEl) : "";
|
|
1554
|
+
const commentPrEl = findChild(c, "commentPr");
|
|
1555
|
+
const comment = {
|
|
1556
|
+
cell: ref,
|
|
1557
|
+
author: authors[authorId] ?? "",
|
|
1558
|
+
text
|
|
1559
|
+
};
|
|
1560
|
+
if (commentPrEl) comment.commentPr = parseCommentPr(commentPrEl);
|
|
1561
|
+
comments.push(comment);
|
|
1562
|
+
}
|
|
1563
|
+
return { comments };
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
const vmlNotesDesc = {
|
|
1567
|
+
kind: "custom",
|
|
1568
|
+
stringify(opts, _ctx) {
|
|
1569
|
+
if (opts.comments.length === 0) return void 0;
|
|
1570
|
+
const p = [
|
|
1571
|
+
"<xml xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\">",
|
|
1572
|
+
"<o:shapelayout v:ext=\"edit\"><o:idmap v:ext=\"edit\" data=\"1\"/></o:shapelayout>",
|
|
1573
|
+
"<v:shapetype id=\"_x0000_t202\" coordsize=\"21600,21600\" o:spt=\"202\" path=\"m,l,21600r21600,l21600,xe\">",
|
|
1574
|
+
"<v:stroke joinstyle=\"miter\"/>",
|
|
1575
|
+
"<v:path gradientshapeok=\"t\" o:connecttype=\"rect\"/>",
|
|
1576
|
+
"</v:shapetype>"
|
|
1577
|
+
];
|
|
1578
|
+
for (let i = 0; i < opts.comments.length; i++) {
|
|
1579
|
+
const c = opts.comments[i];
|
|
1580
|
+
const { col, row } = cellRefToVmlCoords(c.cell);
|
|
1581
|
+
const anchor = `${col}, 0, ${row}, 0, ${col + 2}, 0, ${row + 2}, 0`;
|
|
1582
|
+
p.push(`<v:shape id="_x0000_s${1025 + i}" type="#_x0000_t202" style="position:absolute;margin-left:59.25pt;margin-top:1.5pt;width:108pt;height:59.25pt;z-index:1;visibility:hidden" fillcolor="infoBackground [80]" strokecolor="none [81]" o:insetmode="auto">`, `<v:fill color2="infoBackground [80]"/>`, `<v:shadow color="none [81]" obscured="t"/>`, `<v:path o:connecttype="none"/>`, `<v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox>`, `<x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/>`, `<x:Anchor>${anchor}</x:Anchor>`, `<x:AutoFill>False</x:AutoFill>`, `<x:Row>${row}</x:Row>`, `<x:Column>${col}</x:Column>`, `</x:ClientData>`, `</v:shape>`);
|
|
1583
|
+
}
|
|
1584
|
+
p.push("</xml>");
|
|
1585
|
+
return p.join("");
|
|
1586
|
+
},
|
|
1587
|
+
parse(_el, _ctx) {
|
|
1588
|
+
return { comments: [] };
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
function collectAuthors(comments) {
|
|
1592
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1593
|
+
const result = [];
|
|
1594
|
+
for (const entry of comments) if (!seen.has(entry.author)) {
|
|
1595
|
+
seen.add(entry.author);
|
|
1596
|
+
result.push(entry.author);
|
|
1597
|
+
}
|
|
1598
|
+
return result.length > 0 ? result : [""];
|
|
1599
|
+
}
|
|
1600
|
+
/** Serialize CT_CommentPr. anchor is required (CT_ObjectAnchor), defaults to empty. */
|
|
1601
|
+
function buildCommentPrXml(pr) {
|
|
1602
|
+
const attrs = [];
|
|
1603
|
+
if (pr.locked !== void 0) attrs.push(`locked="${pr.locked ? 1 : 0}"`);
|
|
1604
|
+
if (pr.defaultSize !== void 0) attrs.push(`defaultSize="${pr.defaultSize ? 1 : 0}"`);
|
|
1605
|
+
if (pr.print !== void 0) attrs.push(`print="${pr.print ? 1 : 0}"`);
|
|
1606
|
+
if (pr.disabled !== void 0) attrs.push(`disabled="${pr.disabled ? 1 : 0}"`);
|
|
1607
|
+
if (pr.autoFill !== void 0) attrs.push(`autoFill="${pr.autoFill ? 1 : 0}"`);
|
|
1608
|
+
if (pr.autoLine !== void 0) attrs.push(`autoLine="${pr.autoLine ? 1 : 0}"`);
|
|
1609
|
+
if (pr.altText !== void 0) attrs.push(`altText="${escapeXml(pr.altText)}"`);
|
|
1610
|
+
if (pr.textHAlign !== void 0) attrs.push(`textHAlign="${pr.textHAlign}"`);
|
|
1611
|
+
if (pr.textVAlign !== void 0) attrs.push(`textVAlign="${pr.textVAlign}"`);
|
|
1612
|
+
if (pr.lockText !== void 0) attrs.push(`lockText="${pr.lockText ? 1 : 0}"`);
|
|
1613
|
+
if (pr.justLastX !== void 0) attrs.push(`justLastX="${pr.justLastX ? 1 : 0}"`);
|
|
1614
|
+
if (pr.autoScale !== void 0) attrs.push(`autoScale="${pr.autoScale ? 1 : 0}"`);
|
|
1615
|
+
return `<commentPr ${attrs.join(" ")}>${buildAnchorXml(pr.anchor)}</commentPr>`;
|
|
1616
|
+
}
|
|
1617
|
+
/** Serialize CT_ObjectAnchor. from/to/ext are optional in the XSD; attributes required. */
|
|
1618
|
+
function buildAnchorXml(anchor) {
|
|
1619
|
+
return `<xdr:anchor moveWithCells="${anchor?.moveWithCells ? 1 : 0}" sizeWithCells="${anchor?.sizeWithCells ? 1 : 0}"/>`;
|
|
1620
|
+
}
|
|
1621
|
+
function parseCommentPr(el) {
|
|
1622
|
+
const pr = {};
|
|
1623
|
+
const locked = attr(el, "locked");
|
|
1624
|
+
if (locked !== void 0) pr.locked = locked === "1";
|
|
1625
|
+
const defaultSize = attr(el, "defaultSize");
|
|
1626
|
+
if (defaultSize !== void 0) pr.defaultSize = defaultSize === "1";
|
|
1627
|
+
const print = attr(el, "print");
|
|
1628
|
+
if (print !== void 0) pr.print = print === "1";
|
|
1629
|
+
const disabled = attr(el, "disabled");
|
|
1630
|
+
if (disabled !== void 0) pr.disabled = disabled === "1";
|
|
1631
|
+
const autoFill = attr(el, "autoFill");
|
|
1632
|
+
if (autoFill !== void 0) pr.autoFill = autoFill === "1";
|
|
1633
|
+
const autoLine = attr(el, "autoLine");
|
|
1634
|
+
if (autoLine !== void 0) pr.autoLine = autoLine === "1";
|
|
1635
|
+
const altText = attr(el, "altText");
|
|
1636
|
+
if (altText !== void 0) pr.altText = altText;
|
|
1637
|
+
const textHAlign = attr(el, "textHAlign");
|
|
1638
|
+
if (textHAlign !== void 0) pr.textHAlign = textHAlign;
|
|
1639
|
+
const textVAlign = attr(el, "textVAlign");
|
|
1640
|
+
if (textVAlign !== void 0) pr.textVAlign = textVAlign;
|
|
1641
|
+
const lockText = attr(el, "lockText");
|
|
1642
|
+
if (lockText !== void 0) pr.lockText = lockText === "1";
|
|
1643
|
+
const justLastX = attr(el, "justLastX");
|
|
1644
|
+
if (justLastX !== void 0) pr.justLastX = justLastX === "1";
|
|
1645
|
+
const autoScale = attr(el, "autoScale");
|
|
1646
|
+
if (autoScale !== void 0) pr.autoScale = autoScale === "1";
|
|
1647
|
+
const anchorEl = findChild(el, "xdr:anchor");
|
|
1648
|
+
if (anchorEl) pr.anchor = parseAnchor(anchorEl);
|
|
1649
|
+
return pr;
|
|
1650
|
+
}
|
|
1651
|
+
function parseAnchor(el) {
|
|
1652
|
+
return {
|
|
1653
|
+
moveWithCells: attr(el, "moveWithCells") === "1",
|
|
1654
|
+
sizeWithCells: attr(el, "sizeWithCells") === "1"
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
function cellRefToVmlCoords(ref) {
|
|
1658
|
+
let i = 0;
|
|
1659
|
+
while (i < ref.length && ref.charCodeAt(i) >= 65 && ref.charCodeAt(i) <= 90) i++;
|
|
1660
|
+
let col = 0;
|
|
1661
|
+
for (let j = 0; j < i; j++) col = col * 26 + (ref.charCodeAt(j) - 64);
|
|
1662
|
+
return {
|
|
1663
|
+
col: col - 1,
|
|
1664
|
+
row: parseInt(ref.slice(i), 10) - 1
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
/** Build rich text (CT_Rst) XML from runs. */
|
|
1668
|
+
function buildRstXml(rst) {
|
|
1669
|
+
const runs = rst.runs ?? [];
|
|
1670
|
+
const parts = [];
|
|
1671
|
+
for (const run of runs) {
|
|
1672
|
+
const props = run.properties;
|
|
1673
|
+
if (!props) {
|
|
1674
|
+
parts.push(`<r><t>${escapeXml(run.text)}</t></r>`);
|
|
1675
|
+
continue;
|
|
1676
|
+
}
|
|
1677
|
+
const rPr = [];
|
|
1678
|
+
if (props.bold) rPr.push("<b/>");
|
|
1679
|
+
if (props.italic) rPr.push("<i/>");
|
|
1680
|
+
if (props.underline) rPr.push(`<u val="${props.underline}"/>`);
|
|
1681
|
+
if (props.strike) rPr.push("<strike/>");
|
|
1682
|
+
if (props.size) rPr.push(`<sz val="${props.size}"/>`);
|
|
1683
|
+
if (props.color) rPr.push(`<color rgb="${props.color}"/>`);
|
|
1684
|
+
if (props.font) rPr.push(`<rFont val="${props.font}"/>`);
|
|
1685
|
+
const rPrXml = rPr.length ? `<rPr>${rPr.join("")}</rPr>` : "";
|
|
1686
|
+
parts.push(`<r>${rPrXml}<t>${escapeXml(run.text)}</t></r>`);
|
|
1687
|
+
}
|
|
1688
|
+
return parts.join("");
|
|
1689
|
+
}
|
|
1690
|
+
/** Parse rich text element into a plain string or rich runs. */
|
|
1691
|
+
function parseRst(textEl) {
|
|
1692
|
+
const runs = [];
|
|
1693
|
+
const parts = [];
|
|
1694
|
+
let hasRuns = false;
|
|
1695
|
+
for (const child of textEl.elements ?? []) if (child.name === "t") parts.push(textOf(child) ?? "");
|
|
1696
|
+
else if (child.name === "r") {
|
|
1697
|
+
hasRuns = true;
|
|
1698
|
+
const t = findChild(child, "t");
|
|
1699
|
+
const run = { text: t ? textOf(t) ?? "" : "" };
|
|
1700
|
+
const rPr = findChild(child, "rPr");
|
|
1701
|
+
if (rPr) {
|
|
1702
|
+
const props = {};
|
|
1703
|
+
if (findChild(rPr, "b")) props.bold = true;
|
|
1704
|
+
if (findChild(rPr, "i")) props.italic = true;
|
|
1705
|
+
const uEl = findChild(rPr, "u");
|
|
1706
|
+
if (uEl) props.underline = attr(uEl, "val") ?? "single";
|
|
1707
|
+
if (findChild(rPr, "strike")) props.strike = true;
|
|
1708
|
+
const szEl = findChild(rPr, "sz");
|
|
1709
|
+
if (szEl) {
|
|
1710
|
+
const sz = Number(attr(szEl, "val"));
|
|
1711
|
+
if (!Number.isNaN(sz)) props.size = sz;
|
|
1712
|
+
}
|
|
1713
|
+
const colorEl = findChild(rPr, "color");
|
|
1714
|
+
if (colorEl && attr(colorEl, "rgb")) props.color = attr(colorEl, "rgb");
|
|
1715
|
+
const rFontEl = findChild(rPr, "rFont");
|
|
1716
|
+
if (rFontEl && attr(rFontEl, "val")) props.font = attr(rFontEl, "val");
|
|
1717
|
+
run.properties = props;
|
|
1718
|
+
}
|
|
1719
|
+
runs.push(run);
|
|
1720
|
+
}
|
|
1721
|
+
if (hasRuns) return { runs };
|
|
1722
|
+
return parts.join("");
|
|
1723
|
+
}
|
|
1724
|
+
//#endregion
|
|
1725
|
+
export { SharedStrings as a, worksheetDesc as i, vmlNotesDesc as n, sharedStringsDesc as o, stringifyWorksheet as r, commentsDesc as t };
|
|
1726
|
+
|
|
1727
|
+
//# sourceMappingURL=comments-CIu-wLTT.mjs.map
|