@quirekit/xlsx 0.0.0-stage → 0.3.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.md +21 -0
- package/THIRD_PARTY_NOTICES.md +150 -0
- package/dist/index.d.mts +122 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +19167 -0
- package/dist/index.mjs.map +1 -0
- package/licenses/saxes.LICENSE +64 -0
- package/licenses/xmlchars.LICENSE +18 -0
- package/package.json +52 -3
- package/src/bundle.ts +17 -0
- package/src/comments/legacy/read.ts +68 -0
- package/src/comments/legacy/write.ts +64 -0
- package/src/comments/package/ranges.ts +78 -0
- package/src/comments/package/read.ts +95 -0
- package/src/comments/package/roundtrip.test.ts +106 -0
- package/src/comments/package/write.ts +130 -0
- package/src/comments/thread/read.ts +69 -0
- package/src/comments/thread/write.ts +61 -0
- package/src/comments/types.ts +43 -0
- package/src/comments/xml.ts +50 -0
- package/src/create.ts +13 -0
- package/src/drawing/cache.ts +48 -0
- package/src/drawing/chart.test.ts +96 -0
- package/src/drawing/chart.ts +87 -0
- package/src/drawing/definition/plots.ts +76 -0
- package/src/drawing/definition/read.ts +65 -0
- package/src/drawing/definition/shape.ts +40 -0
- package/src/drawing/definition/types.ts +24 -0
- package/src/drawing/editable-picture.ts +80 -0
- package/src/drawing/graph.ts +148 -0
- package/src/drawing/identity.ts +22 -0
- package/src/drawing/import.ts +133 -0
- package/src/drawing/namespaces.ts +11 -0
- package/src/drawing/picture.test.ts +98 -0
- package/src/drawing/picture.ts +54 -0
- package/src/drawing/placement/anchor.ts +71 -0
- package/src/drawing/placement/axes.ts +113 -0
- package/src/drawing/placement/marker.ts +16 -0
- package/src/drawing/placement/transform.ts +132 -0
- package/src/drawing/placement/types.ts +20 -0
- package/src/drawing/presentation/cartesian/axes.ts +103 -0
- package/src/drawing/presentation/cartesian/plot.ts +109 -0
- package/src/drawing/presentation/cartesian/types.ts +9 -0
- package/src/drawing/presentation/layout.ts +29 -0
- package/src/drawing/presentation/paint.ts +56 -0
- package/src/drawing/presentation/properties.ts +31 -0
- package/src/drawing/read.ts +85 -0
- package/src/drawing/shapes/connector.ts +55 -0
- package/src/drawing/shapes/paint.ts +108 -0
- package/src/drawing/shapes/read.ts +89 -0
- package/src/drawing/shapes/text.ts +89 -0
- package/src/drawing/shapes/types.ts +13 -0
- package/src/drawing/sources.test.ts +27 -0
- package/src/drawing/sources.ts +43 -0
- package/src/drawing/types.ts +54 -0
- package/src/drawing/worksheet-connector.test.ts +135 -0
- package/src/drawing/worksheet-shape.test.ts +61 -0
- package/src/drawing/write/anchor.ts +17 -0
- package/src/drawing/write/axes.ts +23 -0
- package/src/drawing/write/chart.ts +56 -0
- package/src/drawing/write/drawing.ts +61 -0
- package/src/drawing/write/pictures.ts +68 -0
- package/src/drawing/write/series.ts +43 -0
- package/src/drawing/write/shapes.ts +113 -0
- package/src/drawing/write/text.ts +26 -0
- package/src/drawing/write/workbook.test.ts +199 -0
- package/src/drawing/write/workbook.ts +217 -0
- package/src/external-links/formulas.ts +21 -0
- package/src/external-links/read.test.ts +93 -0
- package/src/external-links/read.ts +104 -0
- package/src/external-links/types.ts +9 -0
- package/src/external-links/write.ts +120 -0
- package/src/image/excel.ts +122 -0
- package/src/image/native.ts +21 -0
- package/src/image/ownership.ts +77 -0
- package/src/image/parts.ts +45 -0
- package/src/image/raster.ts +25 -0
- package/src/image/read.test.ts +95 -0
- package/src/image/read.ts +66 -0
- package/src/image/relationships.ts +26 -0
- package/src/image/types.ts +48 -0
- package/src/image/wps.ts +43 -0
- package/src/image/write.test.ts +53 -0
- package/src/image/write.ts +118 -0
- package/src/index.ts +6 -0
- package/src/metadata/dynamic-array.ts +105 -0
- package/src/metadata/package.ts +75 -0
- package/src/metadata/types.ts +7 -0
- package/src/opc/archive.ts +26 -0
- package/src/opc/ownership.ts +40 -0
- package/src/opc/relationships.ts +98 -0
- package/src/opc/revision.ts +28 -0
- package/src/opc/shape.ts +23 -0
- package/src/opc/types.ts +13 -0
- package/src/opc/xml.test.ts +49 -0
- package/src/opc/xml.ts +128 -0
- package/src/optimization/blanks.ts +53 -0
- package/src/optimization/optimize.test.ts +117 -0
- package/src/optimization/optimize.ts +41 -0
- package/src/optimization/package.ts +65 -0
- package/src/optimization/rules.ts +46 -0
- package/src/optimization/styles.ts +76 -0
- package/src/optimization/types.ts +33 -0
- package/src/package/assembly.test.ts +117 -0
- package/src/package/calculation-metadata.test.ts +85 -0
- package/src/package/calculation-metadata.ts +88 -0
- package/src/package/checkboxes.ts +37 -0
- package/src/package/cleanup.test.ts +61 -0
- package/src/package/dashboard.test.ts +53 -0
- package/src/package/dashboard.ts +84 -0
- package/src/package/extensions.ts +16 -0
- package/src/package/merge-recipes.ts +84 -0
- package/src/package/names/conditional.ts +64 -0
- package/src/package/names/defined.test.ts +52 -0
- package/src/package/names/defined.ts +75 -0
- package/src/package/names/filter.ts +68 -0
- package/src/package/names/print-layout.ts +62 -0
- package/src/package/names/print.ts +62 -0
- package/src/package/new.ts +46 -0
- package/src/package/open/appearance.ts +46 -0
- package/src/package/open/directory.ts +61 -0
- package/src/package/open/restrictions.ts +27 -0
- package/src/package/open/snapshot.test.ts +48 -0
- package/src/package/open/snapshot.ts +34 -0
- package/src/package/open/source-write.ts +130 -0
- package/src/package/open/types.ts +73 -0
- package/src/package/open/worksheets.ts +149 -0
- package/src/package/positions.ts +40 -0
- package/src/package/read.ts +143 -0
- package/src/package/save/types.ts +57 -0
- package/src/package/save/worksheets.ts +126 -0
- package/src/package/selection-copy.test.ts +70 -0
- package/src/package/styles.ts +39 -0
- package/src/package/types.ts +52 -0
- package/src/package/workbook-views.ts +34 -0
- package/src/package/worksheets.test.ts +190 -0
- package/src/package/worksheets.ts +162 -0
- package/src/package/write.ts +175 -0
- package/src/pivot/cache/calculated.ts +34 -0
- package/src/pivot/cache/dates.ts +124 -0
- package/src/pivot/cache/groups.ts +11 -0
- package/src/pivot/cache/members.ts +99 -0
- package/src/pivot/cache/numbers.ts +63 -0
- package/src/pivot/cache/read.ts +131 -0
- package/src/pivot/cache/time.ts +20 -0
- package/src/pivot/cache/values.ts +43 -0
- package/src/pivot/cache/write.ts +117 -0
- package/src/pivot/definition/axes.ts +35 -0
- package/src/pivot/definition/dates.ts +87 -0
- package/src/pivot/definition/display.ts +86 -0
- package/src/pivot/definition/extension.ts +57 -0
- package/src/pivot/definition/field-settings/caption.ts +38 -0
- package/src/pivot/definition/field-settings/comparison.ts +47 -0
- package/src/pivot/definition/field-settings/field.ts +66 -0
- package/src/pivot/definition/field-settings/filters.ts +86 -0
- package/src/pivot/definition/field-settings/measure.ts +79 -0
- package/src/pivot/definition/field-settings/types.ts +19 -0
- package/src/pivot/definition/functions.ts +21 -0
- package/src/pivot/definition/items.ts +144 -0
- package/src/pivot/definition/members.ts +98 -0
- package/src/pivot/definition/numbers.ts +19 -0
- package/src/pivot/definition/presentation.ts +52 -0
- package/src/pivot/definition/read.ts +143 -0
- package/src/pivot/definition/report-layout.ts +39 -0
- package/src/pivot/definition/write.ts +157 -0
- package/src/pivot/package/calculated.test.ts +103 -0
- package/src/pivot/package/dates.test.ts +266 -0
- package/src/pivot/package/display.test.ts +133 -0
- package/src/pivot/package/field-settings.test.ts +59 -0
- package/src/pivot/package/layout.test.ts +148 -0
- package/src/pivot/package/measure-settings.test.ts +85 -0
- package/src/pivot/package/members.test.ts +167 -0
- package/src/pivot/package/numbers.test.ts +120 -0
- package/src/pivot/package/read.ts +93 -0
- package/src/pivot/package/roundtrip.test.ts +244 -0
- package/src/pivot/package/write.ts +103 -0
- package/src/pivot/types.ts +36 -0
- package/src/pivot/xml.ts +50 -0
- package/src/presentation.test.ts +186 -0
- package/src/roundtrip.test.ts +72 -0
- package/src/styles/checkbox/bags.ts +85 -0
- package/src/styles/checkbox/style.ts +45 -0
- package/src/styles/checkbox/types.ts +7 -0
- package/src/styles/color.ts +64 -0
- package/src/styles/differential-preview.ts +60 -0
- package/src/styles/differential.ts +119 -0
- package/src/styles/numbers.ts +9 -0
- package/src/styles/parts.ts +107 -0
- package/src/styles/read.ts +95 -0
- package/src/styles/reference.ts +14 -0
- package/src/styles/types.ts +9 -0
- package/src/styles/write.test.ts +88 -0
- package/src/styles/write.ts +162 -0
- package/src/table/conversion.test.ts +73 -0
- package/src/table/definition.ts +89 -0
- package/src/table/filter.ts +42 -0
- package/src/table/ownership.ts +112 -0
- package/src/table/read.test.ts +274 -0
- package/src/table/read.ts +117 -0
- package/src/table/remove.ts +55 -0
- package/src/table/sort.test.ts +79 -0
- package/src/table/styles/builtin.ts +40 -0
- package/src/table/styles/differential.ts +55 -0
- package/src/table/styles/preset-data.ts +17 -0
- package/src/table/styles/presets/dark.ts +104 -0
- package/src/table/styles/presets/light-grid.ts +68 -0
- package/src/table/styles/presets/light.ts +145 -0
- package/src/table/styles/presets/medium-edges.ts +131 -0
- package/src/table/styles/presets/medium.ts +131 -0
- package/src/table/styles/read.ts +70 -0
- package/src/table/styles/types.ts +27 -0
- package/src/table/totals.test.ts +77 -0
- package/src/table/totals.ts +79 -0
- package/src/table/types.ts +21 -0
- package/src/table/write.ts +189 -0
- package/src/types.ts +74 -0
- package/src/value/date.ts +21 -0
- package/src/worksheet/appearance.ts +55 -0
- package/src/worksheet/axis.test.ts +185 -0
- package/src/worksheet/axis.ts +131 -0
- package/src/worksheet/background/read.ts +41 -0
- package/src/worksheet/background/roundtrip.test.ts +77 -0
- package/src/worksheet/background/write.ts +96 -0
- package/src/worksheet/cell-shift.ts +44 -0
- package/src/worksheet/cells.ts +75 -0
- package/src/worksheet/checkbox/formats.ts +53 -0
- package/src/worksheet/checkbox/ranges.ts +112 -0
- package/src/worksheet/checkbox/write.test.ts +62 -0
- package/src/worksheet/conditional/color-scale.ts +61 -0
- package/src/worksheet/conditional/data-bar.ts +76 -0
- package/src/worksheet/conditional/extensions.ts +95 -0
- package/src/worksheet/conditional/icon-reference.ts +69 -0
- package/src/worksheet/conditional/icon-set.test.ts +60 -0
- package/src/worksheet/conditional/icon-set.ts +79 -0
- package/src/worksheet/conditional/preview.ts +44 -0
- package/src/worksheet/conditional/read.ts +185 -0
- package/src/worksheet/conditional/text.test.ts +71 -0
- package/src/worksheet/conditional/text.ts +122 -0
- package/src/worksheet/conditional/threshold.ts +47 -0
- package/src/worksheet/conditional/types.ts +20 -0
- package/src/worksheet/conditional/write-bar.ts +66 -0
- package/src/worksheet/conditional/write.test.ts +218 -0
- package/src/worksheet/conditional/write.ts +103 -0
- package/src/worksheet/copied-axis.ts +70 -0
- package/src/worksheet/data/rows.ts +59 -0
- package/src/worksheet/data/source.test.ts +68 -0
- package/src/worksheet/data/source.ts +31 -0
- package/src/worksheet/data/types.ts +9 -0
- package/src/worksheet/data.test.ts +314 -0
- package/src/worksheet/dimensions/columns.ts +87 -0
- package/src/worksheet/dimensions/write.test.ts +110 -0
- package/src/worksheet/dimensions/write.ts +36 -0
- package/src/worksheet/filters/advanced.test.ts +57 -0
- package/src/worksheet/filters/color.ts +105 -0
- package/src/worksheet/filters/icon.test.ts +83 -0
- package/src/worksheet/filters/icon.ts +39 -0
- package/src/worksheet/filters/read.ts +114 -0
- package/src/worksheet/filters/relative-dates.ts +47 -0
- package/src/worksheet/filters/restore-icons.ts +33 -0
- package/src/worksheet/filters/restore.ts +169 -0
- package/src/worksheet/filters/rules.ts +23 -0
- package/src/worksheet/filters/types.ts +23 -0
- package/src/worksheet/filters/visibility.ts +188 -0
- package/src/worksheet/filters/write.ts +121 -0
- package/src/worksheet/formula/cache.ts +29 -0
- package/src/worksheet/formula/external-results.test.ts +39 -0
- package/src/worksheet/formula/functions.ts +29 -0
- package/src/worksheet/formula/prefix.ts +27 -0
- package/src/worksheet/formula/shared/read.test.ts +121 -0
- package/src/worksheet/formula/shared/read.ts +94 -0
- package/src/worksheet/formula/shared/references.ts +100 -0
- package/src/worksheet/formula/shared/types.ts +21 -0
- package/src/worksheet/formula/spill-read.ts +54 -0
- package/src/worksheet/formula/spill-write.ts +32 -0
- package/src/worksheet/formula/spill.test.ts +101 -0
- package/src/worksheet/formula/write.test.ts +26 -0
- package/src/worksheet/hyperlinks/location.ts +59 -0
- package/src/worksheet/hyperlinks/model.ts +22 -0
- package/src/worksheet/hyperlinks/read.ts +70 -0
- package/src/worksheet/hyperlinks/types.ts +21 -0
- package/src/worksheet/hyperlinks/write.test.ts +203 -0
- package/src/worksheet/hyperlinks/write.ts +51 -0
- package/src/worksheet/merge.test.ts +58 -0
- package/src/worksheet/merge.ts +61 -0
- package/src/worksheet/outline/columns.ts +46 -0
- package/src/worksheet/outline/metadata.ts +68 -0
- package/src/worksheet/outline/native.ts +81 -0
- package/src/worksheet/outline/read.ts +50 -0
- package/src/worksheet/outline/roundtrip.test.ts +73 -0
- package/src/worksheet/outline/types.ts +37 -0
- package/src/worksheet/outline/write.ts +110 -0
- package/src/worksheet/positions.test.ts +46 -0
- package/src/worksheet/positions.ts +48 -0
- package/src/worksheet/print/breaks.ts +72 -0
- package/src/worksheet/print/elements.ts +16 -0
- package/src/worksheet/print/page-text.ts +139 -0
- package/src/worksheet/print/setup.test.ts +141 -0
- package/src/worksheet/print/setup.ts +116 -0
- package/src/worksheet/progress/read.ts +73 -0
- package/src/worksheet/progress/solid.ts +26 -0
- package/src/worksheet/progress/types.ts +11 -0
- package/src/worksheet/progress/write.test.ts +63 -0
- package/src/worksheet/progress/write.ts +46 -0
- package/src/worksheet/read.ts +197 -0
- package/src/worksheet/rich-text.test.ts +41 -0
- package/src/worksheet/rich-text.ts +76 -0
- package/src/worksheet/sort/read.ts +115 -0
- package/src/worksheet/sort/relocate.ts +62 -0
- package/src/worksheet/sort/roundtrip.test.ts +116 -0
- package/src/worksheet/sort/types.ts +11 -0
- package/src/worksheet/sort/write.ts +77 -0
- package/src/worksheet/template.ts +9 -0
- package/src/worksheet/text.ts +33 -0
- package/src/worksheet/validation/extended.ts +36 -0
- package/src/worksheet/validation/image.ts +7 -0
- package/src/worksheet/validation/list-options/portable.ts +90 -0
- package/src/worksheet/validation/list-options/types.ts +14 -0
- package/src/worksheet/validation/list-options/wps.ts +51 -0
- package/src/worksheet/validation/read.ts +162 -0
- package/src/worksheet/validation/text.ts +13 -0
- package/src/worksheet/validation/write.test.ts +259 -0
- package/src/worksheet/validation/write.ts +99 -0
- package/src/worksheet/view/coordinates.ts +39 -0
- package/src/worksheet/view/named/read.ts +116 -0
- package/src/worksheet/view/named/roundtrip.test.ts +136 -0
- package/src/worksheet/view/named/sort.ts +57 -0
- package/src/worksheet/view/named/types.ts +15 -0
- package/src/worksheet/view/named/write.ts +107 -0
- package/src/worksheet/view/named/xml.ts +33 -0
- package/src/worksheet/view/panes.ts +75 -0
- package/src/worksheet/view/read.ts +61 -0
- package/src/worksheet/view/relocate.ts +57 -0
- package/src/worksheet/view/write.test.ts +91 -0
- package/src/worksheet/view/write.ts +57 -0
- package/src/worksheet/write.ts +86 -0
- package/README.md +0 -3
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import {
|
|
3
|
+
escapeWorkbookPrintText, formatWorkbookPrintField, replaceWorkbookPrintFields, workbookPrintTextPositions,
|
|
4
|
+
type WorkbookPrintPageText, type WorkbookPrintPageTextVariant, type WorkbookPrintTextField, type WorkbookPrintTextPosition,
|
|
5
|
+
type WorkbookPrintTextSection, type WorkbookPrintTextSections, type WorkbookTextStyle
|
|
6
|
+
} from "@quirekit/workbook";
|
|
7
|
+
import { child, children, isTrue, spreadNs } from "../../opc/xml";
|
|
8
|
+
import { decodeXlsxText, encodeXlsxText, insertXlsxText } from "../text";
|
|
9
|
+
import { afterXlsxPrintElements, ensureXlsxPrintElement } from "./elements";
|
|
10
|
+
|
|
11
|
+
const fieldCodes: Readonly<Record<WorkbookPrintTextField, string>> = { page: "P", pages: "N", sheet: "A", file: "F", date: "D", time: "T" };
|
|
12
|
+
const fieldsByCode = new Map(Object.entries(fieldCodes).map(([key, code]) => [code, key as WorkbookPrintTextField]));
|
|
13
|
+
const positionCodes: Readonly<Record<WorkbookPrintTextPosition, string>> = { left: "L", center: "C", right: "R" };
|
|
14
|
+
const positionsByCode = new Map(Object.entries(positionCodes).map(([position, code]) => [code, position as WorkbookPrintTextPosition]));
|
|
15
|
+
const nativeElements = ["oddHeader", "oddFooter", "evenHeader", "evenFooter", "firstHeader", "firstFooter"] as const;
|
|
16
|
+
const nativeFlags = ["differentFirst", "differentOddEven", "scaleWithDoc", "alignWithMargins"] as const;
|
|
17
|
+
const booleanTextStyles = { B: "bold", I: "italic", U: "underline", S: "strike" } as const;
|
|
18
|
+
const unsupported = "工作表含暂未支持的页眉页脚图片、字段或混合格式。";
|
|
19
|
+
|
|
20
|
+
/** @param specification - Native font name and style. @returns Uniform section font. */
|
|
21
|
+
function sectionFont(specification: string): WorkbookTextStyle {
|
|
22
|
+
const [family, formatting = "", extra] = specification.split(",");
|
|
23
|
+
if (extra !== undefined) throw new Error(unsupported);
|
|
24
|
+
const method = formatting.toLowerCase().trim();
|
|
25
|
+
const normal = ["", "-", "regular", "normal", "常规", "标准"].includes(method);
|
|
26
|
+
const bold = ["bold", "bold italic", "加粗", "粗体", "粗斜体", "加粗 倾斜"].includes(method);
|
|
27
|
+
const italic = ["italic", "bold italic", "斜体", "倾斜", "粗斜体", "加粗 倾斜"].includes(method);
|
|
28
|
+
if (!normal && !bold && !italic) throw new Error(unsupported);
|
|
29
|
+
return { ...(family && family !== "-" && { fontFamily: family }), ...(bold && { bold }), ...(italic && { italic }) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @param value - Native instructions for a header or footer. @returns Canonical text in each of its occupied positions. */
|
|
33
|
+
function readSections(value: string): WorkbookPrintTextSections | undefined {
|
|
34
|
+
const sections: Partial<Record<WorkbookPrintTextPosition, WorkbookPrintTextSection>> = {};
|
|
35
|
+
let position: WorkbookPrintTextPosition = "center", text = "", literal = "", style: WorkbookTextStyle = {};
|
|
36
|
+
/** Appends the complete literal run so escaping can see neighboring braces. */
|
|
37
|
+
function flushLiteral(): void { text += escapeWorkbookPrintText(literal); literal = ""; }
|
|
38
|
+
/** Records one section with its own initial font. */
|
|
39
|
+
function flushSection(): void {
|
|
40
|
+
flushLiteral();
|
|
41
|
+
if (text) {
|
|
42
|
+
if (sections[position]) throw new Error(unsupported);
|
|
43
|
+
sections[position] = { text, ...(Object.keys(style).length && { style }) };
|
|
44
|
+
}
|
|
45
|
+
text = "";
|
|
46
|
+
style = {};
|
|
47
|
+
}
|
|
48
|
+
// Native codes are parsed in lexical order because both text and font state belong to the current section.
|
|
49
|
+
for (const match of value.matchAll(/[^&]+|&(?:P[+-]\d+|B&B|"[^"]*"|\d+|K[0-9a-fA-F]{6}|[\s\S])|&/gu)) {
|
|
50
|
+
const token = match[0];
|
|
51
|
+
if (!token.startsWith("&") || token === "&&") {
|
|
52
|
+
literal += token === "&&" ? "&" : token;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (token === "&B&B") continue;
|
|
56
|
+
const code = token.slice(1);
|
|
57
|
+
const nextPosition = positionsByCode.get(code), field = fieldsByCode.get(code);
|
|
58
|
+
if (nextPosition) { flushSection(); position = nextPosition; continue; }
|
|
59
|
+
if (field) { flushLiteral(); text += formatWorkbookPrintField(field); continue; }
|
|
60
|
+
if (literal || text) throw new Error(unsupported);
|
|
61
|
+
const toggle = booleanTextStyles[code as keyof typeof booleanTextStyles];
|
|
62
|
+
if (toggle) style = { ...style, [toggle]: !style[toggle] };
|
|
63
|
+
else if (code.startsWith('"') && code.endsWith('"') && code.length >= 2) style = { ...style, ...sectionFont(code.slice(1, -1)) };
|
|
64
|
+
else if (/^\d+$/u.test(code)) style = { ...style, fontSize: Number(code) };
|
|
65
|
+
else if (/^K[0-9a-f]{6}$/iu.test(code)) style = { ...style, color: "#" + code.slice(1).toUpperCase() };
|
|
66
|
+
else throw new Error(unsupported);
|
|
67
|
+
}
|
|
68
|
+
flushSection();
|
|
69
|
+
if (Object.keys(sections).length) return sections;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @param sheet - Source worksheet. @returns Supported headers and footers at their original page variants. */
|
|
73
|
+
export function readXlsxPrintPageText(sheet: Element): WorkbookPrintPageText | undefined {
|
|
74
|
+
const roots = children(sheet, "headerFooter");
|
|
75
|
+
if (child(sheet, "legacyDrawingHF") || roots.length > 1) throw new Error(unsupported);
|
|
76
|
+
const [node] = roots;
|
|
77
|
+
if (!node) return;
|
|
78
|
+
const entries = children(node);
|
|
79
|
+
if (node.namespaceURI !== spreadNs || Array.from(node.attributes).some(attr => attr.namespaceURI ||
|
|
80
|
+
!nativeFlags.some(flag => flag === attr.name) || !["0", "1", "false", "true"].includes(attr.value)) ||
|
|
81
|
+
new Set(entries.map(element => element.localName)).size !== entries.length ||
|
|
82
|
+
entries.some(entry => entry.namespaceURI !== spreadNs || !nativeElements.some(name => name === entry.localName)
|
|
83
|
+
|| entry.attributes.length || children(entry).length)) throw new Error(unsupported);
|
|
84
|
+
/** @param prefix - Physical page variant. @returns Text positions and formatting supported for that variant. */
|
|
85
|
+
function variant(prefix: "odd" | "first" | "even"): WorkbookPrintPageTextVariant {
|
|
86
|
+
const header = readSections(decodeXlsxText(child(node!, prefix + "Header")?.textContent ?? ""));
|
|
87
|
+
const footer = readSections(decodeXlsxText(child(node!, prefix + "Footer")?.textContent ?? ""));
|
|
88
|
+
return { ...(header && { header }), ...(footer && { footer }) };
|
|
89
|
+
}
|
|
90
|
+
const regular = variant("odd");
|
|
91
|
+
const first = isTrue(node.getAttribute("differentFirst")) ? variant("first") : undefined;
|
|
92
|
+
const even = isTrue(node.getAttribute("differentOddEven")) ? variant("even") : undefined;
|
|
93
|
+
const scaleWithDocument = node.hasAttribute("scaleWithDoc") && !isTrue(node.getAttribute("scaleWithDoc")) ? false : undefined;
|
|
94
|
+
const alignWithMargins = node.hasAttribute("alignWithMargins") && !isTrue(node.getAttribute("alignWithMargins")) ? false : undefined;
|
|
95
|
+
const result = { ...regular, ...(first && { first }), ...(even && { even }),
|
|
96
|
+
...(scaleWithDocument === false && { scaleWithDocument }), ...(alignWithMargins === false && { alignWithMargins }) };
|
|
97
|
+
if (Object.keys(result).length) return result;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** @param section - Saved text and optional font. @returns Native section body, without its placement marker. */
|
|
101
|
+
function writeSection({ text, style = {} }: WorkbookPrintTextSection): string {
|
|
102
|
+
let followsPageNumber = false;
|
|
103
|
+
const content = replaceWorkbookPrintFields(text, value => {
|
|
104
|
+
// A pair of cancelling markers disambiguates a literal sign from a native page-number offset.
|
|
105
|
+
const separator = followsPageNumber && /^[+-]\d/u.test(value) ? "&B&B" : "";
|
|
106
|
+
if (value) followsPageNumber = false;
|
|
107
|
+
return separator + value.replaceAll("&", "&&");
|
|
108
|
+
}, field => {
|
|
109
|
+
followsPageNumber = field === "page";
|
|
110
|
+
return "&" + fieldCodes[field];
|
|
111
|
+
});
|
|
112
|
+
const { fontFamily, fontSize, bold, italic, underline, strike, color } = style;
|
|
113
|
+
const size = fontSize ? "&" + fontSize : "";
|
|
114
|
+
const marks = (bold ? "&B" : "") + (italic ? "&I" : "") + (underline ? "&U" : "") + (strike ? "&S" : "")
|
|
115
|
+
+ (color ? "&K" + color.slice(1) : "");
|
|
116
|
+
const separator = size && !marks && /^\d/u.test(content) ? "&B&B" : "";
|
|
117
|
+
return (fontFamily ? '&"' + fontFamily + ',Regular"' : "") + size + marks + separator + content;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @param sheet - Mutable worksheet. @param pageText - Authored decorations for its pages. */
|
|
121
|
+
export function writeXlsxPrintPageText(sheet: Element, pageText: WorkbookPrintPageText | undefined): void {
|
|
122
|
+
const prior = child(sheet, "headerFooter");
|
|
123
|
+
if (prior) sheet.removeChild(prior);
|
|
124
|
+
if (!pageText) return;
|
|
125
|
+
const node = ensureXlsxPrintElement(sheet, "headerFooter", ["rowBreaks", "colBreaks", ...afterXlsxPrintElements]);
|
|
126
|
+
if (pageText.first) node.setAttribute("differentFirst", "1");
|
|
127
|
+
if (pageText.even) node.setAttribute("differentOddEven", "1");
|
|
128
|
+
if (pageText.scaleWithDocument === false) node.setAttribute("scaleWithDoc", "0");
|
|
129
|
+
if (pageText.alignWithMargins === false) node.setAttribute("alignWithMargins", "0");
|
|
130
|
+
for (const name of nativeElements) {
|
|
131
|
+
const variant = name.startsWith("first") ? pageText.first : name.startsWith("even") ? pageText.even : pageText;
|
|
132
|
+
const sections = name.endsWith("Header") ? variant?.header : variant?.footer;
|
|
133
|
+
const value = workbookPrintTextPositions.map(position => {
|
|
134
|
+
const section = sections?.[position];
|
|
135
|
+
return section ? "&" + positionCodes[position] + writeSection(section) : "";
|
|
136
|
+
}).join("");
|
|
137
|
+
if (value) insertXlsxText(sheet.ownerDocument!, node, name, encodeXlsxText(value));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
|
3
|
+
import { openWorkbook, parseWorkbookRange, type WorkbookSession, type WorkbookSnapshot } from "@quirekit/workbook";
|
|
4
|
+
import { createXlsx, openXlsx } from "../../index";
|
|
5
|
+
|
|
6
|
+
const sheetPath = "xl/worksheets/sheet1.xml", workbookPath = "xl/workbook.xml";
|
|
7
|
+
const seed: WorkbookSnapshot = { id: "print", name: "Ledger", version: 1, revision: 0,
|
|
8
|
+
sheets: [{ id: "orders", name: "Q1, O'Brien", cells: [{ row: 1, column: 3, input: { kind: "value", value: 32 } }] }] };
|
|
9
|
+
|
|
10
|
+
/** @param workbook - Editing session. @param layout - Print command patch. @returns Published revision. */
|
|
11
|
+
async function saveLayout(workbook: WorkbookSession, layout: unknown) {
|
|
12
|
+
const sheet = workbook.worksheets()[0]!;
|
|
13
|
+
return workbook.commit(workbook.prepare({ baseRevision: workbook.revision, operationId: "print-" + workbook.revision,
|
|
14
|
+
commands: [{ name: "setWorksheetPrintLayout", target: parseWorkbookRange(sheet.id, "A1"), params: { layout } }] }).id);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("native worksheet print layout", () => {
|
|
18
|
+
it("saves names, titles and physical settings without rewriting unrelated worksheet values", async () => {
|
|
19
|
+
const original = openXlsx("Ledger", createXlsx(seed));
|
|
20
|
+
const workbook = await openWorkbook(original.snapshot);
|
|
21
|
+
try {
|
|
22
|
+
await saveLayout(workbook, { areas: ["B2:D30", "A:C"], titleRows: "1:2", titleColumns: "A:A",
|
|
23
|
+
paper: "a3", landscape: true, scaling: { kind: "fit", width: 1, height: 0 }, gridlines: true,
|
|
24
|
+
pageOrder: "overThenDown", margins: { left: 0.6, right: 0.25, top: 0.4, bottom: 0.5 } });
|
|
25
|
+
const bytes = original.write(workbook.snapshot());
|
|
26
|
+
const parts = unzipSync(bytes);
|
|
27
|
+
const xml = strFromU8(parts[workbookPath]!);
|
|
28
|
+
expect(xml).toContain(`'Q1, O''Brien'!$B$2:$D$30,'Q1, O''Brien'!$A:$C`);
|
|
29
|
+
expect(xml).toContain(`'Q1, O''Brien'!$1:$2,'Q1, O''Brien'!$A:$A`);
|
|
30
|
+
const sheet = strFromU8(parts[sheetPath]!);
|
|
31
|
+
expect(sheet).toContain('<pageSetUpPr fitToPage="1"');
|
|
32
|
+
expect(sheet).toContain('fitToWidth="1" fitToHeight="0"');
|
|
33
|
+
expect(sheet).toContain("<v>32</v>");
|
|
34
|
+
const reopened = openXlsx("Ledger", bytes);
|
|
35
|
+
expect(reopened.snapshot.sheets[0]!.view?.printLayout).toEqual(workbook.snapshot().sheets[0]!.view?.printLayout);
|
|
36
|
+
expect(reopened.axisRestrictions.size).toBe(0);
|
|
37
|
+
const reset = await openWorkbook(reopened.snapshot);
|
|
38
|
+
try {
|
|
39
|
+
const id = reset.worksheets()[0]!.id;
|
|
40
|
+
await reset.commit(reset.prepare({ baseRevision: 0, operationId: "relocate-areas", commands: [
|
|
41
|
+
{ name: "insertRows", target: parseWorkbookRange(id, "A2"), params: {} }
|
|
42
|
+
] }).id);
|
|
43
|
+
const movedFile = openXlsx("Ledger", reopened.write(reset.snapshot()));
|
|
44
|
+
expect(movedFile.snapshot.sheets[0]!.view?.printLayout).toMatchObject({
|
|
45
|
+
areas: [{ startRow: 2, endRow: 30 }, { startRow: 0, endRow: 1048575 }], titleRows: { first: 0, last: 2 }
|
|
46
|
+
});
|
|
47
|
+
await saveLayout(reset, null);
|
|
48
|
+
const resetFile = reopened.write(reset.snapshot());
|
|
49
|
+
expect(strFromU8(unzipSync(resetFile)[workbookPath]!)).not.toContain("_xlnm.Print_");
|
|
50
|
+
expect(openXlsx("Ledger", resetFile).snapshot.sheets[0]!.view?.printLayout).toBeUndefined();
|
|
51
|
+
} finally { await reset.close(); }
|
|
52
|
+
} finally { await workbook.close(); }
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("round-trips full-axis manual breaks and dynamic text from a native worksheet", async () => {
|
|
56
|
+
const parts = unzipSync(createXlsx(seed));
|
|
57
|
+
parts[sheetPath] = strToU8(strFromU8(parts[sheetPath]!).replace("</worksheet>",
|
|
58
|
+
'<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.22" footer="0.25"/>' +
|
|
59
|
+
'<pageSetup paperSize="9" firstPageNumber="10" useFirstPageNumber="1"/>' +
|
|
60
|
+
'<headerFooter differentFirst="1" differentOddEven="1" scaleWithDoc="0"><oddHeader>&L&"Arial,Bold"&10Ledger && tax</oddHeader>' +
|
|
61
|
+
'<oddFooter>&C&P / &N</oddFooter><evenFooter>&R&A&T</evenFooter><firstHeader>&RStart</firstHeader></headerFooter>' +
|
|
62
|
+
'<rowBreaks count="2" manualBreakCount="1"><brk id="4" max="16383" man="1"/><brk id="8" min="0" max="16383"/></rowBreaks>' +
|
|
63
|
+
'<colBreaks count="1" manualBreakCount="1"><brk id="3" min="0" max="1048575" man="true"/></colBreaks></worksheet>'));
|
|
64
|
+
const source = openXlsx("Ledger", zipSync(parts));
|
|
65
|
+
expect(source.axisRestrictions.size).toBe(0);
|
|
66
|
+
expect(source.printLayoutRestrictions.size).toBe(0);
|
|
67
|
+
const sheet = source.snapshot.sheets[0]!;
|
|
68
|
+
expect(sheet.view?.printLayout).toMatchObject({
|
|
69
|
+
rowBreaks: [4], columnBreaks: [3], firstPageNumber: 10, margins: { header: 0.22, footer: 0.25 }, pageText: {
|
|
70
|
+
header: { left: { text: "Ledger & tax", style: { fontFamily: "Arial", fontSize: 10, bold: true } } },
|
|
71
|
+
footer: { center: { text: "{{page}} / {{pages}}" } }, first: { header: { right: { text: "Start" } } },
|
|
72
|
+
even: { footer: { right: { text: "{{sheet}}{{time}}" } } }, scaleWithDocument: false
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const workbook = await openWorkbook(source.snapshot);
|
|
76
|
+
try {
|
|
77
|
+
await workbook.commit(workbook.prepare({ baseRevision: 0, operationId: "slide-page-boundary", commands: [
|
|
78
|
+
{ name: "insertRows", target: parseWorkbookRange(sheet.id, "A2"), params: {} }
|
|
79
|
+
] }).id);
|
|
80
|
+
const moved = openXlsx("Ledger", source.write(workbook.snapshot()));
|
|
81
|
+
expect(moved.snapshot.sheets[0]!.view?.printLayout?.rowBreaks).toEqual([5]);
|
|
82
|
+
await saveLayout(workbook, { firstPageNumber: 3, columnBreaks: ["C"],
|
|
83
|
+
margins: { left: 0.7, right: 0.7, top: 0.8, bottom: 0.75 }, pageText: {
|
|
84
|
+
header: { left: { text: "收款 & {{sheet}}" } }, footer: { center: { text: "{{page}}-2026", style: { fontSize: 11 } }, right: { text: "2026年", style: { fontSize: 11 } } }, even: {}
|
|
85
|
+
} });
|
|
86
|
+
const exported = source.write(workbook.snapshot());
|
|
87
|
+
const xml = strFromU8(unzipSync(exported)[sheetPath]!);
|
|
88
|
+
expect(xml).toContain('firstPageNumber="3"');
|
|
89
|
+
expect(xml).toContain('header="0.22" footer="0.25"');
|
|
90
|
+
expect(xml).toContain('<oddHeader>&L收款 && &A</oddHeader>');
|
|
91
|
+
expect(xml).toContain("<oddFooter>&C&11&P&B&B-2026&R&11&B&B2026年</oddFooter>");
|
|
92
|
+
expect(xml).toContain('id="2" min="0" max="1048575" man="1"');
|
|
93
|
+
expect(openXlsx("Ledger", exported).snapshot.sheets[0]!.view?.printLayout).toEqual(workbook.worksheetView(sheet.id).printLayout);
|
|
94
|
+
await workbook.commit(workbook.prepare({ baseRevision: workbook.revision, operationId: "remove-page-boundary", commands: [
|
|
95
|
+
{ name: "deleteRows", target: parseWorkbookRange(sheet.id, "A6"), params: {} }
|
|
96
|
+
] }).id);
|
|
97
|
+
expect(openXlsx("Ledger", source.write(workbook.snapshot())).snapshot.sheets[0]!.view?.printLayout?.rowBreaks).toBeUndefined();
|
|
98
|
+
await saveLayout(workbook, null);
|
|
99
|
+
expect(strFromU8(unzipSync(source.write(workbook.snapshot()))[sheetPath]!)).not.toMatch(/headerFooter|rowBreaks|colBreaks|firstPageNumber/);
|
|
100
|
+
} finally { await workbook.close(); }
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("retains a native partial manual break as opaque print XML", async () => {
|
|
104
|
+
const parts = unzipSync(createXlsx(seed));
|
|
105
|
+
const partialBreak = '<rowBreaks count="1" manualBreakCount="1"><brk id="2" min="1" max="5" man="1"/></rowBreaks>';
|
|
106
|
+
parts[sheetPath] = strToU8(strFromU8(parts[sheetPath]!).replace("</worksheet>", partialBreak + "</worksheet>"));
|
|
107
|
+
const file = openXlsx("Ledger", zipSync(parts));
|
|
108
|
+
const [sheet] = file.snapshot.sheets;
|
|
109
|
+
expect(file.printLayoutRestrictions.has(sheet!.id)).toBe(true);
|
|
110
|
+
expect(file.axisRestrictions.has(sheet!.id)).toBe(true);
|
|
111
|
+
expect(file.cellShiftRestrictions.has(sheet!.id)).toBe(false);
|
|
112
|
+
const workbook = await openWorkbook(file.snapshot, { printLayoutRestrictions: file.printLayoutRestrictions });
|
|
113
|
+
try {
|
|
114
|
+
await workbook.commit(workbook.prepare({ baseRevision: 0, operationId: "edit-safe-cell", commands: [
|
|
115
|
+
{ name: "setCells", target: parseWorkbookRange(sheet!.id, "D2"), params: { cells: [[{ kind: "value", value: 72 }]] } }
|
|
116
|
+
] }).id);
|
|
117
|
+
expect(strFromU8(unzipSync(file.write(workbook.snapshot()))[sheetPath]!)).toContain(partialBreak);
|
|
118
|
+
} finally { await workbook.close(); }
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("protects unrecognized printing instructions while allowing unrelated cells to be edited", async () => {
|
|
122
|
+
const parts = unzipSync(createXlsx(seed));
|
|
123
|
+
parts[sheetPath] = strToU8(strFromU8(parts[sheetPath]!).replace("</worksheet>",
|
|
124
|
+
'<pageSetup paperSize="999" /><headerFooter><oddFooter>&P</oddFooter></headerFooter></worksheet>'));
|
|
125
|
+
const source = openXlsx("Ledger", zipSync(parts));
|
|
126
|
+
expect(source.restrictions).toEqual([]);
|
|
127
|
+
const sheet = source.snapshot.sheets[0]!;
|
|
128
|
+
expect(source.printLayoutRestrictions.get(sheet.id)).toBeTruthy();
|
|
129
|
+
const workbook = await openWorkbook(source.snapshot, { printLayoutRestrictions: source.printLayoutRestrictions });
|
|
130
|
+
try {
|
|
131
|
+
await expect(saveLayout(workbook, { paper: "a3" })).rejects.toThrow(/打印/);
|
|
132
|
+
await workbook.commit(workbook.prepare({ baseRevision: 0, operationId: "edit-value", commands: [
|
|
133
|
+
{ name: "setCells", target: parseWorkbookRange(sheet.id, "D2"), params: { cells: [[{ kind: "value", value: 64 }]] } }
|
|
134
|
+
] }).id);
|
|
135
|
+
const preserved = strFromU8(unzipSync(source.write(workbook.snapshot()))[sheetPath]!);
|
|
136
|
+
expect(preserved).toContain('paperSize="999"');
|
|
137
|
+
expect(preserved).toContain("<oddFooter>&P</oddFooter>");
|
|
138
|
+
expect(preserved).toContain("<v>64</v>");
|
|
139
|
+
} finally { await workbook.close(); }
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import { copyWorkbookPrintLayout, defaultWorkbookPrintLayout, defaultWorkbookPrintTextMargin, sameWorkbookPrintPageText, type WorkbookPrintPaper,
|
|
3
|
+
type WorkbookWorksheetPrintLayout, type WorkbookWorksheetPrintPatch } from "@quirekit/workbook";
|
|
4
|
+
import { child, children, isTrue } from "../../opc/xml";
|
|
5
|
+
import { readXlsxPrintBreaks, writeXlsxPrintBreaks } from "./breaks";
|
|
6
|
+
import { afterXlsxPrintElements, ensureXlsxPrintElement } from "./elements";
|
|
7
|
+
import { readXlsxPrintPageText, writeXlsxPrintPageText } from "./page-text";
|
|
8
|
+
|
|
9
|
+
const nativeDefaultMargins = { left: 0.7, right: 0.7, top: 0.75, bottom: 0.75, header: defaultWorkbookPrintTextMargin, footer: defaultWorkbookPrintTextMargin } as const;
|
|
10
|
+
const paperIds: Readonly<Record<WorkbookPrintPaper, number>> = { letter: 1, legal: 5, a3: 8, a4: 9, a5: 11, b5: 13 };
|
|
11
|
+
const paperById = new Map(Object.entries(paperIds).map(([name, id]) => [id, name as WorkbookPrintPaper]));
|
|
12
|
+
const marginKeys = ["left", "right", "top", "bottom", "header", "footer"] as const;
|
|
13
|
+
const setupKeys = ["paperSize", "orientation", "scale", "fitToWidth", "fitToHeight", "pageOrder"] as const;
|
|
14
|
+
const afterPageSetup = ["headerFooter", "rowBreaks", "colBreaks", ...afterXlsxPrintElements];
|
|
15
|
+
|
|
16
|
+
/** @param element - Optional native layout element. @param name - Numeric attribute. @param fallback - Implicit native setting.
|
|
17
|
+
* @returns Explicit or implicit native number. */
|
|
18
|
+
function numberAttribute(element: Element | undefined, name: string, fallback: number): number {
|
|
19
|
+
return element?.hasAttribute(name) ? Number(element.getAttribute(name)) : fallback;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @param sheet - Original worksheet. @param ranges - Scope and titles from the workbook part.
|
|
23
|
+
* @returns Compatible native layout, or undefined when no print settings are authored. */
|
|
24
|
+
export function readXlsxPageSetup(sheet: Element, ranges: WorkbookWorksheetPrintPatch): WorkbookWorksheetPrintLayout | undefined {
|
|
25
|
+
const setup = child(sheet, "pageSetup"), margins = child(sheet, "pageMargins"), print = child(sheet, "printOptions");
|
|
26
|
+
const userSize = setup?.hasAttribute("paperWidth") || setup?.hasAttribute("paperHeight");
|
|
27
|
+
const paper = paperById.get(numberAttribute(setup, "paperSize", 1));
|
|
28
|
+
const orientation = setup?.getAttribute("orientation"), order = setup?.getAttribute("pageOrder");
|
|
29
|
+
const properties = child(sheet, "sheetPr");
|
|
30
|
+
const flags = properties && child(properties, "pageSetUpPr");
|
|
31
|
+
const fit = isTrue(flags?.getAttribute("fitToPage"));
|
|
32
|
+
const gridlines = isTrue(print?.getAttribute("gridLines"));
|
|
33
|
+
const physical = {
|
|
34
|
+
left: numberAttribute(margins, "left", nativeDefaultMargins.left), right: numberAttribute(margins, "right", nativeDefaultMargins.right),
|
|
35
|
+
top: numberAttribute(margins, "top", nativeDefaultMargins.top), bottom: numberAttribute(margins, "bottom", nativeDefaultMargins.bottom),
|
|
36
|
+
header: numberAttribute(margins, "header", nativeDefaultMargins.header), footer: numberAttribute(margins, "footer", nativeDefaultMargins.footer)
|
|
37
|
+
};
|
|
38
|
+
if (!paper || userSize || (orientation && !["default", "portrait", "landscape"].includes(orientation))
|
|
39
|
+
|| (order && order !== "downThenOver" && order !== "overThenDown")
|
|
40
|
+
|| ["horizontalCentered", "verticalCentered", "headings"].some(name => isTrue(print?.getAttribute(name)))
|
|
41
|
+
|| ["blackAndWhite", "draft"].some(name => isTrue(setup?.getAttribute(name)))) {
|
|
42
|
+
throw new Error("工作表含暂未支持的纸型或打印方式。");
|
|
43
|
+
}
|
|
44
|
+
const rowBreaks = readXlsxPrintBreaks(sheet, "row"), columnBreaks = readXlsxPrintBreaks(sheet, "column");
|
|
45
|
+
const pageText = readXlsxPrintPageText(sheet);
|
|
46
|
+
const firstPageNumber = isTrue(setup?.getAttribute("useFirstPageNumber")) ? numberAttribute(setup, "firstPageNumber", 1) : undefined;
|
|
47
|
+
if (!Object.keys(ranges).length && !fit && !gridlines && !setupKeys.some(key => setup?.hasAttribute(key))
|
|
48
|
+
&& !rowBreaks.length && !columnBreaks.length && !pageText && firstPageNumber === undefined
|
|
49
|
+
&& marginKeys.every(key => physical[key] === nativeDefaultMargins[key])) return;
|
|
50
|
+
const width = numberAttribute(setup, "fitToWidth", 1), height = numberAttribute(setup, "fitToHeight", 1);
|
|
51
|
+
const scaling = fit && (width || height) ? { kind: "fit" as const, width, height }
|
|
52
|
+
: { kind: "percent" as const, percent: numberAttribute(setup, "scale", 100) };
|
|
53
|
+
return copyWorkbookPrintLayout({ ...defaultWorkbookPrintLayout, ...ranges, paper, landscape: orientation === "landscape",
|
|
54
|
+
pageOrder: order === "overThenDown" ? order : "downThenOver", margins: physical, gridlines, scaling, rowBreaks, columnBreaks, firstPageNumber, pageText });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @param sheet - Mutable native worksheet. @param before - Parsed previous layout. @param after - Layout being saved. */
|
|
58
|
+
export function writeXlsxPageSetup(sheet: Element, before: WorkbookWorksheetPrintLayout | undefined,
|
|
59
|
+
after: WorkbookWorksheetPrintLayout | undefined): void {
|
|
60
|
+
const properties = child(sheet, "sheetPr");
|
|
61
|
+
writeXlsxPrintBreaks(sheet, "row", after?.rowBreaks);
|
|
62
|
+
writeXlsxPrintBreaks(sheet, "column", after?.columnBreaks);
|
|
63
|
+
if (!after || !sameWorkbookPrintPageText(before?.pageText, after.pageText)) writeXlsxPrintPageText(sheet, after?.pageText);
|
|
64
|
+
if (!after) {
|
|
65
|
+
const setup = child(sheet, "pageSetup"), print = child(sheet, "printOptions"), margins = child(sheet, "pageMargins");
|
|
66
|
+
for (const key of [...setupKeys, "firstPageNumber", "useFirstPageNumber"]) setup?.removeAttribute(key);
|
|
67
|
+
if (properties) child(properties, "pageSetUpPr")?.removeAttribute("fitToPage");
|
|
68
|
+
print?.removeAttribute("gridLines");
|
|
69
|
+
print?.removeAttribute("gridLinesSet");
|
|
70
|
+
if (margins) for (const [key, value] of Object.entries(nativeDefaultMargins)) margins.setAttribute(key, String(value));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// A named area or title change alone leaves the producer's physical settings intact.
|
|
74
|
+
const changedMargins = !before || marginKeys.some(key => before.margins[key] !== after.margins[key]);
|
|
75
|
+
if (changedMargins) {
|
|
76
|
+
const margins = ensureXlsxPrintElement(sheet, "pageMargins", ["pageSetup", ...afterPageSetup]);
|
|
77
|
+
for (const key of marginKeys) margins.setAttribute(key, String(after.margins[key] ?? nativeDefaultMargins[key]));
|
|
78
|
+
}
|
|
79
|
+
if (before?.gridlines !== after.gridlines) {
|
|
80
|
+
const print = ensureXlsxPrintElement(sheet, "printOptions", ["pageMargins", "pageSetup", ...afterPageSetup]);
|
|
81
|
+
print.setAttribute("gridLines", after.gridlines ? "1" : "0");
|
|
82
|
+
print.setAttribute("gridLinesSet", "1");
|
|
83
|
+
}
|
|
84
|
+
const scaleChanged = !before || JSON.stringify(before.scaling) !== JSON.stringify(after.scaling);
|
|
85
|
+
const startChanged = before?.firstPageNumber !== after.firstPageNumber;
|
|
86
|
+
if (before?.paper === after.paper && before.landscape === after.landscape && before.pageOrder === after.pageOrder && !scaleChanged && !startChanged) return;
|
|
87
|
+
const setup = ensureXlsxPrintElement(sheet, "pageSetup", afterPageSetup);
|
|
88
|
+
if (startChanged) {
|
|
89
|
+
if (after.firstPageNumber === undefined) {
|
|
90
|
+
setup.removeAttribute("firstPageNumber");
|
|
91
|
+
setup.removeAttribute("useFirstPageNumber");
|
|
92
|
+
} else {
|
|
93
|
+
setup.setAttribute("firstPageNumber", String(after.firstPageNumber));
|
|
94
|
+
setup.setAttribute("useFirstPageNumber", "1");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (before?.paper !== after.paper) setup.setAttribute("paperSize", String(paperIds[after.paper]));
|
|
98
|
+
if (before?.landscape !== after.landscape) setup.setAttribute("orientation", after.landscape ? "landscape" : "portrait");
|
|
99
|
+
if (before?.pageOrder !== after.pageOrder) setup.setAttribute("pageOrder", after.pageOrder);
|
|
100
|
+
if (scaleChanged) {
|
|
101
|
+
// The owning sheet flag is required even when the page dimensions are explicitly set.
|
|
102
|
+
const sheetPr = properties ?? ensureXlsxPrintElement(sheet, "sheetPr", children(sheet).map(node => node.localName ?? ""));
|
|
103
|
+
const membership = ensureXlsxPrintElement(sheetPr, "pageSetUpPr");
|
|
104
|
+
const scale = after.scaling;
|
|
105
|
+
membership.setAttribute("fitToPage", scale.kind === "fit" ? "1" : "0");
|
|
106
|
+
if (scale.kind === "fit") {
|
|
107
|
+
setup.setAttribute("fitToWidth", String(scale.width));
|
|
108
|
+
setup.setAttribute("fitToHeight", String(scale.height));
|
|
109
|
+
setup.removeAttribute("scale");
|
|
110
|
+
} else {
|
|
111
|
+
setup.setAttribute("scale", String(scale.percent));
|
|
112
|
+
setup.removeAttribute("fitToWidth");
|
|
113
|
+
setup.removeAttribute("fitToHeight");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import { formatWorkbookColumn, formatWorkbookRange, parseWorkbookRange } from "@quirekit/workbook";
|
|
3
|
+
import { hasKnownAttributes, hasKnownChildren } from "../../opc/shape";
|
|
4
|
+
import { child, children, readIndex, spreadNs } from "../../opc/xml";
|
|
5
|
+
import type { styleColorReader } from "../../styles/color";
|
|
6
|
+
import type { XlsxDifferentialStyle } from "../../styles/types";
|
|
7
|
+
import { xlsxConditionExtensions } from "../conditional/extensions";
|
|
8
|
+
import { hasXlsxSolidProgress } from "./solid";
|
|
9
|
+
import type { XlsxProgressPresentation } from "./types";
|
|
10
|
+
|
|
11
|
+
/** @param node - SpreadsheetML rule. @param anchor - Relative cell at the top left. @param styles - Parsed differential records.
|
|
12
|
+
* @returns Whether it supplies only the percentage display for a progress region. */
|
|
13
|
+
function isProgressLabel(node: Element, anchor: string, styles: readonly (XlsxDifferentialStyle | undefined)[]): boolean {
|
|
14
|
+
const style = styles[readIndex(node, "dxfId") ?? -1];
|
|
15
|
+
const formula = child(node, "formula");
|
|
16
|
+
return node.getAttribute("type") === "expression" && Boolean(readIndex(node, "priority"))
|
|
17
|
+
&& hasKnownAttributes(node, ["type", "priority", "dxfId"]) && style?.progressPercent === true && Object.keys(style).length === 1
|
|
18
|
+
&& children(node).length === 1 && formula?.namespaceURI === spreadNs && hasKnownAttributes(formula, [])
|
|
19
|
+
&& hasKnownChildren(formula, []) && formula.textContent?.trim().toUpperCase() === `ISNUMBER(${anchor})`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @param rule - SpreadsheetML rule. @param resolve - Producer palette. @returns Fixed 0–1 bar color if its geometry is supported. */
|
|
23
|
+
function barColor(rule: Element, resolve: ReturnType<typeof styleColorReader>): string | undefined {
|
|
24
|
+
const bar = child(rule, "dataBar");
|
|
25
|
+
if (rule.getAttribute("type") !== "dataBar" || !readIndex(rule, "priority") || !hasKnownAttributes(rule, ["type", "priority"])
|
|
26
|
+
|| !bar || bar.namespaceURI !== spreadNs || !hasKnownAttributes(bar, ["minLength", "maxLength", "showValue"])
|
|
27
|
+
|| !["", "1", "true"].includes(bar.getAttribute("showValue") ?? "")) return;
|
|
28
|
+
const parts = children(bar), [low, high, color] = parts;
|
|
29
|
+
if (parts.length !== 3 || color?.localName !== "color" || color.namespaceURI !== spreadNs
|
|
30
|
+
|| !hasKnownAttributes(color, ["rgb", "theme", "indexed", "tint"]) || !hasKnownChildren(color, [])
|
|
31
|
+
|| ![low, high].every((bound, index) => bound?.namespaceURI === spreadNs && bound.localName === "cfvo"
|
|
32
|
+
&& hasKnownAttributes(bound, ["type", "val"]) && hasKnownChildren(bound, [])
|
|
33
|
+
&& bound.getAttribute("type") === "num" && bound.getAttribute("val") === String(index))) return;
|
|
34
|
+
return resolve(color);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param worksheet - Source worksheet. @param sheetId - Worksheet coordinates. @param styles - Parsed differentials.
|
|
38
|
+
* @param resolve - Producer palette. @returns Candidate progress presentations indexed by their exact range. */
|
|
39
|
+
export function readXlsxProgressFormats(worksheet: Element, sheetId: string, styles: readonly (XlsxDifferentialStyle | undefined)[],
|
|
40
|
+
resolve: ReturnType<typeof styleColorReader>): ReadonlyMap<string, XlsxProgressPresentation> {
|
|
41
|
+
const solid = xlsxConditionExtensions(worksheet);
|
|
42
|
+
const bars = new Map<string, XlsxProgressPresentation>(), labels = new Map<string, Element>();
|
|
43
|
+
const duplicates = new Set<string>();
|
|
44
|
+
for (const container of children(worksheet, "conditionalFormatting")) {
|
|
45
|
+
const raw = container.getAttribute("sqref")?.trim() ?? "";
|
|
46
|
+
if (!raw || /\s/u.test(raw) || container.namespaceURI !== spreadNs || !hasKnownAttributes(container, ["sqref"])) continue;
|
|
47
|
+
try {
|
|
48
|
+
const range = parseWorkbookRange(sheetId, raw), key = formatWorkbookRange(range);
|
|
49
|
+
const anchor = formatWorkbookColumn(range.startColumn) + (range.startRow + 1);
|
|
50
|
+
for (const rule of children(container, "cfRule")) {
|
|
51
|
+
if (rule.namespaceURI !== spreadNs) continue;
|
|
52
|
+
if (isProgressLabel(rule, anchor, styles)) {
|
|
53
|
+
if (labels.has(key)) duplicates.add(key);
|
|
54
|
+
labels.set(key, rule);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const color = barColor(rule, resolve), bar = child(rule, "dataBar");
|
|
58
|
+
if (!color || !bar) continue;
|
|
59
|
+
const wps = Boolean(solid && children(rule).length === 2 && hasXlsxSolidProgress(rule, raw, solid));
|
|
60
|
+
const native = children(rule).length === 1 && bar.getAttribute("minLength") === "0" && bar.getAttribute("maxLength") === "100";
|
|
61
|
+
if (!wps && !native) continue;
|
|
62
|
+
if (bars.has(key)) duplicates.add(key);
|
|
63
|
+
bars.set(key, { color, conditions: [rule], wps });
|
|
64
|
+
}
|
|
65
|
+
} catch { /* Unhandled records remain under the existing file-preservation boundary. */ }
|
|
66
|
+
}
|
|
67
|
+
for (const [key, bar] of bars) {
|
|
68
|
+
const label = labels.get(key);
|
|
69
|
+
if (duplicates.has(key) || !bar.wps && !label) bars.delete(key);
|
|
70
|
+
else if (!bar.wps && label) bars.set(key, { ...bar, conditions: [...bar.conditions, label] });
|
|
71
|
+
}
|
|
72
|
+
return bars;
|
|
73
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import { hasKnownAttributes } from "../../opc/shape";
|
|
3
|
+
import { child, children } from "../../opc/xml";
|
|
4
|
+
import { xlsxConditionalNamespace, xlsxConditionalOperands, xlsxDataBarExtension } from "../conditional/extensions";
|
|
5
|
+
|
|
6
|
+
/** @param bound - Potential x14 numeric threshold. @returns Its finite, uncalculated value. */
|
|
7
|
+
export function xlsxExtendedBarBound(bound: Element | undefined): number | undefined {
|
|
8
|
+
const text = bound && child(bound, "f");
|
|
9
|
+
if (bound?.namespaceURI !== xlsxConditionalNamespace || bound.localName !== "cfvo" || !hasKnownAttributes(bound, ["type"])
|
|
10
|
+
|| bound.getAttribute("type") !== "num" || children(bound).length !== 1 || text?.namespaceURI !== xlsxConditionalOperands) return;
|
|
11
|
+
const literal = text.textContent?.trim() ?? "";
|
|
12
|
+
return /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/iu.test(literal) && Number.isFinite(Number(literal)) ? Number(literal) : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @param rule - Standard fallback rule. @param sqref - Its target range. @param source - Indexed extended targets.
|
|
16
|
+
* @returns Whether the paired extension uses the fixed solid progress semantics. */
|
|
17
|
+
export function hasXlsxSolidProgress(rule: Element, sqref: string, source: ReadonlyMap<string, Element>): boolean {
|
|
18
|
+
const bar = xlsxDataBarExtension(rule, sqref, source);
|
|
19
|
+
if (!bar) return false;
|
|
20
|
+
if (!hasKnownAttributes(bar, ["minLength", "maxLength", "gradient", "negativeBarColorSameAsPositive", "axisPosition"])
|
|
21
|
+
|| bar.getAttribute("minLength") !== "0" || bar.getAttribute("maxLength") !== "100" || bar.getAttribute("gradient") !== "0"
|
|
22
|
+
|| bar.getAttribute("axisPosition") !== "none" || bar.getAttribute("negativeBarColorSameAsPositive") !== "1") return false;
|
|
23
|
+
const parts = children(bar), [minimum, maximum, axis] = parts;
|
|
24
|
+
return parts.length === 3 && axis?.namespaceURI === xlsxConditionalNamespace && axis.localName === "axisColor"
|
|
25
|
+
&& xlsxExtendedBarBound(minimum) === 0 && xlsxExtendedBarBound(maximum) === 1;
|
|
26
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
|
|
3
|
+
/** Native presentation associated with a progress validation. */
|
|
4
|
+
export interface XlsxProgressPresentation {
|
|
5
|
+
/** Data bar fill stored by the spreadsheet producer. */
|
|
6
|
+
readonly color: string;
|
|
7
|
+
/** Conditional rules owned by this single progress range. */
|
|
8
|
+
readonly conditions: readonly Element[];
|
|
9
|
+
/** Whether the producer used a WPS custom validation and solid-bar extension. */
|
|
10
|
+
readonly wps: boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { openWorkbook, parseWorkbookRange, type WorkbookSnapshot } from "@quirekit/workbook";
|
|
2
|
+
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { createXlsx, openXlsx } from "../../index";
|
|
5
|
+
|
|
6
|
+
const id = "tasks";
|
|
7
|
+
const range = parseWorkbookRange(id, "A2:A1048576");
|
|
8
|
+
const source: WorkbookSnapshot = { version: 1, revision: 0, id, name: "Tasks", sheets: [{
|
|
9
|
+
id, name: "Tasks", cells: [
|
|
10
|
+
{ row: 0, column: 0, input: { kind: "value", value: "Progress" } },
|
|
11
|
+
{ row: 1, column: 0, input: { kind: "value", value: 0.35 } },
|
|
12
|
+
{ row: 2, column: 0, input: { kind: "formula", formula: "=A2*2" } },
|
|
13
|
+
{ row: 3, column: 0, input: { kind: "value", value: "Keep this text" } }
|
|
14
|
+
], formats: [{ row: 1, column: 0, format: { bold: true, numberFormat: "0.00" } }],
|
|
15
|
+
validations: [{ range, definition: { type: "progress", color: "#54AFDB" } }],
|
|
16
|
+
conditionalFormats: [{ id: "highlight", ranges: [parseWorkbookRange(id, "B2:B4")], predicate: { kind: "duplicate" },
|
|
17
|
+
style: { background: "#FFF000" }, stopIfTrue: false }]
|
|
18
|
+
}] };
|
|
19
|
+
const path = "xl/worksheets/sheet1.xml";
|
|
20
|
+
|
|
21
|
+
it("writes a sparse native progress range and removes only its associated native rules", async () => {
|
|
22
|
+
const bytes = createXlsx(source, { result: () => ({ status: "value", value: 0.7 }) });
|
|
23
|
+
const parts = unzipSync(bytes), xml = strFromU8(parts[path]!);
|
|
24
|
+
expect(xml).toContain('sqref="A2:A1048576"');
|
|
25
|
+
expect(xml).toContain('<formula>ISNUMBER(A2)</formula>');
|
|
26
|
+
expect(xml).toContain('<dataBar minLength="0" maxLength="100" showValue="1"><cfvo type="num" val="0"/><cfvo type="num" val="1"/>');
|
|
27
|
+
expect(xml).toContain('<color rgb="FF54AFDB"/>');
|
|
28
|
+
expect(xml).toContain('<formula1>0</formula1><formula2>1</formula2>');
|
|
29
|
+
expect(xml.match(/<c /gu)).toHaveLength(4);
|
|
30
|
+
expect(strFromU8(parts["xl/styles.xml"]!)).toContain('<numFmt numFmtId="9" formatCode="0%"/>');
|
|
31
|
+
|
|
32
|
+
const file = openXlsx("Tasks", bytes);
|
|
33
|
+
const owner = file.snapshot.sheets[0]!.id;
|
|
34
|
+
expect(file.restrictions).toEqual([]);
|
|
35
|
+
expect(file.snapshot.sheets[0]?.validations).toMatchObject([{ range: { ...range, sheetId: owner }, definition: { type: "progress", color: "#54AFDB" } }]);
|
|
36
|
+
expect(file.snapshot.sheets[0]?.conditionalFormats).toMatchObject([{ predicate: { kind: "duplicate" } }]);
|
|
37
|
+
expect(file.snapshot.sheets[0]?.cells.map(({ input }) => input)).toEqual(source.sheets[0]?.cells.map(({ input }) => input));
|
|
38
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
39
|
+
try {
|
|
40
|
+
const candidate = workbook.prepare({ operationId: "remove-progress", baseRevision: workbook.revision, commands: [
|
|
41
|
+
{ name: "clearDataValidation", target: parseWorkbookRange(owner, "A2:A1048576"), params: {} }
|
|
42
|
+
] });
|
|
43
|
+
await workbook.commit(candidate.id);
|
|
44
|
+
const saved = file.write(workbook.snapshot());
|
|
45
|
+
const result = strFromU8(unzipSync(saved)[path]!);
|
|
46
|
+
expect(result).not.toMatch(/dataBar|ISNUMBER|dataValidations/u);
|
|
47
|
+
expect(result).toContain('type="duplicateValues"');
|
|
48
|
+
expect(openXlsx("Tasks", saved).restrictions).toEqual([]);
|
|
49
|
+
expect(workbook.readFormat({ sheetId: owner, row: 1, column: 0 })).toMatchObject({ bold: true, numberFormat: "0.00" });
|
|
50
|
+
await workbook.undo("restore-progress");
|
|
51
|
+
expect(file.write(workbook.snapshot())).toEqual(bytes);
|
|
52
|
+
} finally { await workbook.close(); }
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("retains an original conditional format whose progress components differ", () => {
|
|
56
|
+
const parts = unzipSync(createXlsx(source));
|
|
57
|
+
parts[path] = strToU8(strFromU8(parts[path]!).replace("ISNUMBER(A2)", "A2>=2"));
|
|
58
|
+
const bytes = zipSync(parts);
|
|
59
|
+
const file = openXlsx("Unmatched native conditions", bytes);
|
|
60
|
+
expect(file.restrictions).toContain("条件格式包含暂未支持的规则或样式");
|
|
61
|
+
expect(file.snapshot.sheets[0]?.validations?.[0]?.definition.type).toBe("decimal");
|
|
62
|
+
expect(file.write(file.snapshot)).toEqual(bytes);
|
|
63
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import { formatWorkbookColumn, formatWorkbookRange, workbookProgressColor, type WorkbookProgressValidationRule } from "@quirekit/workbook";
|
|
3
|
+
import { spreadNs } from "../../opc/xml";
|
|
4
|
+
|
|
5
|
+
/** @param worksheet - Native worksheet. @param before - Schema insertion point. @param progress - Current progress coverage.
|
|
6
|
+
* @param differential - Shared number format for all percentage labels. @returns First unused conditional priority. */
|
|
7
|
+
export function writeXlsxProgressFormats(worksheet: Element, before: Element | null, progress: readonly WorkbookProgressValidationRule[], differential: number): number {
|
|
8
|
+
const document = worksheet.ownerDocument!;
|
|
9
|
+
let priority = 1;
|
|
10
|
+
for (const { range, definition } of progress) {
|
|
11
|
+
const group = document.createElementNS(spreadNs, "conditionalFormatting");
|
|
12
|
+
group.setAttribute("sqref", formatWorkbookRange(range));
|
|
13
|
+
|
|
14
|
+
// Percent display applies to current and future numeric cells without overriding their base cell format.
|
|
15
|
+
const label = document.createElementNS(spreadNs, "cfRule");
|
|
16
|
+
label.setAttribute("type", "expression");
|
|
17
|
+
label.setAttribute("priority", String(priority++));
|
|
18
|
+
label.setAttribute("dxfId", String(differential));
|
|
19
|
+
const condition = document.createElementNS(spreadNs, "formula");
|
|
20
|
+
const anchor = formatWorkbookColumn(range.startColumn) + (range.startRow + 1);
|
|
21
|
+
condition.appendChild(document.createTextNode(`ISNUMBER(${anchor})`));
|
|
22
|
+
label.appendChild(condition);
|
|
23
|
+
group.appendChild(label);
|
|
24
|
+
|
|
25
|
+
const visual = document.createElementNS(spreadNs, "cfRule");
|
|
26
|
+
visual.setAttribute("type", "dataBar");
|
|
27
|
+
visual.setAttribute("priority", String(priority++));
|
|
28
|
+
const bar = document.createElementNS(spreadNs, "dataBar");
|
|
29
|
+
bar.setAttribute("minLength", "0");
|
|
30
|
+
bar.setAttribute("maxLength", "100");
|
|
31
|
+
bar.setAttribute("showValue", "1");
|
|
32
|
+
for (const value of ["0", "1"]) {
|
|
33
|
+
const endpoint = document.createElementNS(spreadNs, "cfvo");
|
|
34
|
+
endpoint.setAttribute("type", "num");
|
|
35
|
+
endpoint.setAttribute("val", value);
|
|
36
|
+
bar.appendChild(endpoint);
|
|
37
|
+
}
|
|
38
|
+
const fill = document.createElementNS(spreadNs, "color");
|
|
39
|
+
fill.setAttribute("rgb", "FF" + (definition.color ?? workbookProgressColor).slice(1));
|
|
40
|
+
bar.appendChild(fill);
|
|
41
|
+
visual.appendChild(bar);
|
|
42
|
+
group.appendChild(visual);
|
|
43
|
+
worksheet.insertBefore(group, before);
|
|
44
|
+
}
|
|
45
|
+
return priority;
|
|
46
|
+
}
|