javascript-excel 2.0.0-alpha.1 → 2.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/dist/csv-DyVH9y7S.cjs +647 -0
- package/dist/csv-pXfaputs.js +618 -0
- package/dist/csv.cjs +6 -622
- package/dist/csv.js +1 -618
- package/dist/dom.cjs +3 -27
- package/dist/dom.js +3 -27
- package/dist/index.cjs +561 -1358
- package/dist/index.d.cts +119 -4
- package/dist/index.d.ts +119 -4
- package/dist/index.js +556 -1356
- package/dist/iso-date-3TY1OlGd.cjs +57 -0
- package/dist/iso-date-CXnn-9mT.js +46 -0
- package/dist/{numfmt-DEm0sYBJ.js → numfmt-BBgB7iQA.js} +39 -9
- package/dist/{numfmt-B-TlCgr7.cjs → numfmt-Dv6AjopS.cjs} +44 -8
- package/dist/read-C6L7Nyy3.d.cts +78 -0
- package/dist/read-DDN5ZsPe.js +2909 -0
- package/dist/read-Ddkks7qC.d.ts +78 -0
- package/dist/read-Ym1voUct.cjs +2932 -0
- package/dist/read.cjs +5 -2898
- package/dist/read.d.cts +2 -75
- package/dist/read.d.ts +2 -75
- package/dist/read.js +1 -2895
- package/dist/{sheet-names-Cm-IhbBk.cjs → sheet-names-qpXsvMpM.cjs} +3 -2
- package/dist/{sheet-names-CDsVK15c.js → sheet-names-uT2EH5Ui.js} +3 -2
- package/dist/worker.cjs +236 -7
- package/dist/worker.d.cts +62 -5
- package/dist/worker.d.ts +62 -5
- package/dist/worker.js +235 -7
- package/dist/write-BOh9jfu1.cjs +1487 -0
- package/dist/write-DubvcG-x.js +1470 -0
- package/package.json +46 -12
- package/dist/iso-date-B22IvwL1.js +0 -21
- package/dist/iso-date-BSUsPSWO.cjs +0 -26
package/dist/index.cjs
CHANGED
|
@@ -1,1400 +1,600 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_errors = require("./errors-DOPrrGS4.cjs");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const FLAG_UTF8 = 2048;
|
|
9
|
-
const MAX_ENTRIES = 65534;
|
|
10
|
-
function zip64Required(what) {
|
|
11
|
-
return new require_errors.ValidationError("ZIP64_REQUIRED", `The archive needs zip64 (${what}), which the writer does not produce.`);
|
|
12
|
-
}
|
|
13
|
-
function isAscii(s) {
|
|
14
|
-
for (let i = 0; i < s.length; i++) if (s.charCodeAt(i) > 127) return false;
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
function toChunks(data) {
|
|
18
|
-
if (typeof data === "string") return [require_numfmt.encodeUtf8(data)];
|
|
19
|
-
if (data instanceof Uint8Array) return [data];
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
/** Writes the entries, in order, into one zip archive. */
|
|
23
|
-
async function writeZip(entries, options = {}) {
|
|
24
|
-
const codec = options.codec ?? require_numfmt.nativeCodec;
|
|
25
|
-
const defaultModified = options.modified ?? /* @__PURE__ */ new Date();
|
|
26
|
-
const seen = /* @__PURE__ */ new Set();
|
|
27
|
-
const written = [];
|
|
28
|
-
let offset = 0;
|
|
29
|
-
for await (const entry of entries) {
|
|
30
|
-
require_numfmt.throwIfAborted(options.signal);
|
|
31
|
-
const { name } = entry;
|
|
32
|
-
if (name.length === 0 || name.startsWith("/") || name.includes("\0") || name.includes("\\")) throw new Error(`Invalid zip entry name: ${JSON.stringify(name)}`);
|
|
33
|
-
if (seen.has(name)) throw new Error(`Duplicate zip entry name: ${name}`);
|
|
34
|
-
seen.add(name);
|
|
35
|
-
if (written.length >= MAX_ENTRIES) throw zip64Required("more than 65,534 entries");
|
|
36
|
-
const nameBytes = require_numfmt.encodeUtf8(name);
|
|
37
|
-
if (nameBytes.length > 65535) throw new Error(`Zip entry name too long: ${name.slice(0, 40)}...`);
|
|
38
|
-
let size = 0;
|
|
39
|
-
let crc = 0;
|
|
40
|
-
let kept = [];
|
|
41
|
-
async function* tap(src) {
|
|
42
|
-
for await (const chunk of src) {
|
|
43
|
-
size += chunk.length;
|
|
44
|
-
if (size > 4294967294) throw zip64Required(`entry ${name} over 4 GiB`);
|
|
45
|
-
crc = require_numfmt.crc32(chunk, crc);
|
|
46
|
-
if (kept) {
|
|
47
|
-
if (size <= 65536) kept.push(chunk);
|
|
48
|
-
else kept = void 0;
|
|
49
|
-
}
|
|
50
|
-
yield chunk;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const compression = entry.compression ?? options.compression ?? "deflate";
|
|
54
|
-
let method;
|
|
55
|
-
let data;
|
|
56
|
-
if (compression === "store") {
|
|
57
|
-
const parts = [];
|
|
58
|
-
for await (const chunk of tap(toChunks(entry.data))) parts.push(chunk);
|
|
59
|
-
method = 0;
|
|
60
|
-
data = require_numfmt.concatBytes(parts);
|
|
61
|
-
} else {
|
|
62
|
-
const deflated = await codec.deflateRaw(tap(toChunks(entry.data)), options.signal);
|
|
63
|
-
if (kept && deflated.length >= size) {
|
|
64
|
-
method = 0;
|
|
65
|
-
data = require_numfmt.concatBytes(kept);
|
|
66
|
-
} else {
|
|
67
|
-
method = 8;
|
|
68
|
-
data = deflated;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const { time, date } = require_numfmt.toDosDateTime(entry.modified ?? defaultModified);
|
|
72
|
-
const flags = isAscii(name) ? 0 : FLAG_UTF8;
|
|
73
|
-
written.push({
|
|
74
|
-
nameBytes,
|
|
75
|
-
flags,
|
|
76
|
-
method,
|
|
77
|
-
crc,
|
|
78
|
-
size,
|
|
79
|
-
data,
|
|
80
|
-
time,
|
|
81
|
-
date,
|
|
82
|
-
offset
|
|
83
|
-
});
|
|
84
|
-
offset += 30 + nameBytes.length + data.length;
|
|
85
|
-
if (offset > 4294967294) throw zip64Required("archive over 4 GiB");
|
|
86
|
-
}
|
|
87
|
-
const parts = [];
|
|
88
|
-
for (const w of written) {
|
|
89
|
-
const h = new require_numfmt.ByteWriter(30 + w.nameBytes.length);
|
|
90
|
-
h.u32(SIG_LOCAL);
|
|
91
|
-
h.u16(w.method === 8 ? 20 : 10);
|
|
92
|
-
h.u16(w.flags);
|
|
93
|
-
h.u16(w.method);
|
|
94
|
-
h.u16(w.time);
|
|
95
|
-
h.u16(w.date);
|
|
96
|
-
h.u32(w.crc);
|
|
97
|
-
h.u32(w.data.length);
|
|
98
|
-
h.u32(w.size);
|
|
99
|
-
h.u16(w.nameBytes.length);
|
|
100
|
-
h.u16(0);
|
|
101
|
-
h.raw(w.nameBytes);
|
|
102
|
-
parts.push(h.bytes, w.data);
|
|
103
|
-
}
|
|
104
|
-
const cdOffset = offset;
|
|
105
|
-
let cdSize = 0;
|
|
106
|
-
for (const w of written) {
|
|
107
|
-
const c = new require_numfmt.ByteWriter(46 + w.nameBytes.length);
|
|
108
|
-
c.u32(SIG_CENTRAL);
|
|
109
|
-
c.u16(20);
|
|
110
|
-
c.u16(w.method === 8 ? 20 : 10);
|
|
111
|
-
c.u16(w.flags);
|
|
112
|
-
c.u16(w.method);
|
|
113
|
-
c.u16(w.time);
|
|
114
|
-
c.u16(w.date);
|
|
115
|
-
c.u32(w.crc);
|
|
116
|
-
c.u32(w.data.length);
|
|
117
|
-
c.u32(w.size);
|
|
118
|
-
c.u16(w.nameBytes.length);
|
|
119
|
-
c.u16(0);
|
|
120
|
-
c.u16(0);
|
|
121
|
-
c.u16(0);
|
|
122
|
-
c.u16(0);
|
|
123
|
-
c.u32(0);
|
|
124
|
-
c.u32(w.offset);
|
|
125
|
-
c.raw(w.nameBytes);
|
|
126
|
-
parts.push(c.bytes);
|
|
127
|
-
cdSize += c.bytes.length;
|
|
128
|
-
}
|
|
129
|
-
if (cdOffset + cdSize > 4294967294) throw zip64Required("archive over 4 GiB");
|
|
130
|
-
const e = new require_numfmt.ByteWriter(22);
|
|
131
|
-
e.u32(SIG_EOCD);
|
|
132
|
-
e.u16(0);
|
|
133
|
-
e.u16(0);
|
|
134
|
-
e.u16(written.length);
|
|
135
|
-
e.u16(written.length);
|
|
136
|
-
e.u32(cdSize);
|
|
137
|
-
e.u32(cdOffset);
|
|
138
|
-
e.u16(0);
|
|
139
|
-
parts.push(e.bytes);
|
|
140
|
-
return require_numfmt.concatBytes(parts);
|
|
141
|
-
}
|
|
142
|
-
// src/internal/write/parts.ts
|
|
143
|
-
/**
|
|
144
|
-
* workbook.xml, defined names, document properties and the default theme
|
|
145
|
-
* (docs/api.md §5.1). Content types and relationships are in package.ts.
|
|
146
|
-
*/
|
|
147
|
-
const NS_MAIN$2 = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
148
|
-
const NS_REL$1 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
149
|
-
function workbookXml(w) {
|
|
150
|
-
let x = `${require_sheet_names.XML_DECL}<workbook xmlns="${NS_MAIN$2}" xmlns:r="${NS_REL$1}">` + (w.date1904 ? "<workbookPr date1904=\"1\"/>" : "<workbookPr/>") + `<bookViews><workbookView${w.activeSheet > 0 ? ` activeTab="${w.activeSheet}"` : ""}/></bookViews><sheets>`;
|
|
151
|
-
w.sheets.forEach((s, i) => {
|
|
152
|
-
const state = s.state === "visible" ? "" : ` state="${s.state}"`;
|
|
153
|
-
x += `<sheet name="${require_sheet_names.xmlAttr(s.name)}" sheetId="${i + 1}"${state} r:id="${s.relId}"/>`;
|
|
154
|
-
});
|
|
155
|
-
x += "</sheets>";
|
|
156
|
-
if (w.definedNames) x += w.definedNames;
|
|
157
|
-
if (w.fullCalcOnLoad) x += "<calcPr fullCalcOnLoad=\"1\"/>";
|
|
158
|
-
return `${x}</workbook>`;
|
|
159
|
-
}
|
|
160
|
-
function propertyError(message, details) {
|
|
161
|
-
return new require_errors.ValidationError("INVALID_PROPERTY", message, { details });
|
|
162
|
-
}
|
|
163
|
-
/** W3CDTF timestamp without milliseconds, as Excel writes. */
|
|
164
|
-
function w3cdtf(d, field) {
|
|
165
|
-
if (!(d instanceof Date) || !Number.isFinite(d.getTime())) throw propertyError(`Document property ${field} must be a valid Date.`, { property: field });
|
|
166
|
-
return d.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
167
|
-
}
|
|
168
|
-
function optString(props, key) {
|
|
169
|
-
const v = props[key];
|
|
170
|
-
if (v === void 0) return void 0;
|
|
171
|
-
if (typeof v !== "string") throw propertyError(`Document property ${key} must be a string.`, { property: key });
|
|
172
|
-
return v;
|
|
173
|
-
}
|
|
174
|
-
function coreXml(props, now) {
|
|
175
|
-
const el = (tag, key) => {
|
|
176
|
-
const v = optString(props, key);
|
|
177
|
-
return v === void 0 ? "" : `<${tag}>${require_sheet_names.xmlText(v)}</${tag}>`;
|
|
178
|
-
};
|
|
179
|
-
return `${require_sheet_names.XML_DECL}<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">` + el("dc:title", "title") + el("dc:subject", "subject") + el("dc:creator", "creator") + el("cp:keywords", "keywords") + el("dc:description", "description") + el("cp:lastModifiedBy", "lastModifiedBy") + el("cp:category", "category") + `<dcterms:created xsi:type="dcterms:W3CDTF">${w3cdtf(props.created ?? now, "created")}</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">${w3cdtf(props.modified ?? now, "modified")}</dcterms:modified></cp:coreProperties>`;
|
|
180
|
-
}
|
|
181
|
-
function appXml(props) {
|
|
182
|
-
const el = (tag, key, fallback) => {
|
|
183
|
-
const v = optString(props, key) ?? fallback;
|
|
184
|
-
return v === void 0 ? "" : `<${tag}>${require_sheet_names.xmlText(v)}</${tag}>`;
|
|
185
|
-
};
|
|
186
|
-
return `${require_sheet_names.XML_DECL}<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">` + el("Application", "application", "javascript-excel") + el("Manager", "manager") + el("Company", "company") + "</Properties>";
|
|
187
|
-
}
|
|
188
|
-
/** FMTID_UserDefinedProperties, required on every custom property. */
|
|
189
|
-
const FMTID_USER = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
|
|
190
|
-
function customXml(custom) {
|
|
191
|
-
const seen = /* @__PURE__ */ new Set();
|
|
192
|
-
let x = `${require_sheet_names.XML_DECL}<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">`;
|
|
193
|
-
custom.forEach((p, i) => {
|
|
194
|
-
if (typeof p?.name !== "string" || p.name.length === 0 || p.name.length > 255) throw propertyError("Custom property names must be 1 to 255 characters.", { index: i });
|
|
195
|
-
const key = p.name.toLowerCase();
|
|
196
|
-
if (seen.has(key)) throw propertyError(`Duplicate custom property ${p.name}.`, { property: p.name });
|
|
197
|
-
seen.add(key);
|
|
198
|
-
const v = p.value;
|
|
199
|
-
let typed;
|
|
200
|
-
if (typeof v === "string") typed = `<vt:lpwstr>${require_sheet_names.xmlText(v)}</vt:lpwstr>`;
|
|
201
|
-
else if (typeof v === "boolean") typed = `<vt:bool>${v ? "true" : "false"}</vt:bool>`;
|
|
202
|
-
else if (typeof v === "number") {
|
|
203
|
-
if (!Number.isFinite(v)) throw propertyError(`Custom property ${p.name} must be a finite number.`, { property: p.name });
|
|
204
|
-
typed = Number.isInteger(v) && v >= -2147483648 && v <= 2147483647 ? `<vt:i4>${v}</vt:i4>` : `<vt:r8>${require_sheet_names.num(v)}</vt:r8>`;
|
|
205
|
-
} else if (v instanceof Date) typed = `<vt:filetime>${w3cdtf(v, p.name)}</vt:filetime>`;
|
|
206
|
-
else throw propertyError(`Custom property ${p.name} has an unsupported value.`, { property: p.name });
|
|
207
|
-
x += `<property fmtid="${FMTID_USER}" pid="${i + 2}" name="${require_sheet_names.xmlAttr(p.name)}">${typed}</property>`;
|
|
208
|
-
});
|
|
209
|
-
return `${x}</Properties>`;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* A minimal, schema-complete DrawingML theme with the Office 2013–2022 colour
|
|
213
|
-
* scheme and Calibri / Calibri Light fonts, so `{ theme: n }` colours resolve
|
|
214
|
-
* to the colours users expect. The format scheme is the simplest valid one.
|
|
215
|
-
*/
|
|
216
|
-
const THEME_XML = `${require_sheet_names.XML_DECL}<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="44546A"/></a:dk2><a:lt2><a:srgbClr val="E7E6E6"/></a:lt2><a:accent1><a:srgbClr val="4472C4"/></a:accent1><a:accent2><a:srgbClr val="ED7D31"/></a:accent2><a:accent3><a:srgbClr val="A5A5A5"/></a:accent3><a:accent4><a:srgbClr val="FFC000"/></a:accent4><a:accent5><a:srgbClr val="5B9BD5"/></a:accent5><a:accent6><a:srgbClr val="70AD47"/></a:accent6><a:hlink><a:srgbClr val="0563C1"/></a:hlink><a:folHlink><a:srgbClr val="954F72"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Calibri Light"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst>` + "<a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill>".repeat(3) + "</a:fillStyleLst><a:lnStyleLst><a:ln w=\"6350\"><a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill></a:ln><a:ln w=\"12700\"><a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill></a:ln><a:ln w=\"19050\"><a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill></a:ln></a:lnStyleLst><a:effectStyleLst>" + "<a:effectStyle><a:effectLst/></a:effectStyle>".repeat(3) + "</a:effectStyleLst><a:bgFillStyleLst>" + "<a:solidFill><a:schemeClr val=\"phClr\"/></a:solidFill>".repeat(3) + "</a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>";
|
|
217
|
-
function nameError(message, details) {
|
|
218
|
-
return new require_errors.ValidationError("INVALID_DEFINED_NAME", message, { details });
|
|
219
|
-
}
|
|
220
|
-
const NAME_RE = /^[\p{L}_\\][\p{L}\p{N}_.\\?]*$/u;
|
|
221
|
-
const A1_LIKE = /^\$?([A-Za-z]{1,3})\$?([0-9]+)$/;
|
|
222
|
-
const R1C1_LIKE = /^[Rr]([0-9]*)([Cc]([0-9]*))?$|^[Cc][0-9]*$/;
|
|
223
|
-
function isCellLike(name) {
|
|
224
|
-
const m = A1_LIKE.exec(name);
|
|
225
|
-
if (!m) return false;
|
|
226
|
-
const letters = m[1].toUpperCase();
|
|
227
|
-
let col = 0;
|
|
228
|
-
for (const ch of letters) col = col * 26 + (ch.charCodeAt(0) - 64);
|
|
229
|
-
const row = Number(m[2]);
|
|
230
|
-
return col <= 16384 && row >= 1 && row <= 1048576;
|
|
231
|
-
}
|
|
3
|
+
const require_write = require("./write-BOh9jfu1.cjs");
|
|
4
|
+
const require_numfmt = require("./numfmt-Dv6AjopS.cjs");
|
|
5
|
+
const require_sheet_names = require("./sheet-names-qpXsvMpM.cjs");
|
|
6
|
+
const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
|
|
7
|
+
// src/dataset.ts
|
|
232
8
|
/**
|
|
233
|
-
*
|
|
234
|
-
* (autofilter database, print area, print titles). Names are unique per scope,
|
|
235
|
-
* case-insensitively. Returns the <definedNames> element, or ''.
|
|
236
|
-
*/
|
|
237
|
-
function definedNamesXml(user, builtins, sheetCount) {
|
|
238
|
-
const seen = /* @__PURE__ */ new Set();
|
|
239
|
-
const items = [];
|
|
240
|
-
const scopeKey = (name, sheet) => `${sheet ?? "wb"}\u0000${name.toLowerCase()}`;
|
|
241
|
-
if (user !== void 0 && !Array.isArray(user)) throw nameError("definedNames must be an array.", {});
|
|
242
|
-
(user ?? []).forEach((d, i) => {
|
|
243
|
-
if (typeof d !== "object" || d === null) throw nameError(`definedNames[${i}] must be an object.`, { index: i });
|
|
244
|
-
const { name } = d;
|
|
245
|
-
if (typeof name !== "string" || name.length === 0 || name.length > 255 || !NAME_RE.test(name) || isCellLike(name) || R1C1_LIKE.test(name)) throw nameError(`Defined name ${JSON.stringify(name)} is not a valid Excel name (start with a letter, '_' or '\\'; letters, digits, '.', '_'; no spaces; not a cell reference).`, {
|
|
246
|
-
index: i,
|
|
247
|
-
name
|
|
248
|
-
});
|
|
249
|
-
if (name.toLowerCase().startsWith("_xlnm.")) throw nameError(`Defined name ${name} is reserved; set print.printArea, print.printTitles or autoFilter instead.`, {
|
|
250
|
-
index: i,
|
|
251
|
-
name
|
|
252
|
-
});
|
|
253
|
-
if (d.sheet !== void 0 && (!Number.isInteger(d.sheet) || d.sheet < 0 || d.sheet >= sheetCount)) throw nameError(`Defined name ${name}: sheet ${String(d.sheet)} is not a sheet index.`, {
|
|
254
|
-
index: i,
|
|
255
|
-
name,
|
|
256
|
-
sheet: d.sheet
|
|
257
|
-
});
|
|
258
|
-
if (typeof d.ref !== "string" || d.ref.replace(/^=/, "").length === 0) throw nameError(`Defined name ${name}: ref must be a non-empty formula such as "'Sheet 1'!$A$1".`, {
|
|
259
|
-
index: i,
|
|
260
|
-
name
|
|
261
|
-
});
|
|
262
|
-
if (d.hidden !== void 0 && typeof d.hidden !== "boolean") throw nameError(`Defined name ${name}: hidden must be a boolean.`, {
|
|
263
|
-
index: i,
|
|
264
|
-
name
|
|
265
|
-
});
|
|
266
|
-
if (d.comment !== void 0 && typeof d.comment !== "string") throw nameError(`Defined name ${name}: comment must be a string.`, {
|
|
267
|
-
index: i,
|
|
268
|
-
name
|
|
269
|
-
});
|
|
270
|
-
const key = scopeKey(name, d.sheet);
|
|
271
|
-
if (seen.has(key)) throw nameError(`Defined name ${name} is defined twice in the same scope.`, {
|
|
272
|
-
index: i,
|
|
273
|
-
name
|
|
274
|
-
});
|
|
275
|
-
seen.add(key);
|
|
276
|
-
let attrs = ` name="${require_sheet_names.xmlAttr(name)}"`;
|
|
277
|
-
if (d.comment) attrs += ` comment="${require_sheet_names.xmlAttr(d.comment)}"`;
|
|
278
|
-
if (d.sheet !== void 0) attrs += ` localSheetId="${d.sheet}"`;
|
|
279
|
-
if (d.hidden) attrs += " hidden=\"1\"";
|
|
280
|
-
items.push(`<definedName${attrs}>${require_sheet_names.xstring(d.ref.replace(/^=/, ""))}</definedName>`);
|
|
281
|
-
});
|
|
282
|
-
for (const b of builtins) items.push(`<definedName name="${b.name}" localSheetId="${b.sheet}"${b.hidden ? " hidden=\"1\"" : ""}>${require_sheet_names.xstring(b.ref)}</definedName>`);
|
|
283
|
-
return items.length ? `<definedNames>${items.join("")}</definedNames>` : "";
|
|
284
|
-
}
|
|
285
|
-
// src/internal/write/style-registry.ts
|
|
286
|
-
/**
|
|
287
|
-
* Turns model styles into styles.xml (docs/api.md §3.5).
|
|
9
|
+
* Dataset builders (docs/api.md §4.3): `{ columns, data }` ↔ Sheet.
|
|
288
10
|
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* Excel requires.
|
|
11
|
+
* `fromDataset` lays out header rows (with header groups as merged cells),
|
|
12
|
+
* data rows and an optional totals row; `fromDatasets` stacks several blocks
|
|
13
|
+
* on one sheet; `toDataset` goes the other way for import.
|
|
293
14
|
*/
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const MAX_CELL_XFS = 64e3;
|
|
297
|
-
const PATTERNS = /* @__PURE__ */ new Set([
|
|
298
|
-
"none",
|
|
299
|
-
"solid",
|
|
300
|
-
"mediumGray",
|
|
301
|
-
"darkGray",
|
|
302
|
-
"lightGray",
|
|
303
|
-
"darkHorizontal",
|
|
304
|
-
"darkVertical",
|
|
305
|
-
"darkDown",
|
|
306
|
-
"darkUp",
|
|
307
|
-
"darkGrid",
|
|
308
|
-
"darkTrellis",
|
|
309
|
-
"lightHorizontal",
|
|
310
|
-
"lightVertical",
|
|
311
|
-
"lightDown",
|
|
312
|
-
"lightUp",
|
|
313
|
-
"lightGrid",
|
|
314
|
-
"lightTrellis",
|
|
315
|
-
"gray125",
|
|
316
|
-
"gray0625"
|
|
317
|
-
]);
|
|
318
|
-
const BORDER_STYLES = /* @__PURE__ */ new Set([
|
|
319
|
-
"none",
|
|
320
|
-
"thin",
|
|
321
|
-
"medium",
|
|
322
|
-
"thick",
|
|
323
|
-
"double",
|
|
324
|
-
"hair",
|
|
325
|
-
"dotted",
|
|
326
|
-
"dashed",
|
|
327
|
-
"dashDot",
|
|
328
|
-
"dashDotDot",
|
|
329
|
-
"mediumDashed",
|
|
330
|
-
"mediumDashDot",
|
|
331
|
-
"mediumDashDotDot",
|
|
332
|
-
"slantDashDot"
|
|
333
|
-
]);
|
|
334
|
-
const UNDERLINES = /* @__PURE__ */ new Set([
|
|
335
|
-
"single",
|
|
336
|
-
"double",
|
|
337
|
-
"singleAccounting",
|
|
338
|
-
"doubleAccounting"
|
|
339
|
-
]);
|
|
340
|
-
const VERT_ALIGNS = /* @__PURE__ */ new Set([
|
|
341
|
-
"superscript",
|
|
342
|
-
"subscript",
|
|
343
|
-
"baseline"
|
|
344
|
-
]);
|
|
345
|
-
const SCHEMES = /* @__PURE__ */ new Set([
|
|
346
|
-
"major",
|
|
347
|
-
"minor",
|
|
348
|
-
"none"
|
|
349
|
-
]);
|
|
350
|
-
const HORIZONTAL = /* @__PURE__ */ new Set([
|
|
351
|
-
"general",
|
|
352
|
-
"left",
|
|
353
|
-
"center",
|
|
354
|
-
"right",
|
|
355
|
-
"fill",
|
|
356
|
-
"justify",
|
|
357
|
-
"centerContinuous",
|
|
358
|
-
"distributed"
|
|
359
|
-
]);
|
|
360
|
-
const VERTICAL = /* @__PURE__ */ new Set([
|
|
361
|
-
"top",
|
|
362
|
-
"center",
|
|
363
|
-
"bottom",
|
|
364
|
-
"justify",
|
|
365
|
-
"distributed"
|
|
366
|
-
]);
|
|
367
|
-
const READING_ORDER = {
|
|
368
|
-
context: 0,
|
|
369
|
-
ltr: 1,
|
|
370
|
-
rtl: 2
|
|
371
|
-
};
|
|
372
|
-
var Checker = class {
|
|
373
|
-
ctx;
|
|
374
|
-
constructor(ctx) {
|
|
375
|
-
this.ctx = ctx;
|
|
376
|
-
}
|
|
377
|
-
fail(path, value, why, code = "INVALID_STYLE") {
|
|
378
|
-
const where = this.ctx.ref ? ` (${this.ctx.sheet ?? "?"}!${this.ctx.ref})` : this.ctx.sheet ? ` (${this.ctx.sheet})` : "";
|
|
379
|
-
throw new require_errors.ValidationError(code, `Invalid style ${path}: ${why}${where}.`, { details: {
|
|
380
|
-
path,
|
|
381
|
-
value,
|
|
382
|
-
...this.ctx.sheet !== void 0 && { sheet: this.ctx.sheet },
|
|
383
|
-
...this.ctx.ref !== void 0 && { ref: this.ctx.ref }
|
|
384
|
-
} });
|
|
385
|
-
}
|
|
386
|
-
bool(path, v) {
|
|
387
|
-
if (v === void 0) return void 0;
|
|
388
|
-
if (typeof v !== "boolean") this.fail(path, v, "expected a boolean");
|
|
389
|
-
return v;
|
|
390
|
-
}
|
|
391
|
-
number(path, v, min, max, integer = false) {
|
|
392
|
-
if (v === void 0) return void 0;
|
|
393
|
-
if (typeof v !== "number" || !Number.isFinite(v) || v < min || v > max || integer && !Number.isInteger(v)) this.fail(path, v, `expected ${integer ? "an integer" : "a number"} from ${min} to ${max}`);
|
|
394
|
-
return v;
|
|
395
|
-
}
|
|
396
|
-
oneOf(path, v, allowed) {
|
|
397
|
-
if (v === void 0) return void 0;
|
|
398
|
-
if (typeof v !== "string" || !allowed.has(v)) this.fail(path, v, `expected one of ${[...allowed].join(", ")}`);
|
|
399
|
-
return v;
|
|
400
|
-
}
|
|
401
|
-
color(path, c) {
|
|
402
|
-
if (c === void 0) return void 0;
|
|
403
|
-
if (typeof c === "string") return { rgb: this.argb(path, c) };
|
|
404
|
-
if (typeof c !== "object" || c === null) this.fail(path, c, "expected a colour");
|
|
405
|
-
if ("rgb" in c) return { rgb: this.argb(`${path}.rgb`, c.rgb) };
|
|
406
|
-
if ("theme" in c) {
|
|
407
|
-
const theme = this.number(`${path}.theme`, c.theme, 0, 11, true);
|
|
408
|
-
const tint = this.number(`${path}.tint`, c.tint, -1, 1);
|
|
409
|
-
return tint === void 0 || tint === 0 ? { theme } : {
|
|
410
|
-
theme,
|
|
411
|
-
tint
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
if ("indexed" in c) return { indexed: this.number(`${path}.indexed`, c.indexed, 0, 65, true) };
|
|
415
|
-
if ("auto" in c && c.auto === true) return { auto: true };
|
|
416
|
-
return this.fail(path, c, "expected a string, { rgb }, { theme, tint }, { indexed } or { auto: true }");
|
|
417
|
-
}
|
|
418
|
-
argb(path, s) {
|
|
419
|
-
if (typeof s !== "string") this.fail(path, s, "expected a hex colour string");
|
|
420
|
-
const hex = s.startsWith("#") ? s.slice(1) : s;
|
|
421
|
-
if (!/^(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(hex)) this.fail(path, s, "expected RRGGBB or AARRGGBB hex");
|
|
422
|
-
return (hex.length === 6 ? `FF${hex}` : hex).toUpperCase();
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
function colorAttrs(c) {
|
|
426
|
-
if ("rgb" in c) return ` rgb="${c.rgb}"`;
|
|
427
|
-
if ("theme" in c) return ` theme="${c.theme}"${c.tint !== void 0 ? ` tint="${require_sheet_names.num(c.tint)}"` : ""}`;
|
|
428
|
-
if ("indexed" in c) return ` indexed="${c.indexed}"`;
|
|
429
|
-
return ` auto="1"`;
|
|
430
|
-
}
|
|
431
|
-
/** Font body, shared by <font> (nameTag 'name') and rich-text <rPr> (nameTag 'rFont'). */
|
|
432
|
-
function fontXml(f, nameTag) {
|
|
433
|
-
let x = "";
|
|
434
|
-
if (f.bold) x += "<b/>";
|
|
435
|
-
if (f.italic) x += "<i/>";
|
|
436
|
-
if (f.strike) x += "<strike/>";
|
|
437
|
-
if (f.condense) x += "<condense/>";
|
|
438
|
-
if (f.extend) x += "<extend/>";
|
|
439
|
-
if (f.outline) x += "<outline/>";
|
|
440
|
-
if (f.shadow) x += "<shadow/>";
|
|
441
|
-
if (f.underline) x += f.underline === "single" ? "<u/>" : `<u val="${f.underline}"/>`;
|
|
442
|
-
if (f.vertAlign) x += `<vertAlign val="${f.vertAlign}"/>`;
|
|
443
|
-
x += `<sz val="${require_sheet_names.num(f.size)}"/>`;
|
|
444
|
-
if (f.color) x += `<color${colorAttrs(f.color)}/>`;
|
|
445
|
-
x += `<${nameTag} val="${require_sheet_names.xmlAttr(f.name)}"/>`;
|
|
446
|
-
if (f.family !== void 0) x += `<family val="${f.family}"/>`;
|
|
447
|
-
if (f.charset !== void 0) x += `<charset val="${f.charset}"/>`;
|
|
448
|
-
if (f.scheme) x += `<scheme val="${f.scheme}"/>`;
|
|
449
|
-
return x;
|
|
450
|
-
}
|
|
451
|
-
function fillXml(f) {
|
|
452
|
-
if (f.kind === "pattern") {
|
|
453
|
-
if (!f.fg && !f.bg) return `<fill><patternFill patternType="${f.pattern}"/></fill>`;
|
|
454
|
-
let x = `<fill><patternFill patternType="${f.pattern}">`;
|
|
455
|
-
if (f.fg) x += `<fgColor${colorAttrs(f.fg)}/>`;
|
|
456
|
-
if (f.bg) x += `<bgColor${colorAttrs(f.bg)}/>`;
|
|
457
|
-
return `${x}</patternFill></fill>`;
|
|
458
|
-
}
|
|
459
|
-
let attrs = f.gradient === "path" ? " type=\"path\"" : "";
|
|
460
|
-
if (f.degree !== void 0) attrs += ` degree="${require_sheet_names.num(f.degree)}"`;
|
|
461
|
-
for (const k of [
|
|
462
|
-
"left",
|
|
463
|
-
"right",
|
|
464
|
-
"top",
|
|
465
|
-
"bottom"
|
|
466
|
-
]) if (f[k] !== void 0) attrs += ` ${k}="${require_sheet_names.num(f[k])}"`;
|
|
467
|
-
const stops = f.stops.map((s) => `<stop position="${require_sheet_names.num(s.position)}"><color${colorAttrs(s.color)}/></stop>`).join("");
|
|
468
|
-
return `<fill><gradientFill${attrs}>${stops}</gradientFill></fill>`;
|
|
469
|
-
}
|
|
470
|
-
function borderXml(b) {
|
|
471
|
-
let attrs = "";
|
|
472
|
-
if (b.diagonalUp) attrs += " diagonalUp=\"1\"";
|
|
473
|
-
if (b.diagonalDown) attrs += " diagonalDown=\"1\"";
|
|
474
|
-
let x = `<border${attrs}>`;
|
|
475
|
-
for (const side of [
|
|
476
|
-
"left",
|
|
477
|
-
"right",
|
|
478
|
-
"top",
|
|
479
|
-
"bottom",
|
|
480
|
-
"diagonal"
|
|
481
|
-
]) {
|
|
482
|
-
const s = b[side];
|
|
483
|
-
if (!s) x += `<${side}/>`;
|
|
484
|
-
else if (!s.color) x += `<${side} style="${s.style}"/>`;
|
|
485
|
-
else x += `<${side} style="${s.style}"><color${colorAttrs(s.color)}/></${side}>`;
|
|
486
|
-
}
|
|
487
|
-
return `${x}</border>`;
|
|
15
|
+
function columnError(message, details = {}) {
|
|
16
|
+
return new require_errors.ValidationError("INVALID_COLUMN", message, { details });
|
|
488
17
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
size: 11,
|
|
494
|
-
color: { theme: 1 },
|
|
495
|
-
family: 2,
|
|
496
|
-
scheme: "minor"
|
|
497
|
-
};
|
|
498
|
-
var StyleRegistry = class {
|
|
499
|
-
defaultFont;
|
|
500
|
-
fonts = [];
|
|
501
|
-
fontIndex = /* @__PURE__ */ new Map();
|
|
502
|
-
fills = [];
|
|
503
|
-
fillIndex = /* @__PURE__ */ new Map();
|
|
504
|
-
borders = [];
|
|
505
|
-
borderIndex = /* @__PURE__ */ new Map();
|
|
506
|
-
numFmts = /* @__PURE__ */ new Map();
|
|
507
|
-
xfs = [];
|
|
508
|
-
xfIndex = /* @__PURE__ */ new Map();
|
|
509
|
-
/** Resolved-xf cache keyed by the identity of the style layers. */
|
|
510
|
-
layerCache = /* @__PURE__ */ new Map();
|
|
511
|
-
ids = /* @__PURE__ */ new WeakMap();
|
|
512
|
-
nextId = 1;
|
|
513
|
-
constructor(defaultFont) {
|
|
514
|
-
const c = new Checker({});
|
|
515
|
-
this.defaultFont = defaultFont ? this.normFont(c, "defaultFont", defaultFont, DEFAULT_FONT) : DEFAULT_FONT;
|
|
516
|
-
this.addFont(this.defaultFont);
|
|
517
|
-
this.addFill({
|
|
518
|
-
kind: "pattern",
|
|
519
|
-
pattern: "none"
|
|
520
|
-
});
|
|
521
|
-
this.addFill({
|
|
522
|
-
kind: "pattern",
|
|
523
|
-
pattern: "gray125"
|
|
524
|
-
});
|
|
525
|
-
this.addBorder({});
|
|
526
|
-
this.addXf({
|
|
527
|
-
numFmtId: 0,
|
|
528
|
-
fontId: 0,
|
|
529
|
-
fillId: 0,
|
|
530
|
-
borderId: 0,
|
|
531
|
-
alignment: "",
|
|
532
|
-
protection: ""
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
/** The workbook default font, normalised. */
|
|
536
|
-
get baseFont() {
|
|
537
|
-
return this.defaultFont;
|
|
538
|
-
}
|
|
539
|
-
id(o) {
|
|
540
|
-
if (!o) return 0;
|
|
541
|
-
let n = this.ids.get(o);
|
|
542
|
-
if (n === void 0) {
|
|
543
|
-
n = this.nextId++;
|
|
544
|
-
this.ids.set(o, n);
|
|
545
|
-
}
|
|
546
|
-
return n;
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* The cellXfs index for a cell, given its style layers (§3.5.7):
|
|
550
|
-
* sheet default → column → row → cell. `isDate` adds the default date format
|
|
551
|
-
* when no layer sets a number format.
|
|
552
|
-
*/
|
|
553
|
-
xfFor(layers, isDate, ctx) {
|
|
554
|
-
let key = isDate ? "d" : "";
|
|
555
|
-
let any = isDate;
|
|
556
|
-
for (const l of layers) {
|
|
557
|
-
key += `:${this.id(l)}`;
|
|
558
|
-
if (l) any = true;
|
|
559
|
-
}
|
|
560
|
-
if (!any) return 0;
|
|
561
|
-
const cached = this.layerCache.get(key);
|
|
562
|
-
if (cached !== void 0) return cached;
|
|
563
|
-
const merged = layers.length === 1 && layers[0] ? layers[0] : require_sheet_names.mergeStyles(...layers);
|
|
564
|
-
const index = this.resolve(merged, isDate, ctx);
|
|
565
|
-
this.layerCache.set(key, index);
|
|
566
|
-
return index;
|
|
567
|
-
}
|
|
568
|
-
/** Normalises a run font for rich text (merged over `base`), or undefined. */
|
|
569
|
-
runFont(font, base, ctx) {
|
|
570
|
-
if (!font) return void 0;
|
|
571
|
-
return this.normFont(new Checker(ctx), "richText.font", font, base);
|
|
572
|
-
}
|
|
573
|
-
/** The resolved font of a style (its font merged over the default font). */
|
|
574
|
-
fontOf(style, ctx) {
|
|
575
|
-
if (!style?.font) return this.defaultFont;
|
|
576
|
-
return this.normFont(new Checker(ctx), "font", style.font, this.defaultFont);
|
|
577
|
-
}
|
|
578
|
-
/** Validates a colour and returns its CT_Color attributes (e.g. ` rgb="FFFF0000"`). */
|
|
579
|
-
colorAttrs(path, color, ctx) {
|
|
580
|
-
const n = new Checker(ctx).color(path, color);
|
|
581
|
-
return n ? colorAttrs(n) : "";
|
|
582
|
-
}
|
|
583
|
-
get cellXfCount() {
|
|
584
|
-
return this.xfs.length;
|
|
585
|
-
}
|
|
586
|
-
resolve(style, isDate, ctx) {
|
|
587
|
-
const c = new Checker(ctx);
|
|
588
|
-
if (typeof style !== "object" || style === null) c.fail("style", style, "expected an object");
|
|
589
|
-
let numFmtId = this.numFmtId(c, style.numFmt);
|
|
590
|
-
if (isDate && style.numFmt === void 0) numFmtId = 14;
|
|
591
|
-
const fontId = style.font ? this.addFont(this.normFont(c, "font", style.font, this.defaultFont)) : 0;
|
|
592
|
-
const fill = style.fill === void 0 ? void 0 : this.normFill(c, style.fill);
|
|
593
|
-
const fillId = fill ? this.addFill(fill) : 0;
|
|
594
|
-
const borderId = style.border ? this.addBorder(this.normBorder(c, style.border)) : 0;
|
|
595
|
-
const alignment = style.alignment ? this.alignmentAttrs(c, style.alignment) : "";
|
|
596
|
-
const protection = style.protection ? this.protectionAttrs(c, style.protection) : "";
|
|
597
|
-
return this.addXf({
|
|
598
|
-
numFmtId,
|
|
599
|
-
fontId,
|
|
600
|
-
fillId,
|
|
601
|
-
borderId,
|
|
602
|
-
alignment,
|
|
603
|
-
protection
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
normFont(c, path, f, base) {
|
|
607
|
-
if (typeof f !== "object" || f === null) c.fail(path, f, "expected an object");
|
|
608
|
-
const out = { ...base };
|
|
609
|
-
if (f.name !== void 0) {
|
|
610
|
-
if (typeof f.name !== "string" || f.name.length === 0 || f.name.length > 31) c.fail(`${path}.name`, f.name, "expected a font name of 1 to 31 characters");
|
|
611
|
-
if (f.name !== base.name) {
|
|
612
|
-
delete out.scheme;
|
|
613
|
-
delete out.family;
|
|
614
|
-
}
|
|
615
|
-
out.name = f.name;
|
|
616
|
-
}
|
|
617
|
-
const size = c.number(`${path}.size`, f.size, 1, 409);
|
|
618
|
-
if (size !== void 0) out.size = size;
|
|
619
|
-
const color = c.color(`${path}.color`, f.color);
|
|
620
|
-
if (color) out.color = color;
|
|
621
|
-
for (const k of [
|
|
622
|
-
"bold",
|
|
623
|
-
"italic",
|
|
624
|
-
"strike",
|
|
625
|
-
"outline",
|
|
626
|
-
"shadow",
|
|
627
|
-
"condense",
|
|
628
|
-
"extend"
|
|
629
|
-
]) {
|
|
630
|
-
const v = c.bool(`${path}.${k}`, f[k]);
|
|
631
|
-
if (v === true) out[k] = true;
|
|
632
|
-
else if (v === false) delete out[k];
|
|
633
|
-
}
|
|
634
|
-
if (f.underline !== void 0) {
|
|
635
|
-
if (f.underline === true) out.underline = "single";
|
|
636
|
-
else if (f.underline === false) delete out.underline;
|
|
637
|
-
else out.underline = c.oneOf(`${path}.underline`, f.underline, UNDERLINES);
|
|
638
|
-
}
|
|
639
|
-
const va = c.oneOf(`${path}.vertAlign`, f.vertAlign, VERT_ALIGNS);
|
|
640
|
-
if (va) out.vertAlign = va;
|
|
641
|
-
const family = c.number(`${path}.family`, f.family, 0, 14, true);
|
|
642
|
-
if (family !== void 0) out.family = family;
|
|
643
|
-
const charset = c.number(`${path}.charset`, f.charset, 0, 255, true);
|
|
644
|
-
if (charset !== void 0) out.charset = charset;
|
|
645
|
-
const scheme = c.oneOf(`${path}.scheme`, f.scheme, SCHEMES);
|
|
646
|
-
if (scheme) out.scheme = scheme;
|
|
647
|
-
const ordered = {
|
|
648
|
-
name: out.name,
|
|
649
|
-
size: out.size
|
|
650
|
-
};
|
|
651
|
-
for (const k of [
|
|
652
|
-
"color",
|
|
653
|
-
"bold",
|
|
654
|
-
"italic",
|
|
655
|
-
"underline",
|
|
656
|
-
"strike",
|
|
657
|
-
"vertAlign",
|
|
658
|
-
"family",
|
|
659
|
-
"charset",
|
|
660
|
-
"scheme",
|
|
661
|
-
"outline",
|
|
662
|
-
"shadow",
|
|
663
|
-
"condense",
|
|
664
|
-
"extend"
|
|
665
|
-
]) if (out[k] !== void 0) ordered[k] = out[k];
|
|
666
|
-
return ordered;
|
|
667
|
-
}
|
|
668
|
-
normFill(c, f) {
|
|
669
|
-
if (typeof f === "string") return {
|
|
670
|
-
kind: "pattern",
|
|
671
|
-
pattern: "solid",
|
|
672
|
-
fg: { rgb: c.argb("fill", f) },
|
|
673
|
-
bg: { indexed: 64 }
|
|
674
|
-
};
|
|
675
|
-
if (typeof f !== "object" || f === null) return c.fail("fill", f, "expected a colour string or a fill object");
|
|
676
|
-
if (f.type === "gradient") {
|
|
677
|
-
const gradient = c.oneOf("fill.gradient", f.gradient, /* @__PURE__ */ new Set(["linear", "path"]));
|
|
678
|
-
if (!gradient) c.fail("fill.gradient", f.gradient, "required for a gradient fill");
|
|
679
|
-
if (!Array.isArray(f.stops) || f.stops.length < 2) c.fail("fill.stops", f.stops, "a gradient needs at least two stops");
|
|
680
|
-
const out = {
|
|
681
|
-
kind: "gradient",
|
|
682
|
-
gradient,
|
|
683
|
-
stops: f.stops.map((s, i) => ({
|
|
684
|
-
position: c.number(`fill.stops[${i}].position`, s.position, 0, 1) ?? c.fail(`fill.stops[${i}].position`, s.position, "required"),
|
|
685
|
-
color: c.color(`fill.stops[${i}].color`, s.color) ?? c.fail(`fill.stops[${i}].color`, s.color, "required")
|
|
686
|
-
}))
|
|
687
|
-
};
|
|
688
|
-
const degree = c.number("fill.degree", f.degree, -360, 360);
|
|
689
|
-
if (degree !== void 0) out.degree = degree;
|
|
690
|
-
for (const k of [
|
|
691
|
-
"left",
|
|
692
|
-
"right",
|
|
693
|
-
"top",
|
|
694
|
-
"bottom"
|
|
695
|
-
]) {
|
|
696
|
-
const v = c.number(`fill.${k}`, f[k], 0, 1);
|
|
697
|
-
if (v !== void 0) out[k] = v;
|
|
698
|
-
}
|
|
699
|
-
return out;
|
|
700
|
-
}
|
|
701
|
-
if (f.type !== void 0 && f.type !== "pattern") c.fail("fill.type", f.type, "expected 'pattern' or 'gradient'");
|
|
702
|
-
const pattern = c.oneOf("fill.pattern", f.pattern, PATTERNS);
|
|
703
|
-
if (!pattern) return c.fail("fill.pattern", f.pattern, "required for a pattern fill");
|
|
704
|
-
if (pattern === "none") return void 0;
|
|
705
|
-
const out = {
|
|
706
|
-
kind: "pattern",
|
|
707
|
-
pattern
|
|
708
|
-
};
|
|
709
|
-
const fg = c.color("fill.fgColor", f.fgColor);
|
|
710
|
-
const bg = c.color("fill.bgColor", f.bgColor);
|
|
711
|
-
if (fg) out.fg = fg;
|
|
712
|
-
if (bg) out.bg = bg;
|
|
713
|
-
else if (pattern === "solid") out.bg = { indexed: 64 };
|
|
714
|
-
return out;
|
|
715
|
-
}
|
|
716
|
-
normSide(c, path, s) {
|
|
717
|
-
if (s === void 0) return void 0;
|
|
718
|
-
if (typeof s !== "object" || s === null) c.fail(path, s, "expected { style, color? }");
|
|
719
|
-
const style = c.oneOf(`${path}.style`, s.style, BORDER_STYLES);
|
|
720
|
-
if (!style) return c.fail(`${path}.style`, s.style, "required");
|
|
721
|
-
if (style === "none") return void 0;
|
|
722
|
-
const color = c.color(`${path}.color`, s.color);
|
|
723
|
-
return color ? {
|
|
724
|
-
style,
|
|
725
|
-
color
|
|
726
|
-
} : { style };
|
|
727
|
-
}
|
|
728
|
-
normBorder(c, b) {
|
|
729
|
-
if (typeof b !== "object" || b === null) c.fail("border", b, "expected an object");
|
|
730
|
-
const out = {};
|
|
731
|
-
for (const side of [
|
|
732
|
-
"left",
|
|
733
|
-
"right",
|
|
734
|
-
"top",
|
|
735
|
-
"bottom",
|
|
736
|
-
"diagonal"
|
|
737
|
-
]) {
|
|
738
|
-
const s = this.normSide(c, `border.${side}`, b[side]);
|
|
739
|
-
if (s) out[side] = s;
|
|
740
|
-
}
|
|
741
|
-
if (c.bool("border.diagonalUp", b.diagonalUp)) out.diagonalUp = true;
|
|
742
|
-
if (c.bool("border.diagonalDown", b.diagonalDown)) out.diagonalDown = true;
|
|
743
|
-
return out;
|
|
744
|
-
}
|
|
745
|
-
alignmentAttrs(c, a) {
|
|
746
|
-
if (typeof a !== "object" || a === null) c.fail("alignment", a, "expected an object");
|
|
747
|
-
let x = "";
|
|
748
|
-
const h = c.oneOf("alignment.horizontal", a.horizontal, HORIZONTAL);
|
|
749
|
-
if (h) x += ` horizontal="${h}"`;
|
|
750
|
-
const v = c.oneOf("alignment.vertical", a.vertical, VERTICAL);
|
|
751
|
-
if (v) x += ` vertical="${v}"`;
|
|
752
|
-
if (a.rotation !== void 0) {
|
|
753
|
-
let r;
|
|
754
|
-
if (a.rotation === "vertical") r = 255;
|
|
755
|
-
else {
|
|
756
|
-
const deg = c.number("alignment.rotation", a.rotation, -90, 90, true);
|
|
757
|
-
r = deg >= 0 ? deg : 90 - deg;
|
|
758
|
-
}
|
|
759
|
-
if (r !== 0) x += ` textRotation="${r}"`;
|
|
760
|
-
}
|
|
761
|
-
if (c.bool("alignment.wrapText", a.wrapText)) x += " wrapText=\"1\"";
|
|
762
|
-
const indent = c.number("alignment.indent", a.indent, 0, 250, true);
|
|
763
|
-
if (indent) x += ` indent="${indent}"`;
|
|
764
|
-
if (c.bool("alignment.justifyLastLine", a.justifyLastLine)) x += " justifyLastLine=\"1\"";
|
|
765
|
-
if (c.bool("alignment.shrinkToFit", a.shrinkToFit)) x += " shrinkToFit=\"1\"";
|
|
766
|
-
if (a.readingOrder !== void 0) {
|
|
767
|
-
const ro = READING_ORDER[c.oneOf("alignment.readingOrder", a.readingOrder, new Set(Object.keys(READING_ORDER)))];
|
|
768
|
-
if (ro !== 0) x += ` readingOrder="${ro}"`;
|
|
769
|
-
}
|
|
770
|
-
return x;
|
|
771
|
-
}
|
|
772
|
-
protectionAttrs(c, p) {
|
|
773
|
-
if (typeof p !== "object" || p === null) c.fail("protection", p, "expected an object");
|
|
774
|
-
let x = "";
|
|
775
|
-
if (c.bool("protection.locked", p.locked) === false) x += " locked=\"0\"";
|
|
776
|
-
if (c.bool("protection.hidden", p.hidden) === true) x += " hidden=\"1\"";
|
|
777
|
-
return x;
|
|
778
|
-
}
|
|
779
|
-
numFmtId(c, f) {
|
|
780
|
-
if (f === void 0) return 0;
|
|
781
|
-
if (typeof f === "number") {
|
|
782
|
-
if (!Number.isInteger(f) || f < 0 || f > 163) c.fail("numFmt", f, "a built-in format id is an integer from 0 to 163", "INVALID_NUMFMT");
|
|
783
|
-
return f;
|
|
784
|
-
}
|
|
785
|
-
if (typeof f !== "string" || f.length === 0) return c.fail("numFmt", f, "expected a built-in id or a non-empty format code", "INVALID_NUMFMT");
|
|
786
|
-
if (f.toLowerCase() === "general") return 0;
|
|
787
|
-
let id = this.numFmts.get(f);
|
|
788
|
-
if (id === void 0) {
|
|
789
|
-
id = 164 + this.numFmts.size;
|
|
790
|
-
this.numFmts.set(f, id);
|
|
791
|
-
}
|
|
792
|
-
return id;
|
|
793
|
-
}
|
|
794
|
-
addFont(f) {
|
|
795
|
-
const k = keyOf(f);
|
|
796
|
-
let i = this.fontIndex.get(k);
|
|
797
|
-
if (i === void 0) {
|
|
798
|
-
i = this.fonts.length;
|
|
799
|
-
this.fonts.push(`<font>${fontXml(f, "name")}</font>`);
|
|
800
|
-
this.fontIndex.set(k, i);
|
|
801
|
-
}
|
|
802
|
-
return i;
|
|
803
|
-
}
|
|
804
|
-
addFill(f) {
|
|
805
|
-
const k = keyOf(f);
|
|
806
|
-
let i = this.fillIndex.get(k);
|
|
807
|
-
if (i === void 0) {
|
|
808
|
-
i = this.fills.length;
|
|
809
|
-
this.fills.push(fillXml(f));
|
|
810
|
-
this.fillIndex.set(k, i);
|
|
811
|
-
}
|
|
812
|
-
return i;
|
|
813
|
-
}
|
|
814
|
-
addBorder(b) {
|
|
815
|
-
const k = keyOf(b);
|
|
816
|
-
let i = this.borderIndex.get(k);
|
|
817
|
-
if (i === void 0) {
|
|
818
|
-
i = this.borders.length;
|
|
819
|
-
this.borders.push(borderXml(b));
|
|
820
|
-
this.borderIndex.set(k, i);
|
|
821
|
-
}
|
|
822
|
-
return i;
|
|
823
|
-
}
|
|
824
|
-
addXf(xf) {
|
|
825
|
-
const k = `${xf.numFmtId},${xf.fontId},${xf.fillId},${xf.borderId},${xf.alignment},${xf.protection}`;
|
|
826
|
-
let i = this.xfIndex.get(k);
|
|
827
|
-
if (i === void 0) {
|
|
828
|
-
if (this.xfs.length >= 64e3) throw new require_errors.ValidationError("TOO_MANY_STYLES", `More than ${MAX_CELL_XFS} distinct cell styles.`, { details: { max: MAX_CELL_XFS } });
|
|
829
|
-
i = this.xfs.length;
|
|
830
|
-
this.xfs.push(xf);
|
|
831
|
-
this.xfIndex.set(k, i);
|
|
832
|
-
}
|
|
833
|
-
return i;
|
|
834
|
-
}
|
|
835
|
-
toXml() {
|
|
836
|
-
const parts = [require_sheet_names.XML_DECL, `<styleSheet xmlns="${NS_MAIN$1}">`];
|
|
837
|
-
if (this.numFmts.size > 0) {
|
|
838
|
-
parts.push(`<numFmts count="${this.numFmts.size}">`);
|
|
839
|
-
for (const [code, id] of this.numFmts) parts.push(`<numFmt numFmtId="${id}" formatCode="${require_sheet_names.xmlAttr(code)}"/>`);
|
|
840
|
-
parts.push("</numFmts>");
|
|
841
|
-
}
|
|
842
|
-
parts.push(`<fonts count="${this.fonts.length}">`, ...this.fonts, "</fonts>");
|
|
843
|
-
parts.push(`<fills count="${this.fills.length}">`, ...this.fills, "</fills>");
|
|
844
|
-
parts.push(`<borders count="${this.borders.length}">`, ...this.borders, "</borders>");
|
|
845
|
-
parts.push("<cellStyleXfs count=\"1\"><xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\"/></cellStyleXfs>");
|
|
846
|
-
parts.push(`<cellXfs count="${this.xfs.length}">`);
|
|
847
|
-
for (const xf of this.xfs) {
|
|
848
|
-
let attrs = `numFmtId="${xf.numFmtId}" fontId="${xf.fontId}" fillId="${xf.fillId}" borderId="${xf.borderId}" xfId="0"`;
|
|
849
|
-
if (xf.numFmtId !== 0) attrs += " applyNumberFormat=\"1\"";
|
|
850
|
-
if (xf.fontId !== 0) attrs += " applyFont=\"1\"";
|
|
851
|
-
if (xf.fillId !== 0) attrs += " applyFill=\"1\"";
|
|
852
|
-
if (xf.borderId !== 0) attrs += " applyBorder=\"1\"";
|
|
853
|
-
if (xf.alignment) attrs += " applyAlignment=\"1\"";
|
|
854
|
-
if (xf.protection) attrs += " applyProtection=\"1\"";
|
|
855
|
-
const children = (xf.alignment ? `<alignment${xf.alignment}/>` : "") + (xf.protection ? `<protection${xf.protection}/>` : "");
|
|
856
|
-
parts.push(children ? `<xf ${attrs}>${children}</xf>` : `<xf ${attrs}/>`);
|
|
857
|
-
}
|
|
858
|
-
parts.push("</cellXfs>");
|
|
859
|
-
parts.push("<cellStyles count=\"1\"><cellStyle name=\"Normal\" xfId=\"0\" builtinId=\"0\"/></cellStyles>");
|
|
860
|
-
parts.push("<dxfs count=\"0\"/><tableStyles count=\"0\"/>");
|
|
861
|
-
parts.push("</styleSheet>");
|
|
862
|
-
return parts.join("");
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
// src/internal/write/sheet.ts
|
|
866
|
-
/**
|
|
867
|
-
* Worksheet XML and shared strings (docs/api.md §3.4).
|
|
868
|
-
*
|
|
869
|
-
* Sheet XML is produced as a stream of UTF-8 chunks, so a large sheet is never
|
|
870
|
-
* held as one string.
|
|
871
|
-
*/
|
|
872
|
-
const NS_MAIN = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
873
|
-
const NS_REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
874
|
-
/** Excel's limit on characters in one cell. */
|
|
875
|
-
const MAX_CELL_CHARS = 32767;
|
|
876
|
-
const ERROR_CODES = /* @__PURE__ */ new Set([
|
|
877
|
-
"#NULL!",
|
|
878
|
-
"#DIV/0!",
|
|
879
|
-
"#VALUE!",
|
|
880
|
-
"#REF!",
|
|
881
|
-
"#NAME?",
|
|
882
|
-
"#NUM!",
|
|
883
|
-
"#N/A"
|
|
18
|
+
const FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set([
|
|
19
|
+
"__proto__",
|
|
20
|
+
"prototype",
|
|
21
|
+
"constructor"
|
|
884
22
|
]);
|
|
885
|
-
/**
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
/** Number of cells that reference the table. */
|
|
892
|
-
count = 0;
|
|
893
|
-
/** Index of a plain string. */
|
|
894
|
-
plain(s) {
|
|
895
|
-
this.count++;
|
|
896
|
-
let i = this.index.get(s);
|
|
897
|
-
if (i === void 0) {
|
|
898
|
-
i = this.items.length;
|
|
899
|
-
this.items.push(`<si>${textElement(s)}</si>`);
|
|
900
|
-
this.index.set(s, i);
|
|
901
|
-
}
|
|
902
|
-
return i;
|
|
903
|
-
}
|
|
904
|
-
/** Index of rich text, given its serialised runs. */
|
|
905
|
-
rich(runsXml) {
|
|
906
|
-
this.count++;
|
|
907
|
-
const key = `\u0000${runsXml}`;
|
|
908
|
-
let i = this.index.get(key);
|
|
909
|
-
if (i === void 0) {
|
|
910
|
-
i = this.items.length;
|
|
911
|
-
this.items.push(`<si>${runsXml}</si>`);
|
|
912
|
-
this.index.set(key, i);
|
|
913
|
-
}
|
|
914
|
-
return i;
|
|
915
|
-
}
|
|
916
|
-
get uniqueCount() {
|
|
917
|
-
return this.items.length;
|
|
918
|
-
}
|
|
919
|
-
toXml() {
|
|
920
|
-
return `${require_sheet_names.XML_DECL}<sst xmlns="${NS_MAIN}" count="${this.count}" uniqueCount="${this.items.length}">${this.items.join("")}</sst>`;
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
function textElement(s) {
|
|
924
|
-
return require_sheet_names.needsPreserve(s) ? `<t xml:space="preserve">${require_sheet_names.xstring(s)}</t>` : `<t>${require_sheet_names.xstring(s)}</t>`;
|
|
925
|
-
}
|
|
926
|
-
function cellError(code, message, sheet, ref, extra) {
|
|
927
|
-
return new require_errors.ValidationError(code, `${message} (${sheet}!${ref}).`, { details: {
|
|
928
|
-
sheet,
|
|
929
|
-
ref,
|
|
930
|
-
...extra
|
|
931
|
-
} });
|
|
932
|
-
}
|
|
933
|
-
/** A value object `{ error }` or `{ richText }`, as opposed to a Cell. */
|
|
934
|
-
function isValueObject(v) {
|
|
935
|
-
return "error" in v || "richText" in v;
|
|
936
|
-
}
|
|
937
|
-
function typeOf(v) {
|
|
938
|
-
if (v === null || v === void 0) return "empty";
|
|
939
|
-
if (typeof v === "string") return "string";
|
|
940
|
-
if (typeof v === "number") return "number";
|
|
941
|
-
if (typeof v === "boolean") return "boolean";
|
|
942
|
-
if (v instanceof Date) return "date";
|
|
943
|
-
if (typeof v === "object" && "error" in v) return "error";
|
|
944
|
-
return "richText";
|
|
945
|
-
}
|
|
946
|
-
/**
|
|
947
|
-
* Validates a sheet's features, scans its cells for the used range (checking
|
|
948
|
-
* the format's row and column limits) and measures 'auto' column widths.
|
|
949
|
-
*/
|
|
950
|
-
function planSheet(sheet, index, tabSelected, styles, schemes) {
|
|
951
|
-
const features = new require_sheet_names.SheetFeatures(sheet, index, tabSelected, styles);
|
|
952
|
-
const rels = new require_sheet_names.Rels();
|
|
953
|
-
const plan = {
|
|
954
|
-
sheet,
|
|
955
|
-
features,
|
|
956
|
-
rels,
|
|
957
|
-
links: new require_sheet_names.SheetLinks(sheet.name, schemes, rels),
|
|
958
|
-
minRow: 1e400,
|
|
959
|
-
maxRow: -1,
|
|
960
|
-
minCol: 1e400,
|
|
961
|
-
maxCol: -1,
|
|
962
|
-
tabSelected
|
|
23
|
+
/** Parses 'a.b', 'items[0].name', "a['x.y']" and 'a["x"]' into segments. */
|
|
24
|
+
function parsePath(path) {
|
|
25
|
+
const segs = [];
|
|
26
|
+
let i = 0;
|
|
27
|
+
const fail = () => {
|
|
28
|
+
throw columnError(`Invalid path ${JSON.stringify(path)}.`, { path });
|
|
963
29
|
};
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
sheet: sheet.name,
|
|
980
|
-
row: r,
|
|
981
|
-
col: c
|
|
982
|
-
} });
|
|
983
|
-
used = true;
|
|
984
|
-
if (measuring) features.measure(c, require_sheet_names.cellText(cell));
|
|
985
|
-
if (c < plan.minCol) plan.minCol = c;
|
|
986
|
-
if (c > plan.maxCol) plan.maxCol = c;
|
|
987
|
-
}
|
|
988
|
-
if (used) {
|
|
989
|
-
if (r >= 1048576) throw new require_errors.ValidationError("OUT_OF_BOUNDS", `Sheet ${sheet.name}: row ${r + 1} is beyond row ${require_sheet_names.MAX_ROWS}.`, { details: {
|
|
990
|
-
sheet: sheet.name,
|
|
991
|
-
row: r
|
|
992
|
-
} });
|
|
993
|
-
if (r < plan.minRow) plan.minRow = r;
|
|
994
|
-
plan.maxRow = r;
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
return plan;
|
|
998
|
-
}
|
|
999
|
-
function planRowCount(plan) {
|
|
1000
|
-
return plan.maxRow < 0 ? 0 : plan.maxRow - plan.minRow + 1;
|
|
1001
|
-
}
|
|
1002
|
-
/** First and last row to write: rows with cells and rows with properties. */
|
|
1003
|
-
function rowSpan(plan) {
|
|
1004
|
-
let first = plan.maxRow < 0 ? 1e400 : plan.minRow;
|
|
1005
|
-
for (const r of plan.features.rowAttrs.keys()) if (r < first) first = r;
|
|
1006
|
-
return [first, Math.max(plan.maxRow, plan.features.maxPropRow)];
|
|
1007
|
-
}
|
|
1008
|
-
/** Streams the worksheet XML as UTF-8 chunks. `onRow` is called after each row with data. */
|
|
1009
|
-
async function* sheetXml(plan, ctx, onRow) {
|
|
1010
|
-
const { sheet, features, links } = plan;
|
|
1011
|
-
const name = sheet.name;
|
|
1012
|
-
const dimension = plan.maxRow < 0 ? "A1" : plan.minRow === plan.maxRow && plan.minCol === plan.maxCol ? `${require_sheet_names.encodeCol(plan.minCol)}${plan.minRow + 1}` : `${require_sheet_names.encodeCol(plan.minCol)}${plan.minRow + 1}:${require_sheet_names.encodeCol(plan.maxCol)}${plan.maxRow + 1}`;
|
|
1013
|
-
let buf = `${require_sheet_names.XML_DECL}<worksheet xmlns="${NS_MAIN}" xmlns:r="${NS_REL}">` + features.sheetPrXml + `<dimension ref="${dimension}"/>` + features.sheetViewsXml + features.sheetFormatPrXml + features.colsXml() + "<sheetData>";
|
|
1014
|
-
const colLetters = [];
|
|
1015
|
-
const letters = (c) => colLetters[c] ??= require_sheet_names.encodeCol(c);
|
|
1016
|
-
const rows = sheet.rows;
|
|
1017
|
-
const defaultStyle = sheet.defaultStyle;
|
|
1018
|
-
const colProps = sheet.colProps;
|
|
1019
|
-
const rowProps = sheet.rowProps;
|
|
1020
|
-
const rowAttrs = features.rowAttrs;
|
|
1021
|
-
const [firstRow, lastRow] = rowSpan(plan);
|
|
1022
|
-
for (let r = firstRow; r <= lastRow; r++) {
|
|
1023
|
-
const row = rows[r];
|
|
1024
|
-
const attrs = rowAttrs.get(r) ?? "";
|
|
1025
|
-
if (!row && !attrs) continue;
|
|
1026
|
-
const rowStyle = rowProps?.[r]?.style;
|
|
1027
|
-
const rowNum = r + 1;
|
|
1028
|
-
let rowXml = "";
|
|
1029
|
-
if (row) for (let c = 0; c < row.length; c++) {
|
|
1030
|
-
const input = row[c];
|
|
1031
|
-
if (input === void 0 || input === null) continue;
|
|
1032
|
-
const ref = `${letters(c)}${rowNum}`;
|
|
1033
|
-
rowXml += cellXml(input, ref, name, ctx, [
|
|
1034
|
-
defaultStyle,
|
|
1035
|
-
colProps?.[c]?.style,
|
|
1036
|
-
rowStyle
|
|
1037
|
-
]);
|
|
1038
|
-
links.add(ref, require_sheet_names.hyperlinkOf(input));
|
|
1039
|
-
}
|
|
1040
|
-
if (rowXml || attrs) {
|
|
1041
|
-
buf += rowXml ? `<row r="${rowNum}"${attrs}>${rowXml}</row>` : `<row r="${rowNum}"${attrs}/>`;
|
|
1042
|
-
if (rowXml) onRow();
|
|
1043
|
-
if (buf.length >= CHUNK_CHARS) {
|
|
1044
|
-
yield require_numfmt.encodeUtf8(buf);
|
|
1045
|
-
buf = "";
|
|
30
|
+
if (typeof path !== "string" || path.length === 0) fail();
|
|
31
|
+
while (i < path.length) {
|
|
32
|
+
if (path[i] === "[") {
|
|
33
|
+
const q = path[i + 1];
|
|
34
|
+
if (q === "'" || q === "\"") {
|
|
35
|
+
const end = path.indexOf(`${q}]`, i + 2);
|
|
36
|
+
if (end < 0) fail();
|
|
37
|
+
segs.push(path.slice(i + 2, end));
|
|
38
|
+
i = end + 2;
|
|
39
|
+
} else {
|
|
40
|
+
const end = path.indexOf("]", i);
|
|
41
|
+
const n = path.slice(i + 1, end);
|
|
42
|
+
if (end < 0 || !/^\d+$/.test(n)) fail();
|
|
43
|
+
segs.push(n);
|
|
44
|
+
i = end + 1;
|
|
1046
45
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
let formula;
|
|
1061
|
-
if (cell.formula !== void 0) {
|
|
1062
|
-
if (typeof cell.formula !== "string") throw cellError("INVALID_CELL", "formula must be a string", sheet, ref);
|
|
1063
|
-
formula = cell.formula.startsWith("=") ? cell.formula.slice(1) : cell.formula;
|
|
1064
|
-
if (formula.length === 0) throw cellError("INVALID_CELL", "formula is empty", sheet, ref);
|
|
1065
|
-
if (vtype === "richText") throw cellError("INVALID_CELL", "A formula's cached value cannot be rich text", sheet, ref);
|
|
1066
|
-
}
|
|
1067
|
-
if (cell.arrayRef !== void 0 && formula === void 0) throw cellError("INVALID_CELL", "arrayRef needs a formula", sheet, ref);
|
|
1068
|
-
const s = ctx.styles.xfFor([...layers, cell.style], vtype === "date", {
|
|
1069
|
-
sheet,
|
|
1070
|
-
ref
|
|
46
|
+
if (path[i] === ".") i++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
let j = i;
|
|
50
|
+
while (j < path.length && path[j] !== "." && path[j] !== "[") j++;
|
|
51
|
+
if (j === i) fail();
|
|
52
|
+
segs.push(path.slice(i, j));
|
|
53
|
+
i = path[j] === "." ? j + 1 : j;
|
|
54
|
+
if (path[j] === "." && i >= path.length) fail();
|
|
55
|
+
}
|
|
56
|
+
for (const s of segs) if (FORBIDDEN_SEGMENTS.has(s)) throw columnError(`Path ${JSON.stringify(path)} uses the forbidden segment ${s}.`, {
|
|
57
|
+
path,
|
|
58
|
+
segment: s
|
|
1071
59
|
});
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
60
|
+
return segs;
|
|
61
|
+
}
|
|
62
|
+
const own = (o, k) => o !== null && (typeof o === "object" || typeof o === "function") && Object.prototype.hasOwnProperty.call(o, k) ? o[k] : void 0;
|
|
63
|
+
function accessorOf(def, position) {
|
|
64
|
+
if ([
|
|
65
|
+
def.key !== void 0,
|
|
66
|
+
def.path !== void 0,
|
|
67
|
+
def.value !== void 0,
|
|
68
|
+
def.index !== void 0
|
|
69
|
+
].filter(Boolean).length > 1) throw columnError(`Column ${JSON.stringify(def.title ?? def.key ?? def.path)} has more than one accessor (key, path, value, index).`);
|
|
70
|
+
if (def.key !== void 0) {
|
|
71
|
+
if (typeof def.key !== "string") throw columnError("key must be a string.");
|
|
72
|
+
const key = def.key;
|
|
73
|
+
return (row) => own(row, key);
|
|
74
|
+
}
|
|
75
|
+
if (def.path !== void 0) {
|
|
76
|
+
const segs = parsePath(def.path);
|
|
77
|
+
return (row) => {
|
|
78
|
+
let v = row;
|
|
79
|
+
for (const s of segs) {
|
|
80
|
+
v = own(v, s);
|
|
81
|
+
if (v === void 0) return void 0;
|
|
1080
82
|
}
|
|
1081
|
-
|
|
1082
|
-
}
|
|
1083
|
-
if (vtype === "empty") {
|
|
1084
|
-
ctx.formulaWithoutValue = true;
|
|
1085
|
-
return `<c r="${ref}"${sAttr}>${f}</c>`;
|
|
1086
|
-
}
|
|
1087
|
-
const { t, v } = scalar(value, vtype, sheet, ref, ctx, true);
|
|
1088
|
-
return `<c r="${ref}"${sAttr}${t}>${f}<v>${v}</v></c>`;
|
|
1089
|
-
}
|
|
1090
|
-
if (vtype === "empty") return `<c r="${ref}"${sAttr}/>`;
|
|
1091
|
-
if (vtype === "string") {
|
|
1092
|
-
const str = value;
|
|
1093
|
-
if (str.length > 32767) throw cellError("STRING_TOO_LONG", `Text longer than ${MAX_CELL_CHARS} characters`, sheet, ref, { length: str.length });
|
|
1094
|
-
if (ctx.strings) return `<c r="${ref}"${sAttr} t="s"><v>${ctx.strings.plain(str)}</v></c>`;
|
|
1095
|
-
return `<c r="${ref}"${sAttr} t="inlineStr"><is>${textElement(str)}</is></c>`;
|
|
1096
|
-
}
|
|
1097
|
-
if (vtype === "richText") {
|
|
1098
|
-
const runs = richRunsXml(value, [...layers, cell.style], sheet, ref, ctx);
|
|
1099
|
-
if (ctx.strings) return `<c r="${ref}"${sAttr} t="s"><v>${ctx.strings.rich(runs)}</v></c>`;
|
|
1100
|
-
return `<c r="${ref}"${sAttr} t="inlineStr"><is>${runs}</is></c>`;
|
|
83
|
+
return v;
|
|
84
|
+
};
|
|
1101
85
|
}
|
|
1102
|
-
|
|
1103
|
-
|
|
86
|
+
if (def.value !== void 0) {
|
|
87
|
+
if (typeof def.value !== "function") throw columnError("value must be a function.");
|
|
88
|
+
const fn = def.value;
|
|
89
|
+
return (row, rowIndex) => fn(row, { rowIndex });
|
|
90
|
+
}
|
|
91
|
+
const index = def.index ?? position;
|
|
92
|
+
if (!Number.isInteger(index) || index < 0) throw columnError(`index must be a non-negative integer, got ${String(def.index)}.`);
|
|
93
|
+
const named = def.index !== void 0;
|
|
94
|
+
return (row) => {
|
|
95
|
+
if (Array.isArray(row)) return row[index];
|
|
96
|
+
if (named || row === null || row === void 0) return void 0;
|
|
97
|
+
throw columnError(`Column ${JSON.stringify(def.title ?? `#${position + 1}`)} has no accessor (key, path, value or index) and the data rows are objects.`);
|
|
98
|
+
};
|
|
1104
99
|
}
|
|
1105
|
-
|
|
1106
|
-
function
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
100
|
+
const PLAIN_NUMBER = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
101
|
+
function isCellObject(v) {
|
|
102
|
+
return typeof v === "object" && v !== null && !(v instanceof Date) && !("error" in v) && !("richText" in v);
|
|
103
|
+
}
|
|
104
|
+
function coerce(v, type) {
|
|
105
|
+
if (v === null || v === void 0 || type === void 0 || type === "auto") return {
|
|
106
|
+
value: v,
|
|
107
|
+
failed: false
|
|
108
|
+
};
|
|
109
|
+
switch (type) {
|
|
110
|
+
case "string":
|
|
111
|
+
if (v instanceof Date) return {
|
|
112
|
+
value: Number.isFinite(v.getTime()) ? require_iso_date.isoDate(v, "local") : "",
|
|
113
|
+
failed: false
|
|
114
|
+
};
|
|
1111
115
|
return {
|
|
1112
|
-
|
|
1113
|
-
|
|
116
|
+
value: typeof v === "object" ? require_sheet_names.cellText(v) : String(v),
|
|
117
|
+
failed: false
|
|
118
|
+
};
|
|
119
|
+
case "number":
|
|
120
|
+
if (typeof v === "number") return {
|
|
121
|
+
value: v,
|
|
122
|
+
failed: false
|
|
123
|
+
};
|
|
124
|
+
if (typeof v === "string" && PLAIN_NUMBER.test(v.trim())) return {
|
|
125
|
+
value: Number(v.trim()),
|
|
126
|
+
failed: false
|
|
1114
127
|
};
|
|
1115
|
-
}
|
|
1116
|
-
case "boolean": return {
|
|
1117
|
-
t: " t=\"b\"",
|
|
1118
|
-
v: value ? "1" : "0"
|
|
1119
|
-
};
|
|
1120
|
-
case "date": {
|
|
1121
|
-
let serial;
|
|
1122
|
-
try {
|
|
1123
|
-
serial = require_numfmt.dateToSerial(value, {
|
|
1124
|
-
date1904: ctx.date1904,
|
|
1125
|
-
dateZone: ctx.dateZone
|
|
1126
|
-
});
|
|
1127
|
-
} catch {
|
|
1128
|
-
throw cellError("INVALID_DATE", "Date is invalid or outside 1900-01-01..9999-12-31 (1904 system: 1904-01-01..)", sheet, ref);
|
|
1129
|
-
}
|
|
1130
128
|
return {
|
|
1131
|
-
|
|
1132
|
-
|
|
129
|
+
value: typeof v === "object" && !(v instanceof Date) ? require_sheet_names.cellText(v) : String(v instanceof Date ? require_iso_date.isoDate(v, "local") : v),
|
|
130
|
+
failed: true
|
|
131
|
+
};
|
|
132
|
+
case "boolean":
|
|
133
|
+
if (typeof v === "boolean") return {
|
|
134
|
+
value: v,
|
|
135
|
+
failed: false
|
|
136
|
+
};
|
|
137
|
+
if (typeof v === "string" && /^(true|false)$/i.test(v.trim())) return {
|
|
138
|
+
value: v.trim().toLowerCase() === "true",
|
|
139
|
+
failed: false
|
|
1133
140
|
};
|
|
1134
|
-
}
|
|
1135
|
-
case "error": {
|
|
1136
|
-
const code = value.error;
|
|
1137
|
-
if (typeof code !== "string" || !ERROR_CODES.has(code)) throw cellError("INVALID_CELL", `Unknown error value ${JSON.stringify(code)}`, sheet, ref);
|
|
1138
141
|
return {
|
|
1139
|
-
|
|
1140
|
-
|
|
142
|
+
value: typeof v === "object" ? require_sheet_names.cellText(v) : String(v),
|
|
143
|
+
failed: true
|
|
1141
144
|
};
|
|
1142
|
-
|
|
1143
|
-
case "
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
145
|
+
case "date":
|
|
146
|
+
case "datetime":
|
|
147
|
+
if (v instanceof Date) return Number.isFinite(v.getTime()) ? {
|
|
148
|
+
value: v,
|
|
149
|
+
failed: false
|
|
150
|
+
} : {
|
|
151
|
+
value: "Invalid Date",
|
|
152
|
+
failed: true
|
|
153
|
+
};
|
|
154
|
+
if (typeof v === "number" && Number.isFinite(v)) return {
|
|
155
|
+
value: new Date(v),
|
|
156
|
+
failed: false
|
|
157
|
+
};
|
|
158
|
+
if (typeof v === "string") {
|
|
159
|
+
const d = require_iso_date.parseIsoDate(v);
|
|
160
|
+
if (d) return {
|
|
161
|
+
value: d,
|
|
162
|
+
failed: false
|
|
163
|
+
};
|
|
164
|
+
}
|
|
1147
165
|
return {
|
|
1148
|
-
|
|
1149
|
-
|
|
166
|
+
value: typeof v === "object" ? require_sheet_names.cellText(v) : String(v),
|
|
167
|
+
failed: true
|
|
1150
168
|
};
|
|
1151
|
-
}
|
|
1152
|
-
default: throw cellError("INVALID_CELL", "Unsupported cell value", sheet, ref);
|
|
169
|
+
default: throw columnError(`Unknown column type ${JSON.stringify(type)}.`, { type });
|
|
1153
170
|
}
|
|
1154
171
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
172
|
+
const set = (g, r, c, v) => {
|
|
173
|
+
if (r >= 1048576 || c >= 16384) throw new require_errors.ValidationError("OUT_OF_BOUNDS", `Dataset does not fit the sheet: ${require_sheet_names.encodeCol(Math.min(c, require_sheet_names.MAX_COLS - 1))}${r + 1} is out of bounds.`);
|
|
174
|
+
(g.rows[r] ??= [])[c] = v;
|
|
175
|
+
};
|
|
176
|
+
const range = (r1, c1, r2, c2) => {
|
|
177
|
+
const a = require_sheet_names.encodeCell({
|
|
178
|
+
row: r1,
|
|
179
|
+
col: c1
|
|
180
|
+
});
|
|
181
|
+
const b = require_sheet_names.encodeCell({
|
|
182
|
+
row: r2,
|
|
183
|
+
col: c2
|
|
184
|
+
});
|
|
185
|
+
return a === b ? a : `${a}:${b}`;
|
|
186
|
+
};
|
|
187
|
+
function normalise(defs) {
|
|
188
|
+
const out = [];
|
|
189
|
+
for (const d of defs) {
|
|
190
|
+
if (!d) continue;
|
|
191
|
+
if (typeof d !== "object") throw columnError("A column definition must be an object.");
|
|
192
|
+
if ("children" in d && d.children !== void 0) {
|
|
193
|
+
if (!Array.isArray(d.children)) throw columnError("children must be an array.");
|
|
194
|
+
const children = normalise(d.children);
|
|
195
|
+
if (children.length) out.push({
|
|
196
|
+
group: d,
|
|
197
|
+
children
|
|
1168
198
|
});
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
199
|
+
} else out.push({ leaf: d });
|
|
200
|
+
}
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
const depthOf = (n) => "group" in n ? 1 + Math.max(...n.children.map(depthOf)) : 1;
|
|
204
|
+
const leafCount = (n) => "group" in n ? n.children.reduce((s, c) => s + leafCount(c), 0) : 1;
|
|
205
|
+
function titleCell(title, style) {
|
|
206
|
+
if (title === void 0) return style ? {
|
|
207
|
+
value: "",
|
|
208
|
+
style
|
|
209
|
+
} : "";
|
|
210
|
+
if (isCellObject(title)) return {
|
|
211
|
+
...title,
|
|
212
|
+
style: require_sheet_names.mergeStyles(style, title.style)
|
|
213
|
+
};
|
|
214
|
+
return style ? {
|
|
215
|
+
value: title,
|
|
216
|
+
style
|
|
217
|
+
} : title;
|
|
218
|
+
}
|
|
219
|
+
function layoutBlock(g, dataset, options, top, left, sheet) {
|
|
220
|
+
if (typeof dataset !== "object" || dataset === null || !Array.isArray(dataset.data)) throw columnError("A dataset needs a data array.");
|
|
221
|
+
const data = dataset.data;
|
|
222
|
+
let defs = dataset.columns;
|
|
223
|
+
let inferredArrays = false;
|
|
224
|
+
if (defs === void 0) {
|
|
225
|
+
const first = data.find((r) => r !== null && r !== void 0);
|
|
226
|
+
if (Array.isArray(first)) {
|
|
227
|
+
inferredArrays = true;
|
|
228
|
+
const width = data.reduce((m, r) => Array.isArray(r) ? Math.max(m, r.length) : m, 0);
|
|
229
|
+
defs = Array.from({ length: width }, (_, i) => ({ index: i }));
|
|
230
|
+
} else if (first !== void 0 && typeof first === "object") defs = Object.keys(first).map((key) => ({
|
|
231
|
+
title: key,
|
|
232
|
+
key
|
|
233
|
+
}));
|
|
234
|
+
else defs = [];
|
|
235
|
+
}
|
|
236
|
+
if (!Array.isArray(defs)) throw columnError("columns must be an array.");
|
|
237
|
+
const nodes = normalise(defs);
|
|
238
|
+
const leaves = [];
|
|
239
|
+
const collect = (n) => {
|
|
240
|
+
if ("group" in n) n.children.forEach(collect);
|
|
241
|
+
else {
|
|
242
|
+
const def = n.leaf;
|
|
243
|
+
leaves.push({
|
|
244
|
+
def,
|
|
245
|
+
col: leaves.length,
|
|
246
|
+
get: accessorOf(def, leaves.length)
|
|
1172
247
|
});
|
|
1173
|
-
|
|
1174
|
-
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
nodes.forEach(collect);
|
|
251
|
+
const headerOn = options.header !== false && !inferredArrays && leaves.length > 0;
|
|
252
|
+
const headerRows = headerOn ? Math.max(...nodes.map(depthOf)) : 0;
|
|
253
|
+
const baseHeader = options.headerStyle ?? { font: { bold: true } };
|
|
254
|
+
for (const { def, col } of leaves) {
|
|
255
|
+
const c = left + col;
|
|
256
|
+
if (def.width === "auto" || def.width === void 0 && options.autoWidth) g.autoCols.add(c);
|
|
257
|
+
else if (def.width !== void 0 && !g.widths.has(c)) g.widths.set(c, def.width);
|
|
258
|
+
if (def.hidden) g.hidden.add(c);
|
|
259
|
+
}
|
|
260
|
+
if (headerOn) {
|
|
261
|
+
let next = 0;
|
|
262
|
+
const place = (n, level) => {
|
|
263
|
+
if ("group" in n) {
|
|
264
|
+
const span = leafCount(n);
|
|
265
|
+
const c = left + next;
|
|
266
|
+
set(g, top + level, c, titleCell(n.group.title, require_sheet_names.mergeStyles(baseHeader, n.group.headerStyle)));
|
|
267
|
+
if (span > 1) g.merges.push(range(top + level, c, top + level, c + span - 1));
|
|
268
|
+
n.children.forEach((child) => place(child, level + 1));
|
|
269
|
+
} else {
|
|
270
|
+
const def = n.leaf;
|
|
271
|
+
const c = left + next++;
|
|
272
|
+
const cell = titleCell(def.title ?? def.key ?? def.path ?? "", require_sheet_names.mergeStyles(baseHeader, def.headerStyle));
|
|
273
|
+
set(g, top + level, c, cell);
|
|
274
|
+
if (level < headerRows - 1) g.merges.push(range(top + level, c, top + headerRows - 1, c));
|
|
275
|
+
if (g.autoCols.has(c)) g.measured.set(c, Math.max(g.measured.get(c) ?? 0, require_sheet_names.textWidth(require_sheet_names.cellText(cell))));
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
nodes.forEach((n) => place(n, 0));
|
|
279
|
+
}
|
|
280
|
+
const warn = options.onWarning ?? (() => {});
|
|
281
|
+
const dataTop = top + headerRows;
|
|
282
|
+
const sampleRows = typeof options.autoWidth === "object" && options.autoWidth.sampleRows !== void 0 ? options.autoWidth.sampleRows : 1e400;
|
|
283
|
+
const columnValues = leaves.map(() => []);
|
|
284
|
+
const columnStyles = leaves.map(({ def }) => {
|
|
285
|
+
const typeFmt = def.type === "date" ? { numFmt: 14 } : def.type === "datetime" ? { numFmt: 22 } : void 0;
|
|
286
|
+
const merged = require_sheet_names.mergeStyles(typeFmt, def.style, def.numFmt !== void 0 ? { numFmt: def.numFmt } : void 0);
|
|
287
|
+
return Object.keys(merged).length ? merged : void 0;
|
|
288
|
+
});
|
|
289
|
+
const rowMerges = /* @__PURE__ */ new WeakMap();
|
|
290
|
+
const styleFor = (col, rowStyle, cellStyle) => {
|
|
291
|
+
if (cellStyle) return require_sheet_names.mergeStyles(columnStyles[col], rowStyle, cellStyle);
|
|
292
|
+
if (!rowStyle) return columnStyles[col];
|
|
293
|
+
let perColumn = rowMerges.get(rowStyle);
|
|
294
|
+
if (!perColumn) rowMerges.set(rowStyle, perColumn = []);
|
|
295
|
+
if (!(col in perColumn)) perColumn[col] = require_sheet_names.mergeStyles(columnStyles[col], rowStyle);
|
|
296
|
+
return perColumn[col];
|
|
297
|
+
};
|
|
298
|
+
data.forEach((row, i) => {
|
|
299
|
+
const r = dataTop + i;
|
|
300
|
+
const rowStyle = options.rowStyle?.(row, i);
|
|
301
|
+
for (const { def, col, get } of leaves) {
|
|
302
|
+
const c = left + col;
|
|
303
|
+
const refOf = () => require_sheet_names.encodeCell({
|
|
304
|
+
row: r,
|
|
305
|
+
col: c
|
|
306
|
+
});
|
|
307
|
+
const raw = get(row, i);
|
|
308
|
+
let cell = isCellObject(raw) ? { ...raw } : { value: raw };
|
|
309
|
+
if (!cell.formula) {
|
|
310
|
+
const { value, failed } = coerce(cell.value, def.type);
|
|
311
|
+
if (failed) {
|
|
312
|
+
const ref = refOf();
|
|
313
|
+
warn({
|
|
314
|
+
code: "COERCION_FAILED",
|
|
315
|
+
message: `${sheet}!${ref}: value does not fit type '${def.type}'; written as text.`,
|
|
316
|
+
sheet,
|
|
317
|
+
ref
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
cell.value = value;
|
|
321
|
+
}
|
|
322
|
+
if (typeof cell.value === "number" && !Number.isFinite(cell.value)) {
|
|
323
|
+
const ref = refOf();
|
|
324
|
+
warn({
|
|
325
|
+
code: "NON_FINITE_NUMBER",
|
|
326
|
+
message: `${sheet}!${ref}: ${String(cell.value)} cannot be stored; the cell is left empty.`,
|
|
327
|
+
sheet,
|
|
328
|
+
ref
|
|
329
|
+
});
|
|
330
|
+
cell = {
|
|
331
|
+
...cell,
|
|
332
|
+
value: null
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
const style = styleFor(col, rowStyle, isCellObject(raw) ? raw.style : void 0);
|
|
336
|
+
const out = style !== void 0 && Object.keys(style).length > 0 ? {
|
|
337
|
+
...cell,
|
|
338
|
+
style
|
|
339
|
+
} : Object.keys(cell).length === 1 && "value" in cell ? cell.value : cell;
|
|
340
|
+
if (out !== void 0 && out !== null) set(g, r, c, out);
|
|
341
|
+
const v = cell.value;
|
|
342
|
+
if (v !== null && v !== void 0) columnValues[col].push(v);
|
|
343
|
+
if (i < sampleRows && g.autoCols.has(c)) g.measured.set(c, Math.max(g.measured.get(c) ?? 0, require_sheet_names.textWidth(require_sheet_names.cellText(out))));
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
const lastDataRow = dataTop + data.length - 1;
|
|
347
|
+
const hasTotals = leaves.some(({ def }) => def.total !== void 0);
|
|
348
|
+
let lastRow = Math.max(top + headerRows - 1, lastDataRow);
|
|
349
|
+
if (hasTotals) {
|
|
350
|
+
const r = lastDataRow + 1;
|
|
351
|
+
const totalsStyle = options.totals?.style;
|
|
352
|
+
leaves.forEach(({ def, col }, k) => {
|
|
353
|
+
const c = left + col;
|
|
354
|
+
const values = columnValues[col];
|
|
355
|
+
const dataRange = data.length ? range(dataTop, c, lastDataRow, c) : "";
|
|
356
|
+
let cell;
|
|
357
|
+
if (def.total === void 0) {
|
|
358
|
+
if (k !== 0 || options.totals?.label === void 0) return;
|
|
359
|
+
cell = {
|
|
360
|
+
value: options.totals.label,
|
|
361
|
+
...totalsStyle ? { style: totalsStyle } : {}
|
|
362
|
+
};
|
|
363
|
+
} else {
|
|
364
|
+
cell = totalCell(def.total, dataRange, values);
|
|
365
|
+
const base = def.total === "count" ? {
|
|
366
|
+
...columnStyles[col],
|
|
367
|
+
numFmt: void 0
|
|
368
|
+
} : columnStyles[col];
|
|
369
|
+
const cellStyle = isCellObject(cell) ? cell.style : void 0;
|
|
370
|
+
const style = require_sheet_names.mergeStyles(base, totalsStyle, cellStyle);
|
|
371
|
+
if (Object.keys(style).length) cell = isCellObject(cell) ? {
|
|
372
|
+
...cell,
|
|
373
|
+
style
|
|
374
|
+
} : {
|
|
375
|
+
value: cell,
|
|
376
|
+
style
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
set(g, r, c, cell);
|
|
380
|
+
if (g.autoCols.has(c)) g.measured.set(c, Math.max(g.measured.get(c) ?? 0, require_sheet_names.textWidth(require_sheet_names.cellText(cell))));
|
|
381
|
+
});
|
|
382
|
+
lastRow = r;
|
|
1175
383
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
384
|
+
return {
|
|
385
|
+
headerRows,
|
|
386
|
+
firstRow: top,
|
|
387
|
+
lastHeaderRow: top + headerRows - 1,
|
|
388
|
+
lastDataRow: Math.max(lastDataRow, top + headerRows - 1),
|
|
389
|
+
firstCol: left,
|
|
390
|
+
lastCol: left + Math.max(leaves.length, 1) - 1,
|
|
391
|
+
lastRow
|
|
392
|
+
};
|
|
1178
393
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
empty: "must be a non-empty string",
|
|
1186
|
-
"too-long": "is longer than 31 characters",
|
|
1187
|
-
"forbidden-char": "contains one of \\ / ? * [ ] :",
|
|
1188
|
-
apostrophe: "starts or ends with an apostrophe",
|
|
1189
|
-
reserved: "'History' is reserved by Excel"
|
|
394
|
+
const SUBTOTAL = {
|
|
395
|
+
sum: 109,
|
|
396
|
+
average: 101,
|
|
397
|
+
count: 103,
|
|
398
|
+
min: 105,
|
|
399
|
+
max: 104
|
|
1190
400
|
};
|
|
1191
|
-
function
|
|
1192
|
-
const
|
|
1193
|
-
|
|
401
|
+
function numeric(values) {
|
|
402
|
+
const out = [];
|
|
403
|
+
for (const v of values) if (typeof v === "number") out.push(v);
|
|
404
|
+
else if (v instanceof Date) try {
|
|
405
|
+
out.push(require_numfmt.dateToSerial(v));
|
|
406
|
+
} catch {}
|
|
407
|
+
return out;
|
|
408
|
+
}
|
|
409
|
+
function totalCell(total, dataRange, values) {
|
|
410
|
+
if (typeof total === "function") return total({
|
|
411
|
+
range: dataRange,
|
|
412
|
+
values
|
|
413
|
+
});
|
|
414
|
+
if (typeof total === "string" && total in SUBTOTAL) {
|
|
415
|
+
const nums = numeric(values);
|
|
416
|
+
let cached;
|
|
417
|
+
switch (total) {
|
|
418
|
+
case "sum":
|
|
419
|
+
cached = nums.reduce((a, b) => a + b, 0);
|
|
420
|
+
break;
|
|
421
|
+
case "average":
|
|
422
|
+
cached = nums.length ? nums.reduce((a, b) => a + b, 0) / nums.length : { error: "#DIV/0!" };
|
|
423
|
+
break;
|
|
424
|
+
case "count":
|
|
425
|
+
cached = values.length;
|
|
426
|
+
break;
|
|
427
|
+
case "min":
|
|
428
|
+
cached = nums.length ? Math.min(...nums) : 0;
|
|
429
|
+
break;
|
|
430
|
+
default: cached = nums.length ? Math.max(...nums) : 0;
|
|
431
|
+
}
|
|
432
|
+
return dataRange ? {
|
|
433
|
+
formula: `SUBTOTAL(${SUBTOTAL[total]},${dataRange})`,
|
|
434
|
+
value: cached
|
|
435
|
+
} : { value: cached };
|
|
436
|
+
}
|
|
437
|
+
return total;
|
|
438
|
+
}
|
|
439
|
+
function finish(g, options, first, name) {
|
|
440
|
+
const sheet = {
|
|
441
|
+
name,
|
|
442
|
+
rows: g.rows
|
|
443
|
+
};
|
|
444
|
+
if (g.merges.length) sheet.merges = g.merges;
|
|
445
|
+
const auto = typeof options.autoWidth === "object" ? options.autoWidth : {};
|
|
446
|
+
const min = auto.min ?? require_sheet_names.AUTO_WIDTH.min;
|
|
447
|
+
const max = Math.min(255, auto.max ?? require_sheet_names.AUTO_WIDTH.max);
|
|
448
|
+
const cols = /* @__PURE__ */ new Set([
|
|
449
|
+
...g.widths.keys(),
|
|
450
|
+
...g.autoCols,
|
|
451
|
+
...g.hidden
|
|
452
|
+
]);
|
|
453
|
+
if (cols.size) {
|
|
454
|
+
const colProps = [];
|
|
455
|
+
for (const c of [...cols].sort((a, b) => a - b)) {
|
|
456
|
+
const p = {};
|
|
457
|
+
const w = g.autoCols.has(c) ? Math.min(max, Math.max(min, (g.measured.get(c) ?? 0) + require_sheet_names.AUTO_WIDTH.padding)) : g.widths.get(c);
|
|
458
|
+
if (w !== void 0) p.width = w;
|
|
459
|
+
if (g.hidden.has(c)) p.hidden = true;
|
|
460
|
+
colProps[c] = p;
|
|
461
|
+
}
|
|
462
|
+
sheet.colProps = colProps;
|
|
463
|
+
}
|
|
464
|
+
const view = {};
|
|
465
|
+
if (options.rightToLeft) view.rightToLeft = true;
|
|
466
|
+
if (options.freezeHeader && first && first.headerRows > 0) view.freeze = { rows: first.lastHeaderRow + 1 };
|
|
467
|
+
if (Object.keys(view).length) sheet.view = view;
|
|
468
|
+
if (options.autoFilter && first && first.headerRows > 0) sheet.autoFilter = range(first.lastHeaderRow, first.firstCol, first.lastDataRow, first.lastCol);
|
|
469
|
+
return sheet;
|
|
470
|
+
}
|
|
471
|
+
function sheetName(options) {
|
|
472
|
+
const name = options.name ?? "Sheet1";
|
|
473
|
+
const problem = require_sheet_names.validateSheetName(name);
|
|
474
|
+
if (problem) throw new require_errors.ValidationError("INVALID_SHEET_NAME", `Sheet name ${JSON.stringify(name)} is invalid (${problem}).`, { details: {
|
|
1194
475
|
sheet: name,
|
|
1195
|
-
index,
|
|
1196
476
|
problem
|
|
1197
477
|
} });
|
|
478
|
+
return name;
|
|
1198
479
|
}
|
|
1199
|
-
function
|
|
1200
|
-
if (
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
if (typeof sheet !== "object" || sheet === null) throw new require_errors.ValidationError("INVALID_SHEET_NAME", `Sheet ${i + 1} is not an object.`, { details: { index: i } });
|
|
1204
|
-
checkSheetName(sheet.name, i);
|
|
1205
|
-
const key = sheet.name.toLowerCase();
|
|
1206
|
-
const prev = seen.get(key);
|
|
1207
|
-
if (prev !== void 0) throw new require_errors.ValidationError("DUPLICATE_SHEET_NAME", `Sheets ${prev + 1} and ${i + 1} are both named ${JSON.stringify(sheet.name)} (names are case-insensitive).`, { details: {
|
|
1208
|
-
sheet: sheet.name,
|
|
1209
|
-
index: i
|
|
1210
|
-
} });
|
|
1211
|
-
seen.set(key, i);
|
|
1212
|
-
const state = sheet.state ?? "visible";
|
|
1213
|
-
if (state !== "visible" && state !== "hidden" && state !== "veryHidden") throw new require_errors.ValidationError("INVALID_SHEET_PROPERTY", `Sheet ${sheet.name}: state must be 'visible', 'hidden' or 'veryHidden'.`, { details: {
|
|
1214
|
-
sheet: sheet.name,
|
|
1215
|
-
path: "state",
|
|
1216
|
-
value: state
|
|
1217
|
-
} });
|
|
1218
|
-
});
|
|
1219
|
-
const activeSheet = wb.activeSheet ?? 0;
|
|
1220
|
-
const active = wb.sheets[activeSheet];
|
|
1221
|
-
if (!Number.isInteger(activeSheet) || !active) throw new require_errors.ValidationError("INVALID_ACTIVE_SHEET", `activeSheet ${String(activeSheet)} is not a sheet index.`, { details: { activeSheet } });
|
|
1222
|
-
if ((active.state ?? "visible") !== "visible") throw new require_errors.ValidationError("INVALID_ACTIVE_SHEET", `The active sheet ${JSON.stringify(active.name)} must be visible.`, { details: { activeSheet } });
|
|
1223
|
-
const sheets = wb.sheets.map((s, i) => planSheet(s, i, i === activeSheet, styles, schemes));
|
|
1224
|
-
return {
|
|
1225
|
-
sheets,
|
|
1226
|
-
activeSheet,
|
|
1227
|
-
totalRows: sheets.reduce((n, p) => n + planRowCount(p), 0)
|
|
480
|
+
function originOf(options) {
|
|
481
|
+
if (options.origin === void 0) return {
|
|
482
|
+
row: 0,
|
|
483
|
+
col: 0
|
|
1228
484
|
};
|
|
485
|
+
return require_sheet_names.decodeCell(options.origin);
|
|
486
|
+
}
|
|
487
|
+
const newGrid = () => ({
|
|
488
|
+
rows: [],
|
|
489
|
+
merges: [],
|
|
490
|
+
widths: /* @__PURE__ */ new Map(),
|
|
491
|
+
measured: /* @__PURE__ */ new Map(),
|
|
492
|
+
autoCols: /* @__PURE__ */ new Set(),
|
|
493
|
+
hidden: /* @__PURE__ */ new Set()
|
|
494
|
+
});
|
|
495
|
+
/** Builds a sheet from `{ columns, data }`. */
|
|
496
|
+
function fromDataset(dataset, options = {}) {
|
|
497
|
+
const name = sheetName(options);
|
|
498
|
+
const origin = originOf(options);
|
|
499
|
+
const g = newGrid();
|
|
500
|
+
return finish(g, options, layoutBlock(g, dataset, options, origin.row, origin.col, name), name);
|
|
1229
501
|
}
|
|
1230
|
-
/**
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
const
|
|
1239
|
-
const
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
502
|
+
/**
|
|
503
|
+
* Stacks several datasets on one sheet (replaces the old xSteps/ySteps).
|
|
504
|
+
* Each block starts `gap` empty rows (default 1) below the previous one, or
|
|
505
|
+
* `offset.rows` rows when given, and `offset.cols` columns right of the
|
|
506
|
+
* origin. Freeze and filter apply to the first block with header rows.
|
|
507
|
+
*/
|
|
508
|
+
function fromDatasets(blocks, options = {}) {
|
|
509
|
+
if (!Array.isArray(blocks)) throw columnError("fromDatasets needs an array of datasets.");
|
|
510
|
+
const name = sheetName(options);
|
|
511
|
+
const origin = originOf(options);
|
|
512
|
+
const gap = options.gap ?? 1;
|
|
513
|
+
if (!Number.isInteger(gap) || gap < 0) throw columnError(`gap must be a non-negative integer, got ${String(gap)}.`);
|
|
514
|
+
const g = newGrid();
|
|
515
|
+
let first;
|
|
516
|
+
let nextRow = origin.row;
|
|
517
|
+
blocks.forEach((block, i) => {
|
|
518
|
+
const offRows = block.offset?.rows;
|
|
519
|
+
const offCols = block.offset?.cols ?? 0;
|
|
520
|
+
const top = i === 0 ? origin.row + (offRows ?? 0) : nextRow + (offRows ?? gap);
|
|
521
|
+
const result = layoutBlock(g, block, options, top, origin.col + offCols, name);
|
|
522
|
+
if (!first && result.headerRows > 0) first = result;
|
|
523
|
+
nextRow = result.lastRow + 1;
|
|
1251
524
|
});
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
const customPart = custom.length > 0 ? customXml(custom) : void 0;
|
|
1272
|
-
const ctx = {
|
|
1273
|
-
styles,
|
|
1274
|
-
strings: sharedStrings ? new SharedStrings() : void 0,
|
|
1275
|
-
date1904: wb.date1904 === true,
|
|
1276
|
-
dateZone: options.dateZone ?? "local",
|
|
1277
|
-
formulaWithoutValue: false
|
|
1278
|
-
};
|
|
1279
|
-
let rowsDone = 0;
|
|
1280
|
-
let lastReported = 0;
|
|
1281
|
-
const ratioOf = () => plan.totalRows === 0 ? .9 : .9 * (rowsDone / plan.totalRows);
|
|
1282
|
-
const onRow = (sheet) => () => {
|
|
1283
|
-
rowsDone++;
|
|
1284
|
-
if (onProgress && rowsDone - lastReported >= PROGRESS_EVERY_ROWS) {
|
|
1285
|
-
lastReported = rowsDone;
|
|
1286
|
-
onProgress({
|
|
1287
|
-
phase: "sheets",
|
|
1288
|
-
sheet,
|
|
1289
|
-
ratio: ratioOf()
|
|
1290
|
-
});
|
|
525
|
+
return finish(g, options, first, name);
|
|
526
|
+
}
|
|
527
|
+
function usedRange(sheet) {
|
|
528
|
+
let minR = 1e400, maxR = -1, minC = 1e400, maxC = -1;
|
|
529
|
+
sheet.rows.forEach((row, r) => row?.forEach((c, col) => {
|
|
530
|
+
if (c === void 0 || c === null) return;
|
|
531
|
+
minR = Math.min(minR, r);
|
|
532
|
+
maxR = Math.max(maxR, r);
|
|
533
|
+
minC = Math.min(minC, col);
|
|
534
|
+
maxC = Math.max(maxC, col);
|
|
535
|
+
}));
|
|
536
|
+
return maxR < 0 ? void 0 : {
|
|
537
|
+
start: {
|
|
538
|
+
row: minR,
|
|
539
|
+
col: minC
|
|
540
|
+
},
|
|
541
|
+
end: {
|
|
542
|
+
row: maxR,
|
|
543
|
+
col: maxC
|
|
1291
544
|
}
|
|
1292
545
|
};
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
});
|
|
1322
|
-
const chunks = sheetXml(sp, ctx, onRow(name));
|
|
1323
|
-
yield {
|
|
1324
|
-
name: `xl/worksheets/sheet${i + 1}.xml`,
|
|
1325
|
-
data: (async function* () {
|
|
1326
|
-
for await (const chunk of chunks) {
|
|
1327
|
-
require_numfmt.throwIfAborted(signal);
|
|
1328
|
-
yield chunk;
|
|
1329
|
-
}
|
|
1330
|
-
})()
|
|
1331
|
-
};
|
|
1332
|
-
const rels = sp.rels.xml();
|
|
1333
|
-
if (rels) yield {
|
|
1334
|
-
name: `xl/worksheets/_rels/sheet${i + 1}.xml.rels`,
|
|
1335
|
-
data: rels
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
onProgress?.({
|
|
1339
|
-
phase: "styles",
|
|
1340
|
-
ratio: .9
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Reads a sheet back into `{ columns, data }` (import direction). Keys come
|
|
549
|
+
* from the header text, deduplicated with _2, _3...; an empty header gives the
|
|
550
|
+
* column letter. Empty rows are skipped. Rows are null-prototype objects, so
|
|
551
|
+
* a header named __proto__ in an untrusted file is just a key.
|
|
552
|
+
*/
|
|
553
|
+
function toDataset(sheet, options = {}) {
|
|
554
|
+
const s = sheet;
|
|
555
|
+
const rng = options.range ? require_sheet_names.decodeRange(options.range) : s.dimension ? require_sheet_names.decodeRange(s.dimension) : usedRange(s);
|
|
556
|
+
if (!rng) return {
|
|
557
|
+
columns: [],
|
|
558
|
+
data: []
|
|
559
|
+
};
|
|
560
|
+
const headerRow = options.headerRow ?? 0;
|
|
561
|
+
if (headerRow !== false && (!Number.isInteger(headerRow) || headerRow < 0)) throw columnError(`headerRow must be a non-negative integer or false, got ${String(headerRow)}.`);
|
|
562
|
+
const asCell = options.values === "cell";
|
|
563
|
+
const columns = [];
|
|
564
|
+
const used = /* @__PURE__ */ new Map();
|
|
565
|
+
for (let c = rng.start.col; c <= rng.end.col; c++) {
|
|
566
|
+
const letter = require_sheet_names.encodeCol(c);
|
|
567
|
+
const title = headerRow === false ? letter : require_sheet_names.cellText(s.rows[headerRow]?.[c]).trim();
|
|
568
|
+
const base = title === "" ? letter : title;
|
|
569
|
+
const n = (used.get(base) ?? 0) + 1;
|
|
570
|
+
used.set(base, n);
|
|
571
|
+
columns.push({
|
|
572
|
+
title: headerRow === false ? letter : title,
|
|
573
|
+
key: n === 1 ? base : `${base}_${n}`
|
|
1341
574
|
});
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
const fullCalc = wb.calc?.fullCalcOnLoad;
|
|
1355
|
-
yield {
|
|
1356
|
-
name: "xl/workbook.xml",
|
|
1357
|
-
data: workbookXml({
|
|
1358
|
-
sheets: plan.sheets.map((p, i) => ({
|
|
1359
|
-
name: p.sheet.name,
|
|
1360
|
-
state: p.sheet.state ?? "visible",
|
|
1361
|
-
relId: sheetRelIds[i]
|
|
1362
|
-
})),
|
|
1363
|
-
activeSheet: plan.activeSheet,
|
|
1364
|
-
date1904: ctx.date1904,
|
|
1365
|
-
fullCalcOnLoad: fullCalc === true || (fullCalc === void 0 || fullCalc === "auto") && ctx.formulaWithoutValue,
|
|
1366
|
-
definedNames
|
|
1367
|
-
})
|
|
1368
|
-
};
|
|
1369
|
-
yield {
|
|
1370
|
-
name: "xl/_rels/workbook.xml.rels",
|
|
1371
|
-
data: pkg.workbook.xml()
|
|
1372
|
-
};
|
|
1373
|
-
onProgress?.({
|
|
1374
|
-
phase: "zip",
|
|
1375
|
-
ratio: .95
|
|
575
|
+
}
|
|
576
|
+
const data = [];
|
|
577
|
+
const firstData = headerRow === false ? rng.start.row : Math.max(rng.start.row, headerRow + 1);
|
|
578
|
+
for (let r = firstData; r <= rng.end.row; r++) {
|
|
579
|
+
const row = s.rows[r];
|
|
580
|
+
if (!row) continue;
|
|
581
|
+
let any = false;
|
|
582
|
+
const obj = Object.create(null);
|
|
583
|
+
columns.forEach(({ key }, k) => {
|
|
584
|
+
const c = row[rng.start.col + k];
|
|
585
|
+
if (!(c === void 0 || c === null || isCellObject(c) && (c.value === void 0 || c.value === null) && !c.formula)) any = true;
|
|
586
|
+
obj[key] = asCell ? c === void 0 ? null : isCellObject(c) ? c : { value: c } : c === void 0 || c === null ? null : isCellObject(c) ? c.value ?? null : c;
|
|
1376
587
|
});
|
|
588
|
+
if (any) data.push(obj);
|
|
1377
589
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
});
|
|
1383
|
-
onProgress?.({
|
|
1384
|
-
phase: "zip",
|
|
1385
|
-
ratio: 1
|
|
1386
|
-
});
|
|
1387
|
-
return bytes;
|
|
1388
|
-
}
|
|
1389
|
-
/** Writes a workbook as an .xlsx Blob (type XLSX_MIME). */
|
|
1390
|
-
async function toBlob(wb, options) {
|
|
1391
|
-
const BlobCtor = globalThis.Blob;
|
|
1392
|
-
if (typeof BlobCtor !== "function") throw new require_errors.EnvironmentError("ENVIRONMENT_UNSUPPORTED", "Blob is not available in this runtime; use toUint8Array instead.", { details: { api: "Blob" } });
|
|
1393
|
-
return new BlobCtor([await toUint8Array(wb, options)], { type: XLSX_MIME });
|
|
590
|
+
return {
|
|
591
|
+
columns,
|
|
592
|
+
data
|
|
593
|
+
};
|
|
1394
594
|
}
|
|
1395
595
|
// src/index.ts
|
|
1396
|
-
/** Package version.
|
|
1397
|
-
const VERSION = "2.0.0-alpha.
|
|
596
|
+
/** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
|
|
597
|
+
const VERSION = "2.0.0-alpha.2";
|
|
1398
598
|
exports.BUILTIN_NUM_FMTS = require_numfmt.BUILTIN_NUM_FMTS;
|
|
1399
599
|
exports.CsvError = require_errors.CsvError;
|
|
1400
600
|
exports.EnvironmentError = require_errors.EnvironmentError;
|
|
@@ -1405,7 +605,7 @@ exports.MAX_COLS = require_sheet_names.MAX_COLS;
|
|
|
1405
605
|
exports.MAX_ROWS = require_sheet_names.MAX_ROWS;
|
|
1406
606
|
exports.VERSION = VERSION;
|
|
1407
607
|
exports.ValidationError = require_errors.ValidationError;
|
|
1408
|
-
exports.XLSX_MIME = XLSX_MIME;
|
|
608
|
+
exports.XLSX_MIME = require_write.XLSX_MIME;
|
|
1409
609
|
exports.cellText = require_sheet_names.cellText;
|
|
1410
610
|
exports.dateToSerial = require_numfmt.dateToSerial;
|
|
1411
611
|
exports.decodeCell = require_sheet_names.decodeCell;
|
|
@@ -1414,11 +614,14 @@ exports.decodeRange = require_sheet_names.decodeRange;
|
|
|
1414
614
|
exports.encodeCell = require_sheet_names.encodeCell;
|
|
1415
615
|
exports.encodeCol = require_sheet_names.encodeCol;
|
|
1416
616
|
exports.encodeRange = require_sheet_names.encodeRange;
|
|
617
|
+
exports.fromDataset = fromDataset;
|
|
618
|
+
exports.fromDatasets = fromDatasets;
|
|
1417
619
|
exports.isDateFormat = require_numfmt.isDateFormat;
|
|
1418
620
|
exports.isExcelError = require_errors.isExcelError;
|
|
1419
621
|
exports.mergeStyles = require_sheet_names.mergeStyles;
|
|
1420
622
|
exports.sanitizeSheetName = require_sheet_names.sanitizeSheetName;
|
|
1421
623
|
exports.serialToDate = require_numfmt.serialToDate;
|
|
1422
|
-
exports.toBlob = toBlob;
|
|
1423
|
-
exports.
|
|
624
|
+
exports.toBlob = require_write.toBlob;
|
|
625
|
+
exports.toDataset = toDataset;
|
|
626
|
+
exports.toUint8Array = require_write.toUint8Array;
|
|
1424
627
|
exports.validateSheetName = require_sheet_names.validateSheetName;
|