@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,131 @@
|
|
|
1
|
+
import type { XlsxPresetTableStyle } from "../types";
|
|
2
|
+
|
|
3
|
+
/** Medium styles with filled headers and contrasting row or column bands. */
|
|
4
|
+
export const xlsxMediumTableStyles: Readonly<Record<string, XlsxPresetTableStyle>> = {
|
|
5
|
+
TableStyleMedium1: {
|
|
6
|
+
wholeTable: {color: [1], borders: {left: ["thin", 1], right: ["thin", 1], top: ["thin", 1], bottom: ["thin", 1], horizontal: ["thin", 1]}},
|
|
7
|
+
headerRow: {bold: true, color: [0], background: [1]},
|
|
8
|
+
totalRow: {bold: true, color: [1], borders: {top: ["double", 1]}},
|
|
9
|
+
firstColumn: {bold: true, color: [1]},
|
|
10
|
+
lastColumn: {bold: true, color: [1]},
|
|
11
|
+
firstRowStripe: {background: [0, -0.1499984740745262]},
|
|
12
|
+
firstColumnStripe: {background: [0, -0.1499984740745262]},
|
|
13
|
+
},
|
|
14
|
+
TableStyleMedium2: {
|
|
15
|
+
wholeTable: {color: [1], borders: {left: ["thin", 4, 0.3999755851924192], right: ["thin", 4, 0.3999755851924192], top: ["thin", 4, 0.3999755851924192], bottom: ["thin", 4, 0.3999755851924192], horizontal: ["thin", 4, 0.3999755851924192]}},
|
|
16
|
+
headerRow: {bold: true, color: [0], background: [4]},
|
|
17
|
+
totalRow: {bold: true, color: [1], borders: {top: ["double", 4]}},
|
|
18
|
+
firstColumn: {bold: true, color: [1]},
|
|
19
|
+
lastColumn: {bold: true, color: [1]},
|
|
20
|
+
firstRowStripe: {background: [4, 0.7999816888943144]},
|
|
21
|
+
firstColumnStripe: {background: [4, 0.7999816888943144]},
|
|
22
|
+
},
|
|
23
|
+
TableStyleMedium3: {
|
|
24
|
+
wholeTable: {color: [1], borders: {left: ["thin", 5, 0.3999755851924192], right: ["thin", 5, 0.3999755851924192], top: ["thin", 5, 0.3999755851924192], bottom: ["thin", 5, 0.3999755851924192], horizontal: ["thin", 5, 0.3999755851924192]}},
|
|
25
|
+
headerRow: {bold: true, color: [0], background: [5]},
|
|
26
|
+
totalRow: {bold: true, color: [1], borders: {top: ["double", 5]}},
|
|
27
|
+
firstColumn: {bold: true, color: [1]},
|
|
28
|
+
lastColumn: {bold: true, color: [1]},
|
|
29
|
+
firstRowStripe: {background: [5, 0.7999816888943144]},
|
|
30
|
+
firstColumnStripe: {background: [5, 0.7999816888943144]},
|
|
31
|
+
},
|
|
32
|
+
TableStyleMedium4: {
|
|
33
|
+
wholeTable: {color: [1], borders: {left: ["thin", 6, 0.3999755851924192], right: ["thin", 6, 0.3999755851924192], top: ["thin", 6, 0.3999755851924192], bottom: ["thin", 6, 0.3999755851924192], horizontal: ["thin", 6, 0.3999755851924192]}},
|
|
34
|
+
headerRow: {bold: true, color: [0], background: [6]},
|
|
35
|
+
totalRow: {bold: true, color: [1], borders: {top: ["double", 6]}},
|
|
36
|
+
firstColumn: {bold: true, color: [1]},
|
|
37
|
+
lastColumn: {bold: true, color: [1]},
|
|
38
|
+
firstRowStripe: {background: [6, 0.7999816888943144]},
|
|
39
|
+
firstColumnStripe: {background: [6, 0.7999816888943144]},
|
|
40
|
+
},
|
|
41
|
+
TableStyleMedium5: {
|
|
42
|
+
wholeTable: {color: [1], borders: {left: ["thin", 7, 0.3999755851924192], right: ["thin", 7, 0.3999755851924192], top: ["thin", 7, 0.3999755851924192], bottom: ["thin", 7, 0.3999755851924192], horizontal: ["thin", 7, 0.3999755851924192]}},
|
|
43
|
+
headerRow: {bold: true, color: [0], background: [7]},
|
|
44
|
+
totalRow: {bold: true, color: [1], borders: {top: ["double", 7]}},
|
|
45
|
+
firstColumn: {bold: true, color: [1]},
|
|
46
|
+
lastColumn: {bold: true, color: [1]},
|
|
47
|
+
firstRowStripe: {background: [7, 0.7999816888943144]},
|
|
48
|
+
firstColumnStripe: {background: [7, 0.7999816888943144]},
|
|
49
|
+
},
|
|
50
|
+
TableStyleMedium6: {
|
|
51
|
+
wholeTable: {color: [1], borders: {left: ["thin", 8, 0.3999755851924192], right: ["thin", 8, 0.3999755851924192], top: ["thin", 8, 0.3999755851924192], bottom: ["thin", 8, 0.3999755851924192], horizontal: ["thin", 8, 0.3999755851924192]}},
|
|
52
|
+
headerRow: {bold: true, color: [0], background: [8]},
|
|
53
|
+
totalRow: {bold: true, color: [1], borders: {top: ["double", 8]}},
|
|
54
|
+
firstColumn: {bold: true, color: [1]},
|
|
55
|
+
lastColumn: {bold: true, color: [1]},
|
|
56
|
+
firstRowStripe: {background: [8, 0.7999816888943144]},
|
|
57
|
+
firstColumnStripe: {background: [8, 0.7999816888943144]},
|
|
58
|
+
},
|
|
59
|
+
TableStyleMedium7: {
|
|
60
|
+
wholeTable: {color: [1], borders: {left: ["thin", 9, 0.3999755851924192], right: ["thin", 9, 0.3999755851924192], top: ["thin", 9, 0.3999755851924192], bottom: ["thin", 9, 0.3999755851924192], horizontal: ["thin", 9, 0.3999755851924192]}},
|
|
61
|
+
headerRow: {bold: true, color: [0], background: [9]},
|
|
62
|
+
totalRow: {bold: true, color: [1], borders: {top: ["double", 9]}},
|
|
63
|
+
firstColumn: {bold: true, color: [1]},
|
|
64
|
+
lastColumn: {bold: true, color: [1]},
|
|
65
|
+
firstRowStripe: {background: [9, 0.7999816888943144]},
|
|
66
|
+
firstColumnStripe: {background: [9, 0.7999816888943144]},
|
|
67
|
+
},
|
|
68
|
+
TableStyleMedium8: {
|
|
69
|
+
wholeTable: {color: [1], background: [0, -0.1499984740745262], borders: {vertical: ["thin", 0], horizontal: ["thin", 0]}},
|
|
70
|
+
headerRow: {bold: true, color: [0], background: [1], borders: {bottom: ["thick", 0]}},
|
|
71
|
+
totalRow: {bold: true, color: [0], background: [1], borders: {top: ["thick", 0]}},
|
|
72
|
+
firstColumn: {bold: true, color: [0], background: [1]},
|
|
73
|
+
lastColumn: {bold: true, color: [0], background: [1]},
|
|
74
|
+
firstRowStripe: {background: [0, -0.3499862666707358]},
|
|
75
|
+
firstColumnStripe: {background: [0, -0.3499862666707358]},
|
|
76
|
+
},
|
|
77
|
+
TableStyleMedium9: {
|
|
78
|
+
wholeTable: {color: [1], background: [4, 0.7999816888943144], borders: {vertical: ["thin", 0], horizontal: ["thin", 0]}},
|
|
79
|
+
headerRow: {bold: true, color: [0], background: [4], borders: {bottom: ["thick", 0]}},
|
|
80
|
+
totalRow: {bold: true, color: [0], background: [4], borders: {top: ["thick", 0]}},
|
|
81
|
+
firstColumn: {bold: true, color: [0], background: [4]},
|
|
82
|
+
lastColumn: {bold: true, color: [0], background: [4]},
|
|
83
|
+
firstRowStripe: {background: [4, 0.5999938962981048]},
|
|
84
|
+
firstColumnStripe: {background: [4, 0.5999938962981048]},
|
|
85
|
+
},
|
|
86
|
+
TableStyleMedium10: {
|
|
87
|
+
wholeTable: {color: [1], background: [5, 0.7999816888943144], borders: {vertical: ["thin", 0], horizontal: ["thin", 0]}},
|
|
88
|
+
headerRow: {bold: true, color: [0], background: [5], borders: {bottom: ["thick", 0]}},
|
|
89
|
+
totalRow: {bold: true, color: [0], background: [5], borders: {top: ["thick", 0]}},
|
|
90
|
+
firstColumn: {bold: true, color: [0], background: [5]},
|
|
91
|
+
lastColumn: {bold: true, color: [0], background: [5]},
|
|
92
|
+
firstRowStripe: {background: [5, 0.5999938962981048]},
|
|
93
|
+
firstColumnStripe: {background: [5, 0.5999938962981048]},
|
|
94
|
+
},
|
|
95
|
+
TableStyleMedium11: {
|
|
96
|
+
wholeTable: {color: [1], background: [6, 0.7999816888943144], borders: {vertical: ["thin", 0], horizontal: ["thin", 0]}},
|
|
97
|
+
headerRow: {bold: true, color: [0], background: [6], borders: {bottom: ["thick", 0]}},
|
|
98
|
+
totalRow: {bold: true, color: [0], background: [6], borders: {top: ["thick", 0]}},
|
|
99
|
+
firstColumn: {bold: true, color: [0], background: [6]},
|
|
100
|
+
lastColumn: {bold: true, color: [0], background: [6]},
|
|
101
|
+
firstRowStripe: {background: [6, 0.5999938962981048]},
|
|
102
|
+
firstColumnStripe: {background: [6, 0.5999938962981048]},
|
|
103
|
+
},
|
|
104
|
+
TableStyleMedium12: {
|
|
105
|
+
wholeTable: {color: [1], background: [7, 0.7999816888943144], borders: {vertical: ["thin", 0], horizontal: ["thin", 0]}},
|
|
106
|
+
headerRow: {bold: true, color: [0], background: [7], borders: {bottom: ["thick", 0]}},
|
|
107
|
+
totalRow: {bold: true, color: [0], background: [7], borders: {top: ["thick", 0]}},
|
|
108
|
+
firstColumn: {bold: true, color: [0], background: [7]},
|
|
109
|
+
lastColumn: {bold: true, color: [0], background: [7]},
|
|
110
|
+
firstRowStripe: {background: [7, 0.5999938962981048]},
|
|
111
|
+
firstColumnStripe: {background: [7, 0.5999938962981048]},
|
|
112
|
+
},
|
|
113
|
+
TableStyleMedium13: {
|
|
114
|
+
wholeTable: {color: [1], background: [8, 0.7999816888943144], borders: {vertical: ["thin", 0], horizontal: ["thin", 0]}},
|
|
115
|
+
headerRow: {bold: true, color: [0], background: [8], borders: {bottom: ["thick", 0]}},
|
|
116
|
+
totalRow: {bold: true, color: [0], background: [8], borders: {top: ["thick", 0]}},
|
|
117
|
+
firstColumn: {bold: true, color: [0], background: [8]},
|
|
118
|
+
lastColumn: {bold: true, color: [0], background: [8]},
|
|
119
|
+
firstRowStripe: {background: [8, 0.5999938962981048]},
|
|
120
|
+
firstColumnStripe: {background: [8, 0.5999938962981048]},
|
|
121
|
+
},
|
|
122
|
+
TableStyleMedium14: {
|
|
123
|
+
wholeTable: {color: [1], background: [9, 0.7999816888943144], borders: {vertical: ["thin", 0], horizontal: ["thin", 0]}},
|
|
124
|
+
headerRow: {bold: true, color: [0], background: [9], borders: {bottom: ["thick", 0]}},
|
|
125
|
+
totalRow: {bold: true, color: [0], background: [9], borders: {top: ["thick", 0]}},
|
|
126
|
+
firstColumn: {bold: true, color: [0], background: [9]},
|
|
127
|
+
lastColumn: {bold: true, color: [0], background: [9]},
|
|
128
|
+
firstRowStripe: {background: [9, 0.5999938962981048]},
|
|
129
|
+
firstColumnStripe: {background: [9, 0.5999938962981048]},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import type { WorkbookTableStyleElement, WorkbookTableStyleElements, WorkbookTableStyleRegion } from "@quirekit/workbook";
|
|
3
|
+
import { child, children, isTrue, readIndex, spreadNs } from "../../opc/xml";
|
|
4
|
+
import type { styleColorReader } from "../../styles/color";
|
|
5
|
+
import { createXlsxBuiltinTableStyles } from "./builtin";
|
|
6
|
+
import { defaultWorkbookStructuredTableStyle } from "@quirekit/workbook";
|
|
7
|
+
import { readXlsxTableDifferential } from "./differential";
|
|
8
|
+
|
|
9
|
+
const regions = ["wholeTable", "firstColumnStripe", "secondColumnStripe", "firstRowStripe", "secondRowStripe",
|
|
10
|
+
"lastColumn", "firstColumn", "headerRow", "totalRow", "firstHeaderCell", "lastHeaderCell", "firstTotalCell", "lastTotalCell"] as const satisfies readonly WorkbookTableStyleRegion[];
|
|
11
|
+
const regionNames = new Set<string>(regions);
|
|
12
|
+
const flags: Partial<Record<WorkbookTableStyleRegion, string>> = {
|
|
13
|
+
firstColumn: "showFirstColumn", lastColumn: "showLastColumn",
|
|
14
|
+
firstColumnStripe: "showColumnStripes", secondColumnStripe: "showColumnStripes",
|
|
15
|
+
firstRowStripe: "showRowStripes", secondRowStripe: "showRowStripes"
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** @param node - Custom style in the workbook. @param records - Workbook differentials by native index.
|
|
19
|
+
* @param color - Source workbook palette. @returns Supported elements, independent of source ordering. */
|
|
20
|
+
function readCustomStyle(node: Element, records: readonly Element[], color: ReturnType<typeof styleColorReader>): WorkbookTableStyleElements {
|
|
21
|
+
const result: Partial<Record<WorkbookTableStyleRegion, WorkbookTableStyleElement>> = {};
|
|
22
|
+
for (const element of children(node, "tableStyleElement")) {
|
|
23
|
+
const key = element.getAttribute("type") ?? "";
|
|
24
|
+
const style = records[readIndex(element, "dxfId") ?? -1];
|
|
25
|
+
const size = readIndex(element, "size");
|
|
26
|
+
if (!regionNames.has(key) || style?.namespaceURI !== spreadNs || style.localName !== "dxf") continue;
|
|
27
|
+
result[key as WorkbookTableStyleRegion] = { ...readXlsxTableDifferential(style, color), ...(size && { size }) };
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @param stylesheet - Native workbook styles. @param theme - Theme colors in SpreadsheetML order.
|
|
33
|
+
* @param color - Workbook palette. @returns Reader of built-in and custom style appearances for each table. */
|
|
34
|
+
export function createXlsxTableStyleReader(stylesheet: Element | undefined, theme: readonly string[], color: ReturnType<typeof styleColorReader>) {
|
|
35
|
+
const catalog = stylesheet && child(stylesheet, "tableStyles");
|
|
36
|
+
const dxfs = stylesheet && child(stylesheet, "dxfs");
|
|
37
|
+
const defaults = catalog?.getAttribute("defaultTableStyle")?.toLowerCase() || "tablestylemedium2";
|
|
38
|
+
const records = dxfs ? children(dxfs) : [];
|
|
39
|
+
const custom = new Map<string, Element>();
|
|
40
|
+
if (catalog) for (const entry of children(catalog, "tableStyle")) {
|
|
41
|
+
const name = entry.getAttribute("name")?.toLowerCase();
|
|
42
|
+
if (name && entry.namespaceURI === spreadNs && !["0", "false"].includes(entry.getAttribute("table") ?? "")) custom.set(name, entry);
|
|
43
|
+
}
|
|
44
|
+
const builtin = createXlsxBuiltinTableStyles(theme);
|
|
45
|
+
const decoded = new Map<string, WorkbookTableStyleElements>();
|
|
46
|
+
/** @param name - Style key from the source. @returns A declared table style if supported. */
|
|
47
|
+
function resolve(name: string): WorkbookTableStyleElements | undefined {
|
|
48
|
+
const saved = decoded.get(name);
|
|
49
|
+
const definition = custom.get(name);
|
|
50
|
+
if (saved || !definition) return saved ?? builtin(name);
|
|
51
|
+
const style = readCustomStyle(definition, records, color);
|
|
52
|
+
decoded.set(name, style);
|
|
53
|
+
return style;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @param info - Native tableStyleInfo, if declared. @returns Differential elements enabled for this table. */
|
|
57
|
+
function read(info: Element | undefined): WorkbookTableStyleElements {
|
|
58
|
+
if (info?.namespaceURI !== spreadNs) return {};
|
|
59
|
+
const name = info.getAttribute("name")?.toLowerCase();
|
|
60
|
+
const style = (name && resolve(name)) || resolve(defaults);
|
|
61
|
+
if (!style) return {};
|
|
62
|
+
return Object.fromEntries(regions.flatMap(region => {
|
|
63
|
+
const value = style[region], flag = flags[region];
|
|
64
|
+
return value && (!flag || isTrue(info.getAttribute(flag))) ? [[region, value]] : [];
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
const { wholeTable, headerRow, firstRowStripe } = builtin(defaultWorkbookStructuredTableStyle.toLowerCase())!;
|
|
68
|
+
const authored: WorkbookTableStyleElements = { wholeTable: wholeTable!, headerRow: headerRow!, firstRowStripe: firstRowStripe! };
|
|
69
|
+
return Object.assign(read, { authored });
|
|
70
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { WorkbookBorderSide, WorkbookCellBorder, WorkbookTableStyleRegion } from "@quirekit/workbook";
|
|
2
|
+
|
|
3
|
+
/** Source palette index and optional SpreadsheetML tint. */
|
|
4
|
+
export type XlsxTableThemeColor = readonly [index: number, tint?: number | undefined];
|
|
5
|
+
|
|
6
|
+
/** Any edge belonging to the styled rectangle, including its inside grid. */
|
|
7
|
+
export type XlsxTableBorderSide = WorkbookBorderSide | "horizontal" | "vertical";
|
|
8
|
+
|
|
9
|
+
/** Source border stroke, theme index and optional tint. */
|
|
10
|
+
export type XlsxTableThemeBorder = readonly [stroke: WorkbookCellBorder["stroke"], ...color: XlsxTableThemeColor];
|
|
11
|
+
|
|
12
|
+
/** Data fields used by the standard ordinary-table style presets. */
|
|
13
|
+
export interface XlsxPresetTableFormat {
|
|
14
|
+
/** Explicit font weight. */
|
|
15
|
+
readonly bold?: boolean;
|
|
16
|
+
/** Theme text color. */
|
|
17
|
+
readonly color?: XlsxTableThemeColor;
|
|
18
|
+
/** Theme fill color. */
|
|
19
|
+
readonly background?: XlsxTableThemeColor;
|
|
20
|
+
/** Stripes with a size other than one. */
|
|
21
|
+
readonly size?: number;
|
|
22
|
+
/** Stroke definitions for the outer and inner edges. */
|
|
23
|
+
readonly borders?: Readonly<Partial<Record<XlsxTableBorderSide, XlsxTableThemeBorder>>>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Each preset provides only its declared ordinary-table regions. */
|
|
27
|
+
export type XlsxPresetTableStyle = Readonly<Partial<Record<WorkbookTableStyleRegion, XlsxPresetTableFormat>>>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { strFromU8, unzipSync } from "fflate";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { createXlsx, openXlsx } from "../index";
|
|
4
|
+
import { openWorkbook, parseWorkbookRange, type WorkbookCommandCall, type WorkbookSnapshot } from "@quirekit/workbook";
|
|
5
|
+
|
|
6
|
+
const range = parseWorkbookRange("data", "A1:B4");
|
|
7
|
+
const table = { id: "orders", name: "Revenue", range, columns: ["Product", "Net"], header: true, totals: false, showFilter: true } as const;
|
|
8
|
+
const seed: WorkbookSnapshot = { id: "totals", name: "Native totals", version: 1, revision: 0, structuredTables: [table], sheets: [{
|
|
9
|
+
id: "data", name: "Data", cells: [
|
|
10
|
+
{ row: 0, column: 0, input: { kind: "value", value: "Product" } },
|
|
11
|
+
{ row: 0, column: 1, input: { kind: "value", value: "Net" } },
|
|
12
|
+
{ row: 1, column: 1, input: { kind: "value", value: 7 } },
|
|
13
|
+
{ row: 2, column: 1, input: { kind: "value", value: 12 } },
|
|
14
|
+
{ row: 3, column: 1, input: { kind: "value", value: 8 } },
|
|
15
|
+
{ row: 4, column: 1, input: { kind: "value", value: 99 } }
|
|
16
|
+
]
|
|
17
|
+
}] };
|
|
18
|
+
|
|
19
|
+
it("saves native visible totals and restores regular formulas and labels after reopening a hidden row", async () => {
|
|
20
|
+
const saved = createXlsx(seed);
|
|
21
|
+
const file = openXlsx("Totals", saved);
|
|
22
|
+
const definition = file.snapshot.structuredTables![0]!;
|
|
23
|
+
const { id, range: target } = definition;
|
|
24
|
+
const { sheetId } = target;
|
|
25
|
+
const book = await openWorkbook(file.snapshot, { appearance: file.appearance, cellShiftRestrictions: file.cellShiftRestrictions });
|
|
26
|
+
/** @param operationId - Test edit. @param commands - Atomic operation(s). @returns Applied revision. */
|
|
27
|
+
const apply = (operationId: string, ...commands: WorkbookCommandCall[]) => book.commit(book.prepare({
|
|
28
|
+
operationId, baseRevision: book.revision, commands
|
|
29
|
+
}).id);
|
|
30
|
+
try {
|
|
31
|
+
expect(file.restrictions).toEqual([]);
|
|
32
|
+
expect(file.cellShiftRestrictions.get(sheetId)).toBeUndefined();
|
|
33
|
+
await apply("show", { name: "setStructuredTableTotals", target, params: { id, visible: true,
|
|
34
|
+
columns: [{ column: "B", aggregation: "sum" }] } },
|
|
35
|
+
{ name: "setCells", target: parseWorkbookRange(sheetId, "A5"), params: { value: "合计" } });
|
|
36
|
+
const visible = file.write(book.snapshot());
|
|
37
|
+
const layout = strFromU8(unzipSync(visible)["xl/tables/table1.xml"]!);
|
|
38
|
+
expect(layout).toMatch(/ref="A1:B5"/u);
|
|
39
|
+
expect(layout).toContain('totalsRowCount="1"');
|
|
40
|
+
expect(layout).toContain('totalsRowFunction="sum"');
|
|
41
|
+
expect(layout).toContain('totalsRowLabel="合计"');
|
|
42
|
+
expect(layout).toContain('<autoFilter ref="A1:B4"');
|
|
43
|
+
expect(openXlsx("Totals", visible).snapshot.sheets[0]?.cells).toEqual(expect.arrayContaining([
|
|
44
|
+
{ row: 4, column: 1, input: { kind: "formula", formula: "=SUBTOTAL(109,[Net])" } },
|
|
45
|
+
{ row: 5, column: 1, input: { kind: "value", value: 99 } }
|
|
46
|
+
]));
|
|
47
|
+
await apply("custom", { name: "setCells", target: parseWorkbookRange(sheetId, "B5"), params: { formula: "=SUM([Net])*2" } });
|
|
48
|
+
await apply("hide", { name: "setStructuredTableTotals", target, params: { id, visible: false } });
|
|
49
|
+
const hidden = file.write(book.snapshot());
|
|
50
|
+
const serialized = strFromU8(unzipSync(hidden)["xl/tables/table1.xml"]!);
|
|
51
|
+
expect(serialized).toContain('totalsRowFunction="custom"');
|
|
52
|
+
expect(serialized).toContain("<totalsRowFormula>SUM([Net])*2</totalsRowFormula>");
|
|
53
|
+
expect(serialized).not.toContain('totalsRowCount="1"');
|
|
54
|
+
const reopened = openXlsx("Totals", hidden);
|
|
55
|
+
expect(reopened.restrictions).toEqual([]);
|
|
56
|
+
const remaining = reopened.snapshot.structuredTables![0]!;
|
|
57
|
+
expect(remaining.hiddenTotals).toEqual([
|
|
58
|
+
{ column: 0, input: { kind: "label", text: "合计" } },
|
|
59
|
+
{ column: 1, input: { kind: "formula", formula: "=SUM([Net])*2" } }
|
|
60
|
+
]);
|
|
61
|
+
const next = await openWorkbook(reopened.snapshot, { appearance: reopened.appearance, cellShiftRestrictions: reopened.cellShiftRestrictions });
|
|
62
|
+
try {
|
|
63
|
+
await next.commit(next.prepare({ operationId: "restore-after-rename", baseRevision: next.revision, commands: [
|
|
64
|
+
{ name: "setCells", target: parseWorkbookRange(remaining.range.sheetId, "B1"), params: { value: "Net [USD]" } },
|
|
65
|
+
{ name: "setStructuredTableTotals", target: remaining.range, params: { id: remaining.id, visible: true } }
|
|
66
|
+
] }).id);
|
|
67
|
+
expect(next.readCell({ sheetId: remaining.range.sheetId, row: 4, column: 1 }).input).toMatchObject({ formula: "=SUM([[Net '[USD']]])*2" });
|
|
68
|
+
expect(next.readCell({ sheetId: remaining.range.sheetId, row: 5, column: 1 }).input).toMatchObject({ value: 99 });
|
|
69
|
+
expect(openXlsx("Totals", reopened.write(next.snapshot())).snapshot.structuredTables?.[0]?.totals).toBe(true);
|
|
70
|
+
} finally { await next.close(); }
|
|
71
|
+
await book.undo("undo-hide");
|
|
72
|
+
expect(book.readCell({ sheetId, row: 4, column: 1 }).input).toMatchObject({ formula: "=SUM([Net])*2" });
|
|
73
|
+
await book.undo("undo-custom");
|
|
74
|
+
await book.undo("undo-show");
|
|
75
|
+
expect(file.write(book.snapshot())).toEqual(saved);
|
|
76
|
+
} finally { await book.close(); }
|
|
77
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import { isWorkbookTableAggregation, workbookTableTotalInput, type WorkbookCell, type WorkbookStructuredTable, type WorkbookTableTotal } from "@quirekit/workbook";
|
|
3
|
+
import { hasKnownAttributes, hasKnownChildren } from "../opc/shape";
|
|
4
|
+
import { child, children, spreadNs } from "../opc/xml";
|
|
5
|
+
import { decodeXlsxText, encodeXlsxText } from "../worksheet/text";
|
|
6
|
+
|
|
7
|
+
/** @param column - Native column element. @param index - Column coordinate.
|
|
8
|
+
* @returns Parsed configuration, null for a blank total, or undefined for an unsupported part. */
|
|
9
|
+
function readTotal(column: Element, index: number): WorkbookTableTotal | null | undefined {
|
|
10
|
+
const kind = column.getAttribute("totalsRowFunction") ?? "none";
|
|
11
|
+
const text = column.getAttribute("totalsRowLabel");
|
|
12
|
+
const formula = child(column, "totalsRowFormula");
|
|
13
|
+
if (kind === "custom") {
|
|
14
|
+
if (!formula || formula.namespaceURI !== spreadNs || !hasKnownAttributes(formula, []) || !hasKnownChildren(formula, [])) return;
|
|
15
|
+
const expression = (formula.textContent ?? "").trim();
|
|
16
|
+
if (!expression || expression.length >= 8192) return;
|
|
17
|
+
return { column: index, input: { kind: "formula", formula: expression.startsWith("=") ? expression : "=" + expression } };
|
|
18
|
+
}
|
|
19
|
+
if (formula) return;
|
|
20
|
+
if (isWorkbookTableAggregation(kind)) return { column: index, input: { kind: "aggregate", aggregation: kind } };
|
|
21
|
+
if (kind !== "none") return;
|
|
22
|
+
if (text === null) return null;
|
|
23
|
+
const label = decodeXlsxText(text);
|
|
24
|
+
if (label.length > 32767) return;
|
|
25
|
+
return { column: index, input: { kind: "label", text: label } };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @param fields - TableColumns element. @param first - First physical table column.
|
|
29
|
+
* @returns Decoded native settings, or undefined when the definitions need original-file preservation. */
|
|
30
|
+
export function readXlsxTableTotals(fields: Element, first: number): WorkbookTableTotal[] | undefined {
|
|
31
|
+
const result: WorkbookTableTotal[] = [];
|
|
32
|
+
for (const [offset, column] of children(fields, "tableColumn").entries()) {
|
|
33
|
+
const total = readTotal(column, first + offset);
|
|
34
|
+
if (total === undefined) return;
|
|
35
|
+
if (total) result.push(total);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @param table - Table layout at one revision. @param cells - Sparse cell inputs across its visible totals row.
|
|
41
|
+
* @returns Native total labels and functions at that revision. */
|
|
42
|
+
export function xlsxTableTotals(table: WorkbookStructuredTable, cells: ReadonlyMap<number, WorkbookCell> | undefined): readonly WorkbookTableTotal[] {
|
|
43
|
+
if (!table.totals) return table.hiddenTotals ?? [];
|
|
44
|
+
if (!cells) return [];
|
|
45
|
+
const { startColumn, endColumn } = table.range;
|
|
46
|
+
return Array.from({ length: endColumn - startColumn + 1 }, (_, offset) => {
|
|
47
|
+
const column = startColumn + offset;
|
|
48
|
+
const input = workbookTableTotalInput(table, column, cells.get(column) ?? null);
|
|
49
|
+
return input ? [{ column, input }] : [];
|
|
50
|
+
}).flat();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @param root - SpreadsheetML table part. @param table - Current table geometry.
|
|
54
|
+
* @param totals - Current or remembered column configuration. */
|
|
55
|
+
export function writeXlsxTableTotals(root: Element, table: WorkbookStructuredTable, totals: readonly WorkbookTableTotal[]): void {
|
|
56
|
+
if (table.totals) root.setAttribute("totalsRowCount", "1");
|
|
57
|
+
else root.removeAttribute("totalsRowCount");
|
|
58
|
+
root.setAttribute("totalsRowShown", table.totals || totals.length ? "1" : "0");
|
|
59
|
+
const settings = new Map(totals.map(entry => [entry.column, entry.input]));
|
|
60
|
+
const fields = child(root, "tableColumns")!;
|
|
61
|
+
for (const [offset, column] of children(fields, "tableColumn").entries()) {
|
|
62
|
+
const before = child(column, "totalsRowFormula");
|
|
63
|
+
if (before) column.removeChild(before);
|
|
64
|
+
column.removeAttribute("totalsRowFunction");
|
|
65
|
+
column.removeAttribute("totalsRowLabel");
|
|
66
|
+
const input = settings.get(table.range.startColumn + offset);
|
|
67
|
+
if (!input) continue;
|
|
68
|
+
if (input.kind === "aggregate") column.setAttribute("totalsRowFunction", input.aggregation);
|
|
69
|
+
else if (input.kind === "label") {
|
|
70
|
+
column.setAttribute("totalsRowFunction", "none");
|
|
71
|
+
column.setAttribute("totalsRowLabel", encodeXlsxText(input.text));
|
|
72
|
+
} else {
|
|
73
|
+
column.setAttribute("totalsRowFunction", "custom");
|
|
74
|
+
const formula = root.ownerDocument!.createElementNS(spreadNs, "totalsRowFormula");
|
|
75
|
+
formula.appendChild(root.ownerDocument!.createTextNode(input.formula.slice(1)));
|
|
76
|
+
column.appendChild(formula);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { WorkbookSourceTable, WorkbookStructuredTableSorts, WorkbookTableTotal } from "@quirekit/workbook";
|
|
2
|
+
|
|
3
|
+
/** An understood native relation and its table layout. */
|
|
4
|
+
export interface XlsxSourceTable {
|
|
5
|
+
/** Exact relationship owner path. */
|
|
6
|
+
readonly owner: string;
|
|
7
|
+
/** Target table part. */
|
|
8
|
+
readonly path: string;
|
|
9
|
+
/** Workbook-wide numeric table ID. */
|
|
10
|
+
readonly id: number;
|
|
11
|
+
/** Programmatic name, when different from the name used in formulas. */
|
|
12
|
+
readonly internalName: string;
|
|
13
|
+
/** Source presentation and column binding. */
|
|
14
|
+
readonly layout: WorkbookSourceTable;
|
|
15
|
+
/** Decoded conditions for each native owner. */
|
|
16
|
+
readonly sorts?: WorkbookStructuredTableSorts;
|
|
17
|
+
/** Whether data-only edits can leave this entire table part unchanged. */
|
|
18
|
+
readonly dataWritable: boolean;
|
|
19
|
+
/** Ordinary column settings retained while the totals row is hidden. */
|
|
20
|
+
readonly hiddenTotals?: readonly WorkbookTableTotal[] | undefined;
|
|
21
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import { defaultWorkbookStructuredTableStyle, formatWorkbookRange, sameWorkbookHiddenTotals, sameWorkbookSortState,
|
|
3
|
+
sameWorkbookStructuredTable, sameWorkbookStructuredTableLayout,
|
|
4
|
+
type WorkbookAutoFilter, type WorkbookSnapshot, type WorkbookStructuredTable, type WorkbookTableTotal } from "@quirekit/workbook";
|
|
5
|
+
import { strToU8 } from "fflate";
|
|
6
|
+
import { editPartRelationships, relationshipsPath } from "../opc/relationships";
|
|
7
|
+
import { child, children, contentTypeNs, parsePart, readIndex, relationshipNs, rootOf, spreadNs, writePart } from "../opc/xml";
|
|
8
|
+
import type { XlsxPackage } from "../package/types";
|
|
9
|
+
import type { XlsxDifferentialStyle } from "../styles/types";
|
|
10
|
+
import { writeXlsxOwnerSort } from "../worksheet/sort/write";
|
|
11
|
+
import { encodeXlsxText } from "../worksheet/text";
|
|
12
|
+
import { writeXlsxTableFilter } from "./filter";
|
|
13
|
+
import { assertXlsxStructuredTableWrites, indexTableEdgeInputs, xlsxTableContentType } from "./ownership";
|
|
14
|
+
import { writeXlsxTableTotals, xlsxTableTotals } from "./totals";
|
|
15
|
+
|
|
16
|
+
/** @param tables - Canonical native definitions at one revision. @returns Active table filters grouped by worksheet. */
|
|
17
|
+
export function xlsxTableFiltersBySheet(tables: readonly WorkbookStructuredTable[] = []): ReadonlyMap<string, readonly WorkbookAutoFilter[]> {
|
|
18
|
+
const filters = new Map<string, WorkbookAutoFilter[]>();
|
|
19
|
+
for (const { range, filter } of tables) {
|
|
20
|
+
if (!filter?.columns.length) continue;
|
|
21
|
+
const sheet = filters.get(range.sheetId) ?? [];
|
|
22
|
+
sheet.push(filter);
|
|
23
|
+
filters.set(range.sheetId, sheet);
|
|
24
|
+
}
|
|
25
|
+
return filters;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @param before - Original file checkpoint. @param after - Published workbook.
|
|
29
|
+
* @param same - Compares either authored definitions or the table layout affecting cells.
|
|
30
|
+
* @returns Whether the definitions match, including when an older client sent only cell data. */
|
|
31
|
+
export function sameXlsxStructuredTables(before: WorkbookSnapshot | undefined, after: WorkbookSnapshot,
|
|
32
|
+
same = sameWorkbookStructuredTable): boolean {
|
|
33
|
+
const prior = before?.structuredTables ?? [], next = after.structuredTables ?? prior;
|
|
34
|
+
const directory = new Map(prior.map(table => [table.id, table]));
|
|
35
|
+
if (prior.length !== next.length) return false;
|
|
36
|
+
for (const table of next) {
|
|
37
|
+
if (!same(directory.get(table.id) ?? null, table)) return false;
|
|
38
|
+
directory.delete(table.id);
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @param parent - Native SpreadsheetML container. @param name - Child name. @param following - Optional schema successor.
|
|
44
|
+
* @returns Existing or inserted native element. */
|
|
45
|
+
function ensureTableChild(parent: Element, name: string, following?: Element): Element {
|
|
46
|
+
const present = child(parent, name);
|
|
47
|
+
if (present) return present;
|
|
48
|
+
const node = parent.ownerDocument!.createElementNS(spreadNs, name);
|
|
49
|
+
parent.insertBefore(node, following ?? null);
|
|
50
|
+
return node;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @param root - Native table part. @param fields - Table columns in physical order. @param next - Current table layout.
|
|
54
|
+
* @param prior - Preserved definition, if imported. */
|
|
55
|
+
function writeTableLayout(root: Element, fields: Element, next: WorkbookStructuredTable, prior?: WorkbookStructuredTable): void {
|
|
56
|
+
const document = root.ownerDocument!;
|
|
57
|
+
const { range, name } = next;
|
|
58
|
+
const previousColumn = prior?.range.startColumn ?? range.startColumn;
|
|
59
|
+
if (!prior || prior.name !== name) {
|
|
60
|
+
root.setAttribute("name", name);
|
|
61
|
+
root.setAttribute("displayName", name);
|
|
62
|
+
}
|
|
63
|
+
root.setAttribute("ref", formatWorkbookRange(range));
|
|
64
|
+
const original = children(fields, "tableColumn");
|
|
65
|
+
const reserved = new Set(original.map(field => readIndex(field, "id")!));
|
|
66
|
+
for (const field of original) fields.removeChild(field);
|
|
67
|
+
let columnId = 1;
|
|
68
|
+
for (const [offset, heading] of next.columns.entries()) {
|
|
69
|
+
const column = original[range.startColumn + offset - previousColumn] ?? document.createElementNS(spreadNs, "tableColumn");
|
|
70
|
+
if (!column.hasAttribute("id")) {
|
|
71
|
+
while (reserved.has(columnId)) columnId++;
|
|
72
|
+
column.setAttribute("id", String(columnId++));
|
|
73
|
+
}
|
|
74
|
+
column.setAttribute("name", encodeXlsxText(heading));
|
|
75
|
+
fields.appendChild(column);
|
|
76
|
+
}
|
|
77
|
+
fields.setAttribute("count", String(next.columns.length));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @param root - Native table part. @param next - Current table layout and sort criteria. @param addStyle - Registers criterion colors.
|
|
81
|
+
* @param prior - Preserved definition, if imported. @param totals - Column calculations to serialize when changed. */
|
|
82
|
+
function writeTableDefinition(root: Element, next: WorkbookStructuredTable, addStyle: (style: XlsxDifferentialStyle) => number,
|
|
83
|
+
prior?: WorkbookStructuredTable, totals?: readonly WorkbookTableTotal[]): void {
|
|
84
|
+
const document = root.ownerDocument!;
|
|
85
|
+
const fields = ensureTableChild(root, "tableColumns");
|
|
86
|
+
if (!sameWorkbookStructuredTableLayout(prior ?? null, next)) writeTableLayout(root, fields, next, prior);
|
|
87
|
+
if (totals) writeXlsxTableTotals(root, next, totals);
|
|
88
|
+
const rebuilt = writeXlsxTableFilter(root, next, child(root, "sortState") ?? fields, addStyle, prior);
|
|
89
|
+
const from = prior?.sorts, to = next.sorts;
|
|
90
|
+
// Rebuilding the filter drops its WPS marker, so serialize table-side header keys as standard body coordinates too.
|
|
91
|
+
if (rebuilt || !sameWorkbookSortState(from?.table, to?.table)) writeXlsxOwnerSort(document, root, from?.table, to?.table, fields, addStyle);
|
|
92
|
+
const filter = child(root, "autoFilter");
|
|
93
|
+
if (filter && (rebuilt || !sameWorkbookSortState(from?.filter, to?.filter))) {
|
|
94
|
+
writeXlsxOwnerSort(document, filter, from?.filter, to?.filter, child(filter, "extLst") ?? null, addStyle);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** @param path - Native table part path. @param serial - Workbook-wide OOXML ID. @param table - Committed definition.
|
|
99
|
+
* @param addStyle - Registers any native color criteria. @param totals - Serialized aggregate settings.
|
|
100
|
+
* @returns Standard native XML with the workbench's default table style. */
|
|
101
|
+
function createTablePart(path: string, serial: number, table: WorkbookStructuredTable, addStyle: (style: XlsxDifferentialStyle) => number,
|
|
102
|
+
totals: readonly WorkbookTableTotal[]): Uint8Array {
|
|
103
|
+
const document = parsePart(strToU8(`<table xmlns="${spreadNs}" id="${serial}" totalsRowShown="0"/>`), path);
|
|
104
|
+
const root = rootOf(document, spreadNs, "table");
|
|
105
|
+
if (!table.header) root.setAttribute("headerRowCount", "0");
|
|
106
|
+
writeTableDefinition(root, table, addStyle, undefined, totals);
|
|
107
|
+
const style = ensureTableChild(root, "tableStyleInfo");
|
|
108
|
+
style.setAttribute("name", defaultWorkbookStructuredTableStyle);
|
|
109
|
+
style.setAttribute("showRowStripes", "1");
|
|
110
|
+
return writePart(document);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @param source - Workbook's original OPC graph. @param parts - Shared staged package. @param snapshot - Final table definitions.
|
|
114
|
+
* @param paths - Final workbook worksheet part URIs. @param addStyle - Registers filter colors.
|
|
115
|
+
* @returns The serial assigned to each surviving table. */
|
|
116
|
+
export function writeWorkbookStructuredTables(source: XlsxPackage, parts: Record<string, Uint8Array>, snapshot: WorkbookSnapshot,
|
|
117
|
+
paths: ReadonlyMap<string, string>, addStyle: (style: XlsxDifferentialStyle) => number): ReadonlyMap<string, number> {
|
|
118
|
+
assertXlsxStructuredTableWrites(source.baseline, snapshot);
|
|
119
|
+
const definitions = snapshot.structuredTables ?? source.baseline?.structuredTables ?? [];
|
|
120
|
+
const currentIds = new Set(definitions.map(table => table.id));
|
|
121
|
+
const serials = new Map<string, number>();
|
|
122
|
+
for (const { layout, id } of source.sourceTables ?? []) if (layout.id && currentIds.has(layout.id)) serials.set(layout.id, id);
|
|
123
|
+
if (!definitions.length || !definitions.some(table => table.totals) && sameXlsxStructuredTables(source.baseline, snapshot)) return serials;
|
|
124
|
+
const prior = new Map(source.baseline?.structuredTables?.map(table => [table.id, table]));
|
|
125
|
+
const oldInputs = source.baseline && indexTableEdgeInputs(source.baseline, [...prior.values()].filter(table => table.totals));
|
|
126
|
+
const newInputs = indexTableEdgeInputs(snapshot, definitions.filter(table => table.totals));
|
|
127
|
+
const retained = new Map(source.sourceTables?.map(record => [record.layout.id, record]));
|
|
128
|
+
const reservedIds = new Set(source.sourceTables?.map(record => record.id));
|
|
129
|
+
const reservedPaths = new Set(Object.keys(parts).map(path => path.toLowerCase()));
|
|
130
|
+
const names = new Set<string>();
|
|
131
|
+
const folder = source.workbookPath.slice(0, source.workbookPath.lastIndexOf("/") + 1);
|
|
132
|
+
let serial = 1;
|
|
133
|
+
const newParts = new Map<string, WorkbookStructuredTable[]>();
|
|
134
|
+
|
|
135
|
+
// Existing owned graphs keep stable relationship IDs. Only changed native definitions are reserialized.
|
|
136
|
+
for (const table of definitions) {
|
|
137
|
+
const record = retained.get(table.id), before = prior.get(table.id);
|
|
138
|
+
const internal = record && before?.name === table.name ? record.internalName : table.name;
|
|
139
|
+
if (names.has(internal.toUpperCase())) throw new Error("原生表的程序名称重复。");
|
|
140
|
+
names.add(internal.toUpperCase());
|
|
141
|
+
if (record && before) {
|
|
142
|
+
const previous = xlsxTableTotals(before, oldInputs?.get(before.range.sheetId)?.get(before.range.endRow));
|
|
143
|
+
const next = xlsxTableTotals(table, newInputs.get(table.range.sheetId)?.get(table.range.endRow));
|
|
144
|
+
const totalsChanged = before.totals !== table.totals || !sameWorkbookHiddenTotals(previous, next);
|
|
145
|
+
if (totalsChanged || !sameWorkbookStructuredTable(before, table)) {
|
|
146
|
+
const document = parsePart(parts[record.path], record.path);
|
|
147
|
+
writeTableDefinition(rootOf(document, spreadNs, "table"), table, addStyle, before, totalsChanged ? next : undefined);
|
|
148
|
+
parts[record.path] = writePart(document);
|
|
149
|
+
}
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const sheetPath = paths.get(table.range.sheetId);
|
|
153
|
+
if (!sheetPath) throw new Error("原生表找不到所属的工作表部件。");
|
|
154
|
+
const tables = newParts.get(sheetPath) ?? [];
|
|
155
|
+
tables.push(table);
|
|
156
|
+
newParts.set(sheetPath, tables);
|
|
157
|
+
}
|
|
158
|
+
if (!newParts.size) return serials;
|
|
159
|
+
|
|
160
|
+
const typesPath = "[Content_Types].xml";
|
|
161
|
+
const manifest = parsePart(parts[typesPath], typesPath);
|
|
162
|
+
const types = rootOf(manifest, contentTypeNs, "Types");
|
|
163
|
+
for (const [sheetPath, tables] of newParts) {
|
|
164
|
+
const document = parsePart(parts[sheetPath], sheetPath);
|
|
165
|
+
const root = rootOf(document, spreadNs, "worksheet");
|
|
166
|
+
const available = ensureTableChild(root, "tableParts", child(root, "extLst"));
|
|
167
|
+
const relationships = editPartRelationships(parts, sheetPath);
|
|
168
|
+
for (const table of tables) {
|
|
169
|
+
let path: string;
|
|
170
|
+
do { path = `${folder}tables/table${serial++}.xml`; }
|
|
171
|
+
while (reservedIds.has(serial - 1) || reservedPaths.has(path.toLowerCase()) || reservedPaths.has(relationshipsPath(path).toLowerCase()));
|
|
172
|
+
serials.set(table.id, serial - 1);
|
|
173
|
+
parts[path] = createTablePart(path, serial - 1, table, addStyle, xlsxTableTotals(table,
|
|
174
|
+
newInputs.get(table.range.sheetId)?.get(table.range.endRow)));
|
|
175
|
+
const override = manifest.createElementNS(contentTypeNs, "Override");
|
|
176
|
+
override.setAttribute("PartName", "/" + path);
|
|
177
|
+
override.setAttribute("ContentType", xlsxTableContentType);
|
|
178
|
+
types.appendChild(override);
|
|
179
|
+
const entry = document.createElementNS(spreadNs, "tablePart");
|
|
180
|
+
entry.setAttributeNS(relationshipNs, "r:id", relationships.add(relationshipNs + "/table", "/" + path));
|
|
181
|
+
available.appendChild(entry);
|
|
182
|
+
}
|
|
183
|
+
available.setAttribute("count", String(children(available, "tablePart").length));
|
|
184
|
+
relationships.write();
|
|
185
|
+
parts[sheetPath] = writePart(document);
|
|
186
|
+
}
|
|
187
|
+
parts[typesPath] = writePart(manifest);
|
|
188
|
+
return serials;
|
|
189
|
+
}
|