@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,57 @@
|
|
|
1
|
+
import type { Element } from "@xmldom/xmldom";
|
|
2
|
+
import { defaultWorkbookWorksheetView, sameWorkbookWorksheetView, type WorkbookWorksheetView } from "@quirekit/workbook";
|
|
3
|
+
import { child, children, spreadNs } from "../../opc/xml";
|
|
4
|
+
import { isNormalXlsxView, primaryXlsxWorksheetView } from "./coordinates";
|
|
5
|
+
import { writeXlsxPane } from "./panes";
|
|
6
|
+
|
|
7
|
+
/** @param before - Original view. @param after - Committed view. @returns Whether native sheetView fields match. */
|
|
8
|
+
export function sameXlsxWorksheetView(before = defaultWorkbookWorksheetView, after = defaultWorkbookWorksheetView): boolean {
|
|
9
|
+
if (before.backgroundAssetId === after.backgroundAssetId && before.printLayout === after.printLayout && before.namedViews === after.namedViews) return sameWorkbookWorksheetView(before, after);
|
|
10
|
+
return sameWorkbookWorksheetView({ ...before, backgroundAssetId: after.backgroundAssetId, printLayout: after.printLayout, namedViews: after.namedViews }, after);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** @param worksheet - Native worksheet root. @returns Its primary saved view, creating valid native containers if needed. */
|
|
14
|
+
function ensureView(worksheet: Element): Element {
|
|
15
|
+
const source = primaryXlsxWorksheetView(worksheet);
|
|
16
|
+
if (source) return source;
|
|
17
|
+
const document = worksheet.ownerDocument!;
|
|
18
|
+
let views = child(worksheet, "sheetViews");
|
|
19
|
+
if (!views) {
|
|
20
|
+
views = document.createElementNS(spreadNs, "sheetViews");
|
|
21
|
+
const next = children(worksheet).find(node => !["sheetPr", "dimension"].includes(node.localName ?? ""));
|
|
22
|
+
worksheet.insertBefore(views, next ?? null);
|
|
23
|
+
}
|
|
24
|
+
const view = document.createElementNS(spreadNs, "sheetView");
|
|
25
|
+
view.setAttribute("workbookViewId", "0");
|
|
26
|
+
views.appendChild(view);
|
|
27
|
+
return view;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @param worksheet - Native root. @param before - Original supported settings. @param after - Committed supported settings. */
|
|
31
|
+
export function writeXlsxWorksheetView(
|
|
32
|
+
worksheet: Element, before = defaultWorkbookWorksheetView, after: WorkbookWorksheetView = defaultWorkbookWorksheetView
|
|
33
|
+
): void {
|
|
34
|
+
const view = ensureView(worksheet);
|
|
35
|
+
if (!view.hasAttribute("workbookViewId")) view.setAttribute("workbookViewId", "0");
|
|
36
|
+
if (before.showGridlines !== after.showGridlines) view.setAttribute("showGridLines", after.showGridlines ? "1" : "0");
|
|
37
|
+
if (before.showHeadings !== after.showHeadings) view.setAttribute("showRowColHeaders", after.showHeadings ? "1" : "0");
|
|
38
|
+
if (before.zoomPercent !== after.zoomPercent) {
|
|
39
|
+
view.setAttribute("zoomScaleNormal", String(after.zoomPercent));
|
|
40
|
+
if (isNormalXlsxView(view)) view.setAttribute("zoomScale", String(after.zoomPercent));
|
|
41
|
+
}
|
|
42
|
+
if (before.freeze.rows !== after.freeze.rows || before.freeze.columns !== after.freeze.columns
|
|
43
|
+
|| before.scrollAnchor?.row !== after.scrollAnchor?.row || before.scrollAnchor?.column !== after.scrollAnchor?.column) {
|
|
44
|
+
writeXlsxPane(view, before, after);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @param workbook - Native workbook root. @returns Whether a backing workbook view was added. */
|
|
49
|
+
export function ensurePrimaryWorkbookView(workbook: Element): boolean {
|
|
50
|
+
const existing = child(workbook, "bookViews");
|
|
51
|
+
if (existing && child(existing, "workbookView")) return false;
|
|
52
|
+
const document = workbook.ownerDocument!;
|
|
53
|
+
const views = existing ?? document.createElementNS(spreadNs, "bookViews");
|
|
54
|
+
views.appendChild(document.createElementNS(spreadNs, "workbookView"));
|
|
55
|
+
if (!existing) workbook.insertBefore(views, child(workbook, "sheets") ?? null);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Document } from "@xmldom/xmldom";
|
|
2
|
+
import { formatWorkbookColumn, hasWorkbookExternalReference, sameWorkbookCell, type WorkbookAddress, type WorkbookCell, type WorkbookFormulaSpill,
|
|
3
|
+
type WorkbookImageCell, type WorkbookSheet } from "@quirekit/workbook";
|
|
4
|
+
import { child, rootOf, spreadNs } from "../opc/xml";
|
|
5
|
+
import type { XlsxWriteOptions } from "../types";
|
|
6
|
+
import { writeCell } from "./cells";
|
|
7
|
+
import { appendOrdered, indexCells, indexRows } from "./positions";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param previous - Checkpoint loaded from this part.
|
|
11
|
+
* @param current - Authored inputs at the written revision.
|
|
12
|
+
* @param supportsExternal - Validates references to the archive's retained source directory.
|
|
13
|
+
* @returns Sparse row patches, including formulas with caches to refresh.
|
|
14
|
+
*/
|
|
15
|
+
export function sheetChanges(previous: WorkbookSheet | undefined, current: WorkbookSheet,
|
|
16
|
+
supportsExternal?: (formula: string) => boolean): Map<number, Map<number, WorkbookCell | null>> {
|
|
17
|
+
const rows = new Map<number, Map<number, WorkbookCell | null>>();
|
|
18
|
+
for (const { row, column } of previous?.cells ?? []) {
|
|
19
|
+
const target = rows.get(row) ?? new Map<number, WorkbookCell | null>();
|
|
20
|
+
target.set(column, null);
|
|
21
|
+
rows.set(row, target);
|
|
22
|
+
}
|
|
23
|
+
const original = new Map(previous?.cells.map(cell => [`${cell.row}:${cell.column}`, cell.input]));
|
|
24
|
+
for (const { row, column, input } of current.cells) {
|
|
25
|
+
if (input.kind === "formula" && hasWorkbookExternalReference(input.formula)
|
|
26
|
+
&& !supportsExternal?.(input.formula)) {
|
|
27
|
+
throw new Error(`${current.name}!${formatWorkbookColumn(column)}${row + 1} 公式中的外部引用缺少原生来源工作簿或工作表。`);
|
|
28
|
+
}
|
|
29
|
+
const former = original.get(`${row}:${column}`);
|
|
30
|
+
if ((input.kind === "value" || input.kind === "error") && sameWorkbookCell(input, former ?? null)) {
|
|
31
|
+
rows.get(row)?.delete(column);
|
|
32
|
+
} else {
|
|
33
|
+
const target = rows.get(row) ?? new Map<number, WorkbookCell | null>();
|
|
34
|
+
target.set(column, input);
|
|
35
|
+
rows.set(row, target);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return new Map([...rows].filter(([, entries]) => entries.size > 0));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Updates only cell payloads in the touched part. Reuses row and cell elements with their source attributes.
|
|
43
|
+
* @param document - Worksheet XML.
|
|
44
|
+
* @param sheetId - Stable workbook identity for calculation reads.
|
|
45
|
+
* @param changes - Sparse rows to write.
|
|
46
|
+
* @param options - Cache access.
|
|
47
|
+
* @param formats - Derived style indices by cell, including blank cells.
|
|
48
|
+
* @param imageIndex - Native value metadata lookup for embedded image cells.
|
|
49
|
+
* @param arrayAt - Authoritative dynamic array ownership of the published cell.
|
|
50
|
+
*/
|
|
51
|
+
export function writeWorksheet(
|
|
52
|
+
document: Document, sheetId: string, changes: ReadonlyMap<number, ReadonlyMap<number, WorkbookCell | null>>, options: XlsxWriteOptions,
|
|
53
|
+
formats: ReadonlyMap<number, ReadonlyMap<number, number>>, imageIndex?: (input: WorkbookImageCell) => number,
|
|
54
|
+
arrayAt?: (address: WorkbookAddress) => WorkbookFormulaSpill | undefined
|
|
55
|
+
): void {
|
|
56
|
+
const root = rootOf(document, spreadNs, "worksheet");
|
|
57
|
+
const data = child(root, "sheetData");
|
|
58
|
+
if (!data) throw new Error("XLSX 工作表缺少单元格数据。");
|
|
59
|
+
const rowNodes = indexRows(data);
|
|
60
|
+
for (const row of new Set([...changes.keys(), ...formats.keys()])) {
|
|
61
|
+
const cells = changes.get(row);
|
|
62
|
+
const styles = formats.get(row);
|
|
63
|
+
const node = rowNodes.get(row) ?? document.createElementNS(spreadNs, "row");
|
|
64
|
+
node.setAttribute("r", String(row + 1));
|
|
65
|
+
rowNodes.set(row, node);
|
|
66
|
+
const cellNodes = indexCells(node);
|
|
67
|
+
for (const column of new Set([...(cells?.keys() ?? []), ...(styles?.keys() ?? [])])) {
|
|
68
|
+
const prior = cellNodes.get(column);
|
|
69
|
+
const input = cells?.get(column);
|
|
70
|
+
const style = styles?.get(column);
|
|
71
|
+
const address = { sheetId, row, column };
|
|
72
|
+
const array = arrayAt?.(address)?.range;
|
|
73
|
+
if (input === null && style === undefined && !prior && !array) continue;
|
|
74
|
+
const element = prior ?? document.createElementNS(spreadNs, "c");
|
|
75
|
+
element.setAttribute("r", formatWorkbookColumn(column) + (row + 1));
|
|
76
|
+
if (input !== undefined) writeCell(document, element, input,
|
|
77
|
+
input?.kind === "formula" || array ? options.result?.(address) : undefined, input?.kind === "image" ? imageIndex?.(input) : undefined, array);
|
|
78
|
+
if (style !== undefined) element.setAttribute("s", String(style));
|
|
79
|
+
cellNodes.set(column, element);
|
|
80
|
+
}
|
|
81
|
+
appendOrdered(node, cellNodes);
|
|
82
|
+
}
|
|
83
|
+
appendOrdered(data, rowNodes);
|
|
84
|
+
const dimension = child(root, "dimension");
|
|
85
|
+
if (dimension) root.removeChild(dimension); // Optional when the previous stored bounds are stale.
|
|
86
|
+
}
|
package/README.md
DELETED