@office-open/xlsx 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/context-BXK92u5G.mjs +5055 -0
- package/dist/context-BXK92u5G.mjs.map +1 -0
- package/dist/generate-BqlKnMiw.mjs +796 -0
- package/dist/generate-BqlKnMiw.mjs.map +1 -0
- package/dist/generate.mjs +1 -1
- package/dist/index.d.mts +9 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/parse-CZQQuAH5.d.mts.map +1 -1
- package/dist/parse.mjs +126 -24
- package/dist/parse.mjs.map +1 -1
- package/dist/patch.d.mts +3 -3
- package/dist/patch.d.mts.map +1 -1
- package/dist/patch.mjs.map +1 -1
- package/dist/worksheet-BbJpRvw2.d.mts.map +1 -1
- package/package.json +3 -3
- package/dist/context-a1lzscdy.mjs +0 -2251
- package/dist/context-a1lzscdy.mjs.map +0 -1
- package/dist/generate-CmgPdwPP.mjs +0 -2786
- package/dist/generate-CmgPdwPP.mjs.map +0 -1
|
@@ -1,2786 +0,0 @@
|
|
|
1
|
-
import { c as sharedStringsDesc, n as XlsxWriteContext, o as stylesDesc, r as stringifyWorksheet } from "./context-a1lzscdy.mjs";
|
|
2
|
-
import { attr, attrNum, attrs, escapeXml, findChild, textOf } from "@office-open/xml";
|
|
3
|
-
import { APP_PROPS_XML, OoxmlMimeType, Relationships, TargetModeType, buildCorePropertiesXmlString, compileMapping, createPacker, derivePasswordHash } from "@office-open/core";
|
|
4
|
-
import { createThemeXml } from "@office-open/core/theme";
|
|
5
|
-
import { chartSpaceDesc } from "@office-open/core/chart";
|
|
6
|
-
//#region src/parts/calc-chain.ts
|
|
7
|
-
const calcChainDesc = {
|
|
8
|
-
kind: "custom",
|
|
9
|
-
stringify(opts, _ctx) {
|
|
10
|
-
const parts = ["<calcChain xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"];
|
|
11
|
-
for (const cell of opts.cells) {
|
|
12
|
-
const cellAttrs = {
|
|
13
|
-
r: cell.reference,
|
|
14
|
-
i: cell.sheetIndex
|
|
15
|
-
};
|
|
16
|
-
if (cell.array) cellAttrs.a = true;
|
|
17
|
-
parts.push(`<c${attrs(cellAttrs)}/>`);
|
|
18
|
-
}
|
|
19
|
-
parts.push("</calcChain>");
|
|
20
|
-
return parts.join("");
|
|
21
|
-
},
|
|
22
|
-
parse(el, _ctx) {
|
|
23
|
-
const result = {};
|
|
24
|
-
const cells = [];
|
|
25
|
-
for (const child of el.elements ?? []) {
|
|
26
|
-
if (child.name !== "c") continue;
|
|
27
|
-
const r = child.attributes?.["r"];
|
|
28
|
-
const i = child.attributes?.["i"];
|
|
29
|
-
if (r && i) {
|
|
30
|
-
const cell = {
|
|
31
|
-
reference: String(r),
|
|
32
|
-
sheetIndex: Number(i)
|
|
33
|
-
};
|
|
34
|
-
if (child.attributes?.["a"]) cell.array = true;
|
|
35
|
-
cells.push(cell);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
result.cells = cells;
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region src/parts/chartsheet.ts
|
|
44
|
-
const chartsheetDesc = {
|
|
45
|
-
kind: "custom",
|
|
46
|
-
stringify(opts, _ctx) {
|
|
47
|
-
const p = ["<chartsheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"];
|
|
48
|
-
if (opts.tabColor || opts.published) {
|
|
49
|
-
const prAttrs = [];
|
|
50
|
-
if (opts.tabColor) prAttrs.push(`<tabColor${attrs({ rgb: opts.tabColor })}/>`);
|
|
51
|
-
const spAttr = opts.published ? " published=\"1\"" : "";
|
|
52
|
-
p.push(`<sheetPr${spAttr}>${prAttrs.join("")}</sheetPr>`);
|
|
53
|
-
}
|
|
54
|
-
const svAttrs = ["workbookViewId=\"0\""];
|
|
55
|
-
if (opts.zoomToFit) svAttrs.push("zoomToFit=\"1\"");
|
|
56
|
-
p.push(`<sheetViews><sheetView ${svAttrs.join(" ")}/></sheetViews>`);
|
|
57
|
-
if (opts.sheetProtection) {
|
|
58
|
-
const sp = opts.sheetProtection;
|
|
59
|
-
const spAttrs = [];
|
|
60
|
-
if (sp.content) spAttrs.push(` content="1"`);
|
|
61
|
-
if (sp.objects) spAttrs.push(` objects="1"`);
|
|
62
|
-
if (spAttrs.length > 0) p.push(`<sheetProtection${spAttrs.join("")}/>`);
|
|
63
|
-
}
|
|
64
|
-
if (opts.pageMargins) {
|
|
65
|
-
const pm = opts.pageMargins;
|
|
66
|
-
p.push(`<pageMargins${attrs({
|
|
67
|
-
left: pm.left ?? .7,
|
|
68
|
-
right: pm.right ?? .7,
|
|
69
|
-
top: pm.top ?? .75,
|
|
70
|
-
bottom: pm.bottom ?? .75,
|
|
71
|
-
header: pm.header ?? .3,
|
|
72
|
-
footer: pm.footer ?? .3
|
|
73
|
-
})}/>`);
|
|
74
|
-
}
|
|
75
|
-
if (opts.pageSetup) {
|
|
76
|
-
const ps = opts.pageSetup;
|
|
77
|
-
p.push(`<pageSetup${attrs({
|
|
78
|
-
paperSize: ps.paperSize,
|
|
79
|
-
orientation: ps.orientation,
|
|
80
|
-
horizontalDpi: ps.horizontalDpi,
|
|
81
|
-
verticalDpi: ps.verticalDpi,
|
|
82
|
-
copies: ps.copies
|
|
83
|
-
})}/>`);
|
|
84
|
-
}
|
|
85
|
-
if (opts.headerFooter) {
|
|
86
|
-
const hf = opts.headerFooter;
|
|
87
|
-
const hfParts = [];
|
|
88
|
-
if (hf.differentFirst) hfParts.push(` differentFirst="1"`);
|
|
89
|
-
if (hf.differentOddEven) hfParts.push(` differentOddEven="1"`);
|
|
90
|
-
const hfContent = [];
|
|
91
|
-
if (hf.oddHeader) hfContent.push(`<oddHeader>${escapeXml(hf.oddHeader)}</oddHeader>`);
|
|
92
|
-
if (hf.oddFooter) hfContent.push(`<oddFooter>${escapeXml(hf.oddFooter)}</oddFooter>`);
|
|
93
|
-
p.push(`<headerFooter${hfParts.join("")}>${hfContent.join("")}</headerFooter>`);
|
|
94
|
-
}
|
|
95
|
-
p.push(`<drawing r:id="${escapeXml(opts.drawingRId)}"/>`);
|
|
96
|
-
p.push("</chartsheet>");
|
|
97
|
-
return p.join("");
|
|
98
|
-
},
|
|
99
|
-
parse(el, _ctx) {
|
|
100
|
-
const result = {};
|
|
101
|
-
const sheetPr = findChild(el, "sheetPr");
|
|
102
|
-
if (sheetPr) {
|
|
103
|
-
if (sheetPr.attributes?.["published"] === "1") result.published = true;
|
|
104
|
-
const tabColor = findChild(sheetPr, "tabColor");
|
|
105
|
-
if (tabColor?.attributes?.["rgb"]) result.tabColor = tabColor.attributes["rgb"];
|
|
106
|
-
}
|
|
107
|
-
const sheetViews = findChild(el, "sheetViews");
|
|
108
|
-
if (sheetViews) {
|
|
109
|
-
if (findChild(sheetViews, "sheetView")?.attributes?.["zoomToFit"] === "1") result.zoomToFit = true;
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region src/parts/comments.ts
|
|
116
|
-
const commentsDesc = {
|
|
117
|
-
kind: "custom",
|
|
118
|
-
stringify(opts, _ctx) {
|
|
119
|
-
if (opts.comments.length === 0) return void 0;
|
|
120
|
-
const authors = collectAuthors(opts.comments);
|
|
121
|
-
const p = [`<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`, `<authors>`];
|
|
122
|
-
for (const author of authors) p.push(`<author>${escapeXml(author)}</author>`);
|
|
123
|
-
p.push("</authors><commentList>");
|
|
124
|
-
for (const entry of opts.comments) {
|
|
125
|
-
const authorId = authors.indexOf(entry.author);
|
|
126
|
-
const textXml = typeof entry.text === "string" ? `<t>${escapeXml(entry.text)}</t>` : buildRstXml(entry.text);
|
|
127
|
-
p.push(`<comment ref="${entry.cell}" authorId="${authorId}"><text>${textXml}</text></comment>`);
|
|
128
|
-
}
|
|
129
|
-
p.push("</commentList></comments>");
|
|
130
|
-
return p.join("");
|
|
131
|
-
},
|
|
132
|
-
parse(el, _ctx) {
|
|
133
|
-
const comments = [];
|
|
134
|
-
const authors = [];
|
|
135
|
-
const authorsEl = findChild(el, "authors");
|
|
136
|
-
if (authorsEl) {
|
|
137
|
-
for (const a of authorsEl.elements ?? []) if (a.name === "author") authors.push(textOf(a) ?? "");
|
|
138
|
-
}
|
|
139
|
-
const listEl = findChild(el, "commentList");
|
|
140
|
-
if (listEl) for (const c of listEl.elements ?? []) {
|
|
141
|
-
if (c.name !== "comment") continue;
|
|
142
|
-
const ref = attr(c, "ref") ?? "";
|
|
143
|
-
const authorId = Number(attr(c, "authorId") ?? 0);
|
|
144
|
-
const textEl = findChild(c, "text");
|
|
145
|
-
const text = textEl ? parseRst(textEl) : "";
|
|
146
|
-
comments.push({
|
|
147
|
-
cell: ref,
|
|
148
|
-
author: authors[authorId] ?? "",
|
|
149
|
-
text
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
return { comments };
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
const vmlNotesDesc = {
|
|
156
|
-
kind: "custom",
|
|
157
|
-
stringify(opts, _ctx) {
|
|
158
|
-
if (opts.comments.length === 0) return void 0;
|
|
159
|
-
const p = [
|
|
160
|
-
"<xml xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\">",
|
|
161
|
-
"<o:shapelayout v:ext=\"edit\"><o:idmap v:ext=\"edit\" data=\"1\"/></o:shapelayout>",
|
|
162
|
-
"<v:shapetype id=\"_x0000_t202\" coordsize=\"21600,21600\" o:spt=\"202\" path=\"m,l,21600r21600,l21600,xe\">",
|
|
163
|
-
"<v:stroke joinstyle=\"miter\"/>",
|
|
164
|
-
"<v:path gradientshapeok=\"t\" o:connecttype=\"rect\"/>",
|
|
165
|
-
"</v:shapetype>"
|
|
166
|
-
];
|
|
167
|
-
for (let i = 0; i < opts.comments.length; i++) {
|
|
168
|
-
const c = opts.comments[i];
|
|
169
|
-
const col = c.cell.charCodeAt(0) - 65;
|
|
170
|
-
const row = parseInt(c.cell.slice(1), 10) - 1;
|
|
171
|
-
const anchor = `${col}, 0, ${row}, 0, ${col + 2}, 0, ${row + 2}, 0`;
|
|
172
|
-
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>`);
|
|
173
|
-
}
|
|
174
|
-
p.push("</xml>");
|
|
175
|
-
return p.join("");
|
|
176
|
-
},
|
|
177
|
-
parse(_el, _ctx) {
|
|
178
|
-
return { comments: [] };
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
function collectAuthors(comments) {
|
|
182
|
-
const seen = /* @__PURE__ */ new Set();
|
|
183
|
-
const result = [];
|
|
184
|
-
for (const entry of comments) if (!seen.has(entry.author)) {
|
|
185
|
-
seen.add(entry.author);
|
|
186
|
-
result.push(entry.author);
|
|
187
|
-
}
|
|
188
|
-
return result.length > 0 ? result : [""];
|
|
189
|
-
}
|
|
190
|
-
/** Build rich text (CT_Rst) XML from runs. */
|
|
191
|
-
function buildRstXml(rst) {
|
|
192
|
-
const runs = rst.runs ?? [];
|
|
193
|
-
const parts = [];
|
|
194
|
-
for (const run of runs) {
|
|
195
|
-
const props = run.properties;
|
|
196
|
-
if (!props) {
|
|
197
|
-
parts.push(`<r><t>${escapeXml(run.text)}</t></r>`);
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
const rPr = [];
|
|
201
|
-
if (props.bold) rPr.push("<b/>");
|
|
202
|
-
if (props.italic) rPr.push("<i/>");
|
|
203
|
-
if (props.underline) rPr.push(`<u val="${props.underline}"/>`);
|
|
204
|
-
if (props.strike) rPr.push("<strike/>");
|
|
205
|
-
if (props.size) rPr.push(`<sz val="${props.size}"/>`);
|
|
206
|
-
if (props.color) rPr.push(`<color rgb="${props.color}"/>`);
|
|
207
|
-
if (props.font) rPr.push(`<rFont val="${props.font}"/>`);
|
|
208
|
-
const rPrXml = rPr.length ? `<rPr>${rPr.join("")}</rPr>` : "";
|
|
209
|
-
parts.push(`<r>${rPrXml}<t>${escapeXml(run.text)}</t></r>`);
|
|
210
|
-
}
|
|
211
|
-
return parts.join("");
|
|
212
|
-
}
|
|
213
|
-
/** Parse rich text element into a simple string. */
|
|
214
|
-
function parseRst(textEl) {
|
|
215
|
-
const parts = [];
|
|
216
|
-
for (const child of textEl.elements ?? []) if (child.name === "t") parts.push(textOf(child) ?? "");
|
|
217
|
-
else if (child.name === "r") {
|
|
218
|
-
const t = findChild(child, "t");
|
|
219
|
-
if (t) parts.push(textOf(t) ?? "");
|
|
220
|
-
}
|
|
221
|
-
return parts.join("");
|
|
222
|
-
}
|
|
223
|
-
//#endregion
|
|
224
|
-
//#region src/parts/drawing.ts
|
|
225
|
-
const XDR_NS = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing";
|
|
226
|
-
const A_NS = "http://schemas.openxmlformats.org/drawingml/2006/main";
|
|
227
|
-
const R_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
228
|
-
const C_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
|
229
|
-
const drawingDesc = {
|
|
230
|
-
kind: "custom",
|
|
231
|
-
stringify(opts, _ctx) {
|
|
232
|
-
const images = opts.images ?? [];
|
|
233
|
-
const charts = opts.charts ?? [];
|
|
234
|
-
if (images.length === 0 && charts.length === 0) return void 0;
|
|
235
|
-
const p = [`<wsDr xmlns="${XDR_NS}" xmlns:a="${A_NS}" xmlns:r="${R_NS}">`];
|
|
236
|
-
let id = 1;
|
|
237
|
-
for (const img of images) {
|
|
238
|
-
p.push(`<twoCellAnchor editAs="oneCell"><from><col>${img.col - 1}</col><colOff>${img.colOffset ?? 0}</colOff><row>${img.row - 1}</row><rowOff>${img.rowOffset ?? 0}</rowOff></from>`, `<to><col>${img.col}</col><colOff>0</colOff><row>${img.row}</row><rowOff>0</rowOff></to>`, `<pic><nvPicPr><cNvPr id="${id}" name="Picture ${id}"/><cNvPicPr preferRelativeResize="1"/></nvPicPr>`, `<blipFill><a:blip r:embed="${img.rId}"/><a:stretch><a:fillRect/></a:stretch></blipFill>`, `<spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="400000" cy="300000"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></spPr></pic>`, `<clientData fLocksWithSheet="${img.locksWithSheet !== false ? 1 : 0}" fPrintsWithSheet="${img.printsWithSheet !== false ? 1 : 0}"/></twoCellAnchor>`);
|
|
239
|
-
id++;
|
|
240
|
-
}
|
|
241
|
-
for (const chart of charts) {
|
|
242
|
-
p.push(`<twoCellAnchor editAs="oneCell"><from><col>${chart.col - 1}</col><colOff>${chart.colOffset ?? 0}</colOff><row>${chart.row - 1}</row><rowOff>${chart.rowOffset ?? 0}</rowOff></from>`, `<to><col>${chart.col + 8}</col><colOff>0</colOff><row>${chart.row + 15}</row><rowOff>0</rowOff></to>`, `<graphicFrame><nvGraphicFramePr><cNvPr id="${id}" name="Chart ${id}"/><cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></cNvGraphicFramePr></nvGraphicFramePr>`, `<xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></xfrm>`, `<a:graphic><a:graphicData uri="${C_URI}"><c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="${R_NS}" r:id="${chart.rId}"/></a:graphicData></a:graphic></graphicFrame>`, `<clientData fLocksWithSheet="${chart.locksWithSheet !== false ? 1 : 0}" fPrintsWithSheet="${chart.printsWithSheet !== false ? 1 : 0}"/></twoCellAnchor>`);
|
|
243
|
-
id++;
|
|
244
|
-
}
|
|
245
|
-
p.push("</wsDr>");
|
|
246
|
-
return p.join("");
|
|
247
|
-
},
|
|
248
|
-
parse(el, _ctx) {
|
|
249
|
-
const result = {};
|
|
250
|
-
const images = [];
|
|
251
|
-
const charts = [];
|
|
252
|
-
for (const anchor of el.elements ?? []) {
|
|
253
|
-
if (anchor.name !== "twoCellAnchor") continue;
|
|
254
|
-
const from = findChild(anchor, "from");
|
|
255
|
-
findChild(anchor, "to");
|
|
256
|
-
if (!from) continue;
|
|
257
|
-
const col = readNumChild(from, "col") + 1;
|
|
258
|
-
const colOffset = readNumChild(from, "colOff") || void 0;
|
|
259
|
-
const row = readNumChild(from, "row") + 1;
|
|
260
|
-
const rowOffset = readNumChild(from, "rowOff") || void 0;
|
|
261
|
-
const pic = findChild(anchor, "pic");
|
|
262
|
-
if (pic) {
|
|
263
|
-
const rId = findChild(findChild(pic, "blipFill") ?? pic, "a:blip")?.attributes?.["r:embed"];
|
|
264
|
-
if (rId) {
|
|
265
|
-
const clientData = findChild(anchor, "clientData");
|
|
266
|
-
images.push({
|
|
267
|
-
col,
|
|
268
|
-
colOffset,
|
|
269
|
-
row,
|
|
270
|
-
rowOffset,
|
|
271
|
-
rId,
|
|
272
|
-
locksWithSheet: clientData?.attributes?.["fLocksWithSheet"] !== "0",
|
|
273
|
-
printsWithSheet: clientData?.attributes?.["fPrintsWithSheet"] !== "0"
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
const graphicFrame = findChild(anchor, "graphicFrame");
|
|
279
|
-
if (graphicFrame) {
|
|
280
|
-
const graphicData = findChild(findChild(graphicFrame, "a:graphic") ?? graphicFrame, "a:graphicData");
|
|
281
|
-
const rId = (graphicData ? findChild(graphicData, "c:chart") : void 0)?.attributes?.["r:id"];
|
|
282
|
-
if (rId) {
|
|
283
|
-
const clientData = findChild(anchor, "clientData");
|
|
284
|
-
charts.push({
|
|
285
|
-
col,
|
|
286
|
-
colOffset,
|
|
287
|
-
row,
|
|
288
|
-
rowOffset,
|
|
289
|
-
rId,
|
|
290
|
-
locksWithSheet: clientData?.attributes?.["fLocksWithSheet"] !== "0",
|
|
291
|
-
printsWithSheet: clientData?.attributes?.["fPrintsWithSheet"] !== "0"
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
if (images.length > 0) result.images = images;
|
|
297
|
-
if (charts.length > 0) result.charts = charts;
|
|
298
|
-
return result;
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
function readNumChild(el, tag) {
|
|
302
|
-
const child = findChild(el, tag);
|
|
303
|
-
if (!child?.elements?.length) return 0;
|
|
304
|
-
const n = Number(child.elements[0]?.text ?? "");
|
|
305
|
-
return Number.isNaN(n) ? 0 : n;
|
|
306
|
-
}
|
|
307
|
-
//#endregion
|
|
308
|
-
//#region src/parts/external-link.ts
|
|
309
|
-
const externalLinkDesc = {
|
|
310
|
-
kind: "custom",
|
|
311
|
-
stringify(opts, _ctx) {
|
|
312
|
-
const p = ["<externalLink xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"];
|
|
313
|
-
if (opts.externalBook) {
|
|
314
|
-
const book = opts.externalBook;
|
|
315
|
-
const bookParts = [];
|
|
316
|
-
if (book.sheetNames && book.sheetNames.length > 0) {
|
|
317
|
-
bookParts.push("<sheetNames>");
|
|
318
|
-
for (const name of book.sheetNames) bookParts.push(`<sheetName val="${escapeXml(name)}"/>`);
|
|
319
|
-
bookParts.push("</sheetNames>");
|
|
320
|
-
}
|
|
321
|
-
if (book.definedNames && book.definedNames.length > 0) {
|
|
322
|
-
bookParts.push("<definedNames>");
|
|
323
|
-
for (const dn of book.definedNames) {
|
|
324
|
-
const dnAttrs = { name: dn.name };
|
|
325
|
-
if (dn.refersTo !== void 0) dnAttrs.refersTo = dn.refersTo;
|
|
326
|
-
if (dn.sheetId !== void 0) dnAttrs.sheetId = dn.sheetId;
|
|
327
|
-
if (dn.publishToServer) dnAttrs.publishToServer = 1;
|
|
328
|
-
if (dn.vbProcedure) dnAttrs.vbProcedure = 1;
|
|
329
|
-
if (dn.workbookParameter) dnAttrs.workbookParameter = 1;
|
|
330
|
-
if (dn.xlm) dnAttrs.xlm = 1;
|
|
331
|
-
bookParts.push(`<definedName${attrs(dnAttrs)}/>`);
|
|
332
|
-
}
|
|
333
|
-
bookParts.push("</definedNames>");
|
|
334
|
-
}
|
|
335
|
-
if (book.sheetDataSet && book.sheetDataSet.length > 0) {
|
|
336
|
-
bookParts.push("<sheetDataSet>");
|
|
337
|
-
for (const sd of book.sheetDataSet) {
|
|
338
|
-
const sdAttrs = { sheetId: sd.sheetId };
|
|
339
|
-
if (sd.refreshError) sdAttrs.refreshError = 1;
|
|
340
|
-
bookParts.push(`<sheetData${attrs(sdAttrs)}>`);
|
|
341
|
-
if (sd.rows) for (const row of sd.rows) {
|
|
342
|
-
bookParts.push(`<row r="${row.rowNumber}">`);
|
|
343
|
-
if (row.cells) for (const cell of row.cells) {
|
|
344
|
-
const cellAttrs = { r: cell.reference };
|
|
345
|
-
if (cell.type !== void 0) cellAttrs.t = cell.type;
|
|
346
|
-
if (cell.value !== void 0) bookParts.push(`<cell${attrs(cellAttrs)}><v>${escapeXml(cell.value)}</v></cell>`);
|
|
347
|
-
else bookParts.push(`<cell${attrs(cellAttrs)}/>`);
|
|
348
|
-
}
|
|
349
|
-
bookParts.push("</row>");
|
|
350
|
-
}
|
|
351
|
-
bookParts.push("</sheetData>");
|
|
352
|
-
}
|
|
353
|
-
bookParts.push("</sheetDataSet>");
|
|
354
|
-
}
|
|
355
|
-
const ridAttr = opts.bookRId ? ` r:id="${opts.bookRId}"` : "";
|
|
356
|
-
p.push(`<externalBook${ridAttr}${bookParts.length > 0 ? `>${bookParts.join("")}</externalBook>` : "/>"}`);
|
|
357
|
-
}
|
|
358
|
-
if (opts.oleLink) {
|
|
359
|
-
const oleRId = opts.oleRId ? ` r:id="${escapeXml(opts.oleRId)}"` : "";
|
|
360
|
-
const oleChildren = [];
|
|
361
|
-
if (opts.oleLink.oleItems && opts.oleLink.oleItems.length > 0) {
|
|
362
|
-
const itemParts = [`<oleItems>`];
|
|
363
|
-
for (const item of opts.oleLink.oleItems) {
|
|
364
|
-
const itemAttrs = [`name="${escapeXml(item.name)}"`];
|
|
365
|
-
if (item.advise) itemAttrs.push("advise=\"1\"");
|
|
366
|
-
if (item.prefer) itemAttrs.push("prefer=\"1\"");
|
|
367
|
-
itemParts.push(`<oleItem ${itemAttrs.join(" ")}/>`);
|
|
368
|
-
}
|
|
369
|
-
itemParts.push("</oleItems>");
|
|
370
|
-
oleChildren.push(itemParts.join(""));
|
|
371
|
-
}
|
|
372
|
-
if (oleChildren.length > 0) p.push(`<oleLink${oleRId}>${oleChildren.join("")}</oleLink>`);
|
|
373
|
-
else p.push(`<oleLink${oleRId}/>`);
|
|
374
|
-
}
|
|
375
|
-
p.push("</externalLink>");
|
|
376
|
-
return p.join("");
|
|
377
|
-
},
|
|
378
|
-
parse(el, _ctx) {
|
|
379
|
-
const result = {};
|
|
380
|
-
const bookEl = findChild(el, "externalBook");
|
|
381
|
-
if (bookEl) {
|
|
382
|
-
const book = {};
|
|
383
|
-
if (bookEl.attributes?.["r:id"]) result.bookRId = bookEl.attributes["r:id"];
|
|
384
|
-
const sheetNamesEl = findChild(bookEl, "sheetNames");
|
|
385
|
-
if (sheetNamesEl) {
|
|
386
|
-
const names = [];
|
|
387
|
-
for (const child of sheetNamesEl.elements ?? []) if (child.name === "sheetName" && child.attributes?.["val"]) names.push(String(child.attributes["val"]));
|
|
388
|
-
if (names.length > 0) book.sheetNames = names;
|
|
389
|
-
}
|
|
390
|
-
result.externalBook = book;
|
|
391
|
-
}
|
|
392
|
-
return result;
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
//#endregion
|
|
396
|
-
//#region src/parts/pivot/pivot-utils.ts
|
|
397
|
-
/** Pivot filter type (ST_PivotFilterType) */
|
|
398
|
-
const PivotFilterType = {
|
|
399
|
-
UNKNOWN: "unknown",
|
|
400
|
-
COUNT: "count",
|
|
401
|
-
PERCENT: "percent",
|
|
402
|
-
SUM: "sum",
|
|
403
|
-
CAPTION_EQUAL: "captionEqual",
|
|
404
|
-
CAPTION_NOT_EQUAL: "captionNotEqual",
|
|
405
|
-
CAPTION_BEGINS_WITH: "captionBeginsWith",
|
|
406
|
-
CAPTION_NOT_BEGINS_WITH: "captionNotBeginsWith",
|
|
407
|
-
CAPTION_ENDS_WITH: "captionEndsWith",
|
|
408
|
-
CAPTION_NOT_ENDS_WITH: "captionNotEndsWith",
|
|
409
|
-
CAPTION_CONTAINS: "captionContains",
|
|
410
|
-
CAPTION_NOT_CONTAINS: "captionNotContains",
|
|
411
|
-
CAPTION_GREATER_THAN: "captionGreaterThan",
|
|
412
|
-
CAPTION_GREATER_THAN_OR_EQUAL: "captionGreaterThanOrEqual",
|
|
413
|
-
CAPTION_LESS_THAN: "captionLessThan",
|
|
414
|
-
CAPTION_LESS_THAN_OR_EQUAL: "captionLessThanOrEqual",
|
|
415
|
-
CAPTION_BETWEEN: "captionBetween",
|
|
416
|
-
CAPTION_NOT_BETWEEN: "captionNotBetween",
|
|
417
|
-
VALUE_EQUAL: "valueEqual",
|
|
418
|
-
VALUE_NOT_EQUAL: "valueNotEqual",
|
|
419
|
-
VALUE_GREATER_THAN: "valueGreaterThan",
|
|
420
|
-
VALUE_GREATER_THAN_OR_EQUAL: "valueGreaterThanOrEqual",
|
|
421
|
-
VALUE_LESS_THAN: "valueLessThan",
|
|
422
|
-
VALUE_LESS_THAN_OR_EQUAL: "valueLessThanOrEqual",
|
|
423
|
-
VALUE_BETWEEN: "valueBetween",
|
|
424
|
-
VALUE_NOT_BETWEEN: "valueNotBetween",
|
|
425
|
-
DATE_EQUAL: "dateEqual",
|
|
426
|
-
DATE_NOT_EQUAL: "dateNotEqual",
|
|
427
|
-
DATE_OLDER_THAN: "dateOlderThan",
|
|
428
|
-
DATE_OLDER_THAN_OR_EQUAL: "dateOlderThanOrEqual",
|
|
429
|
-
DATE_NEWER_THAN: "dateNewerThan",
|
|
430
|
-
DATE_NEWER_THAN_OR_EQUAL: "dateNewerThanOrEqual",
|
|
431
|
-
DATE_BETWEEN: "dateBetween",
|
|
432
|
-
DATE_NOT_BETWEEN: "dateNotBetween",
|
|
433
|
-
TOMORROW: "tomorrow",
|
|
434
|
-
TODAY: "today",
|
|
435
|
-
YESTERDAY: "yesterday",
|
|
436
|
-
NEXT_WEEK: "nextWeek",
|
|
437
|
-
THIS_WEEK: "thisWeek",
|
|
438
|
-
LAST_WEEK: "lastWeek",
|
|
439
|
-
NEXT_MONTH: "nextMonth",
|
|
440
|
-
THIS_MONTH: "thisMonth",
|
|
441
|
-
LAST_MONTH: "lastMonth",
|
|
442
|
-
NEXT_QUARTER: "nextQuarter",
|
|
443
|
-
THIS_QUARTER: "thisQuarter",
|
|
444
|
-
LAST_QUARTER: "lastQuarter",
|
|
445
|
-
NEXT_YEAR: "nextYear",
|
|
446
|
-
THIS_YEAR: "thisYear",
|
|
447
|
-
LAST_YEAR: "lastYear",
|
|
448
|
-
YEAR_TO_DATE: "yearToDate",
|
|
449
|
-
Q1: "Q1",
|
|
450
|
-
Q2: "Q2",
|
|
451
|
-
Q3: "Q3",
|
|
452
|
-
Q4: "Q4",
|
|
453
|
-
M1: "M1",
|
|
454
|
-
M2: "M2",
|
|
455
|
-
M3: "M3",
|
|
456
|
-
M4: "M4",
|
|
457
|
-
M5: "M5",
|
|
458
|
-
M6: "M6",
|
|
459
|
-
M7: "M7",
|
|
460
|
-
M8: "M8",
|
|
461
|
-
M9: "M9",
|
|
462
|
-
M10: "M10",
|
|
463
|
-
M11: "M11",
|
|
464
|
-
M12: "M12"
|
|
465
|
-
};
|
|
466
|
-
/**
|
|
467
|
-
* Extract unique values from source data for a given field index.
|
|
468
|
-
*/
|
|
469
|
-
function collectUniqueValues(records, fieldIdx) {
|
|
470
|
-
const seen = /* @__PURE__ */ new Set();
|
|
471
|
-
const result = [];
|
|
472
|
-
for (const row of records) {
|
|
473
|
-
const val = row[fieldIdx];
|
|
474
|
-
const key = val instanceof Date ? val.toISOString() : String(val);
|
|
475
|
-
if (!seen.has(key)) {
|
|
476
|
-
seen.add(key);
|
|
477
|
-
result.push(val);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return result;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Check if a field is numeric (all non-empty values are numbers).
|
|
484
|
-
*/
|
|
485
|
-
function isNumericField(records, fieldIdx) {
|
|
486
|
-
for (const row of records) {
|
|
487
|
-
const val = row[fieldIdx];
|
|
488
|
-
if (typeof val === "string" && val !== "") return false;
|
|
489
|
-
}
|
|
490
|
-
return true;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Aggregate values using the specified function.
|
|
494
|
-
*/
|
|
495
|
-
function aggregate(values, func) {
|
|
496
|
-
if (values.length === 0) return 0;
|
|
497
|
-
switch (func) {
|
|
498
|
-
case "sum": return values.reduce((a, b) => a + b, 0);
|
|
499
|
-
case "count":
|
|
500
|
-
case "countNums": return values.length;
|
|
501
|
-
case "average": return values.reduce((a, b) => a + b, 0) / values.length;
|
|
502
|
-
case "max": return Math.max(...values);
|
|
503
|
-
case "min": return Math.min(...values);
|
|
504
|
-
case "product": return values.reduce((a, b) => a * b, 1);
|
|
505
|
-
case "var": return sampleVariance(values);
|
|
506
|
-
case "varp": return populationVariance(values);
|
|
507
|
-
case "stdDev": return Math.sqrt(sampleVariance(values));
|
|
508
|
-
case "stdDevp": return Math.sqrt(populationVariance(values));
|
|
509
|
-
default: return values.reduce((a, b) => a + b, 0);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function populationVariance(values) {
|
|
513
|
-
const mean = values.reduce((a, b) => a + b, 0) / values.length;
|
|
514
|
-
return values.reduce((sum, v) => sum + (v - mean) ** 2, 0) / values.length;
|
|
515
|
-
}
|
|
516
|
-
function sampleVariance(values) {
|
|
517
|
-
if (values.length < 2) return 0;
|
|
518
|
-
const mean = values.reduce((a, b) => a + b, 0) / values.length;
|
|
519
|
-
return values.reduce((sum, v) => sum + (v - mean) ** 2, 0) / (values.length - 1);
|
|
520
|
-
}
|
|
521
|
-
//#endregion
|
|
522
|
-
//#region src/parts/pivot-table.ts
|
|
523
|
-
const pivotTableDesc = {
|
|
524
|
-
kind: "custom",
|
|
525
|
-
stringify(opts, _ctx) {
|
|
526
|
-
return stringifyPivotTable(opts.options, opts.sourceData, opts.cacheId);
|
|
527
|
-
},
|
|
528
|
-
parse(el, _ctx) {
|
|
529
|
-
const result = {};
|
|
530
|
-
if (attr(el, "name")) result.name = attr(el, "name");
|
|
531
|
-
if (attr(el, "cacheId") !== void 0) result.cacheId = attrNum(el, "cacheId") ?? 0;
|
|
532
|
-
const locEl = findChild(el, "location");
|
|
533
|
-
if (locEl) result.location = attr(locEl, "ref") ?? "";
|
|
534
|
-
const pfEl = findChild(el, "pivotFields");
|
|
535
|
-
if (pfEl) {
|
|
536
|
-
const fields = [];
|
|
537
|
-
for (const fEl of pfEl.elements ?? []) {
|
|
538
|
-
if (fEl.name !== "pivotField") continue;
|
|
539
|
-
const field = {};
|
|
540
|
-
const axis = attr(fEl, "axis");
|
|
541
|
-
if (axis) field.axis = axis;
|
|
542
|
-
fields.push(field);
|
|
543
|
-
}
|
|
544
|
-
result.pivotFields = fields;
|
|
545
|
-
}
|
|
546
|
-
const dfEl = findChild(el, "dataFields");
|
|
547
|
-
if (dfEl) {
|
|
548
|
-
const dataFields = [];
|
|
549
|
-
for (const dEl of dfEl.elements ?? []) {
|
|
550
|
-
if (dEl.name !== "dataField") continue;
|
|
551
|
-
const df = {};
|
|
552
|
-
if (attr(dEl, "name")) df.name = attr(dEl, "name");
|
|
553
|
-
const fld = attrNum(dEl, "fld");
|
|
554
|
-
if (fld !== void 0) df.fld = fld;
|
|
555
|
-
if (attr(dEl, "subtotal")) df.subtotal = attr(dEl, "subtotal");
|
|
556
|
-
dataFields.push(df);
|
|
557
|
-
}
|
|
558
|
-
result.dataFields = dataFields;
|
|
559
|
-
}
|
|
560
|
-
if (attr(el, "styleName")) result.style = attr(el, "styleName");
|
|
561
|
-
return result;
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
function stringifyPivotTable(o, sd, cacheId) {
|
|
565
|
-
const fields = sd.fieldNames;
|
|
566
|
-
const rowFieldNames = o.rows;
|
|
567
|
-
const colFieldNames = o.columns ?? [];
|
|
568
|
-
const dataFields = o.data;
|
|
569
|
-
const style = o.style ?? "PivotStyleLight16";
|
|
570
|
-
const location = o.location ?? "A3";
|
|
571
|
-
const name = o.name ?? "PivotTable1";
|
|
572
|
-
const rowFieldIndices = rowFieldNames.map((n) => fields.indexOf(n));
|
|
573
|
-
const colFieldIndices = colFieldNames.map((n) => fields.indexOf(n));
|
|
574
|
-
const dataFieldIndices = dataFields.map((df) => fields.indexOf(df.field));
|
|
575
|
-
const pageFieldIndices = (o.pages ?? []).map((n) => fields.indexOf(n));
|
|
576
|
-
const pivotFieldsXml = buildPivotFields(o, sd, rowFieldIndices, colFieldIndices, dataFieldIndices, pageFieldIndices);
|
|
577
|
-
const pageFieldsXml = buildPageFields(o, pageFieldIndices);
|
|
578
|
-
const rowFieldsXml = buildRowFields(rowFieldIndices);
|
|
579
|
-
const rowItemsXml = buildRowItems(sd, rowFieldIndices);
|
|
580
|
-
const colFieldsXml = buildColFields(colFieldIndices);
|
|
581
|
-
const colItemsXml = buildColItems(sd, colFieldIndices, dataFields);
|
|
582
|
-
const dataFieldsXml = buildDataFields(dataFields, dataFieldIndices);
|
|
583
|
-
const locationRef = computeLocationRef(sd, location, rowFieldIndices, colFieldIndices, dataFields);
|
|
584
|
-
const p = [];
|
|
585
|
-
const defAttrs = [
|
|
586
|
-
`name="${escapeXml(name)}"`,
|
|
587
|
-
`cacheId="${cacheId}"`,
|
|
588
|
-
"dataCaption=\"Values\"",
|
|
589
|
-
"updatedVersion=\"6\"",
|
|
590
|
-
"minRefreshableVersion=\"3\"",
|
|
591
|
-
"createdVersion=\"6\"",
|
|
592
|
-
"applyNumberFormats=\"0\"",
|
|
593
|
-
"applyBorderFormats=\"0\"",
|
|
594
|
-
"applyFontFormats=\"0\"",
|
|
595
|
-
"applyPatternFormats=\"0\"",
|
|
596
|
-
"applyAlignmentFormats=\"0\"",
|
|
597
|
-
"applyWidthHeightFormats=\"1\"",
|
|
598
|
-
"autoFormatId=\"0\"",
|
|
599
|
-
"useAutoFormatting=\"1\"",
|
|
600
|
-
"itemPrintTitles=\"1\"",
|
|
601
|
-
"indent=\"0\"",
|
|
602
|
-
"outline=\"1\"",
|
|
603
|
-
"outlineData=\"1\"",
|
|
604
|
-
"compact=\"1\"",
|
|
605
|
-
"compactData=\"1\"",
|
|
606
|
-
"rowGrandTotals=\"1\"",
|
|
607
|
-
"colGrandTotals=\"1\""
|
|
608
|
-
];
|
|
609
|
-
if (o.dataOnRows) defAttrs.push("dataOnRows=\"1\"");
|
|
610
|
-
if (o.grandTotalCaption) defAttrs.push(`grandTotalCaption="${escapeXml(o.grandTotalCaption)}"`);
|
|
611
|
-
if (o.errorCaption) defAttrs.push(`errorCaption="${escapeXml(o.errorCaption)}"`);
|
|
612
|
-
if (o.showError) defAttrs.push("showError=\"1\"");
|
|
613
|
-
if (o.missingCaption) defAttrs.push(`missingCaption="${escapeXml(o.missingCaption)}"`);
|
|
614
|
-
if (o.showMissing === false) defAttrs.push("showMissing=\"0\"");
|
|
615
|
-
if (o.pageStyle) defAttrs.push(`pageStyle="${escapeXml(o.pageStyle)}"`);
|
|
616
|
-
if (o.pivotTableStyle) defAttrs.push(`pivotTableStyle="${escapeXml(o.pivotTableStyle)}"`);
|
|
617
|
-
if (o.tag) defAttrs.push(`tag="${escapeXml(o.tag)}"`);
|
|
618
|
-
if (o.showItems === false) defAttrs.push("showItems=\"0\"");
|
|
619
|
-
if (o.editData) defAttrs.push("editData=\"1\"");
|
|
620
|
-
if (o.disableFieldList) defAttrs.push("disableFieldList=\"1\"");
|
|
621
|
-
if (o.showCalcMbrs === false) defAttrs.push("showCalcMbrs=\"0\"");
|
|
622
|
-
if (o.visualTotals) defAttrs.push("visualTotals=\"1\"");
|
|
623
|
-
if (o.showMultipleLabel === false) defAttrs.push("showMultipleLabel=\"0\"");
|
|
624
|
-
if (o.showDataDropDown === false) defAttrs.push("showDataDropDown=\"0\"");
|
|
625
|
-
if (o.showDrill === false) defAttrs.push("showDrill=\"0\"");
|
|
626
|
-
if (o.printDrill) defAttrs.push("printDrill=\"1\"");
|
|
627
|
-
if (o.showMemberPropertyTips) defAttrs.push("showMemberPropertyTips=\"1\"");
|
|
628
|
-
if (o.showDataTips === false) defAttrs.push("showDataTips=\"0\"");
|
|
629
|
-
if (o.enableWizard === false) defAttrs.push("enableWizard=\"0\"");
|
|
630
|
-
if (o.enableDrill === false) defAttrs.push("enableDrill=\"0\"");
|
|
631
|
-
if (o.enableFieldProperties === false) defAttrs.push("enableFieldProperties=\"0\"");
|
|
632
|
-
if (o.pageWrap !== void 0) defAttrs.push(`pageWrap="${o.pageWrap}"`);
|
|
633
|
-
if (o.pageOverThenDown) defAttrs.push("pageOverThenDown=\"1\"");
|
|
634
|
-
if (o.subtotalHiddenItems) defAttrs.push("subtotalHiddenItems=\"1\"");
|
|
635
|
-
if (o.fieldPrintTitles) defAttrs.push("fieldPrintTitles=\"1\"");
|
|
636
|
-
if (o.mergeItem) defAttrs.push("mergeItem=\"1\"");
|
|
637
|
-
if (o.showDropZones === false) defAttrs.push("showDropZones=\"0\"");
|
|
638
|
-
if (o.showEmptyRow) defAttrs.push("showEmptyRow=\"1\"");
|
|
639
|
-
if (o.showEmptyCol) defAttrs.push("showEmptyCol=\"1\"");
|
|
640
|
-
if (o.showHeaders === false) defAttrs.push("showHeaders=\"0\"");
|
|
641
|
-
if (o.published) defAttrs.push("published=\"1\"");
|
|
642
|
-
if (o.gridDropZones === false) defAttrs.push("gridDropZones=\"0\"");
|
|
643
|
-
if (o.multipleFieldFilters === false) defAttrs.push("multipleFieldFilters=\"0\"");
|
|
644
|
-
if (o.rowHeaderCaption) defAttrs.push(`rowHeaderCaption="${escapeXml(o.rowHeaderCaption)}"`);
|
|
645
|
-
if (o.colHeaderCaption) defAttrs.push(`colHeaderCaption="${escapeXml(o.colHeaderCaption)}"`);
|
|
646
|
-
if (o.fieldListSortAscending) defAttrs.push("fieldListSortAscending=\"1\"");
|
|
647
|
-
if (o.mdxSubqueries) defAttrs.push("mdxSubqueries=\"1\"");
|
|
648
|
-
if (o.customListSort === false) defAttrs.push("customListSort=\"0\"");
|
|
649
|
-
if (o.asteriskTotals) defAttrs.push("asteriskTotals=\"1\"");
|
|
650
|
-
if (o.dataPosition !== void 0) defAttrs.push(`dataPosition="${o.dataPosition}"`);
|
|
651
|
-
if (o.immersive) defAttrs.push("immersive=\"1\"");
|
|
652
|
-
if (o.vacatedStyle) defAttrs.push(`vacatedStyle="${escapeXml(o.vacatedStyle)}"`);
|
|
653
|
-
p.push(`<pivotTableDefinition xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" ${defAttrs.join(" ")}>`);
|
|
654
|
-
const locAttrs = [
|
|
655
|
-
`ref="${escapeXml(locationRef)}"`,
|
|
656
|
-
`firstHeaderRow="1"`,
|
|
657
|
-
`firstDataRow="${colFieldIndices.length + 1}"`,
|
|
658
|
-
`firstDataCol="${rowFieldIndices.length}"`
|
|
659
|
-
];
|
|
660
|
-
if (o.locationColPageCount !== void 0) locAttrs.push(`colPageCount="${o.locationColPageCount}"`);
|
|
661
|
-
if (o.locationRowPageCount !== void 0) locAttrs.push(`rowPageCount="${o.locationRowPageCount}"`);
|
|
662
|
-
p.push(`<location ${locAttrs.join(" ")}/>`);
|
|
663
|
-
p.push(pivotFieldsXml);
|
|
664
|
-
p.push(rowFieldsXml);
|
|
665
|
-
p.push(rowItemsXml);
|
|
666
|
-
if (colFieldIndices.length > 0) p.push(colFieldsXml);
|
|
667
|
-
p.push(colItemsXml);
|
|
668
|
-
if (pageFieldIndices.length > 0) p.push(pageFieldsXml);
|
|
669
|
-
if (dataFields.length > 0) p.push(dataFieldsXml);
|
|
670
|
-
if (o.formats && o.formats.length > 0) {
|
|
671
|
-
const fmtParts = [`<formats count="${o.formats.length}">`];
|
|
672
|
-
for (const fmt of o.formats) {
|
|
673
|
-
const fmtAttrs = [];
|
|
674
|
-
if (fmt.action && fmt.action !== "formatting") fmtAttrs.push(`action="${fmt.action}"`);
|
|
675
|
-
if (fmt.dxfId !== void 0) fmtAttrs.push(`dxfId="${fmt.dxfId}"`);
|
|
676
|
-
fmtParts.push(`<format${fmtAttrs.length ? " " + fmtAttrs.join(" ") : ""}>${buildPivotAreaXml(fmt.pivotArea)}</format>`);
|
|
677
|
-
}
|
|
678
|
-
fmtParts.push("</formats>");
|
|
679
|
-
p.push(fmtParts.join(""));
|
|
680
|
-
}
|
|
681
|
-
if (o.chartFormats && o.chartFormats.length > 0) {
|
|
682
|
-
const cfParts = [`<chartFormats count="${o.chartFormats.length}">`];
|
|
683
|
-
for (const cf of o.chartFormats) {
|
|
684
|
-
const cfAttrs = [`chart="${cf.chart}"`, `format="${cf.format}"`];
|
|
685
|
-
if (cf.series) cfAttrs.push("series=\"1\"");
|
|
686
|
-
const areaXml = cf.pivotArea ? buildPivotAreaXml(cf.pivotArea) : "";
|
|
687
|
-
cfParts.push(`<chartFormat ${cfAttrs.join(" ")}>${areaXml}</chartFormat>`);
|
|
688
|
-
}
|
|
689
|
-
cfParts.push("</chartFormats>");
|
|
690
|
-
p.push(cfParts.join(""));
|
|
691
|
-
}
|
|
692
|
-
if (o.pivotHierarchies && o.pivotHierarchies.length > 0) p.push(buildPivotHierarchies(o.pivotHierarchies));
|
|
693
|
-
p.push(`<pivotTableStyleInfo name="${escapeXml(style)}" showRowHeaders="1" showColHeaders="1" showRowStripes="0" showColStripes="0" showLastColumn="1"/>`);
|
|
694
|
-
if (o.filters && o.filters.length > 0) {
|
|
695
|
-
const fParts = [`<filters count="${o.filters.length}">`];
|
|
696
|
-
for (const f of o.filters) {
|
|
697
|
-
const fAttrs = {
|
|
698
|
-
fld: f.fld,
|
|
699
|
-
type: f.type,
|
|
700
|
-
id: f.id
|
|
701
|
-
};
|
|
702
|
-
if (f.mpFld !== void 0) fAttrs.mpFld = f.mpFld;
|
|
703
|
-
if (f.evalOrder !== void 0) fAttrs.evalOrder = f.evalOrder;
|
|
704
|
-
fParts.push(`<filter${attrs(fAttrs)}><autoFilter></autoFilter></filter>`);
|
|
705
|
-
}
|
|
706
|
-
fParts.push("</filters>");
|
|
707
|
-
p.push(fParts.join(""));
|
|
708
|
-
}
|
|
709
|
-
if (o.rowHierarchiesUsage && o.rowHierarchiesUsage.length > 0) {
|
|
710
|
-
const rhu = o.rowHierarchiesUsage;
|
|
711
|
-
p.push(`<rowHierarchiesUsage count="${rhu.length}">${rhu.map((h) => `<rowHierarchyUsage hierarchyUsage="${h.hierarchyUsage}"/>`).join("")}</rowHierarchiesUsage>`);
|
|
712
|
-
}
|
|
713
|
-
if (o.colHierarchiesUsage && o.colHierarchiesUsage.length > 0) {
|
|
714
|
-
const chu = o.colHierarchiesUsage;
|
|
715
|
-
p.push(`<colHierarchiesUsage count="${chu.length}">${chu.map((h) => `<colHierarchyUsage hierarchyUsage="${h.hierarchyUsage}"/>`).join("")}</colHierarchiesUsage>`);
|
|
716
|
-
}
|
|
717
|
-
p.push("</pivotTableDefinition>");
|
|
718
|
-
return p.join("");
|
|
719
|
-
}
|
|
720
|
-
function buildFieldOverrideAttrs(fo) {
|
|
721
|
-
const a = [];
|
|
722
|
-
if (fo.allDrilled) a.push("allDrilled=\"1\"");
|
|
723
|
-
if (fo.autoShow) a.push("autoShow=\"1\"");
|
|
724
|
-
if (fo.countSubtotal) a.push("countSubtotal=\"1\"");
|
|
725
|
-
if (fo.dataSourceSort) a.push("dataSourceSort=\"1\"");
|
|
726
|
-
if (fo.defaultAttributeDrillState) a.push("defaultAttributeDrillState=\"1\"");
|
|
727
|
-
if (fo.hiddenLevel) a.push("hiddenLevel=\"1\"");
|
|
728
|
-
if (fo.hideNewItems) a.push("hideNewItems=\"1\"");
|
|
729
|
-
if (fo.insertBlankRow) a.push("insertBlankRow=\"1\"");
|
|
730
|
-
if (fo.insertPageBreak) a.push("insertPageBreak=\"1\"");
|
|
731
|
-
if (fo.itemPageCount) a.push("itemPageCount=\"1\"");
|
|
732
|
-
if (fo.measureFilter) a.push("measureFilter=\"1\"");
|
|
733
|
-
if (fo.nonAutoSortDefault) a.push("nonAutoSortDefault=\"1\"");
|
|
734
|
-
if (fo.productSubtotal) a.push("productSubtotal=\"1\"");
|
|
735
|
-
if (fo.rankBy !== void 0) a.push(`rankBy="${fo.rankBy}"`);
|
|
736
|
-
if (fo.serverField) a.push("serverField=\"1\"");
|
|
737
|
-
if (fo.showDropDowns) a.push("showDropDowns=\"1\"");
|
|
738
|
-
if (fo.showPropAsCaption) a.push("showPropAsCaption=\"1\"");
|
|
739
|
-
if (fo.showPropCell) a.push("showPropCell=\"1\"");
|
|
740
|
-
if (fo.showPropTip) a.push("showPropTip=\"1\"");
|
|
741
|
-
if (fo.stdDevPSubtotal) a.push("stdDevPSubtotal=\"1\"");
|
|
742
|
-
if (fo.stdDevSubtotal) a.push("stdDevSubtotal=\"1\"");
|
|
743
|
-
if (fo.subtotalCaption) a.push(`subtotalCaption="${escapeXml(fo.subtotalCaption)}"`);
|
|
744
|
-
if (fo.topAutoShow) a.push("topAutoShow=\"1\"");
|
|
745
|
-
if (fo.uniqueMemberProperty) a.push("uniqueMemberProperty=\"1\"");
|
|
746
|
-
if (fo.varPSubtotal) a.push("varPSubtotal=\"1\"");
|
|
747
|
-
if (fo.varSubtotal) a.push("varSubtotal=\"1\"");
|
|
748
|
-
return a.join(" ");
|
|
749
|
-
}
|
|
750
|
-
function buildPivotFields(o, sd, rowIndices, colIndices, dataIndices, pageIndices) {
|
|
751
|
-
const fieldNames = sd.fieldNames;
|
|
752
|
-
const parts = [`<pivotFields count="${fieldNames.length}">`];
|
|
753
|
-
for (let i = 0; i < fieldNames.length; i++) {
|
|
754
|
-
const isRow = rowIndices.includes(i);
|
|
755
|
-
const isCol = colIndices.includes(i);
|
|
756
|
-
const isData = dataIndices.includes(i);
|
|
757
|
-
const isPage = pageIndices.includes(i);
|
|
758
|
-
const override = o.fieldOverrides?.find((fo) => fo.field === fieldNames[i]);
|
|
759
|
-
const extraAttrs = override ? buildFieldOverrideAttrs(override) : "";
|
|
760
|
-
if (isData) {
|
|
761
|
-
const dataFieldIdx = dataIndices.indexOf(i);
|
|
762
|
-
const df = o.data[dataFieldIdx];
|
|
763
|
-
const dfAttrs = ["dataField=\"1\"", "showAll=\"0\""];
|
|
764
|
-
if (extraAttrs) dfAttrs.push(extraAttrs);
|
|
765
|
-
if (df?.showDataAs) dfAttrs.push(`showDataAs="${df.showDataAs}"`);
|
|
766
|
-
if (df?.baseField !== void 0) dfAttrs.push(`baseField="${df.baseField}"`);
|
|
767
|
-
if (df?.baseItem !== void 0) dfAttrs.push(`baseItem="${df.baseItem}"`);
|
|
768
|
-
if (o.autoSortScope) parts.push(`<pivotField ${dfAttrs.join(" ")}><autoSortScope>${buildPivotAreaXml(o.autoSortScope)}</autoSortScope></pivotField>`);
|
|
769
|
-
else parts.push(`<pivotField ${dfAttrs.join(" ")}/>`);
|
|
770
|
-
} else if (isRow) {
|
|
771
|
-
const uniqueVals = collectUniqueValues(sd.records, i);
|
|
772
|
-
const rAttrs = extraAttrs ? ` axis="axisRow" showAll="0" ${extraAttrs}` : " axis=\"axisRow\" showAll=\"0\"";
|
|
773
|
-
parts.push(`<pivotField${rAttrs}>`);
|
|
774
|
-
parts.push(`<items count="${uniqueVals.length + 1}">`);
|
|
775
|
-
for (let j = 0; j < uniqueVals.length; j++) parts.push(`<item x="${j}"/>`);
|
|
776
|
-
parts.push(`<item t="default"${override?.defaultItemSd === false ? " sd=\"0\"" : ""}/>`);
|
|
777
|
-
parts.push("</items></pivotField>");
|
|
778
|
-
} else if (isCol) {
|
|
779
|
-
const uniqueVals = collectUniqueValues(sd.records, i);
|
|
780
|
-
const cAttrs = extraAttrs ? ` axis="axisCol" showAll="0" ${extraAttrs}` : " axis=\"axisCol\" showAll=\"0\"";
|
|
781
|
-
parts.push(`<pivotField${cAttrs}>`);
|
|
782
|
-
parts.push(`<items count="${uniqueVals.length + 1}">`);
|
|
783
|
-
for (let j = 0; j < uniqueVals.length; j++) parts.push(`<item x="${j}"/>`);
|
|
784
|
-
parts.push(`<item t="default"${override?.defaultItemSd === false ? " sd=\"0\"" : ""}/>`);
|
|
785
|
-
parts.push("</items></pivotField>");
|
|
786
|
-
} else if (isPage) {
|
|
787
|
-
const uniqueVals = collectUniqueValues(sd.records, i);
|
|
788
|
-
const pAttrs = extraAttrs ? ` axis="axisPage" showAll="0" ${extraAttrs}` : " axis=\"axisPage\" showAll=\"0\"";
|
|
789
|
-
parts.push(`<pivotField${pAttrs}>`);
|
|
790
|
-
parts.push(`<items count="${uniqueVals.length + 1}">`);
|
|
791
|
-
for (let j = 0; j < uniqueVals.length; j++) parts.push(`<item x="${j}"/>`);
|
|
792
|
-
parts.push(`<item t="default"${override?.defaultItemSd === false ? " sd=\"0\"" : ""}/>`);
|
|
793
|
-
parts.push("</items></pivotField>");
|
|
794
|
-
} else {
|
|
795
|
-
const nAttrs = extraAttrs ? ` showAll="0" ${extraAttrs}` : " showAll=\"0\"";
|
|
796
|
-
parts.push(`<pivotField${nAttrs}/>`);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
parts.push("</pivotFields>");
|
|
800
|
-
return parts.join("");
|
|
801
|
-
}
|
|
802
|
-
function buildPageFields(o, pageIndices) {
|
|
803
|
-
if (pageIndices.length === 0) return "";
|
|
804
|
-
const parts = [`<pageFields count="${pageIndices.length}">`];
|
|
805
|
-
for (let i = 0; i < pageIndices.length; i++) {
|
|
806
|
-
const cap = o.pageCaptions?.[i];
|
|
807
|
-
const capAttr = cap ? ` cap="${escapeXml(cap)}"` : "";
|
|
808
|
-
parts.push(`<pageField fld="${pageIndices[i]}" hier="${i}"${capAttr}/>`);
|
|
809
|
-
}
|
|
810
|
-
parts.push("</pageFields>");
|
|
811
|
-
return parts.join("");
|
|
812
|
-
}
|
|
813
|
-
function buildRowFields(rowIndices) {
|
|
814
|
-
if (rowIndices.length === 0) return "<rowFields count=\"0\"/>";
|
|
815
|
-
const parts = [`<rowFields count="${rowIndices.length}">`];
|
|
816
|
-
for (const idx of rowIndices) parts.push(`<field x="${idx}"/>`);
|
|
817
|
-
parts.push("</rowFields>");
|
|
818
|
-
return parts.join("");
|
|
819
|
-
}
|
|
820
|
-
function buildRowItems(sd, rowIndices) {
|
|
821
|
-
if (rowIndices.length === 0) return "<rowItems count=\"1\"><i/></rowItems>";
|
|
822
|
-
const allUniqueCounts = [];
|
|
823
|
-
for (const idx of rowIndices) allUniqueCounts.push(collectUniqueValues(sd.records, idx).length);
|
|
824
|
-
if (rowIndices.length === 1) {
|
|
825
|
-
const count = allUniqueCounts[0];
|
|
826
|
-
const parts = [`<rowItems count="${count + 1}">`];
|
|
827
|
-
for (let i = 0; i < count; i++) parts.push(`<i><x v="${i}"/></i>`);
|
|
828
|
-
parts.push(`<i t="grand"><x/></i>`);
|
|
829
|
-
parts.push("</rowItems>");
|
|
830
|
-
return parts.join("");
|
|
831
|
-
}
|
|
832
|
-
const combos = cartesianOfCounts(allUniqueCounts);
|
|
833
|
-
const rowItems = [];
|
|
834
|
-
for (const combo of combos) rowItems.push(`<i>${combo.map((v) => `<x v="${v}"/>`).join("")}</i>`);
|
|
835
|
-
rowItems.push(`<i t="grand">${rowIndices.map(() => "<x/>").join("")}</i>`);
|
|
836
|
-
return `<rowItems count="${rowItems.length}">${rowItems.join("")}</rowItems>`;
|
|
837
|
-
}
|
|
838
|
-
function buildColFields(colIndices) {
|
|
839
|
-
if (colIndices.length === 0) return "<colFields count=\"0\"/>";
|
|
840
|
-
const parts = [`<colFields count="${colIndices.length}">`];
|
|
841
|
-
for (const idx of colIndices) parts.push(`<field x="${idx}"/>`);
|
|
842
|
-
parts.push("</colFields>");
|
|
843
|
-
return parts.join("");
|
|
844
|
-
}
|
|
845
|
-
function buildColItems(sd, colIndices, dataFields) {
|
|
846
|
-
if (colIndices.length > 0) {
|
|
847
|
-
const allUniqueCounts = [];
|
|
848
|
-
for (const idx of colIndices) allUniqueCounts.push(collectUniqueValues(sd.records, idx).length);
|
|
849
|
-
const combos = cartesianOfCounts(allUniqueCounts);
|
|
850
|
-
const items = [];
|
|
851
|
-
for (const combo of combos) items.push(`<i>${combo.map((v) => `<x v="${v}"/>`).join("")}</i>`);
|
|
852
|
-
items.push(`<i t="grand">${colIndices.map(() => "<x/>").join("")}</i>`);
|
|
853
|
-
return `<colItems count="${items.length}">${items.join("")}</colItems>`;
|
|
854
|
-
}
|
|
855
|
-
if (dataFields.length > 1) {
|
|
856
|
-
const items = dataFields.map((_, i) => `<i><x v="${i}"/></i>`);
|
|
857
|
-
return `<colItems count="${items.length}">${items.join("")}</colItems>`;
|
|
858
|
-
}
|
|
859
|
-
return "<colItems count=\"1\"><i/></colItems>";
|
|
860
|
-
}
|
|
861
|
-
function buildDataFields(dataFields, dataFieldIndices) {
|
|
862
|
-
if (dataFields.length === 0) return "<dataFields count=\"0\"/>";
|
|
863
|
-
const parts = [`<dataFields count="${dataFields.length}">`];
|
|
864
|
-
for (let i = 0; i < dataFields.length; i++) {
|
|
865
|
-
const df = dataFields[i];
|
|
866
|
-
const subtotal = df.summarize ?? "sum";
|
|
867
|
-
const dfAttrs = [
|
|
868
|
-
`name="${escapeXml(df.name ?? `${subtotal === "sum" ? "Sum" : subtotal} of ${df.field}`)}"`,
|
|
869
|
-
`fld="${dataFieldIndices[i]}"`,
|
|
870
|
-
`subtotal="${subtotal}"`
|
|
871
|
-
];
|
|
872
|
-
if (df.showDataAs) dfAttrs.push(`showDataAs="${df.showDataAs}"`);
|
|
873
|
-
if (df.baseField !== void 0) dfAttrs.push(`baseField="${df.baseField}"`);
|
|
874
|
-
if (df.baseItem !== void 0) dfAttrs.push(`baseItem="${df.baseItem}"`);
|
|
875
|
-
parts.push(`<dataField ${dfAttrs.join(" ")}/>`);
|
|
876
|
-
}
|
|
877
|
-
parts.push("</dataFields>");
|
|
878
|
-
return parts.join("");
|
|
879
|
-
}
|
|
880
|
-
function computeLocationRef(sd, location, rowFieldIndices, colFieldIndices, dataFields) {
|
|
881
|
-
const match = location.split(":")[0].match(/^([A-Z]+)(\d+)$/);
|
|
882
|
-
if (!match) return location;
|
|
883
|
-
const startCol = match[1];
|
|
884
|
-
const startRow = parseInt(match[2], 10);
|
|
885
|
-
let rowCount = 1;
|
|
886
|
-
if (rowFieldIndices.length > 0) rowCount += collectUniqueValues(sd.records, rowFieldIndices[0]).length;
|
|
887
|
-
rowCount += 1;
|
|
888
|
-
let colCount = Math.max(rowFieldIndices.length, 1);
|
|
889
|
-
if (colFieldIndices.length > 0) colCount += collectUniqueValues(sd.records, colFieldIndices[0]).length;
|
|
890
|
-
else if (dataFields.length > 1) colCount += dataFields.length - 1;
|
|
891
|
-
colCount += 1;
|
|
892
|
-
return `${startCol}${startRow}:${colIndexToLetter$1(letterToColIndex(startCol) + colCount - 1)}${startRow + rowCount - 1}`;
|
|
893
|
-
}
|
|
894
|
-
function buildPivotHierarchies(hierarchies) {
|
|
895
|
-
const parts = [`<pivotHierarchies count="${hierarchies.length}">`];
|
|
896
|
-
for (const h of hierarchies) {
|
|
897
|
-
const hAttrs = [];
|
|
898
|
-
if (h.outline) hAttrs.push("outline=\"1\"");
|
|
899
|
-
if (h.multipleItemSelectionAllowed) hAttrs.push("multipleItemSelectionAllowed=\"1\"");
|
|
900
|
-
if (h.subtotalTop) hAttrs.push("subtotalTop=\"1\"");
|
|
901
|
-
if (h.showInFieldList === false) hAttrs.push("showInFieldList=\"0\"");
|
|
902
|
-
if (h.dragToRow === false) hAttrs.push("dragToRow=\"0\"");
|
|
903
|
-
if (h.dragToCol === false) hAttrs.push("dragToCol=\"0\"");
|
|
904
|
-
if (h.dragToPage === false) hAttrs.push("dragToPage=\"0\"");
|
|
905
|
-
if (h.dragToData) hAttrs.push("dragToData=\"1\"");
|
|
906
|
-
if (h.dragOff === false) hAttrs.push("dragOff=\"0\"");
|
|
907
|
-
if (h.includeNewItemsInFilter) hAttrs.push("includeNewItemsInFilter=\"1\"");
|
|
908
|
-
if (h.caption) hAttrs.push(`caption="${escapeXml(h.caption)}"`);
|
|
909
|
-
const inner = (h.memberProperties ? `<mps count="${h.memberProperties.length}">${h.memberProperties.map((mp) => {
|
|
910
|
-
const mpAttrs = [`field="${mp.field}"`];
|
|
911
|
-
if (mp.name !== void 0) mpAttrs.push(`name="${escapeXml(mp.name)}"`);
|
|
912
|
-
if (mp.showCell) mpAttrs.push("showCell=\"1\"");
|
|
913
|
-
if (mp.showTip) mpAttrs.push("showTip=\"1\"");
|
|
914
|
-
if (mp.showAsCaption) mpAttrs.push("showAsCaption=\"1\"");
|
|
915
|
-
return `<mp ${mpAttrs.join(" ")}/>`;
|
|
916
|
-
}).join("")}</mps>` : "") + (h.members ? `<members count="${h.members.length}">${h.members.map((m) => `<member name="${escapeXml(m.name)}"${m.level !== void 0 ? ` level="${m.level}"` : ""}/>`).join("")}</members>` : "");
|
|
917
|
-
if (inner) parts.push(`<pivotHierarchy ${hAttrs.join(" ")}>${inner}</pivotHierarchy>`);
|
|
918
|
-
else parts.push(`<pivotHierarchy ${hAttrs.join(" ")}/>`);
|
|
919
|
-
}
|
|
920
|
-
parts.push("</pivotHierarchies>");
|
|
921
|
-
return parts.join("");
|
|
922
|
-
}
|
|
923
|
-
function buildPivotAreaXml(area) {
|
|
924
|
-
const aAttrs = [];
|
|
925
|
-
if (area.field !== void 0) aAttrs.push(`field="${area.field}"`);
|
|
926
|
-
if (area.type) aAttrs.push(`type="${area.type}"`);
|
|
927
|
-
if (area.dataOnly === false) aAttrs.push("dataOnly=\"0\"");
|
|
928
|
-
if (area.labelOnly) aAttrs.push("labelOnly=\"1\"");
|
|
929
|
-
if (area.grandRow) aAttrs.push("grandRow=\"1\"");
|
|
930
|
-
if (area.grandCol) aAttrs.push("grandCol=\"1\"");
|
|
931
|
-
if (area.cacheIndex) aAttrs.push("cacheIndex=\"1\"");
|
|
932
|
-
if (area.outline === false) aAttrs.push("outline=\"0\"");
|
|
933
|
-
if (area.offset) aAttrs.push(`offset="${escapeXml(area.offset)}"`);
|
|
934
|
-
if (area.collapsedLevelsAreSubtotals) aAttrs.push("collapsedLevelsAreSubtotals=\"1\"");
|
|
935
|
-
if (area.axis) aAttrs.push(`axis="${area.axis}"`);
|
|
936
|
-
if (area.fieldPosition !== void 0) aAttrs.push(`fieldPosition="${area.fieldPosition}"`);
|
|
937
|
-
const refsXml = area.references ? buildPivotAreaReferences(area.references) : "";
|
|
938
|
-
if (refsXml) return `<pivotArea ${aAttrs.join(" ")}>${refsXml}</pivotArea>`;
|
|
939
|
-
return `<pivotArea ${aAttrs.join(" ")}/>`;
|
|
940
|
-
}
|
|
941
|
-
function buildPivotAreaReferences(refs) {
|
|
942
|
-
const parts = [`<references count="${refs.length}">`];
|
|
943
|
-
for (const ref of refs) {
|
|
944
|
-
const rAttrs = [];
|
|
945
|
-
if (ref.field !== void 0) rAttrs.push(`field="${ref.field}"`);
|
|
946
|
-
if (ref.count !== void 0) rAttrs.push(`count="${ref.count}"`);
|
|
947
|
-
if (ref.selected === false) rAttrs.push("selected=\"0\"");
|
|
948
|
-
if (ref.byPosition) rAttrs.push("byPosition=\"1\"");
|
|
949
|
-
if (ref.relative) rAttrs.push("relative=\"1\"");
|
|
950
|
-
if (ref.defaultSubtotal) rAttrs.push("defaultSubtotal=\"1\"");
|
|
951
|
-
const xXml = ref.x ? ref.x.map((v) => `<x v="${v}"/>`).join("") : "";
|
|
952
|
-
if (xXml) parts.push(`<reference ${rAttrs.join(" ")}>${xXml}</reference>`);
|
|
953
|
-
else parts.push(`<reference ${rAttrs.join(" ")}/>`);
|
|
954
|
-
}
|
|
955
|
-
parts.push("</references>");
|
|
956
|
-
return parts.join("");
|
|
957
|
-
}
|
|
958
|
-
function letterToColIndex(letters) {
|
|
959
|
-
let col = 0;
|
|
960
|
-
for (let i = 0; i < letters.length; i++) col = col * 26 + (letters.charCodeAt(i) - 64);
|
|
961
|
-
return col;
|
|
962
|
-
}
|
|
963
|
-
function colIndexToLetter$1(col) {
|
|
964
|
-
let result = "";
|
|
965
|
-
let n = col;
|
|
966
|
-
while (n > 0) {
|
|
967
|
-
n--;
|
|
968
|
-
result = String.fromCharCode(65 + n % 26) + result;
|
|
969
|
-
n = Math.floor(n / 26);
|
|
970
|
-
}
|
|
971
|
-
return result;
|
|
972
|
-
}
|
|
973
|
-
function cartesianOfCounts(counts) {
|
|
974
|
-
if (counts.length === 0) return [[]];
|
|
975
|
-
let result = [[]];
|
|
976
|
-
for (const count of counts) {
|
|
977
|
-
const next = [];
|
|
978
|
-
for (const prefix of result) for (let i = 0; i < count; i++) next.push([...prefix, i]);
|
|
979
|
-
result = next;
|
|
980
|
-
}
|
|
981
|
-
return result;
|
|
982
|
-
}
|
|
983
|
-
//#endregion
|
|
984
|
-
//#region src/parts/pivot-cache.ts
|
|
985
|
-
const pivotCacheDefDesc = {
|
|
986
|
-
kind: "custom",
|
|
987
|
-
stringify(opts, _ctx) {
|
|
988
|
-
return stringifyPivotCacheDef(opts.sourceRef, opts.sourceSheet, opts.sourceData, opts.recordsRid, opts.cacheDefOpts);
|
|
989
|
-
},
|
|
990
|
-
parse(el, _ctx) {
|
|
991
|
-
const result = {};
|
|
992
|
-
const csEl = findChild(el, "cacheSource");
|
|
993
|
-
if (csEl) {
|
|
994
|
-
result.sourceType = attr(csEl, "type");
|
|
995
|
-
const wssEl = findChild(csEl, "worksheetSource");
|
|
996
|
-
if (wssEl) {
|
|
997
|
-
const wss = {};
|
|
998
|
-
if (attr(wssEl, "ref")) wss.ref = attr(wssEl, "ref");
|
|
999
|
-
if (attr(wssEl, "sheet")) wss.sheet = attr(wssEl, "sheet");
|
|
1000
|
-
result.worksheetSource = wss;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
const cfEl = findChild(el, "cacheFields");
|
|
1004
|
-
if (cfEl) {
|
|
1005
|
-
const fields = [];
|
|
1006
|
-
for (const fEl of cfEl.elements ?? []) {
|
|
1007
|
-
if (fEl.name !== "cacheField") continue;
|
|
1008
|
-
const field = {};
|
|
1009
|
-
if (attr(fEl, "name")) field.name = attr(fEl, "name");
|
|
1010
|
-
if (attrNum(fEl, "numFmtId") !== void 0) field.numFmtId = attrNum(fEl, "numFmtId");
|
|
1011
|
-
const siEl = findChild(fEl, "sharedItems");
|
|
1012
|
-
if (siEl) {
|
|
1013
|
-
const items = [];
|
|
1014
|
-
for (const siChild of siEl.elements ?? []) {
|
|
1015
|
-
const v = attr(siChild, "v");
|
|
1016
|
-
if (v !== void 0) items.push(isNaN(Number(v)) ? v : Number(v));
|
|
1017
|
-
}
|
|
1018
|
-
field.sharedItems = items;
|
|
1019
|
-
}
|
|
1020
|
-
fields.push(field);
|
|
1021
|
-
}
|
|
1022
|
-
result.cacheFields = fields;
|
|
1023
|
-
}
|
|
1024
|
-
return result;
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
const pivotCacheRecordsDesc = {
|
|
1028
|
-
kind: "custom",
|
|
1029
|
-
stringify(opts, _ctx) {
|
|
1030
|
-
return stringifyPivotCacheRecords(opts.sourceData);
|
|
1031
|
-
},
|
|
1032
|
-
parse(el, _ctx) {
|
|
1033
|
-
const records = [];
|
|
1034
|
-
for (const rEl of el.elements ?? []) {
|
|
1035
|
-
if (rEl.name !== "r") continue;
|
|
1036
|
-
const record = [];
|
|
1037
|
-
for (const fEl of rEl.elements ?? []) {
|
|
1038
|
-
const entry = {};
|
|
1039
|
-
if (fEl.name === "x") {
|
|
1040
|
-
entry.type = "string";
|
|
1041
|
-
entry.v = attrNum(fEl, "v") ?? 0;
|
|
1042
|
-
} else if (fEl.name === "n") {
|
|
1043
|
-
entry.type = "number";
|
|
1044
|
-
const v = attr(fEl, "v");
|
|
1045
|
-
entry.v = v !== void 0 ? Number(v) : 0;
|
|
1046
|
-
} else if (fEl.name === "d") {
|
|
1047
|
-
entry.type = "date";
|
|
1048
|
-
entry.v = attr(fEl, "v") ?? "";
|
|
1049
|
-
} else if (fEl.name === "m") entry.type = "missing";
|
|
1050
|
-
record.push(entry);
|
|
1051
|
-
}
|
|
1052
|
-
records.push(record);
|
|
1053
|
-
}
|
|
1054
|
-
return { records };
|
|
1055
|
-
}
|
|
1056
|
-
};
|
|
1057
|
-
function stringifyPivotCacheDef(sourceRef, sourceSheet, sourceData, recordsRid, cacheDefOpts) {
|
|
1058
|
-
const p = [];
|
|
1059
|
-
const rootAttrs = [
|
|
1060
|
-
"xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"",
|
|
1061
|
-
"xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"",
|
|
1062
|
-
`r:id="${escapeXml(recordsRid)}"`,
|
|
1063
|
-
`recordCount="${sourceData.records.length}"`,
|
|
1064
|
-
"createdVersion=\"6\"",
|
|
1065
|
-
"refreshedVersion=\"6\"",
|
|
1066
|
-
"minRefreshableVersion=\"3\""
|
|
1067
|
-
];
|
|
1068
|
-
if (cacheDefOpts) {
|
|
1069
|
-
const cd = cacheDefOpts;
|
|
1070
|
-
if (cd.invalid) rootAttrs.push("invalid=\"1\"");
|
|
1071
|
-
if (cd.saveData === false) rootAttrs.push("saveData=\"0\"");
|
|
1072
|
-
if (cd.optimizeMemory) rootAttrs.push("optimizeMemory=\"1\"");
|
|
1073
|
-
if (cd.enableRefresh === false) rootAttrs.push("enableRefresh=\"0\"");
|
|
1074
|
-
if (cd.refreshedBy) rootAttrs.push(`refreshedBy="${escapeXml(cd.refreshedBy)}"`);
|
|
1075
|
-
if (cd.refreshedDate !== void 0) rootAttrs.push(`refreshedDate="${cd.refreshedDate}"`);
|
|
1076
|
-
if (cd.refreshedDateIso) rootAttrs.push(`refreshedDateIso="${escapeXml(cd.refreshedDateIso)}"`);
|
|
1077
|
-
if (cd.backgroundQuery) rootAttrs.push("backgroundQuery=\"1\"");
|
|
1078
|
-
if (cd.missingItemsLimit !== void 0) rootAttrs.push(`missingItemsLimit="${cd.missingItemsLimit}"`);
|
|
1079
|
-
if (cd.upgradeOnRefresh) rootAttrs.push("upgradeOnRefresh=\"1\"");
|
|
1080
|
-
if (cd.supportSubquery) rootAttrs.push("supportSubquery=\"1\"");
|
|
1081
|
-
if (cd.supportAdvancedDrill) rootAttrs.push("supportAdvancedDrill=\"1\"");
|
|
1082
|
-
}
|
|
1083
|
-
p.push(`<pivotCacheDefinition ${rootAttrs.join(" ")}>`);
|
|
1084
|
-
if (cacheDefOpts?.consolidation) {
|
|
1085
|
-
const con = cacheDefOpts.consolidation;
|
|
1086
|
-
const conParts = ["<cacheSource type=\"consolidation\"><consolidation"];
|
|
1087
|
-
if (con.autoPage === false) conParts.push(" autoPage=\"0\"");
|
|
1088
|
-
conParts.push(">");
|
|
1089
|
-
if (con.pages && con.pages.length > 0) {
|
|
1090
|
-
conParts.push(`<pages count="${con.pages.length}">`);
|
|
1091
|
-
for (const pg of con.pages) {
|
|
1092
|
-
const pgItems = pg.items ?? [];
|
|
1093
|
-
conParts.push(`<page${pgItems.length ? ` count="${pgItems.length}"` : ""}>`);
|
|
1094
|
-
for (const pi of pgItems) conParts.push(`<pageItem name="${escapeXml(pi.name)}"/>`);
|
|
1095
|
-
conParts.push("</page>");
|
|
1096
|
-
}
|
|
1097
|
-
conParts.push("</pages>");
|
|
1098
|
-
}
|
|
1099
|
-
conParts.push(`<rangeSets count="${con.rangeSets.length}">`);
|
|
1100
|
-
for (const rs of con.rangeSets) {
|
|
1101
|
-
const rsAttrs = [];
|
|
1102
|
-
if (rs.i1 !== void 0) rsAttrs.push(`i1="${rs.i1}"`);
|
|
1103
|
-
if (rs.i2 !== void 0) rsAttrs.push(`i2="${rs.i2}"`);
|
|
1104
|
-
if (rs.i3 !== void 0) rsAttrs.push(`i3="${rs.i3}"`);
|
|
1105
|
-
if (rs.i4 !== void 0) rsAttrs.push(`i4="${rs.i4}"`);
|
|
1106
|
-
if (rs.ref) rsAttrs.push(`ref="${escapeXml(rs.ref)}"`);
|
|
1107
|
-
if (rs.name) rsAttrs.push(`name="${escapeXml(rs.name)}"`);
|
|
1108
|
-
if (rs.sheet) rsAttrs.push(`sheet="${escapeXml(rs.sheet)}"`);
|
|
1109
|
-
if (rs.rId) rsAttrs.push(`r:id="${escapeXml(rs.rId)}"`);
|
|
1110
|
-
conParts.push(`<rangeSet ${rsAttrs.join(" ")}/>`);
|
|
1111
|
-
}
|
|
1112
|
-
conParts.push("</rangeSets></consolidation></cacheSource>");
|
|
1113
|
-
p.push(conParts.join(""));
|
|
1114
|
-
} else p.push(`<cacheSource type="worksheet"><worksheetSource ref="${escapeXml(sourceRef)}" sheet="${escapeXml(sourceSheet)}"/></cacheSource>`);
|
|
1115
|
-
const fieldNames = sourceData.fieldNames;
|
|
1116
|
-
p.push(`<cacheFields count="${fieldNames.length}">`);
|
|
1117
|
-
for (let i = 0; i < fieldNames.length; i++) {
|
|
1118
|
-
const fieldName = fieldNames[i];
|
|
1119
|
-
const numeric = isNumericField(sourceData.records, i);
|
|
1120
|
-
const uniqueVals = collectUniqueValues(sourceData.records, i);
|
|
1121
|
-
if (numeric) {
|
|
1122
|
-
let min = Infinity, max = -Infinity;
|
|
1123
|
-
for (const row of sourceData.records) {
|
|
1124
|
-
const v = row[i];
|
|
1125
|
-
if (typeof v === "number") {
|
|
1126
|
-
if (v < min) min = v;
|
|
1127
|
-
if (v > max) max = v;
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
if (!isFinite(min)) {
|
|
1131
|
-
min = 0;
|
|
1132
|
-
max = 0;
|
|
1133
|
-
}
|
|
1134
|
-
const allInteger = sourceData.records.every((row) => typeof row[i] === "number" && Number.isInteger(row[i]));
|
|
1135
|
-
const cfOverride = cacheDefOpts?.cacheFieldOverrides?.get(i);
|
|
1136
|
-
const cfExtraAttrs = [];
|
|
1137
|
-
const siExtraAttrs = [];
|
|
1138
|
-
if (cfOverride) {
|
|
1139
|
-
if (cfOverride.databaseField) cfExtraAttrs.push("databaseField=\"1\"");
|
|
1140
|
-
if (cfOverride.level !== void 0) cfExtraAttrs.push(`level="${cfOverride.level}"`);
|
|
1141
|
-
if (cfOverride.mappingCount !== void 0) cfExtraAttrs.push(`mappingCount="${cfOverride.mappingCount}"`);
|
|
1142
|
-
if (cfOverride.memberPropertyField !== void 0) cfExtraAttrs.push(`memberPropertyField="${cfOverride.memberPropertyField}"`);
|
|
1143
|
-
if (cfOverride.propertyName) cfExtraAttrs.push(`propertyName="${escapeXml(cfOverride.propertyName)}"`);
|
|
1144
|
-
if (cfOverride.serverField) cfExtraAttrs.push("serverField=\"1\"");
|
|
1145
|
-
if (cfOverride.uniqueList) cfExtraAttrs.push("uniqueList=\"1\"");
|
|
1146
|
-
if (cfOverride.containsMixedTypes) siExtraAttrs.push("containsMixedTypes=\"1\"");
|
|
1147
|
-
if (cfOverride.containsNonDate) siExtraAttrs.push("containsNonDate=\"1\"");
|
|
1148
|
-
if (cfOverride.longText) siExtraAttrs.push("longText=\"1\"");
|
|
1149
|
-
}
|
|
1150
|
-
p.push(`<cacheField name="${escapeXml(fieldName)}" ${cfExtraAttrs.length ? cfExtraAttrs.join(" ") + " " : ""}numFmtId="0"><sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="${allInteger ? "1" : "0"}" minValue="${min}" maxValue="${max}" count="${uniqueVals.length}"${siExtraAttrs.length ? " " + siExtraAttrs.join(" ") : ""}/></cacheField>`);
|
|
1151
|
-
} else {
|
|
1152
|
-
let hasDate = false, hasMissing = false;
|
|
1153
|
-
for (const v of uniqueVals) {
|
|
1154
|
-
if (v instanceof Date) hasDate = true;
|
|
1155
|
-
if (v === null) hasMissing = true;
|
|
1156
|
-
}
|
|
1157
|
-
const siAttrs = [`count="${uniqueVals.length}"`];
|
|
1158
|
-
if (hasDate) siAttrs.push("containsDate=\"1\"");
|
|
1159
|
-
if (hasMissing) siAttrs.push("containsBlank=\"1\"");
|
|
1160
|
-
const cfOverride = cacheDefOpts?.cacheFieldOverrides?.get(i);
|
|
1161
|
-
const cfExtraAttrs = [];
|
|
1162
|
-
if (cfOverride) {
|
|
1163
|
-
if (cfOverride.databaseField) cfExtraAttrs.push("databaseField=\"1\"");
|
|
1164
|
-
if (cfOverride.level !== void 0) cfExtraAttrs.push(`level="${cfOverride.level}"`);
|
|
1165
|
-
if (cfOverride.mappingCount !== void 0) cfExtraAttrs.push(`mappingCount="${cfOverride.mappingCount}"`);
|
|
1166
|
-
if (cfOverride.memberPropertyField !== void 0) cfExtraAttrs.push(`memberPropertyField="${cfOverride.memberPropertyField}"`);
|
|
1167
|
-
if (cfOverride.propertyName) cfExtraAttrs.push(`propertyName="${escapeXml(cfOverride.propertyName)}"`);
|
|
1168
|
-
if (cfOverride.serverField) cfExtraAttrs.push("serverField=\"1\"");
|
|
1169
|
-
if (cfOverride.uniqueList) cfExtraAttrs.push("uniqueList=\"1\"");
|
|
1170
|
-
if (cfOverride.containsMixedTypes) siAttrs.push("containsMixedTypes=\"1\"");
|
|
1171
|
-
if (cfOverride.containsNonDate) siAttrs.push("containsNonDate=\"1\"");
|
|
1172
|
-
if (cfOverride.longText) siAttrs.push("longText=\"1\"");
|
|
1173
|
-
}
|
|
1174
|
-
p.push(`<cacheField name="${escapeXml(fieldName)}" ${cfExtraAttrs.length ? cfExtraAttrs.join(" ") + " " : ""}numFmtId="0"><sharedItems ${siAttrs.join(" ")}>`);
|
|
1175
|
-
for (const v of uniqueVals) if (v === null) p.push("<m/>");
|
|
1176
|
-
else if (v instanceof Date) p.push(`<d v="${v.toISOString().replace(/\.\d{3}Z$/, "Z")}"/>`);
|
|
1177
|
-
else p.push(`<s v="${escapeXml(String(v))}"/>`);
|
|
1178
|
-
p.push("</sharedItems>");
|
|
1179
|
-
const fg = cacheDefOpts?.fieldGroups?.get(i);
|
|
1180
|
-
if (fg) {
|
|
1181
|
-
const fgParts = ["<fieldGroup"];
|
|
1182
|
-
if (fg.parent !== void 0) fgParts.push(` par="${fg.parent}"`);
|
|
1183
|
-
if (fg.base !== void 0) fgParts.push(` base="${fg.base}"`);
|
|
1184
|
-
fgParts.push(">");
|
|
1185
|
-
if (fg.rangePr) {
|
|
1186
|
-
const rp = fg.rangePr;
|
|
1187
|
-
const rpAttrs = [];
|
|
1188
|
-
if (rp.autoStart === false) rpAttrs.push("autoStart=\"0\"");
|
|
1189
|
-
if (rp.autoEnd === false) rpAttrs.push("autoEnd=\"0\"");
|
|
1190
|
-
if (rp.groupBy && rp.groupBy !== "range") rpAttrs.push(`groupBy="${rp.groupBy}"`);
|
|
1191
|
-
if (rp.startNum !== void 0) rpAttrs.push(`startNum="${rp.startNum}"`);
|
|
1192
|
-
if (rp.endNum !== void 0) rpAttrs.push(`endNum="${rp.endNum}"`);
|
|
1193
|
-
if (rp.startDate) rpAttrs.push(`startDate="${escapeXml(rp.startDate)}"`);
|
|
1194
|
-
if (rp.endDate) rpAttrs.push(`endDate="${escapeXml(rp.endDate)}"`);
|
|
1195
|
-
if (rp.groupInterval !== void 0) rpAttrs.push(`groupInterval="${rp.groupInterval}"`);
|
|
1196
|
-
fgParts.push(`<rangePr${rpAttrs.length ? " " + rpAttrs.join(" ") : ""}/>`);
|
|
1197
|
-
}
|
|
1198
|
-
if (fg.discretePr && fg.discretePr.length > 0) {
|
|
1199
|
-
fgParts.push(`<discretePr count="${fg.discretePr.length}">`);
|
|
1200
|
-
for (const idx of fg.discretePr) fgParts.push(`<x v="${idx}"/>`);
|
|
1201
|
-
fgParts.push("</discretePr>");
|
|
1202
|
-
}
|
|
1203
|
-
if (fg.groupItems && fg.groupItems.length > 0) {
|
|
1204
|
-
fgParts.push(`<groupItems count="${fg.groupItems.length}">`);
|
|
1205
|
-
for (const gi of fg.groupItems) fgParts.push(`<s v="${escapeXml(gi)}"/>`);
|
|
1206
|
-
fgParts.push("</groupItems>");
|
|
1207
|
-
}
|
|
1208
|
-
fgParts.push("</fieldGroup>");
|
|
1209
|
-
p.push(fgParts.join(""));
|
|
1210
|
-
}
|
|
1211
|
-
p.push("</cacheField>");
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
p.push("</cacheFields>");
|
|
1215
|
-
if (cacheDefOpts?.mpMaps) for (const mp of cacheDefOpts.mpMaps) p.push(`<mpMap x="${mp.x}"/>`);
|
|
1216
|
-
if (cacheDefOpts?.olapPr) {
|
|
1217
|
-
const ol = cacheDefOpts.olapPr;
|
|
1218
|
-
const olAttrs = [];
|
|
1219
|
-
if (ol.local) olAttrs.push(` local="${escapeXml(ol.local)}"`);
|
|
1220
|
-
if (ol.localConnection) olAttrs.push(` localConnection="${escapeXml(ol.localConnection)}"`);
|
|
1221
|
-
if (ol.sendLocale) olAttrs.push(" sendLocale=\"1\"");
|
|
1222
|
-
if (ol.rowDrillCount !== void 0) olAttrs.push(` rowDrillCount="${ol.rowDrillCount}"`);
|
|
1223
|
-
if (ol.colDrillCount !== void 0) olAttrs.push(` colDrillCount="${ol.colDrillCount}"`);
|
|
1224
|
-
if (ol.localRefresh) olAttrs.push(" localRefresh=\"1\"");
|
|
1225
|
-
if (ol.serverFill === false) olAttrs.push(" serverFill=\"0\"");
|
|
1226
|
-
if (ol.serverNumberFormat === false) olAttrs.push(" serverNumberFormat=\"0\"");
|
|
1227
|
-
if (ol.serverFont === false) olAttrs.push(" serverFont=\"0\"");
|
|
1228
|
-
if (ol.serverFontColor === false) olAttrs.push(" serverFontColor=\"0\"");
|
|
1229
|
-
if (olAttrs.length > 0) p.push(`<olapPr${olAttrs.join("")}/>`);
|
|
1230
|
-
}
|
|
1231
|
-
if (cacheDefOpts?.cacheHierarchies && cacheDefOpts.cacheHierarchies.length > 0) {
|
|
1232
|
-
const chs = cacheDefOpts.cacheHierarchies;
|
|
1233
|
-
p.push(`<cacheHierarchies count="${chs.length}">`);
|
|
1234
|
-
for (const ch of chs) {
|
|
1235
|
-
const chAttrs = [`uniqueName="${escapeXml(ch.uniqueName)}"`, `count="${ch.count}"`];
|
|
1236
|
-
if (ch.caption) chAttrs.push(`caption="${escapeXml(ch.caption)}"`);
|
|
1237
|
-
if (ch.measure) chAttrs.push("measure=\"1\"");
|
|
1238
|
-
if (ch.set) chAttrs.push("set=\"1\"");
|
|
1239
|
-
if (ch.parentSet !== void 0) chAttrs.push(`parentSet="${ch.parentSet}"`);
|
|
1240
|
-
if (ch.iconSet !== void 0 && ch.iconSet !== 0) chAttrs.push(`iconSet="${ch.iconSet}"`);
|
|
1241
|
-
if (ch.attribute) chAttrs.push("attribute=\"1\"");
|
|
1242
|
-
if (ch.time) chAttrs.push("time=\"1\"");
|
|
1243
|
-
if (ch.keyAttribute) chAttrs.push("keyAttribute=\"1\"");
|
|
1244
|
-
if (ch.defaultMemberUniqueName) chAttrs.push(`defaultMemberUniqueName="${escapeXml(ch.defaultMemberUniqueName)}"`);
|
|
1245
|
-
if (ch.allUniqueName) chAttrs.push(`allUniqueName="${escapeXml(ch.allUniqueName)}"`);
|
|
1246
|
-
if (ch.allCaption) chAttrs.push(`allCaption="${escapeXml(ch.allCaption)}"`);
|
|
1247
|
-
if (ch.dimensionUniqueName) chAttrs.push(`dimensionUniqueName="${escapeXml(ch.dimensionUniqueName)}"`);
|
|
1248
|
-
if (ch.displayFolder) chAttrs.push(`displayFolder="${escapeXml(ch.displayFolder)}"`);
|
|
1249
|
-
if (ch.measureGroup) chAttrs.push(`measureGroup="${escapeXml(ch.measureGroup)}"`);
|
|
1250
|
-
if (ch.measures) chAttrs.push("measures=\"1\"");
|
|
1251
|
-
if (ch.oneField) chAttrs.push("oneField=\"1\"");
|
|
1252
|
-
if (ch.hidden) chAttrs.push("hidden=\"1\"");
|
|
1253
|
-
if (ch.memberValueDatatype) chAttrs.push(`memberValueDatatype="${ch.memberValueDatatype}"`);
|
|
1254
|
-
if (ch.unbalanced) chAttrs.push("unbalanced=\"1\"");
|
|
1255
|
-
if (ch.unbalancedGroup) chAttrs.push("unbalancedGroup=\"1\"");
|
|
1256
|
-
const hasGL = ch.groupLevels && ch.groupLevels.length > 0;
|
|
1257
|
-
const hasFU = ch.fieldsUsage && ch.fieldsUsage.length > 0;
|
|
1258
|
-
if (hasGL || hasFU) {
|
|
1259
|
-
p.push(`<cacheHierarchy ${chAttrs.join(" ")}>`);
|
|
1260
|
-
if (hasFU) {
|
|
1261
|
-
const fuParts = [`<fieldsUsage count="${ch.fieldsUsage.length}">`];
|
|
1262
|
-
for (const fu of ch.fieldsUsage) fuParts.push(`<fieldUsage v="${fu.value}"/>`);
|
|
1263
|
-
fuParts.push("</fieldsUsage>");
|
|
1264
|
-
p.push(fuParts.join(""));
|
|
1265
|
-
}
|
|
1266
|
-
if (hasGL) {
|
|
1267
|
-
const glParts = [`<groupLevels count="${ch.groupLevels.length}">`];
|
|
1268
|
-
for (const gl of ch.groupLevels) {
|
|
1269
|
-
const glAttrs = [`uniqueName="${escapeXml(gl.uniqueName)}"`, `caption="${escapeXml(gl.caption)}"`];
|
|
1270
|
-
if (gl.user) glAttrs.push("user=\"1\"");
|
|
1271
|
-
if (gl.customRollUp) glAttrs.push("customRollUp=\"1\"");
|
|
1272
|
-
if (gl.groups && gl.groups.length > 0) {
|
|
1273
|
-
glParts.push(`<groupLevel ${glAttrs.join(" ")}><groups count="${gl.groups.length}">`);
|
|
1274
|
-
for (const lg of gl.groups) {
|
|
1275
|
-
const lgAttrs = [
|
|
1276
|
-
`name="${escapeXml(lg.name)}"`,
|
|
1277
|
-
`uniqueName="${escapeXml(lg.uniqueName)}"`,
|
|
1278
|
-
`caption="${escapeXml(lg.caption)}"`
|
|
1279
|
-
];
|
|
1280
|
-
if (lg.uniqueParent) lgAttrs.push(`uniqueParent="${escapeXml(lg.uniqueParent)}"`);
|
|
1281
|
-
if (lg.id !== void 0) lgAttrs.push(`id="${lg.id}"`);
|
|
1282
|
-
glParts.push(`<group ${lgAttrs.join(" ")}><groupMembers count="${lg.members.length}">`);
|
|
1283
|
-
for (const gm of lg.members) {
|
|
1284
|
-
const gmAttrs = [`uniqueName="${escapeXml(gm.uniqueName)}"`];
|
|
1285
|
-
if (gm.group) gmAttrs.push("group=\"1\"");
|
|
1286
|
-
glParts.push(`<groupMember ${gmAttrs.join(" ")}/>`);
|
|
1287
|
-
}
|
|
1288
|
-
glParts.push("</groupMembers></group>");
|
|
1289
|
-
}
|
|
1290
|
-
glParts.push("</groups></groupLevel>");
|
|
1291
|
-
} else glParts.push(`<groupLevel ${glAttrs.join(" ")}/>`);
|
|
1292
|
-
}
|
|
1293
|
-
glParts.push("</groupLevels>");
|
|
1294
|
-
p.push(glParts.join(""));
|
|
1295
|
-
}
|
|
1296
|
-
p.push("</cacheHierarchy>");
|
|
1297
|
-
} else p.push(`<cacheHierarchy ${chAttrs.join(" ")}/>`);
|
|
1298
|
-
}
|
|
1299
|
-
p.push("</cacheHierarchies>");
|
|
1300
|
-
}
|
|
1301
|
-
if (cacheDefOpts?.kpis && cacheDefOpts.kpis.length > 0) {
|
|
1302
|
-
p.push(`<kpis count="${cacheDefOpts.kpis.length}">`);
|
|
1303
|
-
for (const k of cacheDefOpts.kpis) {
|
|
1304
|
-
const kAttrs = [`uniqueName="${escapeXml(k.uniqueName)}"`, `value="${escapeXml(k.value)}"`];
|
|
1305
|
-
if (k.caption) kAttrs.push(`caption="${escapeXml(k.caption)}"`);
|
|
1306
|
-
if (k.displayFolder) kAttrs.push(`displayFolder="${escapeXml(k.displayFolder)}"`);
|
|
1307
|
-
if (k.measureGroup) kAttrs.push(`measureGroup="${escapeXml(k.measureGroup)}"`);
|
|
1308
|
-
if (k.parent) kAttrs.push(`parent="${escapeXml(k.parent)}"`);
|
|
1309
|
-
if (k.goal) kAttrs.push(`goal="${escapeXml(k.goal)}"`);
|
|
1310
|
-
if (k.status) kAttrs.push(`status="${escapeXml(k.status)}"`);
|
|
1311
|
-
if (k.trend) kAttrs.push(`trend="${escapeXml(k.trend)}"`);
|
|
1312
|
-
if (k.weight) kAttrs.push(`weight="${escapeXml(k.weight)}"`);
|
|
1313
|
-
if (k.time) kAttrs.push(`time="${escapeXml(k.time)}"`);
|
|
1314
|
-
p.push(`<kpi ${kAttrs.join(" ")}/>`);
|
|
1315
|
-
}
|
|
1316
|
-
p.push("</kpis>");
|
|
1317
|
-
}
|
|
1318
|
-
if (cacheDefOpts?.measureGroups && cacheDefOpts.measureGroups.length > 0) {
|
|
1319
|
-
p.push(`<measureGroups count="${cacheDefOpts.measureGroups.length}">`);
|
|
1320
|
-
for (const mg of cacheDefOpts.measureGroups) p.push(`<measureGroup name="${escapeXml(mg.name)}" caption="${escapeXml(mg.caption)}"/>`);
|
|
1321
|
-
p.push("</measureGroups>");
|
|
1322
|
-
}
|
|
1323
|
-
if (cacheDefOpts?.measureDimensionMaps && cacheDefOpts.measureDimensionMaps.length > 0) {
|
|
1324
|
-
p.push(`<maps count="${cacheDefOpts.measureDimensionMaps.length}">`);
|
|
1325
|
-
for (const m of cacheDefOpts.measureDimensionMaps) {
|
|
1326
|
-
const mAttrs = [];
|
|
1327
|
-
if (m.measureGroup !== void 0) mAttrs.push(`measureGroup="${m.measureGroup}"`);
|
|
1328
|
-
if (m.dimension !== void 0) mAttrs.push(`dimension="${m.dimension}"`);
|
|
1329
|
-
p.push(`<map ${mAttrs.join(" ")}/>`);
|
|
1330
|
-
}
|
|
1331
|
-
p.push("</maps>");
|
|
1332
|
-
}
|
|
1333
|
-
if (cacheDefOpts?.dimensions && cacheDefOpts.dimensions.length > 0) {
|
|
1334
|
-
p.push(`<dimensions count="${cacheDefOpts.dimensions.length}">`);
|
|
1335
|
-
for (const d of cacheDefOpts.dimensions) {
|
|
1336
|
-
const dAttrs = [
|
|
1337
|
-
`name="${escapeXml(d.name)}"`,
|
|
1338
|
-
`uniqueName="${escapeXml(d.uniqueName)}"`,
|
|
1339
|
-
`caption="${escapeXml(d.caption)}"`
|
|
1340
|
-
];
|
|
1341
|
-
if (d.measure) dAttrs.push("measure=\"1\"");
|
|
1342
|
-
p.push(`<dimension ${dAttrs.join(" ")}/>`);
|
|
1343
|
-
}
|
|
1344
|
-
p.push("</dimensions>");
|
|
1345
|
-
}
|
|
1346
|
-
const cd = cacheDefOpts;
|
|
1347
|
-
const hasEntries = cd?.entries && cd.entries.length > 0;
|
|
1348
|
-
const hasSets = cd?.sets && cd.sets.length > 0;
|
|
1349
|
-
const hasSF = cd?.serverFormats && cd.serverFormats.length > 0;
|
|
1350
|
-
const hasQC = cd?.queryCache && cd.queryCache.length > 0;
|
|
1351
|
-
if (hasEntries || hasSets || hasSF || hasQC) {
|
|
1352
|
-
p.push("<tupleCache>");
|
|
1353
|
-
if (hasEntries) {
|
|
1354
|
-
const entParts = [`<entries count="${cd.entries.length}">`];
|
|
1355
|
-
for (const ent of cd.entries) if (ent.type === "m") entParts.push("<m/>");
|
|
1356
|
-
else if (ent.value !== void 0) entParts.push(`<${ent.type} v="${ent.value}"/>`);
|
|
1357
|
-
entParts.push("</entries>");
|
|
1358
|
-
p.push(entParts.join(""));
|
|
1359
|
-
}
|
|
1360
|
-
if (hasSets) {
|
|
1361
|
-
p.push(`<sets count="${cd.sets.length}">`);
|
|
1362
|
-
for (const s of cd.sets) {
|
|
1363
|
-
const sAttrs = [`maxRank="${s.maxRank}"`, `setDefinition="${escapeXml(s.setDefinition)}"`];
|
|
1364
|
-
if (s.count !== void 0) sAttrs.push(`count="${s.count}"`);
|
|
1365
|
-
if (s.sortType && s.sortType !== "none") sAttrs.push(`sortType="${s.sortType}"`);
|
|
1366
|
-
if (s.queryFailed) sAttrs.push("queryFailed=\"1\"");
|
|
1367
|
-
p.push(`<set ${sAttrs.join(" ")}/>`);
|
|
1368
|
-
}
|
|
1369
|
-
p.push("</sets>");
|
|
1370
|
-
}
|
|
1371
|
-
if (hasSF) {
|
|
1372
|
-
p.push(`<serverFormats count="${cd.serverFormats.length}">`);
|
|
1373
|
-
for (const sf of cd.serverFormats) {
|
|
1374
|
-
const sfAttrs = [];
|
|
1375
|
-
if (sf.culture) sfAttrs.push(`culture="${escapeXml(sf.culture)}"`);
|
|
1376
|
-
if (sf.format) sfAttrs.push(`format="${escapeXml(sf.format)}"`);
|
|
1377
|
-
p.push(`<serverFormat ${sfAttrs.join(" ")}/>`);
|
|
1378
|
-
}
|
|
1379
|
-
p.push("</serverFormats>");
|
|
1380
|
-
}
|
|
1381
|
-
if (hasQC) {
|
|
1382
|
-
p.push(`<queryCache count="${cd.queryCache.length}">`);
|
|
1383
|
-
for (const q of cd.queryCache) {
|
|
1384
|
-
const qInner = q.tpls && q.tpls.length > 0 ? `<tpls count="${q.tpls.length}">${q.tpls.map((tpl) => tpl.items && tpl.items.length > 0 ? `<tpl>${tpl.items.map((x) => `<x v="${x}"/>`).join("")}</tpl>` : "<tpl/>").join("")}</tpls>` : "";
|
|
1385
|
-
if (qInner) p.push(`<query mdx="${escapeXml(q.mdx)}">${qInner}</query>`);
|
|
1386
|
-
else p.push(`<query mdx="${escapeXml(q.mdx)}"/>`);
|
|
1387
|
-
}
|
|
1388
|
-
p.push("</queryCache>");
|
|
1389
|
-
}
|
|
1390
|
-
p.push("</tupleCache>");
|
|
1391
|
-
}
|
|
1392
|
-
p.push("</pivotCacheDefinition>");
|
|
1393
|
-
return p.join("");
|
|
1394
|
-
}
|
|
1395
|
-
function stringifyPivotCacheRecords(sourceData) {
|
|
1396
|
-
const numericFields = sourceData.fieldNames.map((_, i) => isNumericField(sourceData.records, i));
|
|
1397
|
-
const fieldIndexMaps = sourceData.fieldNames.map((_, i) => {
|
|
1398
|
-
if (numericFields[i]) return /* @__PURE__ */ new Map();
|
|
1399
|
-
const unique = collectUniqueValues(sourceData.records, i);
|
|
1400
|
-
const map = /* @__PURE__ */ new Map();
|
|
1401
|
-
for (let j = 0; j < unique.length; j++) map.set(String(unique[j]), j);
|
|
1402
|
-
return map;
|
|
1403
|
-
});
|
|
1404
|
-
const p = [];
|
|
1405
|
-
p.push(`<pivotCacheRecords xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="${sourceData.records.length}">`);
|
|
1406
|
-
for (const row of sourceData.records) {
|
|
1407
|
-
p.push("<r>");
|
|
1408
|
-
for (let i = 0; i < row.length; i++) {
|
|
1409
|
-
const val = row[i];
|
|
1410
|
-
if (val === null) p.push("<m/>");
|
|
1411
|
-
else if (val instanceof Date) p.push(`<d v="${val.toISOString().replace(/\.\d{3}Z$/, "Z")}"/>`);
|
|
1412
|
-
else if (numericFields[i]) p.push(`<n v="${val}"/>`);
|
|
1413
|
-
else p.push(`<x v="${fieldIndexMaps[i].get(String(val)) ?? 0}"/>`);
|
|
1414
|
-
}
|
|
1415
|
-
p.push("</r>");
|
|
1416
|
-
}
|
|
1417
|
-
p.push("</pivotCacheRecords>");
|
|
1418
|
-
return p.join("");
|
|
1419
|
-
}
|
|
1420
|
-
//#endregion
|
|
1421
|
-
//#region src/parts/table.ts
|
|
1422
|
-
const TotalsRowFunction = {
|
|
1423
|
-
NONE: "none",
|
|
1424
|
-
SUM: "sum",
|
|
1425
|
-
MIN: "min",
|
|
1426
|
-
MAX: "max",
|
|
1427
|
-
AVERAGE: "average",
|
|
1428
|
-
COUNT: "count",
|
|
1429
|
-
COUNT_NUMS: "countNums",
|
|
1430
|
-
STD_DEV: "stdDev",
|
|
1431
|
-
VAR: "var",
|
|
1432
|
-
CUSTOM: "custom"
|
|
1433
|
-
};
|
|
1434
|
-
const TableType = {
|
|
1435
|
-
WORKSHEET: "worksheet",
|
|
1436
|
-
XML: "xml",
|
|
1437
|
-
QUERY_TABLE: "queryTable"
|
|
1438
|
-
};
|
|
1439
|
-
function buildAttrs(attrsMap) {
|
|
1440
|
-
const parts = [];
|
|
1441
|
-
for (const [k, v] of Object.entries(attrsMap)) {
|
|
1442
|
-
if (v === void 0) continue;
|
|
1443
|
-
parts.push(` ${k}="${typeof v === "string" ? escapeXml(v) : String(v)}"`);
|
|
1444
|
-
}
|
|
1445
|
-
return parts.join("");
|
|
1446
|
-
}
|
|
1447
|
-
const tableDesc = {
|
|
1448
|
-
kind: "custom",
|
|
1449
|
-
stringify(o, _ctx) {
|
|
1450
|
-
const p = [];
|
|
1451
|
-
const rootAttrs = {
|
|
1452
|
-
id: o.id,
|
|
1453
|
-
name: o.name ?? o.displayName,
|
|
1454
|
-
displayName: o.displayName,
|
|
1455
|
-
ref: o.ref
|
|
1456
|
-
};
|
|
1457
|
-
if (o.tableType && o.tableType !== "worksheet") rootAttrs.tableType = o.tableType;
|
|
1458
|
-
if (o.headerRowCount !== void 0 && o.headerRowCount !== 1) rootAttrs.headerRowCount = o.headerRowCount;
|
|
1459
|
-
if (o.totalsRowCount !== void 0 && o.totalsRowCount > 0) rootAttrs.totalsRowCount = o.totalsRowCount;
|
|
1460
|
-
if (o.totalsRowShown === false) rootAttrs.totalsRowShown = 0;
|
|
1461
|
-
if (o.insertRowShift) rootAttrs.insertRowShift = 1;
|
|
1462
|
-
if (o.published) rootAttrs.published = 1;
|
|
1463
|
-
if (o.headerRowDxfId !== void 0) rootAttrs.headerRowDxfId = o.headerRowDxfId;
|
|
1464
|
-
if (o.dataDxfId !== void 0) rootAttrs.dataDxfId = o.dataDxfId;
|
|
1465
|
-
if (o.totalsRowDxfId !== void 0) rootAttrs.totalsRowDxfId = o.totalsRowDxfId;
|
|
1466
|
-
if (o.headerRowBorderDxfId !== void 0) rootAttrs.headerRowBorderDxfId = o.headerRowBorderDxfId;
|
|
1467
|
-
if (o.tableBorderDxfId !== void 0) rootAttrs.tableBorderDxfId = o.tableBorderDxfId;
|
|
1468
|
-
if (o.totalsRowBorderDxfId !== void 0) rootAttrs.totalsRowBorderDxfId = o.totalsRowBorderDxfId;
|
|
1469
|
-
if (o.headerRowCellStyle) rootAttrs.headerRowCellStyle = o.headerRowCellStyle;
|
|
1470
|
-
if (o.dataCellStyle) rootAttrs.dataCellStyle = o.dataCellStyle;
|
|
1471
|
-
if (o.totalsRowCellStyle) rootAttrs.totalsRowCellStyle = o.totalsRowCellStyle;
|
|
1472
|
-
p.push(`<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="xr xr2" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2"${buildAttrs(rootAttrs)}>`);
|
|
1473
|
-
if (o.autoFilter !== void 0) p.push(`<autoFilter ref="${escapeXml(o.autoFilter)}"/>`);
|
|
1474
|
-
p.push(`<tableColumns count="${o.columns.length}">`);
|
|
1475
|
-
for (let i = 0; i < o.columns.length; i++) {
|
|
1476
|
-
const col = o.columns[i];
|
|
1477
|
-
const colAttrs = {
|
|
1478
|
-
id: i + 1,
|
|
1479
|
-
name: col.name
|
|
1480
|
-
};
|
|
1481
|
-
const inner = [];
|
|
1482
|
-
if (col.calculatedColumnFormula !== void 0) {
|
|
1483
|
-
const fAttrs = col.calculatedColumnFormulaArray ? " array=\"1\"" : "";
|
|
1484
|
-
inner.push(`<calculatedColumnFormula${fAttrs}>${escapeXml(col.calculatedColumnFormula)}</calculatedColumnFormula>`);
|
|
1485
|
-
}
|
|
1486
|
-
if (col.totalsRowFormula !== void 0) {
|
|
1487
|
-
const fAttrs = col.totalsRowFormulaArray ? " array=\"1\"" : "";
|
|
1488
|
-
inner.push(`<totalsRowFormula${fAttrs}>${escapeXml(col.totalsRowFormula)}</totalsRowFormula>`);
|
|
1489
|
-
}
|
|
1490
|
-
if (col.totalsRowFunction !== void 0 && col.totalsRowFunction !== TotalsRowFunction.NONE) colAttrs.totalsRowFunction = col.totalsRowFunction;
|
|
1491
|
-
if (col.totalsRowLabel !== void 0) colAttrs.totalsRowLabel = col.totalsRowLabel;
|
|
1492
|
-
if (col.uniqueName) colAttrs.uniqueName = col.uniqueName;
|
|
1493
|
-
if (col.queryTableFieldId !== void 0) colAttrs.queryTableFieldId = col.queryTableFieldId;
|
|
1494
|
-
if (col.headerRowDxfId !== void 0) colAttrs.headerRowDxfId = col.headerRowDxfId;
|
|
1495
|
-
if (col.dataDxfId !== void 0) colAttrs.dataDxfId = col.dataDxfId;
|
|
1496
|
-
if (col.totalsRowDxfId !== void 0) colAttrs.totalsRowDxfId = col.totalsRowDxfId;
|
|
1497
|
-
if (col.headerRowCellStyle) colAttrs.headerRowCellStyle = col.headerRowCellStyle;
|
|
1498
|
-
if (col.dataCellStyle) colAttrs.dataCellStyle = col.dataCellStyle;
|
|
1499
|
-
if (col.totalsRowCellStyle) colAttrs.totalsRowCellStyle = col.totalsRowCellStyle;
|
|
1500
|
-
if (inner.length > 0) p.push(`<tableColumn${buildAttrs(colAttrs)}>${inner.join("")}</tableColumn>`);
|
|
1501
|
-
else p.push(`<tableColumn${buildAttrs(colAttrs)}/>`);
|
|
1502
|
-
}
|
|
1503
|
-
p.push("</tableColumns>");
|
|
1504
|
-
if (o.style) {
|
|
1505
|
-
const s = o.style;
|
|
1506
|
-
const styleAttrs = {};
|
|
1507
|
-
if (s.name !== void 0) styleAttrs.name = s.name;
|
|
1508
|
-
if (s.showFirstColumn) styleAttrs.showFirstColumn = 1;
|
|
1509
|
-
if (s.showLastColumn) styleAttrs.showLastColumn = 1;
|
|
1510
|
-
if (s.showRowStripes !== false) styleAttrs.showRowStripes = 1;
|
|
1511
|
-
if (s.showColumnStripes) styleAttrs.showColumnStripes = 1;
|
|
1512
|
-
p.push(`<tableStyleInfo${buildAttrs(styleAttrs)}/>`);
|
|
1513
|
-
} else p.push("<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>");
|
|
1514
|
-
p.push("</table>");
|
|
1515
|
-
return p.join("");
|
|
1516
|
-
},
|
|
1517
|
-
parse(el, _ctx) {
|
|
1518
|
-
const result = {};
|
|
1519
|
-
const id = attrNum(el, "id");
|
|
1520
|
-
if (id !== void 0) result.id = id;
|
|
1521
|
-
if (attr(el, "name")) result.name = attr(el, "name");
|
|
1522
|
-
if (attr(el, "displayName")) result.displayName = attr(el, "displayName");
|
|
1523
|
-
if (attr(el, "ref")) result.ref = attr(el, "ref");
|
|
1524
|
-
const headerRowCount = attrNum(el, "headerRowCount");
|
|
1525
|
-
if (headerRowCount !== void 0) result.headerRowCount = headerRowCount;
|
|
1526
|
-
const totalsRowCount = attrNum(el, "totalsRowCount");
|
|
1527
|
-
if (totalsRowCount !== void 0) result.totalsRowCount = totalsRowCount;
|
|
1528
|
-
if (attr(el, "totalsRowShown") === "0") result.totalsRowShown = false;
|
|
1529
|
-
if (attr(el, "tableType")) result.tableType = attr(el, "tableType");
|
|
1530
|
-
if (attr(el, "insertRowShift") === "1") result.insertRowShift = true;
|
|
1531
|
-
if (attr(el, "published") === "1") result.published = true;
|
|
1532
|
-
const afEl = findChild(el, "autoFilter");
|
|
1533
|
-
if (afEl) result.autoFilter = attr(afEl, "ref") ?? "";
|
|
1534
|
-
const colsEl = findChild(el, "tableColumns");
|
|
1535
|
-
if (colsEl) {
|
|
1536
|
-
const columns = [];
|
|
1537
|
-
for (const colEl of colsEl.elements ?? []) {
|
|
1538
|
-
if (colEl.name !== "tableColumn") continue;
|
|
1539
|
-
const col = {};
|
|
1540
|
-
const colId = attrNum(colEl, "id");
|
|
1541
|
-
if (colId !== void 0) col.id = colId;
|
|
1542
|
-
col.name = attr(colEl, "name") ?? "";
|
|
1543
|
-
if (attr(colEl, "totalsRowFunction")) col.totalsRowFunction = attr(colEl, "totalsRowFunction");
|
|
1544
|
-
if (attr(colEl, "totalsRowLabel")) col.totalsRowLabel = attr(colEl, "totalsRowLabel");
|
|
1545
|
-
const trfEl = findChild(colEl, "calculatedColumnFormula");
|
|
1546
|
-
if (trfEl) col.calculatedColumnFormula = textOf(trfEl);
|
|
1547
|
-
if (attr(colEl, "uniqueName")) col.uniqueName = attr(colEl, "uniqueName");
|
|
1548
|
-
const qtfId = attrNum(colEl, "queryTableFieldId");
|
|
1549
|
-
if (qtfId !== void 0) col.queryTableFieldId = qtfId;
|
|
1550
|
-
const hrDxfId = attrNum(colEl, "headerRowDxfId");
|
|
1551
|
-
if (hrDxfId !== void 0) col.headerRowDxfId = hrDxfId;
|
|
1552
|
-
const dDxfId = attrNum(colEl, "dataDxfId");
|
|
1553
|
-
if (dDxfId !== void 0) col.dataDxfId = dDxfId;
|
|
1554
|
-
const trDxfId = attrNum(colEl, "totalsRowDxfId");
|
|
1555
|
-
if (trDxfId !== void 0) col.totalsRowDxfId = trDxfId;
|
|
1556
|
-
if (attr(colEl, "headerRowCellStyle")) col.headerRowCellStyle = attr(colEl, "headerRowCellStyle");
|
|
1557
|
-
if (attr(colEl, "dataCellStyle")) col.dataCellStyle = attr(colEl, "dataCellStyle");
|
|
1558
|
-
if (attr(colEl, "totalsRowCellStyle")) col.totalsRowCellStyle = attr(colEl, "totalsRowCellStyle");
|
|
1559
|
-
columns.push(col);
|
|
1560
|
-
}
|
|
1561
|
-
result.columns = columns;
|
|
1562
|
-
}
|
|
1563
|
-
const siEl = findChild(el, "tableStyleInfo");
|
|
1564
|
-
if (siEl) {
|
|
1565
|
-
const style = {};
|
|
1566
|
-
if (attr(siEl, "name")) style.name = attr(siEl, "name");
|
|
1567
|
-
if (attr(siEl, "showFirstColumn") === "1") style.showFirstColumn = true;
|
|
1568
|
-
if (attr(siEl, "showLastColumn") === "1") style.showLastColumn = true;
|
|
1569
|
-
if (attr(siEl, "showRowStripes") === "1") style.showRowStripes = true;
|
|
1570
|
-
if (attr(siEl, "showColumnStripes") === "1") style.showColumnStripes = true;
|
|
1571
|
-
result.style = style;
|
|
1572
|
-
}
|
|
1573
|
-
const hrDxfId = attrNum(el, "headerRowDxfId");
|
|
1574
|
-
if (hrDxfId !== void 0) result.headerRowDxfId = hrDxfId;
|
|
1575
|
-
const dDxfId = attrNum(el, "dataDxfId");
|
|
1576
|
-
if (dDxfId !== void 0) result.dataDxfId = dDxfId;
|
|
1577
|
-
const trDxfId = attrNum(el, "totalsRowDxfId");
|
|
1578
|
-
if (trDxfId !== void 0) result.totalsRowDxfId = trDxfId;
|
|
1579
|
-
const hrbDxfId = attrNum(el, "headerRowBorderDxfId");
|
|
1580
|
-
if (hrbDxfId !== void 0) result.headerRowBorderDxfId = hrbDxfId;
|
|
1581
|
-
const tbDxfId = attrNum(el, "tableBorderDxfId");
|
|
1582
|
-
if (tbDxfId !== void 0) result.tableBorderDxfId = tbDxfId;
|
|
1583
|
-
const trbDxfId = attrNum(el, "totalsRowBorderDxfId");
|
|
1584
|
-
if (trbDxfId !== void 0) result.totalsRowBorderDxfId = trbDxfId;
|
|
1585
|
-
if (attr(el, "headerRowCellStyle")) result.headerRowCellStyle = attr(el, "headerRowCellStyle");
|
|
1586
|
-
if (attr(el, "dataCellStyle")) result.dataCellStyle = attr(el, "dataCellStyle");
|
|
1587
|
-
if (attr(el, "totalsRowCellStyle")) result.totalsRowCellStyle = attr(el, "totalsRowCellStyle");
|
|
1588
|
-
return result;
|
|
1589
|
-
}
|
|
1590
|
-
};
|
|
1591
|
-
//#endregion
|
|
1592
|
-
//#region src/parts/workbook.ts
|
|
1593
|
-
/**
|
|
1594
|
-
* Workbook types and descriptor for SpreadsheetML documents.
|
|
1595
|
-
*
|
|
1596
|
-
* @module
|
|
1597
|
-
*/
|
|
1598
|
-
const workbookDesc = {
|
|
1599
|
-
kind: "custom",
|
|
1600
|
-
stringify(opts, _ctx) {
|
|
1601
|
-
return stringifyWorkbook(opts);
|
|
1602
|
-
},
|
|
1603
|
-
parse(el, _ctx) {
|
|
1604
|
-
const result = {};
|
|
1605
|
-
const sheetsEl = findChild(el, "sheets");
|
|
1606
|
-
if (sheetsEl) {
|
|
1607
|
-
const sheets = [];
|
|
1608
|
-
for (const s of sheetsEl.elements ?? []) {
|
|
1609
|
-
if (s.name !== "sheet") continue;
|
|
1610
|
-
const name = attr(s, "name") ?? "";
|
|
1611
|
-
const sheetId = attrNum(s, "sheetId") ?? 0;
|
|
1612
|
-
const rId = s.attributes?.["r:id"] ?? "";
|
|
1613
|
-
const state = attr(s, "state");
|
|
1614
|
-
sheets.push({
|
|
1615
|
-
name,
|
|
1616
|
-
sheetId,
|
|
1617
|
-
rId,
|
|
1618
|
-
state
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
result.sheets = sheets;
|
|
1622
|
-
}
|
|
1623
|
-
const pivotCachesEl = findChild(el, "pivotCaches");
|
|
1624
|
-
if (pivotCachesEl) {
|
|
1625
|
-
const caches = [];
|
|
1626
|
-
for (const pc of pivotCachesEl.elements ?? []) {
|
|
1627
|
-
if (pc.name !== "pivotCache") continue;
|
|
1628
|
-
caches.push({
|
|
1629
|
-
cacheId: attrNum(pc, "cacheId") ?? 0,
|
|
1630
|
-
rId: pc.attributes?.["r:id"] ?? ""
|
|
1631
|
-
});
|
|
1632
|
-
}
|
|
1633
|
-
result.pivotCaches = caches;
|
|
1634
|
-
}
|
|
1635
|
-
const protEl = findChild(el, "workbookProtection");
|
|
1636
|
-
if (protEl?.attributes) {
|
|
1637
|
-
const prot = {};
|
|
1638
|
-
if (attr(protEl, "lockStructure") === "1") prot.lockStructure = true;
|
|
1639
|
-
if (attr(protEl, "lockWindows") === "1") prot.lockWindows = true;
|
|
1640
|
-
if (attr(protEl, "lockRevision") === "1") prot.lockRevision = true;
|
|
1641
|
-
if (attr(protEl, "workbookPassword")) prot.workbookPassword = attr(protEl, "workbookPassword");
|
|
1642
|
-
if (attr(protEl, "workbookAlgorithmName")) prot.workbookAlgorithmName = attr(protEl, "workbookAlgorithmName");
|
|
1643
|
-
if (attr(protEl, "workbookHashValue")) prot.workbookHashValue = attr(protEl, "workbookHashValue");
|
|
1644
|
-
if (attr(protEl, "workbookSaltValue")) prot.workbookSaltValue = attr(protEl, "workbookSaltValue");
|
|
1645
|
-
if (attr(protEl, "workbookSpinCount")) prot.workbookSpinCount = attrNum(protEl, "workbookSpinCount");
|
|
1646
|
-
result.protection = prot;
|
|
1647
|
-
}
|
|
1648
|
-
const bookViewsEl = findChild(el, "bookViews");
|
|
1649
|
-
if (bookViewsEl) {
|
|
1650
|
-
const bvEl = findChild(bookViewsEl, "workbookView");
|
|
1651
|
-
if (bvEl?.attributes) {
|
|
1652
|
-
const bv = {};
|
|
1653
|
-
const xw = attrNum(bvEl, "xWindow");
|
|
1654
|
-
if (xw !== void 0) bv.xWindow = xw;
|
|
1655
|
-
const yw = attrNum(bvEl, "yWindow");
|
|
1656
|
-
if (yw !== void 0) bv.yWindow = yw;
|
|
1657
|
-
const ww = attrNum(bvEl, "windowWidth");
|
|
1658
|
-
if (ww !== void 0) bv.windowWidth = ww;
|
|
1659
|
-
const wh = attrNum(bvEl, "windowHeight");
|
|
1660
|
-
if (wh !== void 0) bv.windowHeight = wh;
|
|
1661
|
-
const at = attrNum(bvEl, "activeTab");
|
|
1662
|
-
if (at !== void 0) bv.activeTab = at;
|
|
1663
|
-
if (attr(bvEl, "showHorizontalScroll") === "0") bv.showHorizontalScroll = false;
|
|
1664
|
-
if (attr(bvEl, "showVerticalScroll") === "0") bv.showVerticalScroll = false;
|
|
1665
|
-
if (attr(bvEl, "showSheetTabs") === "0") bv.showSheetTabs = false;
|
|
1666
|
-
result.bookView = bv;
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
const calcPrEl = findChild(el, "calcPr");
|
|
1670
|
-
if (calcPrEl?.attributes) {
|
|
1671
|
-
const calc = {};
|
|
1672
|
-
const calcId = attrNum(calcPrEl, "calcId");
|
|
1673
|
-
if (calcId !== void 0) calc.calcId = calcId;
|
|
1674
|
-
if (attr(calcPrEl, "calcMode")) calc.calcMode = attr(calcPrEl, "calcMode");
|
|
1675
|
-
if (attr(calcPrEl, "fullCalcOnLoad") === "1") calc.fullCalcOnLoad = true;
|
|
1676
|
-
if (attr(calcPrEl, "concurrentCalc") === "0") calc.concurrentCalc = false;
|
|
1677
|
-
if (attr(calcPrEl, "refMode")) calc.refMode = attr(calcPrEl, "refMode");
|
|
1678
|
-
result.calcPr = calc;
|
|
1679
|
-
}
|
|
1680
|
-
const customViewsEl = findChild(el, "customWorkbookViews");
|
|
1681
|
-
if (customViewsEl) {
|
|
1682
|
-
const views = [];
|
|
1683
|
-
for (const v of customViewsEl.elements ?? []) {
|
|
1684
|
-
if (v.name !== "customWorkbookView") continue;
|
|
1685
|
-
views.push({
|
|
1686
|
-
name: attr(v, "name") ?? "",
|
|
1687
|
-
guid: attr(v, "guid") ?? "",
|
|
1688
|
-
windowWidth: attrNum(v, "windowWidth") ?? 0,
|
|
1689
|
-
windowHeight: attrNum(v, "windowHeight") ?? 0,
|
|
1690
|
-
activeSheetId: attrNum(v, "activeSheetId") ?? 1
|
|
1691
|
-
});
|
|
1692
|
-
}
|
|
1693
|
-
if (views.length > 0) result.customViews = views;
|
|
1694
|
-
}
|
|
1695
|
-
const fileSharingEl = findChild(el, "fileSharing");
|
|
1696
|
-
if (fileSharingEl?.attributes) {
|
|
1697
|
-
const fs = {};
|
|
1698
|
-
if (attr(fileSharingEl, "readOnlyRecommended") === "1") fs.readOnlyRecommended = true;
|
|
1699
|
-
if (attr(fileSharingEl, "userName")) fs.userName = attr(fileSharingEl, "userName");
|
|
1700
|
-
if (attr(fileSharingEl, "reservationPassword")) fs.reservationPassword = attr(fileSharingEl, "reservationPassword");
|
|
1701
|
-
result.fileSharing = fs;
|
|
1702
|
-
}
|
|
1703
|
-
const webPublishingEl = findChild(el, "webPublishing");
|
|
1704
|
-
if (webPublishingEl?.attributes) {
|
|
1705
|
-
const wp = {};
|
|
1706
|
-
if (attr(webPublishingEl, "css") === "0") wp.css = false;
|
|
1707
|
-
if (attr(webPublishingEl, "thicket") === "0") wp.thicket = false;
|
|
1708
|
-
if (attr(webPublishingEl, "vml") === "1") wp.vml = true;
|
|
1709
|
-
if (attr(webPublishingEl, "targetScreenSize")) wp.targetScreenSize = attr(webPublishingEl, "targetScreenSize");
|
|
1710
|
-
if (attrNum(webPublishingEl, "dpi") !== void 0) wp.dpi = attrNum(webPublishingEl, "dpi");
|
|
1711
|
-
if (attrNum(webPublishingEl, "codePage") !== void 0) wp.codePage = attrNum(webPublishingEl, "codePage");
|
|
1712
|
-
result.webPublishing = wp;
|
|
1713
|
-
}
|
|
1714
|
-
const fileRecoveryEl = findChild(el, "fileRecoveryPr");
|
|
1715
|
-
if (fileRecoveryEl?.attributes) {
|
|
1716
|
-
const frp = {};
|
|
1717
|
-
if (attr(fileRecoveryEl, "autoRecover") === "0") frp.autoRecover = false;
|
|
1718
|
-
if (attr(fileRecoveryEl, "crashSave") === "1") frp.crashSave = true;
|
|
1719
|
-
if (attr(fileRecoveryEl, "dataExtractLoad") === "1") frp.dataExtractLoad = true;
|
|
1720
|
-
if (attr(fileRecoveryEl, "repairLoad") === "1") frp.repairLoad = true;
|
|
1721
|
-
result.fileRecoveryPr = frp;
|
|
1722
|
-
}
|
|
1723
|
-
if (el.attributes?.["conformance"]) result.conformance = attr(el, "conformance");
|
|
1724
|
-
return result;
|
|
1725
|
-
}
|
|
1726
|
-
};
|
|
1727
|
-
function stringifyWorkbook(opts) {
|
|
1728
|
-
const parts = [`<workbook 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="x15 xr xr6 xr10 xr2" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr6="http://schemas.microsoft.com/office/spreadsheetml/2016/revision6" xmlns:xr10="http://schemas.microsoft.com/office/spreadsheetml/2016/revision10" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2"${opts.conformance ? ` conformance="${opts.conformance}"` : ""}>`, "<fileVersion appName=\"xl\" lastEdited=\"7\" lowestEdited=\"6\" rupBuild=\"29929\"/>"];
|
|
1729
|
-
if (opts.fileSharing) {
|
|
1730
|
-
const fs = opts.fileSharing;
|
|
1731
|
-
const fsAttrs = [];
|
|
1732
|
-
if (fs.readOnlyRecommended) fsAttrs.push("readOnlyRecommended=\"1\"");
|
|
1733
|
-
if (fs.userName) fsAttrs.push(`userName="${escapeXml(fs.userName)}"`);
|
|
1734
|
-
if (fs.reservationPassword) {
|
|
1735
|
-
fsAttrs.push(`reservationPassword="${escapeXml(fs.reservationPassword)}"`);
|
|
1736
|
-
if (fs.hashValue === void 0) {
|
|
1737
|
-
const derived = derivePasswordHash(fs.reservationPassword);
|
|
1738
|
-
fsAttrs.push(`algorithmName="${escapeXml(derived.algorithmName)}"`);
|
|
1739
|
-
fsAttrs.push(`hashValue="${escapeXml(derived.hashValue)}"`);
|
|
1740
|
-
fsAttrs.push(`saltValue="${escapeXml(derived.saltValue)}"`);
|
|
1741
|
-
fsAttrs.push(`spinCount="${derived.spinCount}"`);
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
if (fs.algorithmName) fsAttrs.push(`algorithmName="${escapeXml(fs.algorithmName)}"`);
|
|
1745
|
-
if (fs.hashValue) fsAttrs.push(`hashValue="${escapeXml(fs.hashValue)}"`);
|
|
1746
|
-
if (fs.saltValue) fsAttrs.push(`saltValue="${escapeXml(fs.saltValue)}"`);
|
|
1747
|
-
if (fs.spinCount !== void 0) fsAttrs.push(`spinCount="${fs.spinCount}"`);
|
|
1748
|
-
if (fsAttrs.length > 0) parts.push(`<fileSharing ${fsAttrs.join(" ")}/>`);
|
|
1749
|
-
}
|
|
1750
|
-
if (opts.workbookPr) {
|
|
1751
|
-
const wbPr = opts.workbookPr;
|
|
1752
|
-
const wbPrAttrs = [];
|
|
1753
|
-
if (wbPr.date1904) wbPrAttrs.push("date1904=\"1\"");
|
|
1754
|
-
if (wbPr.defaultThemeVersion !== void 0) wbPrAttrs.push(`defaultThemeVersion="${wbPr.defaultThemeVersion}"`);
|
|
1755
|
-
if (wbPr.showObjects) wbPrAttrs.push(`showObjects="${escapeXml(wbPr.showObjects)}"`);
|
|
1756
|
-
if (wbPr.hidePivotFieldList) wbPrAttrs.push("hidePivotFieldList=\"1\"");
|
|
1757
|
-
if (wbPr.allowRefreshQuery) wbPrAttrs.push("allowRefreshQuery=\"1\"");
|
|
1758
|
-
if (wbPr.filterPrivacy) wbPrAttrs.push("filterPrivacy=\"1\"");
|
|
1759
|
-
if (wbPr.backupFile) wbPrAttrs.push("backupFile=\"1\"");
|
|
1760
|
-
if (wbPr.codeName) wbPrAttrs.push(`codeName="${escapeXml(wbPr.codeName)}"`);
|
|
1761
|
-
if (wbPr.showBorderUnselectedTables) wbPrAttrs.push("showBorderUnselectedTables=\"1\"");
|
|
1762
|
-
if (wbPr.promptedSolutions) wbPrAttrs.push("promptedSolutions=\"1\"");
|
|
1763
|
-
if (wbPr.showInkAnnotation === false) wbPrAttrs.push("showInkAnnotation=\"0\"");
|
|
1764
|
-
if (wbPr.saveExternalLinkValues === false) wbPrAttrs.push("saveExternalLinkValues=\"0\"");
|
|
1765
|
-
if (wbPr.updateLinks) wbPrAttrs.push(`updateLinks="${escapeXml(wbPr.updateLinks)}"`);
|
|
1766
|
-
if (wbPr.showPivotChartFilter) wbPrAttrs.push("showPivotChartFilter=\"1\"");
|
|
1767
|
-
if (wbPr.publishItems) wbPrAttrs.push("publishItems=\"1\"");
|
|
1768
|
-
if (wbPr.checkCompatibility) wbPrAttrs.push("checkCompatibility=\"1\"");
|
|
1769
|
-
if (wbPr.autoCompressPictures === false) wbPrAttrs.push("autoCompressPictures=\"0\"");
|
|
1770
|
-
if (wbPr.refreshAllConnections) wbPrAttrs.push("refreshAllConnections=\"1\"");
|
|
1771
|
-
parts.push(`<workbookPr${wbPrAttrs.length > 0 ? ` ${wbPrAttrs.join(" ")}` : ""}/>`);
|
|
1772
|
-
} else parts.push("<workbookPr/>");
|
|
1773
|
-
if (opts.protection) {
|
|
1774
|
-
const prot = opts.protection;
|
|
1775
|
-
const protAttrs = [];
|
|
1776
|
-
if (prot.lockStructure) protAttrs.push("lockStructure=\"1\"");
|
|
1777
|
-
if (prot.lockWindows) protAttrs.push("lockWindows=\"1\"");
|
|
1778
|
-
if (prot.lockRevision) protAttrs.push("lockRevision=\"1\"");
|
|
1779
|
-
if (prot.workbookPassword) {
|
|
1780
|
-
protAttrs.push(`workbookPassword="${hashPassword(prot.workbookPassword)}"`);
|
|
1781
|
-
if (prot.workbookHashValue === void 0) {
|
|
1782
|
-
const wbDerived = derivePasswordHash(prot.workbookPassword);
|
|
1783
|
-
protAttrs.push(`workbookAlgorithmName="${escapeXml(wbDerived.algorithmName)}"`);
|
|
1784
|
-
protAttrs.push(`workbookHashValue="${escapeXml(wbDerived.hashValue)}"`);
|
|
1785
|
-
protAttrs.push(`workbookSaltValue="${escapeXml(wbDerived.saltValue)}"`);
|
|
1786
|
-
protAttrs.push(`workbookSpinCount="${wbDerived.spinCount}"`);
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
if (prot.workbookAlgorithmName) protAttrs.push(`workbookAlgorithmName="${escapeXml(prot.workbookAlgorithmName)}"`);
|
|
1790
|
-
if (prot.workbookHashValue) protAttrs.push(`workbookHashValue="${escapeXml(prot.workbookHashValue)}"`);
|
|
1791
|
-
if (prot.workbookSaltValue) protAttrs.push(`workbookSaltValue="${escapeXml(prot.workbookSaltValue)}"`);
|
|
1792
|
-
if (prot.workbookSpinCount !== void 0) protAttrs.push(`workbookSpinCount="${prot.workbookSpinCount}"`);
|
|
1793
|
-
if (prot.revisionsPassword) {
|
|
1794
|
-
protAttrs.push(`revisionsPassword="${hashPassword(prot.revisionsPassword)}"`);
|
|
1795
|
-
if (prot.revisionsHashValue === void 0) {
|
|
1796
|
-
const revDerived = derivePasswordHash(prot.revisionsPassword);
|
|
1797
|
-
protAttrs.push(`revisionsAlgorithmName="${escapeXml(revDerived.algorithmName)}"`);
|
|
1798
|
-
protAttrs.push(`revisionsHashValue="${escapeXml(revDerived.hashValue)}"`);
|
|
1799
|
-
protAttrs.push(`revisionsSaltValue="${escapeXml(revDerived.saltValue)}"`);
|
|
1800
|
-
protAttrs.push(`revisionsSpinCount="${revDerived.spinCount}"`);
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
if (prot.revisionsAlgorithmName) protAttrs.push(`revisionsAlgorithmName="${escapeXml(prot.revisionsAlgorithmName)}"`);
|
|
1804
|
-
if (prot.revisionsHashValue) protAttrs.push(`revisionsHashValue="${escapeXml(prot.revisionsHashValue)}"`);
|
|
1805
|
-
if (prot.revisionsSaltValue) protAttrs.push(`revisionsSaltValue="${escapeXml(prot.revisionsSaltValue)}"`);
|
|
1806
|
-
if (prot.revisionsSpinCount !== void 0) protAttrs.push(`revisionsSpinCount="${prot.revisionsSpinCount}"`);
|
|
1807
|
-
if (prot.workbookPasswordCharacterSet) protAttrs.push(`workbookPasswordCharacterSet="${escapeXml(prot.workbookPasswordCharacterSet)}"`);
|
|
1808
|
-
if (prot.revisionsPasswordCharacterSet) protAttrs.push(`revisionsPasswordCharacterSet="${escapeXml(prot.revisionsPasswordCharacterSet)}"`);
|
|
1809
|
-
if (protAttrs.length > 0) parts.push(`<workbookProtection ${protAttrs.join(" ")}/>`);
|
|
1810
|
-
}
|
|
1811
|
-
if (opts.bookView) {
|
|
1812
|
-
const bv = opts.bookView;
|
|
1813
|
-
const bvAttrs = [];
|
|
1814
|
-
if (bv.xWindow !== void 0) bvAttrs.push(`xWindow="${bv.xWindow}"`);
|
|
1815
|
-
else bvAttrs.push("xWindow=\"0\"");
|
|
1816
|
-
if (bv.yWindow !== void 0) bvAttrs.push(`yWindow="${bv.yWindow}"`);
|
|
1817
|
-
else bvAttrs.push("yWindow=\"0\"");
|
|
1818
|
-
if (bv.windowWidth !== void 0) bvAttrs.push(`windowWidth="${bv.windowWidth}"`);
|
|
1819
|
-
else bvAttrs.push("windowWidth=\"28800\"");
|
|
1820
|
-
if (bv.windowHeight !== void 0) bvAttrs.push(`windowHeight="${bv.windowHeight}"`);
|
|
1821
|
-
else bvAttrs.push("windowHeight=\"12300\"");
|
|
1822
|
-
if (bv.activeTab !== void 0) bvAttrs.push(`activeTab="${bv.activeTab}"`);
|
|
1823
|
-
if (bv.autoFilterDateGrouping === false) bvAttrs.push("autoFilterDateGrouping=\"0\"");
|
|
1824
|
-
if (bv.firstSheet !== void 0) bvAttrs.push(`firstSheet="${bv.firstSheet}"`);
|
|
1825
|
-
if (bv.showHorizontalScroll === false) bvAttrs.push("showHorizontalScroll=\"0\"");
|
|
1826
|
-
if (bv.showSheetTabs === false) bvAttrs.push("showSheetTabs=\"0\"");
|
|
1827
|
-
if (bv.showVerticalScroll === false) bvAttrs.push("showVerticalScroll=\"0\"");
|
|
1828
|
-
if (bv.tabRatio !== void 0) bvAttrs.push(`tabRatio="${bv.tabRatio}"`);
|
|
1829
|
-
parts.push(`<bookViews><workbookView ${bvAttrs.join(" ")}/></bookViews>`);
|
|
1830
|
-
} else parts.push("<bookViews><workbookView xWindow=\"0\" yWindow=\"0\" windowWidth=\"28800\" windowHeight=\"12300\"/></bookViews>");
|
|
1831
|
-
parts.push("<sheets>");
|
|
1832
|
-
for (const s of opts.sheets) {
|
|
1833
|
-
const stateAttr = s.state && s.state !== "visible" ? ` state="${s.state}"` : "";
|
|
1834
|
-
parts.push(`<sheet name="${escapeXml(s.name)}" sheetId="${s.sheetId}" r:id="${s.rId}"${stateAttr}/>`);
|
|
1835
|
-
}
|
|
1836
|
-
parts.push("</sheets>");
|
|
1837
|
-
const functionGroups = opts.functionGroups ?? [];
|
|
1838
|
-
if (functionGroups.length > 0) {
|
|
1839
|
-
const fgParts = [`<functionGroups builtInGroupCount="16">`];
|
|
1840
|
-
for (const name of functionGroups) fgParts.push(`<functionGroup name="${escapeXml(name)}"/>`);
|
|
1841
|
-
fgParts.push("</functionGroups>");
|
|
1842
|
-
parts.push(fgParts.join(""));
|
|
1843
|
-
}
|
|
1844
|
-
parts.push("<!--EXTERNAL_REFS-->");
|
|
1845
|
-
if (opts.calcPr) {
|
|
1846
|
-
const cp = opts.calcPr;
|
|
1847
|
-
const cpAttrs = [];
|
|
1848
|
-
cpAttrs.push(`calcId="${cp.calcId ?? 162913}"`);
|
|
1849
|
-
if (cp.calcMode) cpAttrs.push(`calcMode="${escapeXml(cp.calcMode)}"`);
|
|
1850
|
-
if (cp.fullCalcOnLoad) cpAttrs.push("fullCalcOnLoad=\"1\"");
|
|
1851
|
-
if (cp.calcOnSave === false) cpAttrs.push("calcOnSave=\"0\"");
|
|
1852
|
-
if (cp.forceFullCalc) cpAttrs.push("forceFullCalc=\"1\"");
|
|
1853
|
-
if (cp.concurrentCalc === false) cpAttrs.push("concurrentCalc=\"0\"");
|
|
1854
|
-
if (cp.concurrentManualCount !== void 0) cpAttrs.push(`concurrentManualCount="${cp.concurrentManualCount}"`);
|
|
1855
|
-
if (cp.iterate) cpAttrs.push("iterate=\"1\"");
|
|
1856
|
-
if (cp.iterateCount !== void 0) cpAttrs.push(`iterateCount="${cp.iterateCount}"`);
|
|
1857
|
-
if (cp.iterateDelta !== void 0) cpAttrs.push(`iterateDelta="${cp.iterateDelta}"`);
|
|
1858
|
-
if (cp.refMode) cpAttrs.push(`refMode="${escapeXml(cp.refMode)}"`);
|
|
1859
|
-
if (cp.fullPrecision === false) cpAttrs.push("fullPrecision=\"0\"");
|
|
1860
|
-
if (cp.calcCompleted) cpAttrs.push("calcCompleted=\"1\"");
|
|
1861
|
-
parts.push(`<calcPr ${cpAttrs.join(" ")}/>`);
|
|
1862
|
-
} else parts.push("<calcPr calcId=\"162913\"/>");
|
|
1863
|
-
if (opts.customViews && opts.customViews.length > 0) {
|
|
1864
|
-
parts.push("<customWorkbookViews>");
|
|
1865
|
-
for (const v of opts.customViews) {
|
|
1866
|
-
const vAttrs = [
|
|
1867
|
-
`name="${escapeXml(v.name)}"`,
|
|
1868
|
-
`guid="${escapeXml(v.guid)}"`,
|
|
1869
|
-
`windowWidth="${v.windowWidth}"`,
|
|
1870
|
-
`windowHeight="${v.windowHeight}"`,
|
|
1871
|
-
`activeSheetId="${v.activeSheetId}"`
|
|
1872
|
-
];
|
|
1873
|
-
if (v.xWindow !== void 0) vAttrs.push(`xWindow="${v.xWindow}"`);
|
|
1874
|
-
if (v.yWindow !== void 0) vAttrs.push(`yWindow="${v.yWindow}"`);
|
|
1875
|
-
if (v.showFormulaBar === false) vAttrs.push("showFormulaBar=\"0\"");
|
|
1876
|
-
if (v.showStatusbar === false) vAttrs.push("showStatusbar=\"0\"");
|
|
1877
|
-
if (v.showHorizontalScroll === false) vAttrs.push("showHorizontalScroll=\"0\"");
|
|
1878
|
-
if (v.showVerticalScroll === false) vAttrs.push("showVerticalScroll=\"0\"");
|
|
1879
|
-
if (v.showSheetTabs === false) vAttrs.push("showSheetTabs=\"0\"");
|
|
1880
|
-
if (v.tabRatio !== void 0) vAttrs.push(`tabRatio="${v.tabRatio}"`);
|
|
1881
|
-
if (v.includeHiddenRowCol === false) vAttrs.push("includeHiddenRowCol=\"0\"");
|
|
1882
|
-
if (v.includePrintSettings === false) vAttrs.push("includePrintSettings=\"0\"");
|
|
1883
|
-
if (v.personalView) vAttrs.push("personalView=\"1\"");
|
|
1884
|
-
if (v.maximized) vAttrs.push("maximized=\"1\"");
|
|
1885
|
-
if (v.minimized) vAttrs.push("minimized=\"1\"");
|
|
1886
|
-
if (v.autoUpdate) vAttrs.push("autoUpdate=\"1\"");
|
|
1887
|
-
if (v.mergeInterval !== void 0) vAttrs.push(`mergeInterval="${v.mergeInterval}"`);
|
|
1888
|
-
if (v.changesSavedWin) vAttrs.push("changesSavedWin=\"1\"");
|
|
1889
|
-
if (v.onlySync) vAttrs.push("onlySync=\"1\"");
|
|
1890
|
-
if (v.showComments) vAttrs.push(`showComments="${escapeXml(v.showComments)}"`);
|
|
1891
|
-
parts.push(`<customWorkbookView ${vAttrs.join(" ")}/>`);
|
|
1892
|
-
}
|
|
1893
|
-
parts.push("</customWorkbookViews>");
|
|
1894
|
-
}
|
|
1895
|
-
const pivotCaches = opts.pivotCaches ?? [];
|
|
1896
|
-
if (pivotCaches.length > 0) {
|
|
1897
|
-
parts.push("<pivotCaches>");
|
|
1898
|
-
for (const pc of pivotCaches) parts.push(`<pivotCache cacheId="${pc.cacheId}" r:id="${pc.rId}"/>`);
|
|
1899
|
-
parts.push("</pivotCaches>");
|
|
1900
|
-
}
|
|
1901
|
-
if (opts.webPublishing) {
|
|
1902
|
-
const wp = opts.webPublishing;
|
|
1903
|
-
const wpAttrs = [];
|
|
1904
|
-
if (wp.css === false) wpAttrs.push("css=\"0\"");
|
|
1905
|
-
if (wp.thicket === false) wpAttrs.push("thicket=\"0\"");
|
|
1906
|
-
if (wp.longFileNames === false) wpAttrs.push("longFileNames=\"0\"");
|
|
1907
|
-
if (wp.vml) wpAttrs.push("vml=\"1\"");
|
|
1908
|
-
if (wp.allowPng) wpAttrs.push("allowPng=\"1\"");
|
|
1909
|
-
if (wp.targetScreenSize && wp.targetScreenSize !== "800x600") wpAttrs.push(`targetScreenSize="${wp.targetScreenSize}"`);
|
|
1910
|
-
if (wp.dpi !== void 0 && wp.dpi !== 96) wpAttrs.push(`dpi="${wp.dpi}"`);
|
|
1911
|
-
if (wp.codePage !== void 0) wpAttrs.push(`codePage="${wp.codePage}"`);
|
|
1912
|
-
if (wp.characterSet) wpAttrs.push(`characterSet="${escapeXml(wp.characterSet)}"`);
|
|
1913
|
-
parts.push(`<webPublishing ${wpAttrs.join(" ")}/>`);
|
|
1914
|
-
}
|
|
1915
|
-
if (opts.fileRecoveryPr) {
|
|
1916
|
-
const frp = opts.fileRecoveryPr;
|
|
1917
|
-
const frpAttrs = [];
|
|
1918
|
-
if (frp.autoRecover === false) frpAttrs.push("autoRecover=\"0\"");
|
|
1919
|
-
if (frp.crashSave) frpAttrs.push("crashSave=\"1\"");
|
|
1920
|
-
if (frp.dataExtractLoad) frpAttrs.push("dataExtractLoad=\"1\"");
|
|
1921
|
-
if (frp.repairLoad) frpAttrs.push("repairLoad=\"1\"");
|
|
1922
|
-
if (frpAttrs.length > 0) parts.push(`<fileRecoveryPr ${frpAttrs.join(" ")}/>`);
|
|
1923
|
-
}
|
|
1924
|
-
if (opts.webPublishObjects && opts.webPublishObjects.length > 0) {
|
|
1925
|
-
const wpoParts = [`<webPublishObjects count="${opts.webPublishObjects.length}">`];
|
|
1926
|
-
for (const wpo of opts.webPublishObjects) {
|
|
1927
|
-
const wpoAttrs = [`r:id="${escapeXml(wpo.rId)}"`];
|
|
1928
|
-
if (wpo.destinationFile) wpoAttrs.push(`destinationFile="${escapeXml(wpo.destinationFile)}"`);
|
|
1929
|
-
if (wpo.autoRepublish) wpoAttrs.push("autoRepublish=\"1\"");
|
|
1930
|
-
if (wpo.title) wpoAttrs.push(`title="${escapeXml(wpo.title)}"`);
|
|
1931
|
-
if (wpo.sourceObject) wpoAttrs.push(`sourceObject="${escapeXml(wpo.sourceObject)}"`);
|
|
1932
|
-
wpoParts.push(`<webPublishObject ${wpoAttrs.join(" ")}/>`);
|
|
1933
|
-
}
|
|
1934
|
-
wpoParts.push("</webPublishObjects>");
|
|
1935
|
-
parts.push(wpoParts.join(""));
|
|
1936
|
-
}
|
|
1937
|
-
if (opts.volTypes && opts.volTypes.length > 0) {
|
|
1938
|
-
const vtParts = [`<volTypes count="${opts.volTypes.length}">`];
|
|
1939
|
-
for (const vt of opts.volTypes) {
|
|
1940
|
-
const vtType = vt.type ?? "realTimeData";
|
|
1941
|
-
const mains = vt.mains ?? [];
|
|
1942
|
-
if (mains.length > 0) {
|
|
1943
|
-
const mainParts = [];
|
|
1944
|
-
for (const m of mains) {
|
|
1945
|
-
const tpParts = [];
|
|
1946
|
-
for (const topic of m.topics ?? []) {
|
|
1947
|
-
const tpInner = [`<v>${escapeXml(topic.value)}</v>`];
|
|
1948
|
-
for (const stp of topic.stringTopics ?? []) tpInner.push(`<stp>${escapeXml(stp)}</stp>`);
|
|
1949
|
-
for (const tr of topic.refs ?? []) tpInner.push(`<tr r="${escapeXml(tr.reference)}" s="${tr.sheetIndex}"/>`);
|
|
1950
|
-
const tpAttr = topic.valueType && topic.valueType !== "n" ? ` t="${escapeXml(topic.valueType)}"` : "";
|
|
1951
|
-
tpParts.push(`<tp${tpAttr}>${tpInner.join("")}</tp>`);
|
|
1952
|
-
}
|
|
1953
|
-
mainParts.push(`<main first="${escapeXml(m.first)}">${tpParts.join("")}</main>`);
|
|
1954
|
-
}
|
|
1955
|
-
vtParts.push(`<volType type="${vtType}">${mainParts.join("")}</volType>`);
|
|
1956
|
-
} else vtParts.push(`<volType type="${vtType}"/>`);
|
|
1957
|
-
}
|
|
1958
|
-
vtParts.push("</volTypes>");
|
|
1959
|
-
parts.push(vtParts.join(""));
|
|
1960
|
-
}
|
|
1961
|
-
parts.push("</workbook>");
|
|
1962
|
-
return parts.join("");
|
|
1963
|
-
}
|
|
1964
|
-
/** Generate tableParts XML fragment for embedding in a worksheet. */
|
|
1965
|
-
function buildTablePartsXml(tableParts) {
|
|
1966
|
-
if (tableParts.length === 0) return "";
|
|
1967
|
-
const p = [`<tableParts count="${tableParts.length}">`];
|
|
1968
|
-
for (const tp of tableParts) p.push(`<tablePart r:id="${tp.rId}"/>`);
|
|
1969
|
-
p.push("</tableParts>");
|
|
1970
|
-
return p.join("");
|
|
1971
|
-
}
|
|
1972
|
-
/** Generate externalReferences XML fragment for embedding in the workbook. */
|
|
1973
|
-
function buildExternalReferencesXml(refs) {
|
|
1974
|
-
if (refs.length === 0) return "";
|
|
1975
|
-
const p = ["<externalReferences>"];
|
|
1976
|
-
for (const ref of refs) p.push(`<externalReference r:id="${ref.rId}"/>`);
|
|
1977
|
-
p.push("</externalReferences>");
|
|
1978
|
-
return p.join("");
|
|
1979
|
-
}
|
|
1980
|
-
/** Legacy Excel password hash (XOR-based) */
|
|
1981
|
-
function hashPassword(password) {
|
|
1982
|
-
let hash = 0;
|
|
1983
|
-
for (let i = 0; i < password.length; i++) {
|
|
1984
|
-
const c = password.charCodeAt(i);
|
|
1985
|
-
hash = (hash >> 14 & 1) + (hash << 1 & 32767);
|
|
1986
|
-
hash ^= c;
|
|
1987
|
-
hash = hash & 16384 ? hash ^ 1 : hash;
|
|
1988
|
-
}
|
|
1989
|
-
hash = (hash >> 14 & 1) + (hash << 1 & 32767);
|
|
1990
|
-
hash = (hash >> 14 & 1) + (hash << 1 & 32767);
|
|
1991
|
-
hash ^= password.length;
|
|
1992
|
-
return hash.toString(16).toUpperCase().padStart(4, "0");
|
|
1993
|
-
}
|
|
1994
|
-
//#endregion
|
|
1995
|
-
//#region src/compiler.ts
|
|
1996
|
-
/**
|
|
1997
|
-
* XLSX Compiler — compiles WorkbookOptions into a Zippable structure.
|
|
1998
|
-
*
|
|
1999
|
-
* Accepts pure JSON WorkbookOptions — no intermediate File class needed.
|
|
2000
|
-
* Uses XlsxWriteContext for shared state (strings, styles, media, charts).
|
|
2001
|
-
*
|
|
2002
|
-
* @module
|
|
2003
|
-
*/
|
|
2004
|
-
const XML_DECL = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
|
2005
|
-
/**
|
|
2006
|
-
* Compile workbook options into a Zippable structure.
|
|
2007
|
-
*/
|
|
2008
|
-
function compileWorkbook(options, overrides = [], mediaLevel = 0) {
|
|
2009
|
-
const ctx = new XlsxWriteContext();
|
|
2010
|
-
const mapping = {};
|
|
2011
|
-
const worksheetConfigs = options.worksheets ?? [];
|
|
2012
|
-
const chartsheetConfigs = options.chartsheets ?? [];
|
|
2013
|
-
mapping["Properties"] = {
|
|
2014
|
-
data: XML_DECL + buildCorePropertiesXmlString(options),
|
|
2015
|
-
path: "docProps/core.xml"
|
|
2016
|
-
};
|
|
2017
|
-
mapping["AppProperties"] = {
|
|
2018
|
-
data: XML_DECL + APP_PROPS_XML,
|
|
2019
|
-
path: "docProps/app.xml"
|
|
2020
|
-
};
|
|
2021
|
-
mapping["FileRelationships"] = {
|
|
2022
|
-
data: XML_DECL + buildFileRelationships().serialize(),
|
|
2023
|
-
path: "_rels/.rels"
|
|
2024
|
-
};
|
|
2025
|
-
for (let i = 0; i < worksheetConfigs.length; i++) ctx.contentTypes.addWorksheet(i + 1);
|
|
2026
|
-
ctx.contentTypes.addStyles();
|
|
2027
|
-
ctx.contentTypes.addSharedStrings();
|
|
2028
|
-
ctx.contentTypes.addTheme();
|
|
2029
|
-
for (const dxf of options.dxfs ?? []) ctx.registerDxf(dxf);
|
|
2030
|
-
buildWorkbookRelationships(ctx.workbookRels, worksheetConfigs.length, chartsheetConfigs.length);
|
|
2031
|
-
const sheets = [];
|
|
2032
|
-
let sheetId = 1;
|
|
2033
|
-
let rId = 1;
|
|
2034
|
-
for (const ws of worksheetConfigs) sheets.push({
|
|
2035
|
-
name: ws.name ?? `Sheet${sheetId}`,
|
|
2036
|
-
sheetId: sheetId++,
|
|
2037
|
-
rId: `rId${rId++}`
|
|
2038
|
-
});
|
|
2039
|
-
for (const cs of chartsheetConfigs) sheets.push({
|
|
2040
|
-
name: cs.name ?? `Chart${sheetId}`,
|
|
2041
|
-
sheetId: sheetId++,
|
|
2042
|
-
rId: `rId${rId++}`
|
|
2043
|
-
});
|
|
2044
|
-
let globalMediaIdx = 0;
|
|
2045
|
-
let globalChartIdx = 0;
|
|
2046
|
-
let globalPivotIdx = 0;
|
|
2047
|
-
let globalPivotCacheIdx = 0;
|
|
2048
|
-
let globalTableIdx = 0;
|
|
2049
|
-
const pivotCacheDataMap = /* @__PURE__ */ new Map();
|
|
2050
|
-
const calcCells = [];
|
|
2051
|
-
const allTableParts = [];
|
|
2052
|
-
const wsContext = {
|
|
2053
|
-
sharedStrings: ctx.sharedStrings,
|
|
2054
|
-
styles: ctx.styles
|
|
2055
|
-
};
|
|
2056
|
-
for (let i = 0; i < worksheetConfigs.length; i++) {
|
|
2057
|
-
const wsOpts = worksheetConfigs[i];
|
|
2058
|
-
const imgOpts = wsOpts.images ?? [];
|
|
2059
|
-
const chartOpts = wsOpts.charts ?? [];
|
|
2060
|
-
const hlOpts = wsOpts.hyperlinks ?? [];
|
|
2061
|
-
const sheetName = wsOpts.name ?? `Sheet${i + 1}`;
|
|
2062
|
-
let sheetXml = stringifyWorksheet(wsOpts, wsContext);
|
|
2063
|
-
const sheetIdx = i + 1;
|
|
2064
|
-
const wsRows = wsOpts.rows ?? [];
|
|
2065
|
-
for (let ri = 0; ri < wsRows.length; ri++) {
|
|
2066
|
-
const rowOpts = wsRows[ri];
|
|
2067
|
-
const rowNumber = rowOpts.rowNumber ?? ri + 1;
|
|
2068
|
-
if (!rowOpts.cells) continue;
|
|
2069
|
-
for (let ci = 0; ci < rowOpts.cells.length; ci++) {
|
|
2070
|
-
const cell = rowOpts.cells[ci];
|
|
2071
|
-
if (!cell.formula) continue;
|
|
2072
|
-
const ref = cell.reference ?? columnToLetter(ci + 1) + rowNumber;
|
|
2073
|
-
calcCells.push({
|
|
2074
|
-
reference: ref,
|
|
2075
|
-
sheetIndex: sheetIdx,
|
|
2076
|
-
array: cell.formula.type === "array"
|
|
2077
|
-
});
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
const hasMedia = imgOpts.length > 0 || chartOpts.length > 0;
|
|
2081
|
-
const hasExternalHyperlinks = hlOpts.some((h) => h.target.type === "external");
|
|
2082
|
-
const commentOpts = wsOpts.comments ?? [];
|
|
2083
|
-
const hasComments = commentOpts.length > 0;
|
|
2084
|
-
const pivotOpts = wsOpts.pivotTables ?? [];
|
|
2085
|
-
const hasPivots = pivotOpts.length > 0;
|
|
2086
|
-
const tableOpts = wsOpts.tables ?? [];
|
|
2087
|
-
const hasTables = tableOpts.length > 0;
|
|
2088
|
-
const bgImg = wsOpts.backgroundImage;
|
|
2089
|
-
let wsRels;
|
|
2090
|
-
let nextRid = 0;
|
|
2091
|
-
if (hasMedia || hasExternalHyperlinks || hasComments || hasPivots || hasTables || bgImg) wsRels = new Relationships();
|
|
2092
|
-
if (hasExternalHyperlinks) for (const hl of hlOpts) {
|
|
2093
|
-
if (hl.target.type !== "external") continue;
|
|
2094
|
-
const rid = ++nextRid;
|
|
2095
|
-
wsRels.addRelationship(rid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", hl.target.url, "External");
|
|
2096
|
-
}
|
|
2097
|
-
if (hasMedia) {
|
|
2098
|
-
const drawingImages = [];
|
|
2099
|
-
const drawingCharts = [];
|
|
2100
|
-
const drawingRels = new Relationships();
|
|
2101
|
-
let rid = 1;
|
|
2102
|
-
for (const img of imgOpts) {
|
|
2103
|
-
const mediaKey = `image_${globalMediaIdx}`;
|
|
2104
|
-
const ext = img.type === "jpeg" || img.type === "jpg" ? "jpeg" : "png";
|
|
2105
|
-
ctx.media.addImage(mediaKey, {
|
|
2106
|
-
fileName: `image${globalMediaIdx + 1}.${ext}`,
|
|
2107
|
-
type: ext,
|
|
2108
|
-
data: img.data,
|
|
2109
|
-
width: 0,
|
|
2110
|
-
height: 0
|
|
2111
|
-
});
|
|
2112
|
-
drawingRels.addRelationship(rid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `../media/image${globalMediaIdx + 1}.${ext}`);
|
|
2113
|
-
drawingImages.push({
|
|
2114
|
-
col: img.col,
|
|
2115
|
-
row: img.row,
|
|
2116
|
-
rId: `rId${rid}`
|
|
2117
|
-
});
|
|
2118
|
-
rid++;
|
|
2119
|
-
globalMediaIdx++;
|
|
2120
|
-
}
|
|
2121
|
-
for (const chart of chartOpts) {
|
|
2122
|
-
const chartKey = `chart_${globalChartIdx}`;
|
|
2123
|
-
ctx.charts.addChart(chartKey, {
|
|
2124
|
-
key: chartKey,
|
|
2125
|
-
chartSpaceXml: chartSpaceDesc.stringify(chart, ctx) ?? ""
|
|
2126
|
-
});
|
|
2127
|
-
drawingRels.addRelationship(rid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", `../charts/chart${globalChartIdx + 1}.xml`);
|
|
2128
|
-
drawingCharts.push({
|
|
2129
|
-
col: chart.col,
|
|
2130
|
-
row: chart.row,
|
|
2131
|
-
rId: `rId${rid}`
|
|
2132
|
-
});
|
|
2133
|
-
rid++;
|
|
2134
|
-
globalChartIdx++;
|
|
2135
|
-
}
|
|
2136
|
-
const drawingXml = drawingDesc.stringify({
|
|
2137
|
-
images: drawingImages,
|
|
2138
|
-
charts: drawingCharts
|
|
2139
|
-
}, ctx);
|
|
2140
|
-
const drawingIdx = i + 1;
|
|
2141
|
-
mapping[`Drawing${i}`] = {
|
|
2142
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${drawingXml}`,
|
|
2143
|
-
path: `xl/drawings/drawing${drawingIdx}.xml`
|
|
2144
|
-
};
|
|
2145
|
-
mapping[`DrawingRels${i}`] = {
|
|
2146
|
-
data: XML_DECL + drawingRels.serialize(),
|
|
2147
|
-
path: `xl/drawings/_rels/drawing${drawingIdx}.xml.rels`
|
|
2148
|
-
};
|
|
2149
|
-
const drawingRid = ++nextRid;
|
|
2150
|
-
sheetXml = sheetXml.slice(0, -12) + `<drawing r:id="rId${drawingRid}"/></worksheet>`;
|
|
2151
|
-
wsRels.addRelationship(drawingRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing", `../drawings/drawing${drawingIdx}.xml`);
|
|
2152
|
-
ctx.contentTypes.addDrawing(drawingIdx);
|
|
2153
|
-
}
|
|
2154
|
-
if (hasComments) {
|
|
2155
|
-
const commentsIdx = i + 1;
|
|
2156
|
-
const commentsXml = commentsDesc.stringify({ comments: commentOpts }, ctx);
|
|
2157
|
-
mapping[`Comments${i}`] = {
|
|
2158
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${commentsXml}`,
|
|
2159
|
-
path: `xl/comments${commentsIdx}.xml`
|
|
2160
|
-
};
|
|
2161
|
-
const vmlXml = vmlNotesDesc.stringify({ comments: commentOpts }, ctx);
|
|
2162
|
-
mapping[`VmlDrawing${i}`] = {
|
|
2163
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${vmlXml}`,
|
|
2164
|
-
path: `xl/drawings/vmlDrawing${commentsIdx}.vml`
|
|
2165
|
-
};
|
|
2166
|
-
const commentsRid = ++nextRid;
|
|
2167
|
-
wsRels.addRelationship(commentsRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", `../comments${commentsIdx}.xml`);
|
|
2168
|
-
const vmlRid = ++nextRid;
|
|
2169
|
-
wsRels.addRelationship(vmlRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing", `../drawings/vmlDrawing${commentsIdx}.vml`);
|
|
2170
|
-
sheetXml = sheetXml.slice(0, -12) + `<legacyDrawing r:id="rId${vmlRid}"/></worksheet>`;
|
|
2171
|
-
ctx.contentTypes.addComments(commentsIdx);
|
|
2172
|
-
ctx.contentTypes.addVmlDrawing();
|
|
2173
|
-
}
|
|
2174
|
-
if (bgImg) {
|
|
2175
|
-
const ext = bgImg.type === "jpg" ? "jpeg" : bgImg.type;
|
|
2176
|
-
const mediaKey = `bg_${i}`;
|
|
2177
|
-
const mediaIdx = globalMediaIdx + 1;
|
|
2178
|
-
ctx.media.addImage(mediaKey, {
|
|
2179
|
-
fileName: `image${mediaIdx}.${ext}`,
|
|
2180
|
-
type: ext,
|
|
2181
|
-
data: bgImg.data,
|
|
2182
|
-
width: 0,
|
|
2183
|
-
height: 0
|
|
2184
|
-
});
|
|
2185
|
-
globalMediaIdx++;
|
|
2186
|
-
const bgRid = ++nextRid;
|
|
2187
|
-
wsRels.addRelationship(bgRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `../media/image${mediaIdx}.${ext}`);
|
|
2188
|
-
sheetXml = sheetXml.replace("<!--BACKGROUND_PICTURE-->", `<picture r:id="rId${bgRid}"/>`);
|
|
2189
|
-
}
|
|
2190
|
-
if (hasPivots) for (const pt of pivotOpts) {
|
|
2191
|
-
globalPivotIdx++;
|
|
2192
|
-
const pivotIdx = globalPivotIdx;
|
|
2193
|
-
const sourceSheet = pt.sourceSheet ?? sheetName;
|
|
2194
|
-
const sourceWsIdx = worksheetConfigs.findIndex((ws) => (ws.name ?? `Sheet${worksheetConfigs.indexOf(ws) + 1}`) === sourceSheet);
|
|
2195
|
-
if (sourceWsIdx === -1) continue;
|
|
2196
|
-
const sourceData = extractPivotSourceData(worksheetConfigs[sourceWsIdx].rows ?? [], pt.source);
|
|
2197
|
-
const cacheKey = `${sourceSheet}:${pt.source}`;
|
|
2198
|
-
let cacheId;
|
|
2199
|
-
let cacheIdx;
|
|
2200
|
-
const existing = pivotCacheDataMap.get(cacheKey);
|
|
2201
|
-
if (existing) {
|
|
2202
|
-
cacheId = existing.cacheId;
|
|
2203
|
-
cacheIdx = existing.cacheIdx;
|
|
2204
|
-
} else {
|
|
2205
|
-
globalPivotCacheIdx++;
|
|
2206
|
-
cacheIdx = globalPivotCacheIdx;
|
|
2207
|
-
cacheId = cacheIdx;
|
|
2208
|
-
pivotCacheDataMap.set(cacheKey, {
|
|
2209
|
-
cacheId,
|
|
2210
|
-
cacheIdx
|
|
2211
|
-
});
|
|
2212
|
-
const cacheDefRels = new Relationships();
|
|
2213
|
-
cacheDefRels.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords", "pivotCacheRecords1.xml");
|
|
2214
|
-
const cacheDefXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + pivotCacheDefDesc.stringify({
|
|
2215
|
-
sourceRef: pt.source.split(":")[0] ? pt.source : "A1",
|
|
2216
|
-
sourceSheet,
|
|
2217
|
-
sourceData,
|
|
2218
|
-
recordsRid: "rId1"
|
|
2219
|
-
}, ctx);
|
|
2220
|
-
mapping[`PivotCacheDef${cacheIdx}`] = {
|
|
2221
|
-
data: cacheDefXml,
|
|
2222
|
-
path: `xl/pivotCache/pivotCacheDefinition${cacheIdx}.xml`
|
|
2223
|
-
};
|
|
2224
|
-
mapping[`PivotCacheDefRels${cacheIdx}`] = {
|
|
2225
|
-
data: XML_DECL + cacheDefRels.serialize(),
|
|
2226
|
-
path: `xl/pivotCache/_rels/pivotCacheDefinition${cacheIdx}.xml.rels`
|
|
2227
|
-
};
|
|
2228
|
-
const cacheRecordsXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + pivotCacheRecordsDesc.stringify({ sourceData }, ctx);
|
|
2229
|
-
mapping[`PivotCacheRecords${cacheIdx}`] = {
|
|
2230
|
-
data: cacheRecordsXml,
|
|
2231
|
-
path: `xl/pivotCache/pivotCacheRecords${cacheIdx}.xml`
|
|
2232
|
-
};
|
|
2233
|
-
ctx.contentTypes.addPivotCacheDefinition(cacheIdx);
|
|
2234
|
-
ctx.contentTypes.addPivotCacheRecords(cacheIdx);
|
|
2235
|
-
const wbPivotRid = ctx.workbookRels.relationshipCount + 1;
|
|
2236
|
-
ctx.workbookRels.addRelationship(wbPivotRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition", `pivotCache/pivotCacheDefinition${cacheIdx}.xml`);
|
|
2237
|
-
ctx.pivotCacheRefs.push({
|
|
2238
|
-
cacheId,
|
|
2239
|
-
rId: `rId${wbPivotRid}`
|
|
2240
|
-
});
|
|
2241
|
-
}
|
|
2242
|
-
const pivotTableXml = XML_DECL + pivotTableDesc.stringify({
|
|
2243
|
-
options: pt,
|
|
2244
|
-
sourceData,
|
|
2245
|
-
cacheId
|
|
2246
|
-
}, ctx);
|
|
2247
|
-
mapping[`PivotTable${pivotIdx}`] = {
|
|
2248
|
-
data: pivotTableXml,
|
|
2249
|
-
path: `xl/pivotTables/pivotTable${pivotIdx}.xml`
|
|
2250
|
-
};
|
|
2251
|
-
const ptRels = new Relationships();
|
|
2252
|
-
ptRels.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition", `../pivotCache/pivotCacheDefinition${cacheIdx}.xml`);
|
|
2253
|
-
mapping[`PivotTableRels${pivotIdx}`] = {
|
|
2254
|
-
data: XML_DECL + ptRels.serialize(),
|
|
2255
|
-
path: `xl/pivotTables/_rels/pivotTable${pivotIdx}.xml.rels`
|
|
2256
|
-
};
|
|
2257
|
-
const ptRid = ++nextRid;
|
|
2258
|
-
wsRels.addRelationship(ptRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable", `../pivotTables/pivotTable${pivotIdx}.xml`);
|
|
2259
|
-
ctx.contentTypes.addPivotTable(pivotIdx);
|
|
2260
|
-
}
|
|
2261
|
-
const wsTableParts = [];
|
|
2262
|
-
if (hasTables) for (const tbl of tableOpts) {
|
|
2263
|
-
globalTableIdx++;
|
|
2264
|
-
const tableIdx = globalTableIdx;
|
|
2265
|
-
const tableXmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + tableDesc.stringify({
|
|
2266
|
-
...tbl,
|
|
2267
|
-
id: tbl.id ?? tableIdx
|
|
2268
|
-
}, ctx);
|
|
2269
|
-
mapping[`Table${tableIdx}`] = {
|
|
2270
|
-
data: tableXmlStr,
|
|
2271
|
-
path: `xl/tables/table${tableIdx}.xml`
|
|
2272
|
-
};
|
|
2273
|
-
const tblRid = ++nextRid;
|
|
2274
|
-
wsRels.addRelationship(tblRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table", `../tables/table${tableIdx}.xml`);
|
|
2275
|
-
wsTableParts.push({ rId: `rId${tblRid}` });
|
|
2276
|
-
allTableParts.push({ rId: `rId${tblRid}` });
|
|
2277
|
-
ctx.contentTypes.addTable(tableIdx);
|
|
2278
|
-
}
|
|
2279
|
-
if (hasPivots) {
|
|
2280
|
-
const rendered = renderPivotSheetData(pivotOpts, worksheetConfigs, ctx.sharedStrings, sheetName);
|
|
2281
|
-
if (rendered.sheetData.length > 0) {
|
|
2282
|
-
sheetXml = sheetXml.replace(/<sheetData\/>|<sheetData><\/sheetData>/, rendered.sheetData);
|
|
2283
|
-
if (!sheetXml.includes("<dimension")) sheetXml = sheetXml.replace("<sheetViews", `<dimension ref="${rendered.dimensionRef}"/><sheetViews`);
|
|
2284
|
-
}
|
|
2285
|
-
}
|
|
2286
|
-
if (wsTableParts.length > 0) {
|
|
2287
|
-
const tablePartsXml = buildTablePartsXml(wsTableParts);
|
|
2288
|
-
sheetXml = sheetXml.slice(0, -12) + tablePartsXml + "</worksheet>";
|
|
2289
|
-
}
|
|
2290
|
-
if (wsRels) mapping[`WorksheetRels${i}`] = {
|
|
2291
|
-
data: XML_DECL + wsRels.serialize(),
|
|
2292
|
-
path: `xl/worksheets/_rels/sheet${i + 1}.xml.rels`
|
|
2293
|
-
};
|
|
2294
|
-
mapping[`Worksheet${i}`] = {
|
|
2295
|
-
data: sheetXml,
|
|
2296
|
-
path: `xl/worksheets/sheet${i + 1}.xml`
|
|
2297
|
-
};
|
|
2298
|
-
}
|
|
2299
|
-
for (let i = 0; i < chartsheetConfigs.length; i++) {
|
|
2300
|
-
const csOpts = chartsheetConfigs[i];
|
|
2301
|
-
const chartDef = csOpts.chart;
|
|
2302
|
-
const csChartGlobalIdx = ctx.charts.array.length;
|
|
2303
|
-
const csChartKey = `cs_chart_${csChartGlobalIdx}`;
|
|
2304
|
-
ctx.charts.addChart(csChartKey, {
|
|
2305
|
-
key: csChartKey,
|
|
2306
|
-
chartSpaceXml: chartSpaceDesc.stringify({
|
|
2307
|
-
type: chartDef.type,
|
|
2308
|
-
title: chartDef.title,
|
|
2309
|
-
categories: chartDef.categories,
|
|
2310
|
-
series: chartDef.series
|
|
2311
|
-
}, ctx) ?? ""
|
|
2312
|
-
});
|
|
2313
|
-
const csRels = new Relationships();
|
|
2314
|
-
const csDrawingIdx = i + 1;
|
|
2315
|
-
csRels.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing", `../drawings/drawing${csDrawingIdx}.xml`);
|
|
2316
|
-
const csDrawingRels = new Relationships();
|
|
2317
|
-
csDrawingRels.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", `../charts/chart${csChartGlobalIdx + 1}.xml`);
|
|
2318
|
-
const csDrawingXml = `<xdr:wsDr xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><xdr:absoluteAnchor><xdr:pos x="0" y="0"/><xdr:ext cx="9308969" cy="6096000"/><xdr:graphicFrame><xdr:nvGraphicFramePr><xdr:cNvPr id="1" name="Chart ${i + 1}"/><xdr:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></xdr:cNvGraphicFramePr></xdr:nvGraphicFramePr><xdr:xfrm><a:off x="0" y="0"/><a:ext cx="9308969" cy="6096000"/></xdr:xfrm><a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart"><c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" r:id="rId1"/></a:graphicData></a:graphic></xdr:graphicFrame><xdr:clientData/></xdr:absoluteAnchor></xdr:wsDr>`;
|
|
2319
|
-
mapping[`ChartsheetDrawing${i}`] = {
|
|
2320
|
-
data: csDrawingXml,
|
|
2321
|
-
path: `xl/drawings/drawing${csDrawingIdx}.xml`
|
|
2322
|
-
};
|
|
2323
|
-
mapping[`ChartsheetDrawingRels${i}`] = {
|
|
2324
|
-
data: XML_DECL + csDrawingRels.serialize(),
|
|
2325
|
-
path: `xl/drawings/_rels/drawing${csDrawingIdx}.xml.rels`
|
|
2326
|
-
};
|
|
2327
|
-
ctx.contentTypes.addDrawing(csDrawingIdx);
|
|
2328
|
-
mapping[`ChartsheetRels${i}`] = {
|
|
2329
|
-
data: XML_DECL + csRels.serialize(),
|
|
2330
|
-
path: `xl/chartsheets/_rels/sheet${i + 1}.xml.rels`
|
|
2331
|
-
};
|
|
2332
|
-
mapping[`Chartsheet${i}`] = {
|
|
2333
|
-
data: XML_DECL + chartsheetDesc.stringify({
|
|
2334
|
-
...csOpts,
|
|
2335
|
-
drawingRId: "rId1"
|
|
2336
|
-
}, ctx),
|
|
2337
|
-
path: `xl/chartsheets/sheet${i + 1}.xml`
|
|
2338
|
-
};
|
|
2339
|
-
ctx.contentTypes.addChartsheet(i + 1);
|
|
2340
|
-
}
|
|
2341
|
-
let wbXml = workbookDesc.stringify({
|
|
2342
|
-
sheets,
|
|
2343
|
-
pivotCaches: ctx.pivotCacheRefs,
|
|
2344
|
-
protection: options.workbookProtection,
|
|
2345
|
-
customViews: options.customWorkbookViews,
|
|
2346
|
-
fileRecoveryPr: options.fileRecoveryPr,
|
|
2347
|
-
functionGroups: options.functionGroups,
|
|
2348
|
-
webPublishing: options.webPublishing,
|
|
2349
|
-
fileSharing: options.fileSharing,
|
|
2350
|
-
volTypes: options.volTypes,
|
|
2351
|
-
webPublishObjects: options.webPublishObjects
|
|
2352
|
-
}, ctx) ?? "";
|
|
2353
|
-
const extLinks = options.externalLinks ?? [];
|
|
2354
|
-
if (extLinks.length > 0) {
|
|
2355
|
-
const extRefs = [];
|
|
2356
|
-
for (let ei = 0; ei < extLinks.length; ei++) {
|
|
2357
|
-
const elIdx = ei + 1;
|
|
2358
|
-
const elRid = ctx.workbookRels.relationshipCount + 1;
|
|
2359
|
-
ctx.workbookRels.addRelationship(elRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink", `externalLinks/externalLink${elIdx}.xml`);
|
|
2360
|
-
const elOpts = extLinks[ei];
|
|
2361
|
-
let bookRId;
|
|
2362
|
-
if (elOpts.externalBook?.target) {
|
|
2363
|
-
const elRels = new Relationships();
|
|
2364
|
-
elRels.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLinkPath", elOpts.externalBook.target, TargetModeType.EXTERNAL);
|
|
2365
|
-
bookRId = "rId1";
|
|
2366
|
-
mapping[`ExternalLinkRels${elIdx}`] = {
|
|
2367
|
-
data: XML_DECL + elRels.serialize(),
|
|
2368
|
-
path: `xl/externalLinks/_rels/externalLink${elIdx}.xml.rels`
|
|
2369
|
-
};
|
|
2370
|
-
}
|
|
2371
|
-
mapping[`ExternalLink${elIdx}`] = {
|
|
2372
|
-
data: XML_DECL + externalLinkDesc.stringify({
|
|
2373
|
-
...elOpts,
|
|
2374
|
-
bookRId
|
|
2375
|
-
}, ctx),
|
|
2376
|
-
path: `xl/externalLinks/externalLink${elIdx}.xml`
|
|
2377
|
-
};
|
|
2378
|
-
extRefs.push({ rId: `rId${elRid}` });
|
|
2379
|
-
ctx.contentTypes.addExternalLink(elIdx);
|
|
2380
|
-
}
|
|
2381
|
-
const extRefsXml = buildExternalReferencesXml(extRefs);
|
|
2382
|
-
wbXml = wbXml.replace("<!--EXTERNAL_REFS-->", extRefsXml);
|
|
2383
|
-
} else wbXml = wbXml.replace("<!--EXTERNAL_REFS-->", "");
|
|
2384
|
-
mapping["Workbook"] = {
|
|
2385
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${wbXml}`,
|
|
2386
|
-
path: "xl/workbook.xml"
|
|
2387
|
-
};
|
|
2388
|
-
mapping["WorkbookRelationships"] = {
|
|
2389
|
-
data: XML_DECL + ctx.workbookRels.serialize(),
|
|
2390
|
-
path: "xl/_rels/workbook.xml.rels"
|
|
2391
|
-
};
|
|
2392
|
-
if (ctx.sharedStrings.count > 0) mapping["SharedStrings"] = {
|
|
2393
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${sharedStringsDesc.stringify(ctx.sharedStrings.toDescriptorOptions(), ctx)}`,
|
|
2394
|
-
path: "xl/sharedStrings.xml"
|
|
2395
|
-
};
|
|
2396
|
-
mapping["Styles"] = {
|
|
2397
|
-
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${stylesDesc.stringify({ styles: ctx.styles }, ctx)}`,
|
|
2398
|
-
path: "xl/styles.xml"
|
|
2399
|
-
};
|
|
2400
|
-
mapping["Theme"] = {
|
|
2401
|
-
data: XML_DECL + createThemeXml(),
|
|
2402
|
-
path: "xl/theme/theme1.xml"
|
|
2403
|
-
};
|
|
2404
|
-
for (let i = 0; i < ctx.charts.array.length; i++) {
|
|
2405
|
-
const chartData = ctx.charts.array[i];
|
|
2406
|
-
mapping[`Chart${i}`] = {
|
|
2407
|
-
data: XML_DECL + chartData.chartSpaceXml,
|
|
2408
|
-
path: `xl/charts/chart${i + 1}.xml`
|
|
2409
|
-
};
|
|
2410
|
-
ctx.contentTypes.addChart(i + 1);
|
|
2411
|
-
}
|
|
2412
|
-
if (calcCells.length > 0) {
|
|
2413
|
-
mapping["CalcChain"] = {
|
|
2414
|
-
data: calcChainDesc.stringify({ cells: calcCells }, ctx) ?? "",
|
|
2415
|
-
path: "xl/calcChain.xml"
|
|
2416
|
-
};
|
|
2417
|
-
ctx.contentTypes.addCalcChain();
|
|
2418
|
-
const calcChainRid = ctx.workbookRels.relationshipCount + 1;
|
|
2419
|
-
ctx.workbookRels.addRelationship(calcChainRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain", "calcChain.xml");
|
|
2420
|
-
}
|
|
2421
|
-
const imageExts = /* @__PURE__ */ new Set();
|
|
2422
|
-
for (const img of ctx.media.array) {
|
|
2423
|
-
const ext = img.fileName.endsWith(".png") ? "png" : "jpeg";
|
|
2424
|
-
if (!imageExts.has(ext)) {
|
|
2425
|
-
imageExts.add(ext);
|
|
2426
|
-
ctx.contentTypes.addImageType(ext);
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
mapping["ContentTypes"] = {
|
|
2430
|
-
data: XML_DECL + ctx.contentTypes.serialize(),
|
|
2431
|
-
path: "[Content_Types].xml"
|
|
2432
|
-
};
|
|
2433
|
-
const mediaFiles = [];
|
|
2434
|
-
for (const img of ctx.media.array) mediaFiles.push({
|
|
2435
|
-
data: img.data,
|
|
2436
|
-
path: `xl/media/${img.fileName}`
|
|
2437
|
-
});
|
|
2438
|
-
return compileMapping(mapping, overrides, mediaFiles, mediaLevel);
|
|
2439
|
-
}
|
|
2440
|
-
function buildFileRelationships() {
|
|
2441
|
-
const rels = new Relationships();
|
|
2442
|
-
rels.addRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "xl/workbook.xml");
|
|
2443
|
-
rels.addRelationship(2, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml");
|
|
2444
|
-
rels.addRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml");
|
|
2445
|
-
return rels;
|
|
2446
|
-
}
|
|
2447
|
-
function buildWorkbookRelationships(rels, wsCount, csCount) {
|
|
2448
|
-
let rid = 1;
|
|
2449
|
-
for (let i = 0; i < wsCount; i++) rels.addRelationship(rid++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet", `worksheets/sheet${i + 1}.xml`);
|
|
2450
|
-
for (let i = 0; i < csCount; i++) rels.addRelationship(rid++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet", `chartsheets/sheet${i + 1}.xml`);
|
|
2451
|
-
rels.addRelationship(rid++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
|
|
2452
|
-
rels.addRelationship(rid++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", "theme/theme1.xml");
|
|
2453
|
-
rels.addRelationship(rid++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings", "sharedStrings.xml");
|
|
2454
|
-
}
|
|
2455
|
-
function extractPivotSourceData(rows, sourceRef) {
|
|
2456
|
-
const parts = sourceRef.split(":");
|
|
2457
|
-
const startMatch = parts[0]?.match(/^([A-Z]+)(\d+)$/);
|
|
2458
|
-
const endMatch = parts[1]?.match(/^([A-Z]+)(\d+)$/);
|
|
2459
|
-
if (!startMatch) return {
|
|
2460
|
-
fieldNames: [],
|
|
2461
|
-
records: []
|
|
2462
|
-
};
|
|
2463
|
-
const startRow = parseInt(startMatch[2], 10) - 1;
|
|
2464
|
-
const endRow = endMatch ? parseInt(endMatch[2], 10) - 1 : startRow;
|
|
2465
|
-
const startCol = colLetterToIndex(startMatch[1]);
|
|
2466
|
-
const endCol = endMatch ? colLetterToIndex(endMatch[1]) : startCol;
|
|
2467
|
-
const colCount = endCol - startCol + 1;
|
|
2468
|
-
const headerRow = rows[startRow];
|
|
2469
|
-
const fieldNames = [];
|
|
2470
|
-
if (headerRow?.cells) for (let c = startCol; c <= endCol && c < headerRow.cells.length; c++) {
|
|
2471
|
-
const hv = headerRow.cells[c]?.value;
|
|
2472
|
-
fieldNames.push(typeof hv === "string" ? hv : typeof hv === "number" || typeof hv === "boolean" ? String(hv) : `Col${c}`);
|
|
2473
|
-
}
|
|
2474
|
-
const records = [];
|
|
2475
|
-
for (let r = startRow + 1; r <= endRow; r++) {
|
|
2476
|
-
const row = rows[r];
|
|
2477
|
-
if (!row?.cells) continue;
|
|
2478
|
-
const record = [];
|
|
2479
|
-
for (let c = startCol; c <= endCol; c++) {
|
|
2480
|
-
const val = row.cells[c]?.value;
|
|
2481
|
-
if (typeof val === "number") record.push(val);
|
|
2482
|
-
else if (val instanceof Date) record.push(val.getTime());
|
|
2483
|
-
else record.push(typeof val === "string" ? val : typeof val === "boolean" ? String(val) : "");
|
|
2484
|
-
}
|
|
2485
|
-
if (record.length === colCount) records.push(record);
|
|
2486
|
-
}
|
|
2487
|
-
return {
|
|
2488
|
-
fieldNames,
|
|
2489
|
-
records
|
|
2490
|
-
};
|
|
2491
|
-
}
|
|
2492
|
-
function colLetterToIndex(letters) {
|
|
2493
|
-
let col = 0;
|
|
2494
|
-
for (let i = 0; i < letters.length; i++) col = col * 26 + (letters.charCodeAt(i) - 64);
|
|
2495
|
-
return col - 1;
|
|
2496
|
-
}
|
|
2497
|
-
function renderPivotSheetData(pivotOpts, worksheetConfigs, sharedStrings, currentSheetName) {
|
|
2498
|
-
const rowCells = /* @__PURE__ */ new Map();
|
|
2499
|
-
let maxRow = 0;
|
|
2500
|
-
let maxCol = 0;
|
|
2501
|
-
let minRow = Infinity;
|
|
2502
|
-
let minCol = Infinity;
|
|
2503
|
-
for (const pt of pivotOpts) {
|
|
2504
|
-
const locMatch = (pt.location ?? "A3").match(/^([A-Z]+)(\d+)$/);
|
|
2505
|
-
if (!locMatch) continue;
|
|
2506
|
-
const startCol = colLetterToIndex(locMatch[1]);
|
|
2507
|
-
const startRow = parseInt(locMatch[2], 10);
|
|
2508
|
-
const rowFieldNames = pt.rows;
|
|
2509
|
-
const dataFields = pt.data;
|
|
2510
|
-
const sourceSheetName = pt.sourceSheet ?? currentSheetName;
|
|
2511
|
-
const sourceWsIdx = worksheetConfigs.findIndex((ws) => (ws.name ?? `Sheet${worksheetConfigs.indexOf(ws) + 1}`) === sourceSheetName);
|
|
2512
|
-
if (sourceWsIdx === -1) continue;
|
|
2513
|
-
const sourceData = extractPivotSourceData(worksheetConfigs[sourceWsIdx]?.rows ?? [], pt.source);
|
|
2514
|
-
if (sourceData.fieldNames.length === 0) continue;
|
|
2515
|
-
const fields = sourceData.fieldNames;
|
|
2516
|
-
const rowFieldIndices = rowFieldNames.map((n) => fields.indexOf(n));
|
|
2517
|
-
const dataFieldIndices = dataFields.map((df) => fields.indexOf(df.field));
|
|
2518
|
-
if (rowFieldIndices.some((idx) => idx === -1)) continue;
|
|
2519
|
-
if (dataFieldIndices.some((idx) => idx === -1)) continue;
|
|
2520
|
-
const groupMap = /* @__PURE__ */ new Map();
|
|
2521
|
-
for (const record of sourceData.records) {
|
|
2522
|
-
const groupKey = rowFieldIndices.map((fi) => String(record[fi])).join("|");
|
|
2523
|
-
let group = groupMap.get(groupKey);
|
|
2524
|
-
if (!group) {
|
|
2525
|
-
group = {
|
|
2526
|
-
keys: rowFieldIndices.map((fi) => {
|
|
2527
|
-
const v = record[fi];
|
|
2528
|
-
return typeof v === "string" || typeof v === "number" ? v : String(v ?? "");
|
|
2529
|
-
}),
|
|
2530
|
-
values: dataFieldIndices.map(() => [])
|
|
2531
|
-
};
|
|
2532
|
-
groupMap.set(groupKey, group);
|
|
2533
|
-
}
|
|
2534
|
-
for (let di = 0; di < dataFieldIndices.length; di++) {
|
|
2535
|
-
const val = record[dataFieldIndices[di]];
|
|
2536
|
-
if (typeof val === "number") group.values[di].push(val);
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
const colFieldIndices = (pt.columns ?? []).map((n) => fields.indexOf(n));
|
|
2540
|
-
const addCells = (rowIdx, cells) => {
|
|
2541
|
-
let arr = rowCells.get(rowIdx);
|
|
2542
|
-
if (!arr) {
|
|
2543
|
-
arr = [];
|
|
2544
|
-
rowCells.set(rowIdx, arr);
|
|
2545
|
-
}
|
|
2546
|
-
arr.push(...cells);
|
|
2547
|
-
minRow = Math.min(minRow, rowIdx);
|
|
2548
|
-
maxRow = Math.max(maxRow, rowIdx);
|
|
2549
|
-
};
|
|
2550
|
-
if (colFieldIndices.length > 0 && !colFieldIndices.some((idx) => idx === -1)) {
|
|
2551
|
-
const colUniqueVals = collectUniqueValues(sourceData.records, colFieldIndices[0]).map((v) => typeof v === "string" || typeof v === "number" ? String(v) : String(v ?? ""));
|
|
2552
|
-
const crossTabMap = /* @__PURE__ */ new Map();
|
|
2553
|
-
for (const record of sourceData.records) {
|
|
2554
|
-
const rowKey = rowFieldIndices.map((fi) => String(record[fi])).join("|");
|
|
2555
|
-
const colKey = colFieldIndices.map((fi) => String(record[fi])).join("|");
|
|
2556
|
-
let entry = crossTabMap.get(rowKey);
|
|
2557
|
-
if (!entry) {
|
|
2558
|
-
entry = {
|
|
2559
|
-
rowKeys: rowFieldIndices.map((fi) => {
|
|
2560
|
-
const v = record[fi];
|
|
2561
|
-
return typeof v === "string" || typeof v === "number" ? v : String(v ?? "");
|
|
2562
|
-
}),
|
|
2563
|
-
colData: /* @__PURE__ */ new Map(),
|
|
2564
|
-
rowTotals: dataFieldIndices.map(() => [])
|
|
2565
|
-
};
|
|
2566
|
-
crossTabMap.set(rowKey, entry);
|
|
2567
|
-
}
|
|
2568
|
-
let colValues = entry.colData.get(colKey);
|
|
2569
|
-
if (!colValues) {
|
|
2570
|
-
colValues = dataFieldIndices.map(() => []);
|
|
2571
|
-
entry.colData.set(colKey, colValues);
|
|
2572
|
-
}
|
|
2573
|
-
for (let di = 0; di < dataFieldIndices.length; di++) {
|
|
2574
|
-
const val = record[dataFieldIndices[di]];
|
|
2575
|
-
if (typeof val === "number") {
|
|
2576
|
-
colValues[di].push(val);
|
|
2577
|
-
entry.rowTotals[di].push(val);
|
|
2578
|
-
}
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
const numColVals = colUniqueVals.length;
|
|
2582
|
-
const endCol = startCol + (rowFieldNames.length + numColVals + 1) - 1;
|
|
2583
|
-
minCol = Math.min(minCol, startCol);
|
|
2584
|
-
maxCol = Math.max(maxCol, endCol);
|
|
2585
|
-
const headerCells = [];
|
|
2586
|
-
for (const rfName of rowFieldNames) {
|
|
2587
|
-
const cellRef = colIndexToLetter(startCol + headerCells.length) + startRow;
|
|
2588
|
-
const strIdx = sharedStrings.register(rfName);
|
|
2589
|
-
headerCells.push(`<c r="${cellRef}" t="s"><v>${strIdx}</v></c>`);
|
|
2590
|
-
}
|
|
2591
|
-
for (const cv of colUniqueVals) {
|
|
2592
|
-
const cellRef = colIndexToLetter(startCol + headerCells.length) + startRow;
|
|
2593
|
-
const strIdx = sharedStrings.register(cv);
|
|
2594
|
-
headerCells.push(`<c r="${cellRef}" t="s"><v>${strIdx}</v></c>`);
|
|
2595
|
-
}
|
|
2596
|
-
{
|
|
2597
|
-
const cellRef = colIndexToLetter(startCol + headerCells.length) + startRow;
|
|
2598
|
-
const df0 = dataFields[0];
|
|
2599
|
-
const subtotal = df0.summarize ?? "sum";
|
|
2600
|
-
const dfName = df0.name ?? `${subtotal === "sum" ? "Sum" : subtotal} of ${df0.field}`;
|
|
2601
|
-
const strIdx = sharedStrings.register(dfName);
|
|
2602
|
-
headerCells.push(`<c r="${cellRef}" t="s"><v>${strIdx}</v></c>`);
|
|
2603
|
-
}
|
|
2604
|
-
addCells(startRow, headerCells);
|
|
2605
|
-
let currentRow = startRow + 1;
|
|
2606
|
-
for (const [, entry] of crossTabMap) {
|
|
2607
|
-
const cells = [];
|
|
2608
|
-
for (let ri = 0; ri < entry.rowKeys.length; ri++) {
|
|
2609
|
-
const cellRef = colIndexToLetter(startCol + ri) + currentRow;
|
|
2610
|
-
const strIdx = sharedStrings.register(String(entry.rowKeys[ri]));
|
|
2611
|
-
cells.push(`<c r="${cellRef}" t="s"><v>${strIdx}</v></c>`);
|
|
2612
|
-
}
|
|
2613
|
-
for (let ci = 0; ci < numColVals; ci++) {
|
|
2614
|
-
const colKey = colUniqueVals[ci];
|
|
2615
|
-
const colValues = entry.colData.get(colKey);
|
|
2616
|
-
const cellRef = colIndexToLetter(startCol + (rowFieldNames.length + ci)) + currentRow;
|
|
2617
|
-
const subtotal = dataFields[0].summarize ?? "sum";
|
|
2618
|
-
const result = colValues ? aggregate(colValues[0], subtotal) : 0;
|
|
2619
|
-
cells.push(`<c r="${cellRef}"><v>${result}</v></c>`);
|
|
2620
|
-
}
|
|
2621
|
-
{
|
|
2622
|
-
const cellRef = colIndexToLetter(startCol + (rowFieldNames.length + numColVals)) + currentRow;
|
|
2623
|
-
const subtotal = dataFields[0].summarize ?? "sum";
|
|
2624
|
-
const result = aggregate(entry.rowTotals[0], subtotal);
|
|
2625
|
-
cells.push(`<c r="${cellRef}"><v>${result}</v></c>`);
|
|
2626
|
-
}
|
|
2627
|
-
addCells(currentRow, cells);
|
|
2628
|
-
currentRow++;
|
|
2629
|
-
}
|
|
2630
|
-
const gtCells = [];
|
|
2631
|
-
const gtStrIdx = sharedStrings.register("Grand Total");
|
|
2632
|
-
gtCells.push(`<c r="${colIndexToLetter(startCol)}${currentRow}" t="s"><v>${gtStrIdx}</v></c>`);
|
|
2633
|
-
for (let ci = 0; ci < numColVals; ci++) {
|
|
2634
|
-
const colKey = colUniqueVals[ci];
|
|
2635
|
-
const subtotal = dataFields[0].summarize ?? "sum";
|
|
2636
|
-
const colAllValues = [];
|
|
2637
|
-
for (const record of sourceData.records) if (colFieldIndices.map((fi) => String(record[fi])).join("|") === colKey) {
|
|
2638
|
-
const val = record[dataFieldIndices[0]];
|
|
2639
|
-
if (typeof val === "number") colAllValues.push(val);
|
|
2640
|
-
}
|
|
2641
|
-
const cellRef = colIndexToLetter(startCol + (rowFieldNames.length + ci)) + currentRow;
|
|
2642
|
-
const result = aggregate(colAllValues, subtotal);
|
|
2643
|
-
gtCells.push(`<c r="${cellRef}"><v>${result}</v></c>`);
|
|
2644
|
-
}
|
|
2645
|
-
{
|
|
2646
|
-
const subtotal = dataFields[0].summarize ?? "sum";
|
|
2647
|
-
const allValues = sourceData.records.map((r) => r[dataFieldIndices[0]]).filter((v) => typeof v === "number");
|
|
2648
|
-
const cellRef = colIndexToLetter(startCol + (rowFieldNames.length + numColVals)) + currentRow;
|
|
2649
|
-
const result = aggregate(allValues, subtotal);
|
|
2650
|
-
gtCells.push(`<c r="${cellRef}"><v>${result}</v></c>`);
|
|
2651
|
-
}
|
|
2652
|
-
addCells(currentRow, gtCells);
|
|
2653
|
-
} else {
|
|
2654
|
-
const endCol = startCol + rowFieldNames.length + dataFields.length - 1;
|
|
2655
|
-
minCol = Math.min(minCol, startCol);
|
|
2656
|
-
maxCol = Math.max(maxCol, endCol);
|
|
2657
|
-
const headerCells = [];
|
|
2658
|
-
for (const rfName of rowFieldNames) {
|
|
2659
|
-
const cellRef = colIndexToLetter(startCol + headerCells.length) + startRow;
|
|
2660
|
-
const strIdx = sharedStrings.register(rfName);
|
|
2661
|
-
headerCells.push(`<c r="${cellRef}" t="s"><v>${strIdx}</v></c>`);
|
|
2662
|
-
}
|
|
2663
|
-
for (const df of dataFields) {
|
|
2664
|
-
const cellRef = colIndexToLetter(startCol + headerCells.length) + startRow;
|
|
2665
|
-
const subtotal = df.summarize ?? "sum";
|
|
2666
|
-
const dfName = df.name ?? `${subtotal === "sum" ? "Sum" : subtotal} of ${df.field}`;
|
|
2667
|
-
const strIdx = sharedStrings.register(dfName);
|
|
2668
|
-
headerCells.push(`<c r="${cellRef}" t="s"><v>${strIdx}</v></c>`);
|
|
2669
|
-
}
|
|
2670
|
-
addCells(startRow, headerCells);
|
|
2671
|
-
let currentRow = startRow + 1;
|
|
2672
|
-
for (const [, group] of groupMap) {
|
|
2673
|
-
const cells = [];
|
|
2674
|
-
for (let ri = 0; ri < group.keys.length; ri++) {
|
|
2675
|
-
const cellRef = colIndexToLetter(startCol + ri) + currentRow;
|
|
2676
|
-
const strIdx = sharedStrings.register(String(group.keys[ri]));
|
|
2677
|
-
cells.push(`<c r="${cellRef}" t="s"><v>${strIdx}</v></c>`);
|
|
2678
|
-
}
|
|
2679
|
-
for (let di = 0; di < dataFields.length; di++) {
|
|
2680
|
-
const cellRef = colIndexToLetter(startCol + (rowFieldNames.length + di)) + currentRow;
|
|
2681
|
-
const subtotal = dataFields[di].summarize ?? "sum";
|
|
2682
|
-
const result = aggregate(group.values[di], subtotal);
|
|
2683
|
-
cells.push(`<c r="${cellRef}"><v>${result}</v></c>`);
|
|
2684
|
-
}
|
|
2685
|
-
addCells(currentRow, cells);
|
|
2686
|
-
currentRow++;
|
|
2687
|
-
}
|
|
2688
|
-
const gtCells = [];
|
|
2689
|
-
const gtStrIdx = sharedStrings.register("Grand Total");
|
|
2690
|
-
gtCells.push(`<c r="${colIndexToLetter(startCol)}${currentRow}" t="s"><v>${gtStrIdx}</v></c>`);
|
|
2691
|
-
for (let di = 0; di < dataFields.length; di++) {
|
|
2692
|
-
const cellRef = colIndexToLetter(startCol + (rowFieldNames.length + di)) + currentRow;
|
|
2693
|
-
const subtotal = dataFields[di].summarize ?? "sum";
|
|
2694
|
-
const result = aggregate(sourceData.records.map((r) => r[dataFieldIndices[di]]).filter((v) => typeof v === "number"), subtotal);
|
|
2695
|
-
gtCells.push(`<c r="${cellRef}"><v>${result}</v></c>`);
|
|
2696
|
-
}
|
|
2697
|
-
addCells(currentRow, gtCells);
|
|
2698
|
-
}
|
|
2699
|
-
}
|
|
2700
|
-
if (rowCells.size === 0) return {
|
|
2701
|
-
sheetData: "",
|
|
2702
|
-
dimensionRef: ""
|
|
2703
|
-
};
|
|
2704
|
-
const parts = ["<sheetData>"];
|
|
2705
|
-
const sortedRows = [...rowCells.entries()].sort((a, b) => a[0] - b[0]);
|
|
2706
|
-
for (const [rowIdx, cells] of sortedRows) {
|
|
2707
|
-
parts.push(`<row r="${rowIdx}" x14ac:dyDescent="0.25">`);
|
|
2708
|
-
parts.push(...cells);
|
|
2709
|
-
parts.push("</row>");
|
|
2710
|
-
}
|
|
2711
|
-
parts.push("</sheetData>");
|
|
2712
|
-
const dimensionRef = `${colIndexToLetter(minCol === Infinity ? 0 : minCol)}${minRow === Infinity ? 1 : minRow}:${colIndexToLetter(maxCol)}${maxRow}`;
|
|
2713
|
-
return {
|
|
2714
|
-
sheetData: parts.join(""),
|
|
2715
|
-
dimensionRef
|
|
2716
|
-
};
|
|
2717
|
-
}
|
|
2718
|
-
function colIndexToLetter(col) {
|
|
2719
|
-
let result = "";
|
|
2720
|
-
let n = col + 1;
|
|
2721
|
-
while (n > 0) {
|
|
2722
|
-
n--;
|
|
2723
|
-
result = String.fromCharCode(65 + n % 26) + result;
|
|
2724
|
-
n = Math.floor(n / 26);
|
|
2725
|
-
}
|
|
2726
|
-
return result;
|
|
2727
|
-
}
|
|
2728
|
-
function columnToLetter(col) {
|
|
2729
|
-
let result = "";
|
|
2730
|
-
let n = col;
|
|
2731
|
-
while (n > 0) {
|
|
2732
|
-
const remainder = (n - 1) % 26;
|
|
2733
|
-
result = String.fromCharCode(65 + remainder) + result;
|
|
2734
|
-
n = Math.floor((n - 1) / 26);
|
|
2735
|
-
}
|
|
2736
|
-
return result;
|
|
2737
|
-
}
|
|
2738
|
-
//#endregion
|
|
2739
|
-
//#region src/generate.ts
|
|
2740
|
-
/**
|
|
2741
|
-
* Pure function API for generating XLSX files.
|
|
2742
|
-
*
|
|
2743
|
-
* @module
|
|
2744
|
-
*/
|
|
2745
|
-
/** @internal Packer instance for XLSX generation. */
|
|
2746
|
-
const Packer = createPacker({
|
|
2747
|
-
compile: (options, overrides, mediaLevel) => compileWorkbook(options, overrides, mediaLevel),
|
|
2748
|
-
mimeType: OoxmlMimeType.XLSX
|
|
2749
|
-
});
|
|
2750
|
-
/**
|
|
2751
|
-
* Generate an XLSX file from pure JSON options.
|
|
2752
|
-
*
|
|
2753
|
-
* The output format is controlled by `packerOptions.type` (default: `"nodebuffer"` → Buffer).
|
|
2754
|
-
* For synchronous generation, use {@link generateWorkbookSync}. For streaming, use {@link generateWorkbookStream}.
|
|
2755
|
-
*
|
|
2756
|
-
* @param options - Workbook options (worksheets, styles, etc.)
|
|
2757
|
-
* @param packerOptions - Optional packer configuration (type, compression, overrides, etc.)
|
|
2758
|
-
*
|
|
2759
|
-
* @example
|
|
2760
|
-
* ```typescript
|
|
2761
|
-
* import { generateWorkbook } from "@office-open/xlsx";
|
|
2762
|
-
*
|
|
2763
|
-
* const buffer = await generateWorkbook({ worksheets: [...] });
|
|
2764
|
-
* const bytes = await generateWorkbook({ worksheets: [...] }, { type: "uint8array" });
|
|
2765
|
-
* const blob = await generateWorkbook({ worksheets: [...] }, { type: "blob" });
|
|
2766
|
-
* ```
|
|
2767
|
-
*/
|
|
2768
|
-
function generateWorkbook(options, packerOptions) {
|
|
2769
|
-
return Packer.pack(options, packerOptions);
|
|
2770
|
-
}
|
|
2771
|
-
/**
|
|
2772
|
-
* Synchronously generate an XLSX file from pure JSON options.
|
|
2773
|
-
*/
|
|
2774
|
-
function generateWorkbookSync(options, packerOptions) {
|
|
2775
|
-
return Packer.packSync(options, packerOptions);
|
|
2776
|
-
}
|
|
2777
|
-
/**
|
|
2778
|
-
* Generate an XLSX file as a `ReadableStream<Uint8Array>`.
|
|
2779
|
-
*/
|
|
2780
|
-
function generateWorkbookStream(options, packerOptions) {
|
|
2781
|
-
return Packer.toStream(options, packerOptions);
|
|
2782
|
-
}
|
|
2783
|
-
//#endregion
|
|
2784
|
-
export { commentsDesc as _, buildExternalReferencesXml as a, calcChainDesc as b, TableType as c, pivotCacheDefDesc as d, pivotCacheRecordsDesc as f, drawingDesc as g, externalLinkDesc as h, compileWorkbook as i, TotalsRowFunction as l, PivotFilterType as m, generateWorkbookStream as n, buildTablePartsXml as o, pivotTableDesc as p, generateWorkbookSync as r, workbookDesc as s, generateWorkbook as t, tableDesc as u, vmlNotesDesc as v, chartsheetDesc as y };
|
|
2785
|
-
|
|
2786
|
-
//# sourceMappingURL=generate-CmgPdwPP.mjs.map
|