@evotecit/officeimo 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +1222 -2
- package/bundles/officeimo-canopyx.js +11741 -0
- package/bundles/officeimo-canopyx.mjs +11639 -0
- package/bundles/officeimo-csv.js +1264 -0
- package/bundles/officeimo-csv.mjs +1239 -0
- package/bundles/officeimo-datatables.js +12018 -0
- package/bundles/officeimo-datatables.mjs +11915 -0
- package/bundles/officeimo-execution.js +1513 -0
- package/bundles/officeimo-execution.mjs +1489 -0
- package/bundles/officeimo-pdf.js +7009 -0
- package/bundles/officeimo-pdf.mjs +6946 -0
- package/bundles/officeimo-xlsx.js +5344 -0
- package/bundles/officeimo-xlsx.mjs +5290 -0
- package/bundles/officeimo.js +11468 -0
- package/bundles/officeimo.mjs +11369 -0
- package/dist/core/dates.d.ts +1 -0
- package/dist/core/dates.js +16 -0
- package/dist/core/errors.d.ts +12 -0
- package/dist/core/errors.js +31 -0
- package/dist/core/grouped-report.d.ts +87 -0
- package/dist/core/grouped-report.js +252 -0
- package/dist/core/index.d.ts +74 -0
- package/dist/core/index.js +37 -0
- package/dist/core/iteration.d.ts +7 -0
- package/dist/core/iteration.js +149 -0
- package/dist/core/limits.d.ts +7 -0
- package/dist/core/limits.js +56 -0
- package/dist/core/links.d.ts +5 -0
- package/dist/core/links.js +14 -0
- package/dist/core/presentation.d.ts +29 -0
- package/dist/core/presentation.js +59 -0
- package/dist/core/progress.d.ts +1 -0
- package/dist/core/progress.js +10 -0
- package/dist/core/sinks.d.ts +33 -0
- package/dist/core/sinks.js +102 -0
- package/dist/core/table.d.ts +8 -0
- package/dist/core/table.js +1 -0
- package/dist/core/value-text.d.ts +7 -0
- package/dist/core/value-text.js +13 -0
- package/dist/csv/index.d.ts +44 -0
- package/dist/csv/index.js +133 -0
- package/dist/csv/options.d.ts +1 -0
- package/dist/csv/options.js +8 -0
- package/dist/csv/structured-rows.d.ts +3 -0
- package/dist/csv/structured-rows.js +15 -0
- package/dist/execution/host.d.ts +5 -0
- package/dist/execution/host.js +164 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/protocol.d.ts +48 -0
- package/dist/execution/protocol.js +173 -0
- package/dist/execution/types.d.ts +42 -0
- package/dist/execution/types.js +1 -0
- package/dist/execution/worker.d.ts +3 -0
- package/dist/execution/worker.js +147 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -0
- package/dist/integrations/canopyx/dates.d.ts +1 -0
- package/dist/integrations/canopyx/dates.js +34 -0
- package/dist/integrations/canopyx/index.d.ts +10 -0
- package/dist/integrations/canopyx/index.js +45 -0
- package/dist/integrations/canopyx/source.d.ts +3 -0
- package/dist/integrations/canopyx/source.js +122 -0
- package/dist/integrations/canopyx/types.d.ts +83 -0
- package/dist/integrations/canopyx/types.js +1 -0
- package/dist/integrations/datatables/api.d.ts +1 -0
- package/dist/integrations/datatables/api.js +27 -0
- package/dist/integrations/datatables/headings.d.ts +1 -0
- package/dist/integrations/datatables/headings.js +65 -0
- package/dist/integrations/datatables/index.d.ts +12 -0
- package/dist/integrations/datatables/index.js +167 -0
- package/dist/integrations/datatables/snapshot.d.ts +3 -0
- package/dist/integrations/datatables/snapshot.js +206 -0
- package/dist/integrations/datatables/types.d.ts +98 -0
- package/dist/integrations/datatables/types.js +1 -0
- package/dist/integrations/options.d.ts +13 -0
- package/dist/integrations/options.js +34 -0
- package/dist/internal/capture.d.ts +4 -0
- package/dist/internal/capture.js +14 -0
- package/dist/internal/columns.d.ts +27 -0
- package/dist/internal/columns.js +1 -0
- package/dist/internal/crc32.d.ts +6 -0
- package/dist/internal/crc32.js +17 -0
- package/dist/internal/export-values.d.ts +3 -0
- package/dist/internal/export-values.js +14 -0
- package/dist/internal/rows.d.ts +6 -0
- package/dist/internal/rows.js +77 -0
- package/dist/internal/table-spans.d.ts +11 -0
- package/dist/internal/table-spans.js +58 -0
- package/dist/internal/totals.d.ts +15 -0
- package/dist/internal/totals.js +42 -0
- package/dist/opc/index.d.ts +67 -0
- package/dist/opc/index.js +233 -0
- package/dist/opc/properties.d.ts +15 -0
- package/dist/opc/properties.js +18 -0
- package/dist/opc/uri.d.ts +5 -0
- package/dist/opc/uri.js +41 -0
- package/dist/pdf/annotations.d.ts +1 -0
- package/dist/pdf/annotations.js +38 -0
- package/dist/pdf/binary.d.ts +6 -0
- package/dist/pdf/binary.js +24 -0
- package/dist/pdf/document-drawings.d.ts +15 -0
- package/dist/pdf/document-drawings.js +237 -0
- package/dist/pdf/document-grouped.d.ts +1 -0
- package/dist/pdf/document-grouped.js +244 -0
- package/dist/pdf/document-images.d.ts +19 -0
- package/dist/pdf/document-images.js +125 -0
- package/dist/pdf/document-types.d.ts +160 -0
- package/dist/pdf/document-types.js +1 -0
- package/dist/pdf/document-vectors.d.ts +11 -0
- package/dist/pdf/document-vectors.js +77 -0
- package/dist/pdf/document.d.ts +9 -0
- package/dist/pdf/document.js +270 -0
- package/dist/pdf/drawing-types.d.ts +53 -0
- package/dist/pdf/drawing-types.js +1 -0
- package/dist/pdf/font-resources.d.ts +43 -0
- package/dist/pdf/font-resources.js +202 -0
- package/dist/pdf/font-support.d.ts +1 -0
- package/dist/pdf/font-support.js +60 -0
- package/dist/pdf/font.d.ts +17 -0
- package/dist/pdf/font.js +56 -0
- package/dist/pdf/grouped-table.d.ts +6 -0
- package/dist/pdf/grouped-table.js +40 -0
- package/dist/pdf/grouped-types.d.ts +34 -0
- package/dist/pdf/grouped-types.js +1 -0
- package/dist/pdf/grouped.d.ts +10 -0
- package/dist/pdf/grouped.js +37 -0
- package/dist/pdf/index.d.ts +22 -0
- package/dist/pdf/index.js +8 -0
- package/dist/pdf/inline-text.d.ts +30 -0
- package/dist/pdf/inline-text.js +183 -0
- package/dist/pdf/inline-types.d.ts +15 -0
- package/dist/pdf/inline-types.js +1 -0
- package/dist/pdf/list-layout.d.ts +6 -0
- package/dist/pdf/list-layout.js +49 -0
- package/dist/pdf/objects.d.ts +2 -0
- package/dist/pdf/objects.js +320 -0
- package/dist/pdf/outlines.d.ts +1 -0
- package/dist/pdf/outlines.js +55 -0
- package/dist/pdf/page-context.d.ts +1 -0
- package/dist/pdf/page-context.js +12 -0
- package/dist/pdf/pages.d.ts +1 -0
- package/dist/pdf/pages.js +678 -0
- package/dist/pdf/paragraph-layout.d.ts +21 -0
- package/dist/pdf/paragraph-layout.js +71 -0
- package/dist/pdf/paragraph-styles.d.ts +1 -0
- package/dist/pdf/paragraph-styles.js +66 -0
- package/dist/pdf/png.d.ts +9 -0
- package/dist/pdf/png.js +259 -0
- package/dist/pdf/preflight.d.ts +7 -0
- package/dist/pdf/preflight.js +32 -0
- package/dist/pdf/presentation-settings.d.ts +5 -0
- package/dist/pdf/presentation-settings.js +28 -0
- package/dist/pdf/providers/harfbuzz.d.ts +60 -0
- package/dist/pdf/providers/harfbuzz.js +112 -0
- package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
- package/dist/pdf/providers/unicode13-profile.js +115 -0
- package/dist/pdf/section-types.d.ts +15 -0
- package/dist/pdf/section-types.js +40 -0
- package/dist/pdf/session.d.ts +25 -0
- package/dist/pdf/session.js +55 -0
- package/dist/pdf/settings.d.ts +17 -0
- package/dist/pdf/settings.js +196 -0
- package/dist/pdf/shaped-text.d.ts +5 -0
- package/dist/pdf/shaped-text.js +205 -0
- package/dist/pdf/standard-widths.d.ts +1 -0
- package/dist/pdf/standard-widths.js +317 -0
- package/dist/pdf/structure-parent-tree.d.ts +1 -0
- package/dist/pdf/structure-parent-tree.js +57 -0
- package/dist/pdf/structure.d.ts +6 -0
- package/dist/pdf/structure.js +302 -0
- package/dist/pdf/table-band-flow.d.ts +34 -0
- package/dist/pdf/table-band-flow.js +129 -0
- package/dist/pdf/table-band-plan.d.ts +10 -0
- package/dist/pdf/table-band-plan.js +83 -0
- package/dist/pdf/table-layout.d.ts +75 -0
- package/dist/pdf/table-layout.js +217 -0
- package/dist/pdf/table-structure.d.ts +1 -0
- package/dist/pdf/table-structure.js +108 -0
- package/dist/pdf/text-shaping-types.d.ts +39 -0
- package/dist/pdf/text-shaping-types.js +1 -0
- package/dist/pdf/text.d.ts +13 -0
- package/dist/pdf/text.js +101 -0
- package/dist/pdf/truetype-subset.d.ts +5 -0
- package/dist/pdf/truetype-subset.js +217 -0
- package/dist/pdf/truetype.d.ts +1 -0
- package/dist/pdf/truetype.js +235 -0
- package/dist/pdf/types.d.ts +171 -0
- package/dist/pdf/types.js +1 -0
- package/dist/pdf/write.d.ts +6 -0
- package/dist/pdf/write.js +57 -0
- package/dist/pdf/xref.d.ts +1 -0
- package/dist/pdf/xref.js +30 -0
- package/dist/xlsx/attachments.d.ts +30 -0
- package/dist/xlsx/attachments.js +67 -0
- package/dist/xlsx/chart-bindings.d.ts +1 -0
- package/dist/xlsx/chart-bindings.js +122 -0
- package/dist/xlsx/chart-types.d.ts +73 -0
- package/dist/xlsx/chart-types.js +1 -0
- package/dist/xlsx/chart-xml.d.ts +2 -0
- package/dist/xlsx/chart-xml.js +103 -0
- package/dist/xlsx/charts.d.ts +1 -0
- package/dist/xlsx/charts.js +159 -0
- package/dist/xlsx/conditional-formatting.d.ts +1 -0
- package/dist/xlsx/conditional-formatting.js +158 -0
- package/dist/xlsx/conditional-types.d.ts +64 -0
- package/dist/xlsx/conditional-types.js +1 -0
- package/dist/xlsx/data-row-ranges.d.ts +5 -0
- package/dist/xlsx/data-row-ranges.js +39 -0
- package/dist/xlsx/differential-styles.d.ts +1 -0
- package/dist/xlsx/differential-styles.js +102 -0
- package/dist/xlsx/formula.d.ts +8 -0
- package/dist/xlsx/formula.js +104 -0
- package/dist/xlsx/grouped-layout.d.ts +61 -0
- package/dist/xlsx/grouped-layout.js +79 -0
- package/dist/xlsx/grouped.d.ts +16 -0
- package/dist/xlsx/grouped.js +161 -0
- package/dist/xlsx/index.d.ts +24 -0
- package/dist/xlsx/index.js +10 -0
- package/dist/xlsx/layout.d.ts +1 -0
- package/dist/xlsx/layout.js +186 -0
- package/dist/xlsx/options.d.ts +1 -0
- package/dist/xlsx/options.js +16 -0
- package/dist/xlsx/portable.d.ts +27 -0
- package/dist/xlsx/portable.js +44 -0
- package/dist/xlsx/preservation.d.ts +1 -0
- package/dist/xlsx/preservation.js +60 -0
- package/dist/xlsx/ranges.d.ts +1 -0
- package/dist/xlsx/ranges.js +24 -0
- package/dist/xlsx/regions.d.ts +1 -0
- package/dist/xlsx/regions.js +97 -0
- package/dist/xlsx/structured-rows.d.ts +11 -0
- package/dist/xlsx/structured-rows.js +28 -0
- package/dist/xlsx/style-xml.d.ts +1 -0
- package/dist/xlsx/style-xml.js +6 -0
- package/dist/xlsx/styles.d.ts +70 -0
- package/dist/xlsx/styles.js +203 -0
- package/dist/xlsx/table.d.ts +12 -0
- package/dist/xlsx/table.js +35 -0
- package/dist/xlsx/types.d.ts +180 -0
- package/dist/xlsx/types.js +1 -0
- package/dist/xlsx/validation-types.d.ts +18 -0
- package/dist/xlsx/validation-types.js +1 -0
- package/dist/xlsx/validation.d.ts +1 -0
- package/dist/xlsx/validation.js +92 -0
- package/dist/xlsx/values.d.ts +13 -0
- package/dist/xlsx/values.js +87 -0
- package/dist/xlsx/workbook.d.ts +50 -0
- package/dist/xlsx/workbook.js +452 -0
- package/dist/xlsx/worksheet.d.ts +71 -0
- package/dist/xlsx/worksheet.js +700 -0
- package/dist/xlsx/write.d.ts +15 -0
- package/dist/xlsx/write.js +47 -0
- package/dist/xml/index.d.ts +24 -0
- package/dist/xml/index.js +74 -0
- package/dist/zip/entry.d.ts +39 -0
- package/dist/zip/entry.js +122 -0
- package/dist/zip/index.d.ts +44 -0
- package/dist/zip/index.js +248 -0
- package/package.json +104 -4
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { escapeOoxmlAttribute, cleanXml, xmlDeclaration } from "../xml/index.js";
|
|
2
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
3
|
+
import { colorArgb } from "./style-xml.js";
|
|
4
|
+
import { DifferentialStyles } from "./differential-styles.js";
|
|
5
|
+
export { colorArgb } from "./style-xml.js";
|
|
6
|
+
export const spreadsheetNamespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
7
|
+
export const NumberFormats = { General: "General", Integer: "0", Decimal: "0.00", Percent: "0.00%", Date: "yyyy-mm-dd", DateTime: "yyyy-mm-dd hh:mm:ss" };
|
|
8
|
+
function index(value, count, kind) {
|
|
9
|
+
if (!Number.isInteger(value) || value < 0 || value >= count)
|
|
10
|
+
throw new RangeError("Unknown " + kind + " index.");
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function deduplicate(items, indexes, item, maximum) {
|
|
14
|
+
const key = JSON.stringify(item), found = indexes.get(key);
|
|
15
|
+
if (found !== undefined)
|
|
16
|
+
return found;
|
|
17
|
+
if (items.length >= maximum)
|
|
18
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Style component limit exceeded.");
|
|
19
|
+
const id = items.length;
|
|
20
|
+
items.push(item);
|
|
21
|
+
indexes.set(key, id);
|
|
22
|
+
return id;
|
|
23
|
+
}
|
|
24
|
+
/** @internal Observe unsupported promises immediately, even when cell precedence skips the patch. */
|
|
25
|
+
export function validateStylePatch(patch) {
|
|
26
|
+
if (!patch || typeof patch !== "object" || Array.isArray(patch))
|
|
27
|
+
throw new TypeError("A style patch must be a CellStyle object.");
|
|
28
|
+
if (typeof patch.then === "function") {
|
|
29
|
+
void Promise.resolve(patch).catch(() => { });
|
|
30
|
+
throw new TypeError("Style patches must be synchronous CellStyle objects.");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** @internal Capture reusable option patches without retaining caller-owned nested components. */
|
|
34
|
+
export function copyStylePatch(patch) {
|
|
35
|
+
validateStylePatch(patch);
|
|
36
|
+
return Object.freeze({ ...patch,
|
|
37
|
+
...(typeof patch.font === "object" ? { font: Object.freeze({ ...patch.font }) } : {}),
|
|
38
|
+
...(typeof patch.fill === "object" ? { fill: Object.freeze({ ...patch.fill }) } : {}),
|
|
39
|
+
...(typeof patch.border === "object" ? { border: Object.freeze(Object.fromEntries(Object.entries(patch.border).map(([side, edge]) => [side, Object.freeze({ ...edge })]))) } : {})
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** Workbook-owned indexes. Definition inputs are normalized and copied, never retained by reference. */
|
|
43
|
+
export class StyleRegistry {
|
|
44
|
+
policy;
|
|
45
|
+
maximum;
|
|
46
|
+
differential;
|
|
47
|
+
fonts = [{ name: "Calibri", size: 11, bold: false, italic: false, underline: false, strike: false, color: "" }];
|
|
48
|
+
fills = [{ pattern: "none", color: "" }, { pattern: "gray125", color: "" }];
|
|
49
|
+
borders = [{}];
|
|
50
|
+
formats = new Map();
|
|
51
|
+
styles = [];
|
|
52
|
+
indexes = new Map();
|
|
53
|
+
fontIndexes = new Map(this.fonts.map((v, i) => [JSON.stringify(v), i]));
|
|
54
|
+
fillIndexes = new Map(this.fills.map((v, i) => [JSON.stringify(v), i]));
|
|
55
|
+
borderIndexes = new Map(this.borders.map((v, i) => [JSON.stringify(v), i]));
|
|
56
|
+
constructor(policy = "strip", maximum = 64000, maximumDifferential = 1000) {
|
|
57
|
+
this.policy = policy;
|
|
58
|
+
this.maximum = maximum;
|
|
59
|
+
if (!Number.isSafeInteger(maximum) || maximum < 1 || maximum > 64000)
|
|
60
|
+
throw new RangeError("maxStyles must be from 1 through 64,000.");
|
|
61
|
+
if (!Number.isSafeInteger(maximumDifferential) || maximumDifferential < 0)
|
|
62
|
+
throw new RangeError("maxDifferentialStyles must be a nonnegative safe integer.");
|
|
63
|
+
this.differential = new DifferentialStyles(policy, maximumDifferential, format => this.addNumberFormat(format));
|
|
64
|
+
cleanXml("", policy);
|
|
65
|
+
this.add();
|
|
66
|
+
}
|
|
67
|
+
/** @internal */
|
|
68
|
+
checkDifferentials(styles) {
|
|
69
|
+
// A batch must not register some dxfs before its shared number-format capacity fails.
|
|
70
|
+
const formats = new Set(styles.flatMap(style => style.numberFormat === undefined ? [] : [cleanXml(style.numberFormat, this.policy)])
|
|
71
|
+
.filter(format => format !== "General" && !this.formats.has(format)));
|
|
72
|
+
if (this.formats.size + formats.size > 65372)
|
|
73
|
+
throw new RangeError("Too many number formats.");
|
|
74
|
+
this.differential.check(styles);
|
|
75
|
+
}
|
|
76
|
+
/** @internal */
|
|
77
|
+
addDifferentials(styles) { this.checkDifferentials(styles); return this.differential.add(styles); }
|
|
78
|
+
addFont(font) {
|
|
79
|
+
if (font.name !== undefined && typeof font.name !== "string")
|
|
80
|
+
throw new TypeError("Font name must be a string.");
|
|
81
|
+
const name = cleanXml(font.name ?? "Calibri", this.policy), size = font.size ?? 11;
|
|
82
|
+
if (typeof name !== "string" || !name || name.length > 31)
|
|
83
|
+
throw new TypeError("Font name must contain 1 through 31 characters.");
|
|
84
|
+
if (!Number.isFinite(size) || size <= 0 || size > 409)
|
|
85
|
+
throw new RangeError("Font size must be positive and at most 409.");
|
|
86
|
+
return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!font.bold, italic: !!font.italic, underline: !!font.underline, strike: !!font.strike, color: font.color ? colorArgb(font.color) : "" }, this.maximum);
|
|
87
|
+
}
|
|
88
|
+
addFill(fill) {
|
|
89
|
+
const pattern = fill.pattern ?? (fill.color ? "solid" : "none");
|
|
90
|
+
if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !fill.color) || (pattern !== "solid" && fill.color))
|
|
91
|
+
throw new TypeError("A solid fill requires a color; none and gray125 have no color.");
|
|
92
|
+
return deduplicate(this.fills, this.fillIndexes, { pattern, color: fill.color ? colorArgb(fill.color) : "" }, this.maximum + 1);
|
|
93
|
+
}
|
|
94
|
+
addBorder(border) {
|
|
95
|
+
const result = {};
|
|
96
|
+
for (const side of ["left", "right", "top", "bottom"]) {
|
|
97
|
+
const edge = border[side];
|
|
98
|
+
if (edge) {
|
|
99
|
+
if (!["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"].includes(edge.style))
|
|
100
|
+
throw new TypeError("Invalid border style.");
|
|
101
|
+
result[side] = { style: edge.style, ...(edge.color ? { color: colorArgb(edge.color) } : {}) };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return deduplicate(this.borders, this.borderIndexes, result, this.maximum);
|
|
105
|
+
}
|
|
106
|
+
addNumberFormat(format) {
|
|
107
|
+
if (typeof format !== "string" || !format || format.length > 255)
|
|
108
|
+
throw new TypeError("Number format must contain 1 through 255 characters.");
|
|
109
|
+
format = cleanXml(format, this.policy);
|
|
110
|
+
if (!format)
|
|
111
|
+
throw new TypeError("Number format must contain XML-valid characters.");
|
|
112
|
+
if (format === "General")
|
|
113
|
+
return 0;
|
|
114
|
+
let id = this.formats.get(format);
|
|
115
|
+
if (id === undefined) {
|
|
116
|
+
if (this.formats.size >= 65372)
|
|
117
|
+
throw new RangeError("Too many number formats.");
|
|
118
|
+
id = this.formats.size + 164;
|
|
119
|
+
this.formats.set(format, id);
|
|
120
|
+
}
|
|
121
|
+
return id;
|
|
122
|
+
}
|
|
123
|
+
add(style = {}) {
|
|
124
|
+
const font = typeof style.font === "number" ? index(style.font, this.fonts.length, "font") : style.font ? this.addFont(style.font) : 0;
|
|
125
|
+
const fill = typeof style.fill === "number" ? index(style.fill, this.fills.length, "fill") : style.fill ? this.addFill(style.fill) : 0;
|
|
126
|
+
const border = typeof style.border === "number" ? index(style.border, this.borders.length, "border") : style.border ? this.addBorder(style.border) : 0;
|
|
127
|
+
let numberFormat = 0;
|
|
128
|
+
if (typeof style.numberFormat === "string")
|
|
129
|
+
numberFormat = this.addNumberFormat(style.numberFormat);
|
|
130
|
+
else if (style.numberFormat !== undefined) {
|
|
131
|
+
numberFormat = style.numberFormat;
|
|
132
|
+
if (!Number.isInteger(numberFormat) || numberFormat < 0 || (numberFormat > 163 && ![...this.formats.values()].includes(numberFormat)))
|
|
133
|
+
throw new RangeError("Unknown number format index.");
|
|
134
|
+
}
|
|
135
|
+
if (style.alignment !== undefined && !["left", "center", "right", "fill", "justify", "distributed"].includes(style.alignment))
|
|
136
|
+
throw new TypeError("Invalid horizontal alignment.");
|
|
137
|
+
if (style.verticalAlignment !== undefined && !["top", "center", "bottom", "justify", "distributed"].includes(style.verticalAlignment))
|
|
138
|
+
throw new TypeError("Invalid vertical alignment.");
|
|
139
|
+
const registered = { font, fill, border, numberFormat, wrapText: !!style.wrapText, alignment: style.alignment ?? "", verticalAlignment: style.verticalAlignment ?? "" };
|
|
140
|
+
const key = JSON.stringify(registered), found = this.indexes.get(key);
|
|
141
|
+
if (found !== undefined)
|
|
142
|
+
return found;
|
|
143
|
+
if (this.styles.length >= this.maximum)
|
|
144
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Workbook exceeds its cell style limit.");
|
|
145
|
+
const id = this.styles.length;
|
|
146
|
+
this.styles.push(registered);
|
|
147
|
+
this.indexes.set(key, id);
|
|
148
|
+
return id;
|
|
149
|
+
}
|
|
150
|
+
validateStyle(id) { return index(id, this.styles.length, "cell style"); }
|
|
151
|
+
/** Overlay presentation while retaining the base number format, font fields and border edges. Numeric component indexes replace a component. */
|
|
152
|
+
compose(base, overlay) {
|
|
153
|
+
validateStylePatch(overlay);
|
|
154
|
+
const source = this.styles[this.validateStyle(base)];
|
|
155
|
+
return this.add({
|
|
156
|
+
font: source.font, fill: source.fill, border: source.border, numberFormat: source.numberFormat,
|
|
157
|
+
wrapText: source.wrapText,
|
|
158
|
+
...(source.alignment ? { alignment: source.alignment } : {}),
|
|
159
|
+
...(source.verticalAlignment ? { verticalAlignment: source.verticalAlignment } : {}),
|
|
160
|
+
...overlay,
|
|
161
|
+
...(typeof overlay.font === "object" ? { font: { ...this.fonts[source.font], ...overlay.font } } : {}),
|
|
162
|
+
...(typeof overlay.border === "object" ? { border: { ...this.borders[source.border], ...overlay.border } } : {})
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/** @internal Typed headings retain header appearance and the column's date number format. */
|
|
166
|
+
dateHeader(base, dateStyle) {
|
|
167
|
+
return this.compose(base, { numberFormat: this.styles[this.validateStyle(dateStyle)].numberFormat });
|
|
168
|
+
}
|
|
169
|
+
/** @internal Column shorthand and header style composition. */
|
|
170
|
+
forColumn(column, header = false, fill, date = false) {
|
|
171
|
+
const base = !header && column.style !== undefined ? this.styles[this.validateStyle(column.style)] : undefined;
|
|
172
|
+
const format = column.format !== undefined ? column.format || NumberFormats.General : base?.numberFormat || (column.type === "date" || date ? NumberFormats.DateTime : NumberFormats.General);
|
|
173
|
+
return this.add({
|
|
174
|
+
...(base ? { font: base.font, fill: base.fill, border: base.border } : {}),
|
|
175
|
+
numberFormat: format,
|
|
176
|
+
wrapText: column.wrapText ?? base?.wrapText ?? false,
|
|
177
|
+
...(column.alignment ? { alignment: column.alignment } : base?.alignment ? { alignment: base.alignment } : {}),
|
|
178
|
+
...(base?.verticalAlignment ? { verticalAlignment: base.verticalAlignment } : {}),
|
|
179
|
+
...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {})
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
toXml() {
|
|
183
|
+
const fontXml = (f) => '<font>' + (f.bold ? '<b/>' : "") + (f.italic ? '<i/>' : "") + (f.underline ? '<u/>' : "") + (f.strike ? '<strike/>' : "") + '<sz val="' + f.size + '"/>' +
|
|
184
|
+
(f.color ? '<color rgb="' + f.color + '"/>' : "") + '<name val="' + escapeOoxmlAttribute(f.name, this.policy) + '"/></font>';
|
|
185
|
+
const borderXml = (b) => '<border>' + ["left", "right", "top", "bottom"].map(side => {
|
|
186
|
+
const edge = b[side];
|
|
187
|
+
return edge ? '<' + side + ' style="' + edge.style + '">' + (edge.color ? '<color rgb="' + edge.color + '"/>' : "") + '</' + side + '>' : '<' + side + '/>';
|
|
188
|
+
}).join("") + '<diagonal/></border>';
|
|
189
|
+
return xmlDeclaration + '<styleSheet xmlns="' + spreadsheetNamespace + '">' +
|
|
190
|
+
'<numFmts count="' + this.formats.size + '">' + [...this.formats].map(([format, id]) => '<numFmt numFmtId="' + id + '" formatCode="' + escapeOoxmlAttribute(format, this.policy) + '"/>').join("") + '</numFmts>' +
|
|
191
|
+
'<fonts count="' + this.fonts.length + '">' + this.fonts.map(fontXml).join("") + '</fonts>' +
|
|
192
|
+
'<fills count="' + this.fills.length + '">' + this.fills.map(f => '<fill><patternFill patternType="' + f.pattern + '">' +
|
|
193
|
+
(f.color ? '<fgColor rgb="' + f.color + '"/><bgColor indexed="64"/>' : "") + '</patternFill></fill>').join("") + '</fills>' +
|
|
194
|
+
'<borders count="' + this.borders.length + '">' + this.borders.map(borderXml).join("") + '</borders>' +
|
|
195
|
+
'<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs>' +
|
|
196
|
+
'<cellXfs count="' + this.styles.length + '">' + this.styles.map(s => {
|
|
197
|
+
const alignment = s.wrapText || s.alignment || s.verticalAlignment ? '<alignment' + (s.wrapText ? ' wrapText="1"' : "") + (s.alignment ? ' horizontal="' + s.alignment + '"' : "") + (s.verticalAlignment ? ' vertical="' + s.verticalAlignment + '"' : "") + '/>' : "";
|
|
198
|
+
return '<xf numFmtId="' + s.numberFormat + '" fontId="' + s.font + '" fillId="' + s.fill + '" borderId="' + s.border + '" xfId="0"' +
|
|
199
|
+
(s.numberFormat ? ' applyNumberFormat="1"' : "") + (s.font ? ' applyFont="1"' : "") + (s.fill ? ' applyFill="1"' : "") +
|
|
200
|
+
(s.border ? ' applyBorder="1"' : "") + (alignment ? ' applyAlignment="1"' : "") + '>' + alignment + '</xf>';
|
|
201
|
+
}).join("") + '</cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>' + this.differential.toXml() + '</styleSheet>';
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ProjectionColumn } from "../internal/columns.js";
|
|
2
|
+
import type { InvalidCharacterPolicy } from "../xml/index.js";
|
|
3
|
+
import type { TableOptions, FooterOptions } from "./types.js";
|
|
4
|
+
export interface TableDefinition {
|
|
5
|
+
readonly id: number;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly headers: readonly string[];
|
|
8
|
+
readonly keys: readonly string[];
|
|
9
|
+
readonly options: Readonly<TableOptions>;
|
|
10
|
+
}
|
|
11
|
+
export declare function defineTable(id: number, options: TableOptions, columns: readonly ProjectionColumn[], policy: InvalidCharacterPolicy): TableDefinition;
|
|
12
|
+
export declare function tableXml(table: TableDefinition, rowCount: number, policy: InvalidCharacterPolicy, headerRow?: number, footer?: FooterOptions): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { escapeOoxmlAttribute, escapeXml, xmlDeclaration } from "../xml/index.js";
|
|
2
|
+
import { cellText, columnName } from "./values.js";
|
|
3
|
+
import { spreadsheetNamespace } from "./styles.js";
|
|
4
|
+
import { ExportCell } from "../core/presentation.js";
|
|
5
|
+
import { Cell } from "./values.js";
|
|
6
|
+
import { totalFormula } from "./layout.js";
|
|
7
|
+
export function defineTable(id, options, columns, policy) {
|
|
8
|
+
const name = options.name ?? "Table" + id;
|
|
9
|
+
if (typeof name !== "string" || name.length > 255 || !/^[A-Za-z_][A-Za-z0-9_.]*$/.test(name) ||
|
|
10
|
+
/^(?:[A-Za-z]{1,3}[1-9][0-9]*|R[1-9][0-9]*C[1-9][0-9]*|R|C)$/i.test(name))
|
|
11
|
+
throw new TypeError("Table names must be ASCII identifiers, at most 255 characters, and cannot be cell references.");
|
|
12
|
+
const style = options.style ?? "TableStyleMedium2", match = /^TableStyle(Light|Medium|Dark)([1-9][0-9]?)$/.exec(style);
|
|
13
|
+
if (!match || Number(match[2]) > ({ Light: 21, Medium: 28, Dark: 11 }[match[1]] ?? 0))
|
|
14
|
+
throw new TypeError("Unknown built-in Excel table style.");
|
|
15
|
+
const headers = columns.map(column => cellText(column.header, policy));
|
|
16
|
+
if (!headers.length || headers.some(header => !header.trim() || header.length > 255) || new Set(headers.map(header => header.toLowerCase())).size !== headers.length)
|
|
17
|
+
throw new TypeError("Excel tables require nonblank, unique headers of at most 255 characters.");
|
|
18
|
+
return Object.freeze({ id, name, headers: Object.freeze(headers), keys: Object.freeze(columns.map(c => c.key ?? c.header)), options: Object.freeze({ ...options, style }) });
|
|
19
|
+
}
|
|
20
|
+
export function tableXml(table, rowCount, policy, headerRow = 1, footer) {
|
|
21
|
+
const dataRef = "A" + headerRow + ":" + columnName(table.headers.length) + (rowCount + headerRow), ref = "A" + headerRow + ":" + columnName(table.headers.length) + (rowCount + headerRow + (footer ? 1 : 0)), options = table.options;
|
|
22
|
+
const name = escapeOoxmlAttribute(table.name, policy);
|
|
23
|
+
return xmlDeclaration + '<table xmlns="' + spreadsheetNamespace + '" id="' + table.id + '" name="' + name + '" displayName="' + name + '" ref="' + ref + '"' + (footer ? ' totalsRowCount="1"' : ' totalsRowShown="0"') + '>' +
|
|
24
|
+
'<autoFilter ref="' + dataRef + '"/><tableColumns count="' + table.headers.length + '">' +
|
|
25
|
+
table.headers.map((header, i) => {
|
|
26
|
+
const key = table.keys[i], operation = footer?.totals && Object.prototype.hasOwnProperty.call(footer.totals, key) ? footer.totals[key] : undefined, supplied = footer?.values?.[i], value = supplied instanceof Cell || supplied instanceof ExportCell ? supplied.value : supplied;
|
|
27
|
+
const custom = operation && ["average", "min", "max"].includes(operation);
|
|
28
|
+
const attributes = operation ? ' totalsRowFunction="' + (custom ? "custom" : operation === "count" ? "countNums" : operation) + '"' : typeof value === "string" ? ' totalsRowLabel="' + escapeOoxmlAttribute(value, policy) + '"' : "";
|
|
29
|
+
return '<tableColumn id="' + (i + 1) + '" name="' + escapeOoxmlAttribute(header, policy) + '"' + attributes +
|
|
30
|
+
(custom ? '><totalsRowFormula>' + escapeXml(totalFormula(operation, columnName(i + 1), headerRow, rowCount), policy) + '</totalsRowFormula></tableColumn>' : '/>');
|
|
31
|
+
}).join("") +
|
|
32
|
+
'</tableColumns><tableStyleInfo name="' + options.style + '" showFirstColumn="' + (options.firstColumn ? 1 : 0) +
|
|
33
|
+
'" showLastColumn="' + (options.lastColumn ? 1 : 0) + '" showRowStripes="' + (options.bandedRows !== false ? 1 : 0) +
|
|
34
|
+
'" showColumnStripes="' + (options.bandedColumns ? 1 : 0) + '"/></table>';
|
|
35
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { ColumnSettings, CellValue, StreamOptions, TableSpanRows } from "../core/index.js";
|
|
2
|
+
import type { ProjectedColumn } from "../internal/columns.js";
|
|
3
|
+
import type { ExportLimits } from "../core/limits.js";
|
|
4
|
+
import type { InvalidCharacterPolicy } from "../xml/index.js";
|
|
5
|
+
import type { Compression } from "../zip/index.js";
|
|
6
|
+
import type { PackagePart, Relationship } from "../opc/index.js";
|
|
7
|
+
import type { CoreProperties, AppProperties } from "../opc/index.js";
|
|
8
|
+
import type { Cell } from "./values.js";
|
|
9
|
+
import type { CellStyle } from "./styles.js";
|
|
10
|
+
import type { Hyperlink } from "./attachments.js";
|
|
11
|
+
import type { ExportValue } from "../core/presentation.js";
|
|
12
|
+
import type { ConditionalFormat } from "./conditional-types.js";
|
|
13
|
+
import type { FormulaCell } from "./formula.js";
|
|
14
|
+
import type { ListValidation } from "./validation-types.js";
|
|
15
|
+
export type XlsxRow = readonly (ExportValue | Cell | FormulaCell)[] | Readonly<Record<string, ExportValue | Cell | FormulaCell>>;
|
|
16
|
+
export type XlsxRows = Iterable<XlsxRow> | AsyncIterable<XlsxRow>;
|
|
17
|
+
/** Advanced worksheet column with an optional style registered on its owning workbook. */
|
|
18
|
+
interface XlsxColumnSettings extends ColumnSettings {
|
|
19
|
+
readonly style?: number;
|
|
20
|
+
}
|
|
21
|
+
export type XlsxColumn<T = never> = ProjectedColumn<T, ExportValue | Cell | FormulaCell> & XlsxColumnSettings;
|
|
22
|
+
export interface CellWriterContext {
|
|
23
|
+
readonly column: XlsxColumn;
|
|
24
|
+
readonly rowIndex: number;
|
|
25
|
+
readonly worksheetRow: number;
|
|
26
|
+
readonly columnIndex: number;
|
|
27
|
+
readonly sheetName: string;
|
|
28
|
+
}
|
|
29
|
+
/** Convert domain column values to plain values or styled Cells; raw XML is never accepted. */
|
|
30
|
+
export type CellValueWriter = (value: CellValue, context: CellWriterContext) => ExportValue | Cell | FormulaCell;
|
|
31
|
+
/** Data indexes are zero-based. worksheetRow is the explicit one-based Excel coordinate. */
|
|
32
|
+
export interface RowStyleContext {
|
|
33
|
+
readonly rowIndex: number;
|
|
34
|
+
readonly worksheetRow: number;
|
|
35
|
+
readonly values: readonly CellValue[];
|
|
36
|
+
readonly sheetName: string;
|
|
37
|
+
}
|
|
38
|
+
export interface CellStyleContext extends RowStyleContext {
|
|
39
|
+
readonly value: CellValue;
|
|
40
|
+
readonly column: XlsxColumn;
|
|
41
|
+
readonly columnIndex: number;
|
|
42
|
+
}
|
|
43
|
+
/** Native Excel outline metadata for a serialized worksheet data row. */
|
|
44
|
+
export interface RowOutline {
|
|
45
|
+
/** Zero is a summary row; Excel supports at most seven nested detail levels. */
|
|
46
|
+
readonly level?: number;
|
|
47
|
+
readonly hidden?: boolean;
|
|
48
|
+
/** Marks a summary row whose preceding detail rows are initially hidden. */
|
|
49
|
+
readonly collapsed?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** A real Excel table over this worksheet's header and data rows. Empty exports retain headers without a table part. */
|
|
52
|
+
export interface TableOptions {
|
|
53
|
+
readonly name?: string;
|
|
54
|
+
/** Built-in Excel TableStyleLight1..21, TableStyleMedium1..28 or TableStyleDark1..11. */
|
|
55
|
+
readonly style?: string;
|
|
56
|
+
readonly bandedRows?: boolean;
|
|
57
|
+
readonly bandedColumns?: boolean;
|
|
58
|
+
readonly firstColumn?: boolean;
|
|
59
|
+
readonly lastColumn?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface WorkbookOptions extends StreamOptions, CoreProperties {
|
|
62
|
+
/** Selected before rows are written. Streamed worksheets are completed in order. The caller owns the sink. */
|
|
63
|
+
readonly sink?: import("../core/sinks.js").ByteSink;
|
|
64
|
+
readonly limits?: WorkbookLimits;
|
|
65
|
+
readonly dateMode?: "local" | "utc";
|
|
66
|
+
readonly compression?: Compression;
|
|
67
|
+
readonly invalidCharacterPolicy?: InvalidCharacterPolicy;
|
|
68
|
+
readonly appProperties?: AppProperties;
|
|
69
|
+
readonly cellValueWriters?: Readonly<Record<string, CellValueWriter>>;
|
|
70
|
+
/** Reject by default. Preserve keeps a bounded preview and the full text in numbered overflow-sheet chunks. */
|
|
71
|
+
readonly oversizedText?: "reject" | "preserve";
|
|
72
|
+
}
|
|
73
|
+
export interface WorkbookLimits extends ExportLimits {
|
|
74
|
+
readonly maxStyles?: number;
|
|
75
|
+
readonly maxSheets?: number;
|
|
76
|
+
/** Retained UTF-16 units before the overflow sheet is emitted; defaults to 4,000,000. */
|
|
77
|
+
readonly maxOverflowCharacters?: number;
|
|
78
|
+
readonly maxHyperlinks?: number;
|
|
79
|
+
readonly maxImageBytes?: number;
|
|
80
|
+
readonly maxBufferedCells?: number;
|
|
81
|
+
/** UTF-16 units of encoded row XML retained during width sampling, including markup. */
|
|
82
|
+
readonly maxBufferedCharacters?: number;
|
|
83
|
+
/** Includes generated title/group merges across the workbook; defaults to 10,000. */
|
|
84
|
+
readonly maxMergedRanges?: number;
|
|
85
|
+
/** Workbook-wide rule count, including data-only rules on empty sheets; defaults to 1,000. */
|
|
86
|
+
readonly maxConditionalFormats?: number;
|
|
87
|
+
/** Unique conditional differential styles across the workbook; defaults to 1,000. */
|
|
88
|
+
readonly maxDifferentialStyles?: number;
|
|
89
|
+
/** Native charts across the workbook; defaults to 100. Snapshot charts also own a hidden data sheet. */
|
|
90
|
+
readonly maxCharts?: number;
|
|
91
|
+
/** Numeric cached data points across all chart series; defaults to 100,000. */
|
|
92
|
+
readonly maxChartPoints?: number;
|
|
93
|
+
/** Captured category/name/title/axis/label text across all charts; defaults to 1,000,000 UTF-16 units. */
|
|
94
|
+
readonly maxChartTextCharacters?: number;
|
|
95
|
+
/** Authored formula text across all cells; defaults to 1,000,000 UTF-16 units. */
|
|
96
|
+
readonly maxFormulaCharacters?: number;
|
|
97
|
+
/** Inline-list rules across all worksheets, including empty sources; defaults to 1,000. */
|
|
98
|
+
readonly maxDataValidations?: number;
|
|
99
|
+
/** Captured list items and messages across all rules; defaults to 1,000,000 UTF-16 units. */
|
|
100
|
+
readonly maxValidationTextCharacters?: number;
|
|
101
|
+
}
|
|
102
|
+
export interface XlsxExportResult {
|
|
103
|
+
readonly rows: number;
|
|
104
|
+
readonly sheets: number;
|
|
105
|
+
readonly bytes: number;
|
|
106
|
+
}
|
|
107
|
+
export interface SheetOptions<T = never> {
|
|
108
|
+
readonly columns?: readonly XlsxColumn<T>[];
|
|
109
|
+
readonly includeHeader?: boolean;
|
|
110
|
+
/** Replaces inferred group/leaf headings with a rectangular matrix; covered positions are null. */
|
|
111
|
+
readonly headerRows?: TableSpanRows;
|
|
112
|
+
readonly freezeHeader?: boolean;
|
|
113
|
+
readonly autoFilter?: boolean;
|
|
114
|
+
readonly boldHeader?: boolean;
|
|
115
|
+
readonly headerFill?: string;
|
|
116
|
+
readonly headerStyle?: number;
|
|
117
|
+
/** Presentation patches retain column number/date formats. The second data row gets this patch first. */
|
|
118
|
+
readonly alternatingRowStyle?: CellStyle;
|
|
119
|
+
readonly rowStyle?: (context: RowStyleContext) => CellStyle | undefined;
|
|
120
|
+
readonly cellStyle?: (context: CellStyleContext) => CellStyle | undefined;
|
|
121
|
+
/** Native row outlines, captured once during serialization. Requires an explicit maximum level. */
|
|
122
|
+
readonly rowOutline?: (context: RowStyleContext) => RowOutline | undefined;
|
|
123
|
+
/** Declared outline upper bound, from zero through seven; emitted before streamed rows. */
|
|
124
|
+
readonly maxOutlineLevel?: number;
|
|
125
|
+
readonly rowHeight?: number;
|
|
126
|
+
readonly headerHeight?: number;
|
|
127
|
+
/** Fallback width in characters. Native tables default to 20 when no column width is supplied. */
|
|
128
|
+
readonly defaultColumnWidth?: number;
|
|
129
|
+
readonly freezeColumns?: number;
|
|
130
|
+
readonly table?: TableOptions;
|
|
131
|
+
readonly autoSize?: AutoSizeOptions;
|
|
132
|
+
readonly footer?: FooterOptions;
|
|
133
|
+
readonly print?: PrintOptions;
|
|
134
|
+
readonly title?: ReportTitle;
|
|
135
|
+
/** Uppercase A1 ranges within exported rows/columns. Covered cells must be empty; ranges cannot intersect a native table or another merge. */
|
|
136
|
+
readonly mergedCells?: readonly string[];
|
|
137
|
+
readonly hyperlinks?: readonly Hyperlink[];
|
|
138
|
+
readonly conditionalFormats?: readonly ConditionalFormat[];
|
|
139
|
+
readonly dataValidation?: readonly ListValidation[];
|
|
140
|
+
}
|
|
141
|
+
/** A single merged report title above grouped/leaf headings. Print repetition includes headings only. */
|
|
142
|
+
export interface ReportTitle {
|
|
143
|
+
readonly text: string;
|
|
144
|
+
readonly style?: CellStyle;
|
|
145
|
+
readonly height?: number;
|
|
146
|
+
}
|
|
147
|
+
/** Widths use a bounded leading sample and an approximate character count. Automatic sampling stops within buffer budgets; an explicit sampleRows fails when its sample exceeds them. */
|
|
148
|
+
export interface AutoSizeOptions {
|
|
149
|
+
/** Leading rows to inspect, through Excel's row capacity. Large explicit samples require matching buffer budgets. */
|
|
150
|
+
readonly sampleRows?: number;
|
|
151
|
+
readonly minWidth?: number;
|
|
152
|
+
readonly maxWidth?: number;
|
|
153
|
+
}
|
|
154
|
+
export type TotalOperation = "sum" | "count" | "average" | "min" | "max";
|
|
155
|
+
export interface FooterOptions {
|
|
156
|
+
/** Explicit rectangular footer, outside the native table. Cannot accompany values or totals. */
|
|
157
|
+
readonly rows?: TableSpanRows;
|
|
158
|
+
/** One explicit value per declared column; computed totals replace the corresponding value. */
|
|
159
|
+
readonly values?: readonly (ExportValue | Cell | FormulaCell)[];
|
|
160
|
+
readonly totals?: Readonly<Record<string, TotalOperation>>;
|
|
161
|
+
readonly style?: import("./styles.js").CellStyle;
|
|
162
|
+
}
|
|
163
|
+
export interface PrintOptions {
|
|
164
|
+
readonly paper?: "A4" | "Letter";
|
|
165
|
+
readonly orientation?: "portrait" | "landscape";
|
|
166
|
+
readonly fitToWidth?: number;
|
|
167
|
+
readonly fitToHeight?: number;
|
|
168
|
+
readonly repeatHeaders?: boolean;
|
|
169
|
+
readonly margins?: Readonly<Partial<Record<"left" | "right" | "top" | "bottom" | "header" | "footer", number>>>;
|
|
170
|
+
/** Literal center header/footer text. Ampersands are escaped, so Excel control codes are not interpreted. */
|
|
171
|
+
readonly header?: string;
|
|
172
|
+
readonly footer?: string;
|
|
173
|
+
}
|
|
174
|
+
export interface ExtraPart extends PackagePart {
|
|
175
|
+
/** Optional relationship to this part, from the workbook unless a source is supplied. */
|
|
176
|
+
readonly relationship?: Omit<Relationship, "target" | "external"> & {
|
|
177
|
+
readonly source?: string;
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** An inline dropdown applied only to the selected exported data column, after its final row count is known. */
|
|
2
|
+
export interface ListValidation {
|
|
3
|
+
readonly type: "list";
|
|
4
|
+
/** One-based column number, or an unambiguous declared column key. */
|
|
5
|
+
readonly column: string | number;
|
|
6
|
+
/** Literal dropdown choices. Commas are not supported; the quoted list source must fit 255 UTF-16 units. */
|
|
7
|
+
readonly items: readonly string[];
|
|
8
|
+
/** Defaults to true, matching OfficeIMO.Excel.ValidationList. */
|
|
9
|
+
readonly allowBlank?: boolean;
|
|
10
|
+
/** Defaults to true. Excel applies the alert when the user edits a validated cell. */
|
|
11
|
+
readonly showErrorMessage?: boolean;
|
|
12
|
+
/** Defaults to stop. Warning and information alerts allow the user to accept a value outside the list. */
|
|
13
|
+
readonly errorStyle?: "stop" | "warning" | "information";
|
|
14
|
+
/** At most 32 XML-valid UTF-16 units. */
|
|
15
|
+
readonly errorTitle?: string;
|
|
16
|
+
/** At most 255 XML-valid UTF-16 units. */
|
|
17
|
+
readonly errorMessage?: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
2
|
+
import { checkAbort } from "../core/iteration.js";
|
|
3
|
+
import { cleanXml, escapeOoxmlAttribute, escapeXml } from "../xml/index.js";
|
|
4
|
+
import { fields, optionalBoolean } from "./differential-styles.js";
|
|
5
|
+
import { resolveDataColumn } from "./ranges.js";
|
|
6
|
+
import { dataRowReference } from "./data-row-ranges.js";
|
|
7
|
+
function message(value, maximum, name) {
|
|
8
|
+
if (value === undefined)
|
|
9
|
+
return undefined;
|
|
10
|
+
if (typeof value !== "string")
|
|
11
|
+
throw new TypeError(name + " must be text.");
|
|
12
|
+
if (value.length > maximum)
|
|
13
|
+
throw new RangeError(name + " exceeds " + maximum + " UTF-16 units.");
|
|
14
|
+
return cleanXml(value, "reject");
|
|
15
|
+
}
|
|
16
|
+
/** @internal Snapshot and validate before any source iteration or workbook registration. */
|
|
17
|
+
export function prepareDataValidations(rules, columns, availableCount = 1000, availableText = 1000000, signal) {
|
|
18
|
+
checkAbort(signal);
|
|
19
|
+
if (rules === undefined)
|
|
20
|
+
return Object.freeze({ rules: Object.freeze([]), count: 0, textCharacters: 0 });
|
|
21
|
+
if (!Array.isArray(rules))
|
|
22
|
+
throw new TypeError("dataValidation must be an array.");
|
|
23
|
+
const count = rules.length;
|
|
24
|
+
if (count > availableCount)
|
|
25
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxDataValidations exceeded.");
|
|
26
|
+
const prepared = [];
|
|
27
|
+
const usedColumns = new Set();
|
|
28
|
+
let textCharacters = 0;
|
|
29
|
+
const acceptText = (length) => {
|
|
30
|
+
if (textCharacters + length > availableText)
|
|
31
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxValidationTextCharacters exceeded.");
|
|
32
|
+
textCharacters += length;
|
|
33
|
+
};
|
|
34
|
+
for (let index = 0; index < count; index++) {
|
|
35
|
+
checkAbort(signal);
|
|
36
|
+
const rule = rules[index];
|
|
37
|
+
fields(rule, ["type", "column", "items", "allowBlank", "showErrorMessage", "errorStyle", "errorTitle", "errorMessage"], "data validation");
|
|
38
|
+
const { type, column, items, allowBlank, showErrorMessage, errorStyle, errorTitle, errorMessage } = rule;
|
|
39
|
+
if (type !== "list")
|
|
40
|
+
throw new TypeError("Only inline-list data validation is supported.");
|
|
41
|
+
const selected = resolveDataColumn(columns, column, "Validation");
|
|
42
|
+
if (usedColumns.has(selected))
|
|
43
|
+
throw new TypeError("A data column cannot have multiple validation rules.");
|
|
44
|
+
usedColumns.add(selected);
|
|
45
|
+
optionalBoolean(allowBlank, "allowBlank");
|
|
46
|
+
optionalBoolean(showErrorMessage, "showErrorMessage");
|
|
47
|
+
if (errorStyle !== undefined && !["stop", "warning", "information"].includes(errorStyle))
|
|
48
|
+
throw new TypeError("Unsupported validation error style.");
|
|
49
|
+
if (!Array.isArray(items))
|
|
50
|
+
throw new TypeError("Inline validation lists require a nonempty string array.");
|
|
51
|
+
// Even empty choices need separators. Bound the loop before observing any item getters.
|
|
52
|
+
const itemCount = items.length;
|
|
53
|
+
if (!itemCount)
|
|
54
|
+
throw new TypeError("Inline validation lists require a nonempty string array.");
|
|
55
|
+
if (itemCount > 254)
|
|
56
|
+
throw new RangeError("Inline validation lists must fit 255 UTF-16 units including quotes and separators.");
|
|
57
|
+
let formula = '"';
|
|
58
|
+
for (let item = 0; item < itemCount; item++) {
|
|
59
|
+
checkAbort(signal);
|
|
60
|
+
const value = items[item];
|
|
61
|
+
if (typeof value !== "string")
|
|
62
|
+
throw new TypeError("Inline validation choices must be strings.");
|
|
63
|
+
if (value.length > 253 || value.includes(","))
|
|
64
|
+
throw new RangeError("Inline validation choices cannot contain commas and must fit the 255-character list source.");
|
|
65
|
+
cleanXml(value, "reject");
|
|
66
|
+
const escaped = value.replace(/"/g, '""');
|
|
67
|
+
if (formula.length + (item ? 1 : 0) + escaped.length + 1 > 255)
|
|
68
|
+
throw new RangeError("Inline validation lists must fit 255 UTF-16 units including quotes and separators.");
|
|
69
|
+
formula += (item ? "," : "") + escaped;
|
|
70
|
+
}
|
|
71
|
+
formula += '"';
|
|
72
|
+
const title = message(errorTitle, 32, "Validation error title"), error = message(errorMessage, 255, "Validation error message");
|
|
73
|
+
acceptText(formula.length + (title?.length ?? 0) + (error?.length ?? 0));
|
|
74
|
+
const attributes = ' type="list" allowBlank="' + (allowBlank === false ? 0 : 1) + '" showErrorMessage="' + (showErrorMessage === false ? 0 : 1) +
|
|
75
|
+
'" errorStyle="' + (errorStyle ?? "stop") + '"' + (title === undefined ? "" : ' errorTitle="' + escapeOoxmlAttribute(title, "reject") + '"') +
|
|
76
|
+
(error === undefined ? "" : ' error="' + escapeOoxmlAttribute(error, "reject") + '"');
|
|
77
|
+
prepared.push(Object.freeze({ column: selected, attributes, formula }));
|
|
78
|
+
}
|
|
79
|
+
checkAbort(signal);
|
|
80
|
+
return Object.freeze({ rules: Object.freeze(prepared), count, textCharacters });
|
|
81
|
+
}
|
|
82
|
+
/** @internal Empty sources do not create validation over headings, totals or an artificial blank row. */
|
|
83
|
+
export function* dataValidationsXml(prepared, headerRows, dataRows, ranges) {
|
|
84
|
+
if (!prepared.count || !dataRows || ranges?.length === 0)
|
|
85
|
+
return;
|
|
86
|
+
yield '<dataValidations count="' + prepared.count + '">';
|
|
87
|
+
for (const rule of prepared.rules) {
|
|
88
|
+
const reference = dataRowReference(rule.column, rule.column, headerRows, dataRows, ranges);
|
|
89
|
+
yield '<dataValidation' + rule.attributes + ' sqref="' + reference + '"><formula1>' + escapeXml(rule.formula, "reject") + '</formula1></dataValidation>';
|
|
90
|
+
}
|
|
91
|
+
yield '</dataValidations>';
|
|
92
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { InvalidCharacterPolicy } from "../xml/index.js";
|
|
2
|
+
import type { CellValue } from "../core/index.js";
|
|
3
|
+
/** A typed value plus a workbook-local style index. */
|
|
4
|
+
export declare class Cell {
|
|
5
|
+
readonly value: CellValue;
|
|
6
|
+
readonly style?: number | undefined;
|
|
7
|
+
constructor(value: CellValue, style?: number | undefined);
|
|
8
|
+
}
|
|
9
|
+
export declare function cellText(value: unknown, policy?: InvalidCharacterPolicy): string;
|
|
10
|
+
export declare function inlineText(value: unknown, policy: InvalidCharacterPolicy): string;
|
|
11
|
+
export declare function columnName(index: number): string;
|
|
12
|
+
export declare function sheetName(requested: string, names: Set<string>, policy: InvalidCharacterPolicy, register?: boolean): string;
|
|
13
|
+
export declare function excelDate(date: Date, mode: "local" | "utc"): number | null;
|