@evotecit/officeimo 0.0.0-stage → 0.1.0
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 +1219 -2
- package/bundles/officeimo-canopyx.js +11286 -0
- package/bundles/officeimo-canopyx.mjs +11185 -0
- package/bundles/officeimo-csv.js +1254 -0
- package/bundles/officeimo-csv.mjs +1229 -0
- package/bundles/officeimo-datatables.js +11572 -0
- package/bundles/officeimo-datatables.mjs +11470 -0
- package/bundles/officeimo-execution.js +1503 -0
- package/bundles/officeimo-execution.mjs +1479 -0
- package/bundles/officeimo-pdf.js +6564 -0
- package/bundles/officeimo-pdf.mjs +6502 -0
- package/bundles/officeimo-xlsx.js +5333 -0
- package/bundles/officeimo-xlsx.mjs +5279 -0
- package/bundles/officeimo.js +11022 -0
- package/bundles/officeimo.mjs +10924 -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 +72 -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 +101 -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 +116 -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 +68 -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 +194 -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 +201 -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 +142 -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 +143 -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 +679 -0
- package/dist/pdf/paragraph-layout.d.ts +19 -0
- package/dist/pdf/paragraph-layout.js +66 -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 +15 -0
- package/dist/pdf/settings.js +171 -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 +250 -0
- package/dist/pdf/table-band-flow.d.ts +34 -0
- package/dist/pdf/table-band-flow.js +114 -0
- package/dist/pdf/table-band-plan.d.ts +10 -0
- package/dist/pdf/table-band-plan.js +85 -0
- package/dist/pdf/table-layout.d.ts +71 -0
- package/dist/pdf/table-layout.js +205 -0
- package/dist/pdf/table-structure.d.ts +1 -0
- package/dist/pdf/table-structure.js +92 -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 +96 -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 +169 -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/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 +86 -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,158 @@
|
|
|
1
|
+
import { cleanXml, escapeXml, escapeOoxmlAttribute } from "../xml/index.js";
|
|
2
|
+
import { cellPosition } from "./attachments.js";
|
|
3
|
+
import { colorArgb } from "./style-xml.js";
|
|
4
|
+
import { fields, optionalBoolean, differentialXml } from "./differential-styles.js";
|
|
5
|
+
import { resolveDataColumn } from "./ranges.js";
|
|
6
|
+
import { dataRowReference } from "./data-row-ranges.js";
|
|
7
|
+
function target(range, columns) {
|
|
8
|
+
if (typeof range === "string") {
|
|
9
|
+
const parts = range.split(":");
|
|
10
|
+
if (parts.length > 2)
|
|
11
|
+
throw new TypeError("Conditional ranges require one uppercase A1 cell or rectangle.");
|
|
12
|
+
const first = cellPosition(parts[0]), last = cellPosition(parts[1] ?? parts[0]);
|
|
13
|
+
if (last.row < first.row || last.column < first.column || last.column > columns.length)
|
|
14
|
+
throw new RangeError("Conditional ranges require ordered cells within declared columns.");
|
|
15
|
+
return { first: first.column, last: last.column, reference: range, bottom: last.row };
|
|
16
|
+
}
|
|
17
|
+
fields(range, ["column", "through"], "conditional data range");
|
|
18
|
+
const first = resolveDataColumn(columns, range.column, "Conditional"), last = range.through === undefined ? first : resolveDataColumn(columns, range.through, "Conditional");
|
|
19
|
+
if (last < first)
|
|
20
|
+
throw new RangeError("Conditional data ranges require ordered columns.");
|
|
21
|
+
return { first, last };
|
|
22
|
+
}
|
|
23
|
+
function finite(value) {
|
|
24
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
25
|
+
throw new TypeError("Conditional values must be finite numbers.");
|
|
26
|
+
return String(value);
|
|
27
|
+
}
|
|
28
|
+
function comparisonValue(value, operator) {
|
|
29
|
+
if (typeof value !== "string")
|
|
30
|
+
return finite(value);
|
|
31
|
+
if (operator !== "equal" && operator !== "notEqual")
|
|
32
|
+
throw new TypeError("Text conditional comparisons support only equal and notEqual.");
|
|
33
|
+
if (value.length > 8190)
|
|
34
|
+
throw new RangeError("Conditional comparison formulas must fit 8,192 characters including quotes.");
|
|
35
|
+
cleanXml(value, "reject");
|
|
36
|
+
const literal = '"' + value.replace(/"/g, '""') + '"';
|
|
37
|
+
if (literal.length > 8192)
|
|
38
|
+
throw new RangeError("Conditional comparison formulas must fit 8,192 characters including quotes.");
|
|
39
|
+
return literal;
|
|
40
|
+
}
|
|
41
|
+
function formula(value) {
|
|
42
|
+
if (typeof value !== "string")
|
|
43
|
+
throw new TypeError("Conditional formulas must be strings.");
|
|
44
|
+
const text = value.trim().replace(/^=/, "");
|
|
45
|
+
if (!text.trim() || text.length > 8192)
|
|
46
|
+
throw new RangeError("Conditional formulas require 1 through 8,192 characters.");
|
|
47
|
+
// Stripping invalid characters could change a calculation; reject them even under the text-strip policy.
|
|
48
|
+
cleanXml(text, "reject");
|
|
49
|
+
return text;
|
|
50
|
+
}
|
|
51
|
+
function threshold(value, position) {
|
|
52
|
+
fields(value, value.type === "min" || value.type === "max" ? ["type"] : ["type", "value"], "conditional threshold");
|
|
53
|
+
if (value.type === "min" || value.type === "max") {
|
|
54
|
+
if (value.type !== (position === "first" ? "min" : position === "last" ? "max" : ""))
|
|
55
|
+
throw new TypeError("Use min only at the start and max only at the end of a scale.");
|
|
56
|
+
return '<cfvo type="' + value.type + '"/>';
|
|
57
|
+
}
|
|
58
|
+
if (value.type === "formula")
|
|
59
|
+
return '<cfvo type="formula" val="' + escapeOoxmlAttribute(formula(value.value), "reject") + '"/>';
|
|
60
|
+
if (!["number", "percent", "percentile"].includes(value.type))
|
|
61
|
+
throw new TypeError("Unsupported conditional threshold type.");
|
|
62
|
+
if (!("value" in value))
|
|
63
|
+
throw new TypeError("A numeric threshold requires a value.");
|
|
64
|
+
const number = finite(value.value);
|
|
65
|
+
if (value.type !== "number" && (value.value < 0 || value.value > 100))
|
|
66
|
+
throw new RangeError("Conditional percent/percentile thresholds must be from 0 through 100.");
|
|
67
|
+
return '<cfvo type="' + (value.type === "number" ? "num" : value.type) + '" val="' + number + '"/>';
|
|
68
|
+
}
|
|
69
|
+
function ordered(values) {
|
|
70
|
+
for (let i = 1; i < values.length; i++) {
|
|
71
|
+
const before = values[i - 1], after = values[i];
|
|
72
|
+
if ("value" in before && "value" in after && before.type === after.type && typeof before.value === "number" && typeof after.value === "number" && before.value > after.value)
|
|
73
|
+
throw new RangeError("Conditional thresholds of the same numeric type must be ordered.");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** @internal Compile bounded metadata once, outside the row hot path. */
|
|
77
|
+
export function prepareConditionalFormats(rules, columns, policy) {
|
|
78
|
+
if (rules === undefined)
|
|
79
|
+
return [];
|
|
80
|
+
if (!Array.isArray(rules))
|
|
81
|
+
throw new TypeError("conditionalFormats must be an array.");
|
|
82
|
+
return rules.map(rule => {
|
|
83
|
+
const common = ["type", "range"], highlighting = ["style", "stopIfTrue"];
|
|
84
|
+
fields(rule, [...common, ...(rule?.type === "cellIs" ? [...highlighting, "operator", "value", "values"] : rule?.type === "expression" ? [...highlighting, "formula"] : rule?.type === "colorScale" ? ["stops"] : rule?.type === "dataBar" ? ["color", "minimum", "maximum", "showValue"] : [])], "conditional rule");
|
|
85
|
+
const selected = target(rule.range, columns);
|
|
86
|
+
let attributes = "", body = "", style;
|
|
87
|
+
if (rule.type === "cellIs" || rule.type === "expression") {
|
|
88
|
+
optionalBoolean(rule.stopIfTrue, "stopIfTrue");
|
|
89
|
+
differentialXml(rule.style, policy, () => 164);
|
|
90
|
+
style = { ...rule.style, ...(rule.style.font ? { font: { ...rule.style.font } } : {}), ...(rule.style.fill ? { fill: { ...rule.style.fill } } : {}),
|
|
91
|
+
...(rule.style.border ? { border: Object.fromEntries(Object.entries(rule.style.border).filter(([, edge]) => edge !== undefined).map(([side, edge]) => [side, { ...edge }])) } : {}) };
|
|
92
|
+
if (rule.stopIfTrue !== undefined)
|
|
93
|
+
attributes += ' stopIfTrue="' + (rule.stopIfTrue ? 1 : 0) + '"';
|
|
94
|
+
if (rule.type === "expression")
|
|
95
|
+
body = '<formula>' + escapeXml(formula(rule.formula), "reject") + '</formula>';
|
|
96
|
+
else {
|
|
97
|
+
const pair = rule.operator === "between" || rule.operator === "notBetween";
|
|
98
|
+
if (!["equal", "notEqual", "greaterThan", "greaterThanOrEqual", "lessThan", "lessThanOrEqual", "between", "notBetween"].includes(rule.operator))
|
|
99
|
+
throw new TypeError("Unsupported conditional comparison operator.");
|
|
100
|
+
if (pair) {
|
|
101
|
+
if ("value" in rule || !Array.isArray(rule.values) || rule.values.length !== 2)
|
|
102
|
+
throw new TypeError("between/notBetween require exactly two values.");
|
|
103
|
+
body = rule.values.map(value => '<formula>' + finite(value) + '</formula>').join("");
|
|
104
|
+
if (rule.values[0] > rule.values[1])
|
|
105
|
+
throw new RangeError("Conditional comparison bounds must be ordered.");
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if ("values" in rule || !("value" in rule))
|
|
109
|
+
throw new TypeError("A conditional comparison requires one value.");
|
|
110
|
+
body = '<formula>' + escapeXml(comparisonValue(rule.value, rule.operator), "reject") + '</formula>';
|
|
111
|
+
}
|
|
112
|
+
attributes += ' operator="' + rule.operator + '"';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (rule.type === "colorScale") {
|
|
116
|
+
if (!Array.isArray(rule.stops) || (rule.stops.length !== 2 && rule.stops.length !== 3))
|
|
117
|
+
throw new TypeError("Color scales require two or three stops.");
|
|
118
|
+
const colors = [], thresholds = [];
|
|
119
|
+
body = '<colorScale>' + rule.stops.map((stop, i) => {
|
|
120
|
+
fields(stop, ["threshold", "color"], "color stop");
|
|
121
|
+
colors.push(colorArgb(stop.color));
|
|
122
|
+
thresholds.push(stop.threshold);
|
|
123
|
+
return threshold(stop.threshold, i === 0 ? "first" : i === rule.stops.length - 1 ? "last" : "middle");
|
|
124
|
+
}).join("") + colors.map(color => '<color rgb="' + color + '"/>').join("") + '</colorScale>';
|
|
125
|
+
ordered(thresholds);
|
|
126
|
+
}
|
|
127
|
+
else if (rule.type === "dataBar") {
|
|
128
|
+
optionalBoolean(rule.showValue, "showValue");
|
|
129
|
+
const lower = rule.minimum === undefined ? { type: "min" } : rule.minimum, upper = rule.maximum === undefined ? { type: "max" } : rule.maximum;
|
|
130
|
+
body = '<dataBar showValue="' + (rule.showValue === false ? 0 : 1) + '">' + threshold(lower, "first") + threshold(upper, "last") + '<color rgb="' + colorArgb(rule.color) + '"/></dataBar>';
|
|
131
|
+
ordered([lower, upper]);
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
throw new TypeError("Unsupported conditional rule type.");
|
|
135
|
+
return { target: selected, type: rule.type, attributes, body, ...(style ? { style } : {}) };
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/** @internal Immutable worksheet-owned rule metadata; no cells or rows are retained. */
|
|
139
|
+
export class ConditionalFormats {
|
|
140
|
+
rules;
|
|
141
|
+
constructor(prepared, styles) {
|
|
142
|
+
const differential = styles.addDifferentials(prepared.flatMap(rule => rule.style ? [rule.style] : []));
|
|
143
|
+
let styleIndex = 0;
|
|
144
|
+
this.rules = prepared.map((rule, i) => ({ target: rule.target,
|
|
145
|
+
xml: '<cfRule type="' + rule.type + '" priority="' + (i + 1) + '"' + (rule.style ? ' dxfId="' + differential[styleIndex++] + '"' : "") + rule.attributes + '>' + rule.body + '</cfRule>' }));
|
|
146
|
+
}
|
|
147
|
+
get count() { return this.rules.length; }
|
|
148
|
+
*xml(headerRows, dataRows, totalRows, ranges) {
|
|
149
|
+
for (const rule of this.rules) {
|
|
150
|
+
if (rule.target.bottom !== undefined && rule.target.bottom > totalRows)
|
|
151
|
+
throw new RangeError("Conditional ranges must stay within exported rows.");
|
|
152
|
+
const reference = rule.target.reference ?? dataRowReference(rule.target.first, rule.target.last, headerRows, dataRows, ranges);
|
|
153
|
+
if (!reference)
|
|
154
|
+
continue;
|
|
155
|
+
yield '<conditionalFormatting sqref="' + reference + '">' + rule.xml + '</conditionalFormatting>';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Border, Font } from "./styles.js";
|
|
2
|
+
/** A1 cell/range, or data-only columns resolved after streaming finishes. Column numbers are one-based; strings are declared column keys. */
|
|
3
|
+
export type ConditionalRange = string | {
|
|
4
|
+
readonly column: string | number;
|
|
5
|
+
readonly through?: string | number;
|
|
6
|
+
};
|
|
7
|
+
/** Only supplied properties override the cell. Omitting numberFormat preserves the existing number/date format. */
|
|
8
|
+
export interface ConditionalStyle {
|
|
9
|
+
readonly font?: Pick<Font, "bold" | "italic" | "underline" | "strike" | "color">;
|
|
10
|
+
readonly fill?: {
|
|
11
|
+
readonly color: string;
|
|
12
|
+
};
|
|
13
|
+
readonly border?: Border;
|
|
14
|
+
readonly numberFormat?: string;
|
|
15
|
+
}
|
|
16
|
+
export type ConditionalOperator = "equal" | "notEqual" | "greaterThan" | "greaterThanOrEqual" | "lessThan" | "lessThanOrEqual";
|
|
17
|
+
/** Formula text uses Excel's invariant syntax. It is stored, never evaluated by this writer. */
|
|
18
|
+
export type ConditionalThreshold = {
|
|
19
|
+
readonly type: "min" | "max";
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "number" | "percent" | "percentile";
|
|
22
|
+
readonly value: number;
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "formula";
|
|
25
|
+
readonly value: string;
|
|
26
|
+
};
|
|
27
|
+
export interface ConditionalColorStop {
|
|
28
|
+
readonly threshold: ConditionalThreshold;
|
|
29
|
+
readonly color: string;
|
|
30
|
+
}
|
|
31
|
+
interface ConditionalBase {
|
|
32
|
+
readonly range: ConditionalRange;
|
|
33
|
+
}
|
|
34
|
+
interface ConditionalHighlight extends ConditionalBase {
|
|
35
|
+
readonly style: ConditionalStyle;
|
|
36
|
+
readonly stopIfTrue?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Array order sets worksheet-wide priority, starting at one. Overlapping ranges are allowed. */
|
|
39
|
+
export type ConditionalFormat = (ConditionalHighlight & {
|
|
40
|
+
readonly type: "cellIs";
|
|
41
|
+
readonly operator: ConditionalOperator;
|
|
42
|
+
readonly value: number;
|
|
43
|
+
}) | (ConditionalHighlight & {
|
|
44
|
+
readonly type: "cellIs";
|
|
45
|
+
readonly operator: "equal" | "notEqual";
|
|
46
|
+
readonly value: string;
|
|
47
|
+
}) | (ConditionalHighlight & {
|
|
48
|
+
readonly type: "cellIs";
|
|
49
|
+
readonly operator: "between" | "notBetween";
|
|
50
|
+
readonly values: readonly [number, number];
|
|
51
|
+
}) | (ConditionalHighlight & {
|
|
52
|
+
readonly type: "expression";
|
|
53
|
+
readonly formula: string;
|
|
54
|
+
}) | (ConditionalBase & {
|
|
55
|
+
readonly type: "colorScale";
|
|
56
|
+
readonly stops: readonly [ConditionalColorStop, ConditionalColorStop] | readonly [ConditionalColorStop, ConditionalColorStop, ConditionalColorStop];
|
|
57
|
+
}) | (ConditionalBase & {
|
|
58
|
+
readonly type: "dataBar";
|
|
59
|
+
readonly color: string;
|
|
60
|
+
readonly minimum?: ConditionalThreshold;
|
|
61
|
+
readonly maximum?: ConditionalThreshold;
|
|
62
|
+
readonly showValue?: boolean;
|
|
63
|
+
});
|
|
64
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
2
|
+
import { columnName } from "./values.js";
|
|
3
|
+
const scopes = new WeakMap();
|
|
4
|
+
/** @internal A format adapter owns this bounded list until worksheet completion. */
|
|
5
|
+
export function retainDataRowRanges(worksheet, ranges) { scopes.set(worksheet, ranges); }
|
|
6
|
+
/** @internal Ordinary worksheets retain their contiguous data-column contract. */
|
|
7
|
+
export function dataRowRanges(worksheet) { return scopes.get(worksheet); }
|
|
8
|
+
/** @internal Count accepted details while preserving physical row counts for native references. */
|
|
9
|
+
export function dataRowCount(worksheet, headerRows, serializedRows) {
|
|
10
|
+
const ranges = scopes.get(worksheet);
|
|
11
|
+
if (ranges === undefined)
|
|
12
|
+
return serializedRows;
|
|
13
|
+
const lastSerialized = headerRows + serializedRows;
|
|
14
|
+
let rows = 0;
|
|
15
|
+
for (const range of ranges) {
|
|
16
|
+
if (range.firstRow > lastSerialized)
|
|
17
|
+
break;
|
|
18
|
+
rows += Math.min(range.lastRow, lastSerialized) - range.firstRow + 1;
|
|
19
|
+
}
|
|
20
|
+
return rows;
|
|
21
|
+
}
|
|
22
|
+
/** @internal Native editing rules share one finite, bounded space-separated reference. */
|
|
23
|
+
export function dataRowReference(firstColumn, lastColumn, headerRows, dataRows, ranges) {
|
|
24
|
+
if (ranges === undefined)
|
|
25
|
+
return dataRows ? columnName(firstColumn) + (headerRows + 1) + ":" + columnName(lastColumn) + (headerRows + dataRows) : undefined;
|
|
26
|
+
const first = columnName(firstColumn), last = columnName(lastColumn);
|
|
27
|
+
let reference = "", previous = headerRows;
|
|
28
|
+
for (const range of ranges) {
|
|
29
|
+
if (!Number.isSafeInteger(range.firstRow) || !Number.isSafeInteger(range.lastRow) || range.firstRow <= previous ||
|
|
30
|
+
range.lastRow < range.firstRow || range.lastRow > headerRows + dataRows)
|
|
31
|
+
throw new RangeError("Detail editing ranges must be ordered within serialized worksheet rows.");
|
|
32
|
+
const next = first + range.firstRow + ":" + last + range.lastRow;
|
|
33
|
+
if (reference.length + (reference ? 1 : 0) + next.length > 32767)
|
|
34
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Detail editing references exceed 32,767 UTF-16 characters; split the worksheet.");
|
|
35
|
+
reference += (reference ? " " : "") + next;
|
|
36
|
+
previous = range.lastRow;
|
|
37
|
+
}
|
|
38
|
+
return reference || undefined;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
2
|
+
import { cleanXml, escapeOoxmlAttribute } from "../xml/index.js";
|
|
3
|
+
import { colorArgb } from "./style-xml.js";
|
|
4
|
+
/** @internal Reject unsupported properties rather than silently losing presentation. */
|
|
5
|
+
export function fields(value, allowed, label) {
|
|
6
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
7
|
+
throw new TypeError(label + " must be an object.");
|
|
8
|
+
if (typeof value.then === "function") {
|
|
9
|
+
void Promise.resolve(value).catch(() => { });
|
|
10
|
+
throw new TypeError(label + " must be synchronous.");
|
|
11
|
+
}
|
|
12
|
+
for (const key of Object.keys(value))
|
|
13
|
+
if (!allowed.includes(key))
|
|
14
|
+
throw new TypeError("Unsupported " + label + " property: " + key);
|
|
15
|
+
}
|
|
16
|
+
/** @internal */
|
|
17
|
+
export function optionalBoolean(value, name) {
|
|
18
|
+
if (value !== undefined && typeof value !== "boolean")
|
|
19
|
+
throw new TypeError(name + " must be boolean.");
|
|
20
|
+
}
|
|
21
|
+
/** @internal Differential styles contain no default font/fill/border properties. */
|
|
22
|
+
export class DifferentialStyles {
|
|
23
|
+
policy;
|
|
24
|
+
maximum;
|
|
25
|
+
numberFormat;
|
|
26
|
+
definitions = new Map();
|
|
27
|
+
constructor(policy, maximum, numberFormat) {
|
|
28
|
+
this.policy = policy;
|
|
29
|
+
this.maximum = maximum;
|
|
30
|
+
this.numberFormat = numberFormat;
|
|
31
|
+
}
|
|
32
|
+
keys(styles) {
|
|
33
|
+
// Validation and canonical XML precede registration, so equivalent property order shares a dxf.
|
|
34
|
+
const keys = styles.map(style => differentialXml(style, this.policy, () => 164));
|
|
35
|
+
const pending = new Set(keys.filter(definition => !this.definitions.has(definition)));
|
|
36
|
+
if (this.definitions.size + pending.size > this.maximum)
|
|
37
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxDifferentialStyles exceeded.");
|
|
38
|
+
return keys;
|
|
39
|
+
}
|
|
40
|
+
check(styles) { this.keys(styles); }
|
|
41
|
+
add(styles) {
|
|
42
|
+
const keys = this.keys(styles);
|
|
43
|
+
for (let i = 0; i < styles.length; i++)
|
|
44
|
+
if (!this.definitions.has(keys[i]))
|
|
45
|
+
this.definitions.set(keys[i], { id: this.definitions.size, xml: differentialXml(styles[i], this.policy, this.numberFormat) });
|
|
46
|
+
return keys.map(key => this.definitions.get(key).id);
|
|
47
|
+
}
|
|
48
|
+
toXml() {
|
|
49
|
+
return this.definitions.size ? '<dxfs count="' + this.definitions.size + '">' + [...this.definitions.values()].map(style => '<dxf>' + style.xml + '</dxf>').join("") + '</dxfs>' : "";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** @internal Also used for preflight before registering a worksheet name. */
|
|
53
|
+
export function differentialXml(style, policy, numberFormat) {
|
|
54
|
+
fields(style, ["font", "fill", "border", "numberFormat"], "conditional style");
|
|
55
|
+
let xml = "";
|
|
56
|
+
if (style.font !== undefined) {
|
|
57
|
+
fields(style.font, ["bold", "italic", "underline", "strike", "color"], "conditional font");
|
|
58
|
+
let font = "";
|
|
59
|
+
for (const [name, tag] of [["bold", "b"], ["italic", "i"], ["strike", "strike"]]) {
|
|
60
|
+
optionalBoolean(style.font[name], name);
|
|
61
|
+
if (style.font[name] !== undefined)
|
|
62
|
+
font += '<' + tag + ' val="' + (style.font[name] ? 1 : 0) + '"/>';
|
|
63
|
+
}
|
|
64
|
+
optionalBoolean(style.font.underline, "underline");
|
|
65
|
+
if (style.font.underline !== undefined)
|
|
66
|
+
font += '<u val="' + (style.font.underline ? "single" : "none") + '"/>';
|
|
67
|
+
if (style.font.color !== undefined)
|
|
68
|
+
font += '<color rgb="' + colorArgb(style.font.color) + '"/>';
|
|
69
|
+
if (font)
|
|
70
|
+
xml += '<font>' + font + '</font>';
|
|
71
|
+
}
|
|
72
|
+
if (style.numberFormat !== undefined) {
|
|
73
|
+
const format = style.numberFormat;
|
|
74
|
+
if (typeof format !== "string" || !format || format.length > 255 || !cleanXml(format, policy))
|
|
75
|
+
throw new TypeError("Conditional number format requires 1 through 255 XML-valid characters.");
|
|
76
|
+
xml += '<numFmt numFmtId="' + numberFormat(format) + '" formatCode="' + escapeOoxmlAttribute(format, policy) + '"/>';
|
|
77
|
+
}
|
|
78
|
+
if (style.fill !== undefined) {
|
|
79
|
+
fields(style.fill, ["color"], "conditional fill");
|
|
80
|
+
const color = colorArgb(style.fill.color);
|
|
81
|
+
// Excel reads the background color for a differential solid fill; keep both channels explicit.
|
|
82
|
+
xml += '<fill><patternFill patternType="solid"><fgColor rgb="' + color + '"/><bgColor rgb="' + color + '"/></patternFill></fill>';
|
|
83
|
+
}
|
|
84
|
+
if (style.border !== undefined) {
|
|
85
|
+
fields(style.border, ["left", "right", "top", "bottom"], "conditional border");
|
|
86
|
+
let border = "";
|
|
87
|
+
for (const side of ["left", "right", "top", "bottom"]) {
|
|
88
|
+
const edge = style.border[side];
|
|
89
|
+
if (edge !== undefined) {
|
|
90
|
+
fields(edge, ["style", "color"], "conditional border edge");
|
|
91
|
+
if (!["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"].includes(edge.style))
|
|
92
|
+
throw new TypeError("Invalid conditional border style.");
|
|
93
|
+
border += '<' + side + ' style="' + edge.style + '">' + (edge.color !== undefined ? '<color rgb="' + colorArgb(edge.color) + '"/>' : "") + '</' + side + '>';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (border)
|
|
97
|
+
xml += '<border>' + border + '</border>';
|
|
98
|
+
}
|
|
99
|
+
if (!xml)
|
|
100
|
+
throw new TypeError("A conditional style must change at least one property.");
|
|
101
|
+
return xml;
|
|
102
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** An authored XLSX storage expression and its initial numeric or blank result. Future functions retain their required _xlfn prefixes; the writer does not evaluate or normalize function names. */
|
|
2
|
+
export declare class FormulaCell {
|
|
3
|
+
readonly cachedValue: number | null;
|
|
4
|
+
readonly style?: number | undefined;
|
|
5
|
+
static [Symbol.hasInstance](value: unknown): boolean;
|
|
6
|
+
readonly formula: string;
|
|
7
|
+
constructor(formula: string, cachedValue: number | null, style?: number | undefined);
|
|
8
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { NotSupportedError } from "../core/errors.js";
|
|
2
|
+
import { cleanXml, escapeXml } from "../xml/index.js";
|
|
3
|
+
const formulaCells = new WeakSet();
|
|
4
|
+
const nestedAggregateCells = new WeakSet();
|
|
5
|
+
/** Reject external references and identify nested total functions without evaluating Excel expressions. */
|
|
6
|
+
function inspectReferences(formula) {
|
|
7
|
+
let subtotal = false;
|
|
8
|
+
const identifier = /[\p{L}_\\][\p{L}\p{N}\p{M}_.\\]*/uy;
|
|
9
|
+
for (let i = 0; i < formula.length; i++) {
|
|
10
|
+
const character = formula[i];
|
|
11
|
+
if (character === '"') {
|
|
12
|
+
// Excel string literals double their embedded quotes. Their text is not a reference token.
|
|
13
|
+
while (++i < formula.length)
|
|
14
|
+
if (formula[i] === '"') {
|
|
15
|
+
if (formula[i + 1] !== '"')
|
|
16
|
+
break;
|
|
17
|
+
i++;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else if (character === "'") {
|
|
21
|
+
let quoted = "";
|
|
22
|
+
while (++i < formula.length) {
|
|
23
|
+
if (formula[i] === "'") {
|
|
24
|
+
if (formula[i + 1] !== "'")
|
|
25
|
+
break;
|
|
26
|
+
i++;
|
|
27
|
+
}
|
|
28
|
+
quoted += formula[i];
|
|
29
|
+
}
|
|
30
|
+
if (formula.slice(i + 1).trimStart().startsWith("!") && /[\[\]]/.test(quoted))
|
|
31
|
+
throw new NotSupportedError("external-workbook formulas");
|
|
32
|
+
}
|
|
33
|
+
else if (character === "[") {
|
|
34
|
+
let depth = 1;
|
|
35
|
+
while (++i < formula.length && depth) {
|
|
36
|
+
// Apostrophes escape special characters in table-column captions.
|
|
37
|
+
if (formula[i] === "'") {
|
|
38
|
+
i++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (formula[i] === "[")
|
|
42
|
+
depth++;
|
|
43
|
+
else if (formula[i] === "]")
|
|
44
|
+
depth--;
|
|
45
|
+
}
|
|
46
|
+
if (/^[A-Za-z0-9_.]*!/.test(formula.slice(i)))
|
|
47
|
+
throw new NotSupportedError("external-workbook formulas");
|
|
48
|
+
i--;
|
|
49
|
+
}
|
|
50
|
+
else if (character === "|")
|
|
51
|
+
throw new NotSupportedError("DDE formulas");
|
|
52
|
+
else {
|
|
53
|
+
identifier.lastIndex = i;
|
|
54
|
+
const token = identifier.exec(formula);
|
|
55
|
+
if (token) {
|
|
56
|
+
if (["SUBTOTAL", "AGGREGATE", "_XLFN.AGGREGATE"].includes(token[0].toUpperCase()) && /^\s*\(/.test(formula.slice(identifier.lastIndex)))
|
|
57
|
+
subtotal = true;
|
|
58
|
+
i = identifier.lastIndex - 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return subtotal;
|
|
63
|
+
}
|
|
64
|
+
function captureFormula(value) {
|
|
65
|
+
if (typeof value !== "string")
|
|
66
|
+
throw new TypeError("Formula text must be a string.");
|
|
67
|
+
const text = value.trim().replace(/^=/, "");
|
|
68
|
+
if (!text.trim() || text.length > 8192)
|
|
69
|
+
throw new RangeError("Formulas require 1 through 8,192 characters.");
|
|
70
|
+
// Text stripping could change a calculation, so formulas always reject invalid XML characters.
|
|
71
|
+
cleanXml(text, "reject");
|
|
72
|
+
return { text, subtotal: inspectReferences(text) };
|
|
73
|
+
}
|
|
74
|
+
/** An authored XLSX storage expression and its initial numeric or blank result. Future functions retain their required _xlfn prefixes; the writer does not evaluate or normalize function names. */
|
|
75
|
+
export class FormulaCell {
|
|
76
|
+
cachedValue;
|
|
77
|
+
style;
|
|
78
|
+
static [Symbol.hasInstance](value) {
|
|
79
|
+
return value !== null && typeof value === "object" && formulaCells.has(value);
|
|
80
|
+
}
|
|
81
|
+
formula;
|
|
82
|
+
constructor(formula, cachedValue, style) {
|
|
83
|
+
this.cachedValue = cachedValue;
|
|
84
|
+
this.style = style;
|
|
85
|
+
const captured = captureFormula(formula);
|
|
86
|
+
this.formula = captured.text;
|
|
87
|
+
if (cachedValue !== null && (typeof cachedValue !== "number" || !Number.isFinite(cachedValue)))
|
|
88
|
+
throw new TypeError("Formula caches must be finite numbers or null for a blank result.");
|
|
89
|
+
if (style !== undefined && (!Number.isSafeInteger(style) || style < 0))
|
|
90
|
+
throw new RangeError("Formula style indexes must be nonnegative safe integers.");
|
|
91
|
+
formulaCells.add(this);
|
|
92
|
+
if (captured.subtotal)
|
|
93
|
+
nestedAggregateCells.add(this);
|
|
94
|
+
Object.freeze(this);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** @internal Excel excludes cells containing SUBTOTAL or AGGREGATE expressions from a generated SUBTOTAL. */
|
|
98
|
+
export function isSubtotalFormula(cell) { return nestedAggregateCells.has(cell); }
|
|
99
|
+
/** @internal The worksheet owns the cell coordinate, style and cumulative formula budget. */
|
|
100
|
+
export function formulaXml(cell) {
|
|
101
|
+
if (!(cell instanceof FormulaCell))
|
|
102
|
+
throw new TypeError("Formula cells must be created with FormulaCell.");
|
|
103
|
+
return "<f>" + escapeXml(cell.formula, "reject") + "</f><v>" + (cell.cachedValue ?? "") + "</v>";
|
|
104
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ColumnSettings } from "../core/index.js";
|
|
2
|
+
import type { GroupedReportEvent, GroupedReportGroup, GroupedReportSummary } from "../core/grouped-report.js";
|
|
3
|
+
import type { PortableCellStyle, PortableSheetOptions } from "./portable.js";
|
|
4
|
+
import type { ConditionalFormat } from "./conditional-types.js";
|
|
5
|
+
import type { ListValidation } from "./validation-types.js";
|
|
6
|
+
import type { Worksheet } from "./worksheet.js";
|
|
7
|
+
import type { DataRowRange } from "./data-row-ranges.js";
|
|
8
|
+
type GroupEnd = Extract<GroupedReportEvent, {
|
|
9
|
+
readonly kind: "groupEnd";
|
|
10
|
+
}>;
|
|
11
|
+
type Complete = Extract<GroupedReportEvent, {
|
|
12
|
+
readonly kind: "complete";
|
|
13
|
+
}>;
|
|
14
|
+
type GroupedSheet = Omit<PortableSheetOptions, "columns" | "headerRows" | "footer" | "table" | "autoFilter" | "mergedCells" | "hyperlinks" | "conditionalFormats" | "dataValidation" | "rowStyle" | "cellStyle" | "rowOutline" | "maxOutlineLevel">;
|
|
15
|
+
/** Layout for one grouped analysis worksheet in a caller-owned workbook. */
|
|
16
|
+
export interface GroupedXlsxSheetOptions {
|
|
17
|
+
/** A separate label column preserves every visible typed data column. */
|
|
18
|
+
readonly labelColumn: Pick<ColumnSettings, "header" | "width" | "wrapText" | "alignment">;
|
|
19
|
+
readonly subtotalLabel: (group: GroupEnd) => string;
|
|
20
|
+
readonly grandTotalLabel: (summary: Complete) => string;
|
|
21
|
+
readonly includeGrandTotal?: boolean;
|
|
22
|
+
/** Hidden outline details remain included in the native SUBTOTAL calculations. */
|
|
23
|
+
readonly collapseGroups?: boolean;
|
|
24
|
+
readonly sheet?: GroupedSheet & {
|
|
25
|
+
readonly name?: string;
|
|
26
|
+
};
|
|
27
|
+
readonly groupStyle?: PortableCellStyle;
|
|
28
|
+
readonly subtotalStyle?: PortableCellStyle;
|
|
29
|
+
readonly grandTotalStyle?: PortableCellStyle;
|
|
30
|
+
/** Data-only ranges use stable data-column keys or one-based visible data-column numbers. A1 ranges and the generated label column are excluded. */
|
|
31
|
+
readonly conditionalFormats?: readonly ConditionalFormat[];
|
|
32
|
+
/** Inline editing lists apply only to detail rows, using the same data-column selectors. */
|
|
33
|
+
readonly dataValidation?: readonly ListValidation[];
|
|
34
|
+
}
|
|
35
|
+
/** Stable one-based physical coordinates for one generated group and its body. */
|
|
36
|
+
export interface GroupedXlsxGroupRows extends GroupedReportGroup {
|
|
37
|
+
readonly path: readonly GroupedReportGroup[];
|
|
38
|
+
readonly rows: number;
|
|
39
|
+
/** The shared source's column-order aggregates, without reaggregating worksheet cells. */
|
|
40
|
+
readonly totals: readonly (number | null)[];
|
|
41
|
+
readonly startRow: number;
|
|
42
|
+
readonly firstDetailRow: number;
|
|
43
|
+
readonly lastDetailRow: number;
|
|
44
|
+
readonly summaryRow: number;
|
|
45
|
+
}
|
|
46
|
+
/** A completed analysis worksheet; the owning workbook remains open for sibling sheets and finalization. */
|
|
47
|
+
export interface GroupedXlsxWorksheet {
|
|
48
|
+
readonly worksheet: Worksheet;
|
|
49
|
+
/** Accepted source details, excluding generated headings and summaries. */
|
|
50
|
+
readonly rows: number;
|
|
51
|
+
/** Includes the generated label column. */
|
|
52
|
+
readonly columns: number;
|
|
53
|
+
/** Ordered physical detail runs, excluding all generated headings and summaries. Their count is bounded by the source's maxGroups. */
|
|
54
|
+
readonly detailRanges: readonly DataRowRange[];
|
|
55
|
+
/** Opening order, bounded by the source's maxGroups across all hierarchy levels. */
|
|
56
|
+
readonly groups: readonly GroupedXlsxGroupRows[];
|
|
57
|
+
/** The same one-pass source's complete aggregates, including when the grand-total row is omitted. */
|
|
58
|
+
readonly grandSummary: GroupedReportSummary;
|
|
59
|
+
readonly grandTotalRow?: number;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { assertGroupedReportSource } from "../core/grouped-report.js";
|
|
2
|
+
import { captureFields } from "../internal/capture.js";
|
|
3
|
+
import { OfficeIMOError } from "../core/errors.js";
|
|
4
|
+
import { fields } from "./differential-styles.js";
|
|
5
|
+
import { sheetOptionFields } from "./options.js";
|
|
6
|
+
import { portableSheet } from "./portable.js";
|
|
7
|
+
import { resolveDataColumn } from "./ranges.js";
|
|
8
|
+
import { copyStylePatch } from "./styles.js";
|
|
9
|
+
/** @internal */
|
|
10
|
+
export const groupedOptionFields = ["labelColumn", "subtotalLabel", "grandTotalLabel", "includeGrandTotal", "collapseGroups", "sheet", "groupStyle", "subtotalStyle", "grandTotalStyle", "conditionalFormats", "dataValidation"];
|
|
11
|
+
const unsupported = ["columns", "headerRows", "footer", "table", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel"];
|
|
12
|
+
function detailColumn(report, selector) {
|
|
13
|
+
return resolveDataColumn(report.columns, selector, "Grouped detail") + 1;
|
|
14
|
+
}
|
|
15
|
+
function conditionalRules(report, rules, maximum) {
|
|
16
|
+
if (rules === undefined)
|
|
17
|
+
return undefined;
|
|
18
|
+
if (!Array.isArray(rules))
|
|
19
|
+
throw new TypeError("conditionalFormats must be an array.");
|
|
20
|
+
if (rules.length > maximum)
|
|
21
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxConditionalFormats exceeded.");
|
|
22
|
+
return rules.map(input => {
|
|
23
|
+
const rule = captureFields(input, ["type", "range", "style", "stopIfTrue", "operator", "value", "values", "formula", "stops", "color", "minimum", "maximum", "showValue"]);
|
|
24
|
+
const inputRange = rule.range;
|
|
25
|
+
if (typeof inputRange === "string")
|
|
26
|
+
throw new TypeError("Grouped conditional formats require detail-column selectors rather than A1 or generated-row ranges.");
|
|
27
|
+
fields(inputRange, ["column", "through"], "grouped conditional range");
|
|
28
|
+
const range = captureFields(inputRange, ["column", "through"]);
|
|
29
|
+
return { ...rule, range: { column: detailColumn(report, range.column), ...(range.through === undefined ? {} : { through: detailColumn(report, range.through) }) } };
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function validationRules(report, rules, maximum) {
|
|
33
|
+
if (rules === undefined)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (!Array.isArray(rules))
|
|
36
|
+
throw new TypeError("dataValidation must be an array.");
|
|
37
|
+
if (rules.length > maximum)
|
|
38
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxDataValidations exceeded.");
|
|
39
|
+
return rules.map(input => {
|
|
40
|
+
const rule = captureFields(input, ["type", "column", "items", "allowBlank", "showErrorMessage", "errorStyle", "errorTitle", "errorMessage"]);
|
|
41
|
+
return { ...rule, column: detailColumn(report, rule.column) };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** @internal Capture options before creating a worksheet or touching a one-pass source. */
|
|
45
|
+
export function prepareGroupedSheet(report, configuration, maxConditionalFormats = 1000, maxDataValidations = 1000) {
|
|
46
|
+
assertGroupedReportSource(report);
|
|
47
|
+
if (!configuration || typeof configuration !== "object")
|
|
48
|
+
throw new TypeError("Grouped XLSX options require host-authored labels.");
|
|
49
|
+
const options = captureFields(configuration, groupedOptionFields);
|
|
50
|
+
const sheet = captureFields(options.sheet ?? {}, [...sheetOptionFields, "name"]);
|
|
51
|
+
if (!options.labelColumn || typeof options.labelColumn !== "object")
|
|
52
|
+
throw new TypeError("Grouped XLSX needs a leading label column.");
|
|
53
|
+
const labelColumn = captureFields(options.labelColumn, ["header", "width", "wrapText", "alignment"]);
|
|
54
|
+
if (typeof labelColumn.header !== "string")
|
|
55
|
+
throw new TypeError("The leading label column needs a string header.");
|
|
56
|
+
for (const label of [options.subtotalLabel, options.grandTotalLabel])
|
|
57
|
+
if (typeof label !== "function")
|
|
58
|
+
throw new TypeError("Grouped summary labels must be functions.");
|
|
59
|
+
for (const flag of [options.includeGrandTotal, options.collapseGroups])
|
|
60
|
+
if (flag !== undefined && typeof flag !== "boolean")
|
|
61
|
+
throw new TypeError("Grouped XLSX flags must be booleans.");
|
|
62
|
+
for (const key of unsupported)
|
|
63
|
+
if (sheet[key] !== undefined)
|
|
64
|
+
throw new TypeError("Grouped XLSX owns worksheet " + key + ".");
|
|
65
|
+
if (sheet.autoFilter !== undefined && sheet.autoFilter !== false)
|
|
66
|
+
throw new TypeError("Grouped summary rows cannot use a native table or autofilter.");
|
|
67
|
+
for (const style of [options.groupStyle, options.subtotalStyle, options.grandTotalStyle])
|
|
68
|
+
if (style !== undefined)
|
|
69
|
+
portableSheet({ alternatingRowStyle: style });
|
|
70
|
+
for (const column of report.columns)
|
|
71
|
+
if (Object.prototype.hasOwnProperty.call(report.totals, column.key) && column.type !== "number")
|
|
72
|
+
throw new TypeError("Editable grouped totals require explicitly numeric columns.");
|
|
73
|
+
const conditionalFormats = conditionalRules(report, options.conditionalFormats, maxConditionalFormats), dataValidation = validationRules(report, options.dataValidation, maxDataValidations);
|
|
74
|
+
return { ...options, labelColumn, sheet: portableSheet(sheet),
|
|
75
|
+
...(conditionalFormats === undefined ? {} : { conditionalFormats }), ...(dataValidation === undefined ? {} : { dataValidation }),
|
|
76
|
+
...(options.groupStyle ? { groupStyle: copyStylePatch(options.groupStyle) } : {}),
|
|
77
|
+
...(options.subtotalStyle ? { subtotalStyle: copyStylePatch(options.subtotalStyle) } : {}),
|
|
78
|
+
...(options.grandTotalStyle ? { grandTotalStyle: copyStylePatch(options.grandTotalStyle) } : {}) };
|
|
79
|
+
}
|