@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,266 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
|
3
|
+
import { openWorkbook, parseWorkbookRange, workbookDateSerial, type WorkbookCommandCall, type WorkbookSession } from "@quirekit/workbook";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import { createXlsx, openXlsx } from "../../index";
|
|
6
|
+
|
|
7
|
+
const producerFixture = new URL("../../../test/fixtures/native-pivot-date-groups.xlsx", import.meta.url);
|
|
8
|
+
const dailyFixture = new URL("../../../test/fixtures/native-pivot-day-groups.xlsx", import.meta.url);
|
|
9
|
+
const refreshedFixture = new URL("../../../test/fixtures/native-pivot-fixed-date-window.xlsx", import.meta.url);
|
|
10
|
+
|
|
11
|
+
/** @param workbook - Current session. @param commands - Edits sharing one revision. @returns Published receipt. */
|
|
12
|
+
function edit(workbook: WorkbookSession, ...commands: WorkbookCommandCall[]) {
|
|
13
|
+
const baseRevision = workbook.revision;
|
|
14
|
+
return workbook.commit(workbook.prepare({ baseRevision, operationId: "calendar-pivot-" + baseRevision, commands }).id);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
it("reopens a WPS calendar hierarchy and retains native labels after changing the source", async () => {
|
|
18
|
+
const file = openXlsx("Calendar.xlsx", readFileSync(producerFixture));
|
|
19
|
+
expect(file.restrictions).toEqual([]);
|
|
20
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
21
|
+
try {
|
|
22
|
+
const table = workbook.pivotTables()[0]!;
|
|
23
|
+
expect(table).toMatchObject({ rowFields: [0], cache: { dateFields: [0], dateSystem: "1900" }, dateGroups: [
|
|
24
|
+
{ field: 0, units: ["years", "quarters", "months"], labels: { start: "2025-11-03", end: "2026-11-27" } }
|
|
25
|
+
] });
|
|
26
|
+
await edit(workbook, { name: "setCells", target: parseWorkbookRange(table.source.sheetId, "C2"),
|
|
27
|
+
params: { cells: [[{ kind: "value", value: 90 }]] } },
|
|
28
|
+
{ name: "refreshPivotTable", target: table.output, params: { id: table.id } });
|
|
29
|
+
const reopened = openXlsx("Refreshed.xlsx", file.write(workbook.snapshot()));
|
|
30
|
+
expect(reopened.restrictions).toEqual([]);
|
|
31
|
+
expect(reopened.snapshot.pivotTables?.[0]?.dateGroups).toEqual(table.dateGroups);
|
|
32
|
+
expect(reopened.snapshot.sheets[1]!.cells).toEqual(expect.arrayContaining([
|
|
33
|
+
{ row: 1, column: 1, input: { kind: "value", value: "第四季" } },
|
|
34
|
+
{ row: 1, column: 3, input: { kind: "value", value: 130 } },
|
|
35
|
+
{ row: 6, column: 3, input: { kind: "value", value: 410 } }
|
|
36
|
+
]));
|
|
37
|
+
} finally { await workbook.close(); }
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it.each(["1900", "1904"] as const)("writes native date groups, fixed bounds and %s date-time records independently of value fields", async dateSystem => {
|
|
41
|
+
const dates = [workbookDateSerial(2026, 1, 31, dateSystem) + 0.625, workbookDateSerial(2025, 11, 3, dateSystem)];
|
|
42
|
+
const rows = [["Booked", "Region", "Amount"], [dates[0]!, "East", 10], [dates[1]!, "East", 20]];
|
|
43
|
+
const workbook = await openWorkbook({ id: "calendar", version: 1, revision: 0, name: "Calendar", dateSystem, sheets: [
|
|
44
|
+
{ id: "sales", name: "Sales", cells: rows.flatMap((row, index) => row.map((value, column) => ({
|
|
45
|
+
row: index, column, input: { kind: "value", value }
|
|
46
|
+
}))), formats: dates.map((_, index) => ({ row: index + 1, column: 0, format: { numberFormat: "yyyy-mm-dd hh:mm:ss" } })) },
|
|
47
|
+
{ id: "report", name: "Report", cells: [] }
|
|
48
|
+
] });
|
|
49
|
+
try {
|
|
50
|
+
const target = parseWorkbookRange("report", "A1");
|
|
51
|
+
const group = { field: 0, units: ["years", "months"], start: "2026-01-01", end: "2026-01-31" };
|
|
52
|
+
const params = { source: { sheetId: "sales", range: "A1:C3" }, rowFields: [1], columnFields: [0], filters: [],
|
|
53
|
+
values: [{ field: 2, aggregate: "sum" }] };
|
|
54
|
+
await edit(workbook, { name: "setPivotTable", target, params: { ...params, name: "January", dateGroups: [group] } },
|
|
55
|
+
{ name: "setPivotTable", target: parseWorkbookRange("report", "A12"), params: { ...params, name: "Days" } });
|
|
56
|
+
const bytes = createXlsx(workbook.snapshot());
|
|
57
|
+
const parts = unzipSync(bytes);
|
|
58
|
+
const cachePaths = Object.keys(parts).filter(path => /^xl\/pivotCache\/pivotCacheDefinition\d+\.xml$/u.test(path));
|
|
59
|
+
expect(cachePaths).toHaveLength(2);
|
|
60
|
+
const cache = cachePaths.map(path => strFromU8(parts[path]!)).find(xml => xml.includes("fieldGroup"))!;
|
|
61
|
+
expect(cache).toContain('<d v="2026-01-31T15:00:00"/>');
|
|
62
|
+
expect(cache).toMatch(/<rangePr[^>]+autoStart="0"[^>]+autoEnd="0"/u);
|
|
63
|
+
expect(cache).toContain('databaseField="0"');
|
|
64
|
+
const reopened = openXlsx("January.xlsx", bytes);
|
|
65
|
+
expect(reopened.restrictions).toEqual([]);
|
|
66
|
+
expect(reopened.snapshot.pivotTables?.[0]).toMatchObject({
|
|
67
|
+
dateGroups: [group], cache: { dateSystem, dateFields: [0], records: rows.slice(1) }
|
|
68
|
+
});
|
|
69
|
+
expect(reopened.snapshot.sheets[1]!.cells).toContainEqual({ row: 3, column: 2, input: { kind: "value", value: 10 } });
|
|
70
|
+
} finally { await workbook.close(); }
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("reopens WPS daily buckets with exact bounds and retains them across refresh", async () => {
|
|
74
|
+
const file = openXlsx("Day groups.xlsx", readFileSync(dailyFixture));
|
|
75
|
+
expect(file.restrictions).toEqual([]);
|
|
76
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
77
|
+
try {
|
|
78
|
+
const table = workbook.pivotTables()[0]!;
|
|
79
|
+
expect(table.dateGroups).toMatchObject([{ field: 0, units: ["days"], end: "2025-03-01T09:15:00" }]);
|
|
80
|
+
expect(workbook.readCell({ sheetId: table.output.sheetId, row: 1, column: 1 }).input).toEqual({ kind: "value", value: 350 });
|
|
81
|
+
await edit(workbook, { name: "setCells", target: parseWorkbookRange(table.source.sheetId, "B2"), params: { value: 15 } },
|
|
82
|
+
{ name: "refreshPivotTable", target: table.output, params: { id: table.id } });
|
|
83
|
+
const reopened = openXlsx("Refreshed daily.xlsx", file.write(workbook.snapshot()));
|
|
84
|
+
expect(reopened.restrictions).toEqual([]);
|
|
85
|
+
expect(reopened.snapshot.pivotTables?.[0]?.dateGroups).toEqual(table.dateGroups);
|
|
86
|
+
expect(reopened.snapshot.sheets.find(sheet => sheet.name === "Report")?.cells).toEqual(expect.arrayContaining([
|
|
87
|
+
{ row: 1, column: 0, input: { kind: "value", value: "2月28日" } },
|
|
88
|
+
{ row: 1, column: 1, input: { kind: "value", value: 355 } },
|
|
89
|
+
{ row: 5, column: 1, input: { kind: "value", value: 635 } }
|
|
90
|
+
]));
|
|
91
|
+
} finally { await workbook.close(); }
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it.each([
|
|
95
|
+
{ path: "native-pivot-day-interval.xlsx", units: ["days"], daysPerGroup: 2, column: 1, first: 70, next: 240 },
|
|
96
|
+
{ path: "native-pivot-clock-groups.xlsx", units: ["days", "hours", "minutes", "seconds"], column: 4, first: 10, next: 340 }
|
|
97
|
+
])("reopens $path with original names, cache membership and totals", async ({ path, units, daysPerGroup, column, first, next }) => {
|
|
98
|
+
const file = openXlsx(path, readFileSync(new URL(`../../../test/fixtures/${path}`, import.meta.url)));
|
|
99
|
+
expect(file.restrictions).toEqual([]);
|
|
100
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
101
|
+
try {
|
|
102
|
+
const table = workbook.pivotTables()[0]!;
|
|
103
|
+
expect(table.dateGroups).toMatchObject([{ units, ...(daysPerGroup && { daysPerGroup }) }]);
|
|
104
|
+
const owner = table.output.sheetId;
|
|
105
|
+
expect(workbook.readCell({ sheetId: owner, row: 1, column }).input).toEqual({ kind: "value", value: first });
|
|
106
|
+
expect(workbook.readCell({ sheetId: owner, row: 2, column }).input).toEqual({ kind: "value", value: next });
|
|
107
|
+
await edit(workbook, { name: "setCells", target: parseWorkbookRange(table.source.sheetId, "B2"), params: { value: 15 } },
|
|
108
|
+
{ name: "refreshPivotTable", target: table.output, params: { id: table.id } });
|
|
109
|
+
const saved = file.write(workbook.snapshot());
|
|
110
|
+
const reopened = openXlsx(path, saved);
|
|
111
|
+
expect(reopened.restrictions).toEqual([]);
|
|
112
|
+
expect(reopened.snapshot.pivotTables?.[0]?.dateGroups).toEqual(table.dateGroups);
|
|
113
|
+
const report = reopened.snapshot.sheets.find(sheet => sheet.name === "Report")!;
|
|
114
|
+
expect(report.cells).toEqual(expect.arrayContaining([
|
|
115
|
+
{ row: 1, column, input: { kind: "value", value: first + 5 } },
|
|
116
|
+
{ row: table.output.endRow, column, input: { kind: "value", value: 635 } }
|
|
117
|
+
]));
|
|
118
|
+
if (units.includes("seconds")) {
|
|
119
|
+
expect(report.cells).toEqual(expect.arrayContaining([
|
|
120
|
+
{ row: 3, column: 3, input: { kind: "value", value: "59秒" } },
|
|
121
|
+
{ row: 4, column: 3, input: { kind: "value", value: "59秒" } }
|
|
122
|
+
]));
|
|
123
|
+
const parts = unzipSync(saved);
|
|
124
|
+
const cachePath = Object.keys(parts).find(part => /^xl\/pivotCache\/pivotCacheDefinition\d+\.xml$/u.test(part))!;
|
|
125
|
+
expect(strFromU8(parts[cachePath]!).includes('<d v="2024-03-01T23:59:59"/>')).toBe(true);
|
|
126
|
+
}
|
|
127
|
+
} finally { await workbook.close(); }
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("round-trips the whole final day and an exact midnight as distinct bounds", async () => {
|
|
131
|
+
const midnight = workbookDateSerial(2024, 3, 1, "1900");
|
|
132
|
+
const source = { sheetId: "sales", range: "A1:B3" };
|
|
133
|
+
const workbook = await openWorkbook({ id: "bounds", version: 1, revision: 0, name: "Date bounds", sheets: [
|
|
134
|
+
{ id: "sales", name: "Sales", cells: [["Booked", "Amount"], [midnight, 10], [midnight + 0.5, 20]]
|
|
135
|
+
.flatMap((values, row) => values.map((value, column) => ({ row, column, input: { kind: "value", value } }))),
|
|
136
|
+
formats: [1, 2].map(row => ({ row, column: 0, format: { numberFormat: "yyyy-mm-dd hh:mm:ss" } })) },
|
|
137
|
+
{ id: "report", name: "Report", cells: [] }
|
|
138
|
+
] });
|
|
139
|
+
try {
|
|
140
|
+
const layout = { source, rowFields: [0], columnFields: [], filters: [], values: [{ field: 1, aggregate: "sum" }] };
|
|
141
|
+
await edit(workbook, { name: "setPivotTable", target: parseWorkbookRange("report", "A1"), params: { ...layout, name: "AllDay",
|
|
142
|
+
dateGroups: [{ field: 0, units: ["months"], end: "2024-03-01" }] } },
|
|
143
|
+
{ name: "setPivotTable", target: parseWorkbookRange("report", "A10"), params: { ...layout, name: "Midnight",
|
|
144
|
+
dateGroups: [{ field: 0, units: ["months"], end: "2024-03-01T00:00:00" }] } });
|
|
145
|
+
const reopened = openXlsx("Bounds.xlsx", createXlsx(workbook.snapshot()));
|
|
146
|
+
expect(reopened.restrictions).toEqual([]);
|
|
147
|
+
expect(reopened.snapshot.pivotTables?.map(table => table.dateGroups?.[0]?.end)).toEqual(["2024-03-01", "2024-03-01T00:00:00"]);
|
|
148
|
+
expect(reopened.snapshot.sheets[1]!.cells).toEqual(expect.arrayContaining([
|
|
149
|
+
{ row: 1, column: 1, input: { kind: "value", value: 30 } },
|
|
150
|
+
{ row: 10, column: 1, input: { kind: "value", value: 10 } },
|
|
151
|
+
{ row: 11, column: 1, input: { kind: "value", value: 20 } }
|
|
152
|
+
]));
|
|
153
|
+
} finally { await workbook.close(); }
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("retains the exact original when native date groups use members incompatible with the declared grain", () => {
|
|
157
|
+
const parts = unzipSync(readFileSync(producerFixture));
|
|
158
|
+
const path = "xl/pivotCache/pivotCacheDefinition1.xml";
|
|
159
|
+
parts[path] = strToU8(strFromU8(parts[path]!).replace('groupBy="months"', 'groupBy="days"'));
|
|
160
|
+
const bytes = zipSync(parts);
|
|
161
|
+
const file = openXlsx("Days.xlsx", bytes);
|
|
162
|
+
expect(file.restrictions).toContain("未支持的数据透视表、缓存或工作表关系");
|
|
163
|
+
expect(file.snapshot.pivotTables).toBeUndefined();
|
|
164
|
+
expect(file.write(file.snapshot)).toEqual(bytes);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("translates the Values slot between source fields and expanded calendar levels", async () => {
|
|
168
|
+
const file = openXlsx("Grouped dates", readFileSync(producerFixture));
|
|
169
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
170
|
+
try {
|
|
171
|
+
const table = workbook.pivotTables()[0]!;
|
|
172
|
+
const { sheetId, startRow, startColumn } = table.output;
|
|
173
|
+
const preference = { axis: "row", position: 1 };
|
|
174
|
+
await edit(workbook, { name: "setPivotTable",
|
|
175
|
+
target: { sheetId, startRow, startColumn, endRow: startRow, endColumn: startColumn },
|
|
176
|
+
params: { id: table.id, name: table.name, source: { sheetId: table.source.sheetId, range: "A1:C8" },
|
|
177
|
+
rowFields: [0], columnFields: [], values: [{ field: 2, aggregate: "sum" }, { field: 2, aggregate: "max" }], filters: [], valuesAxis: preference } });
|
|
178
|
+
const saved = file.write(workbook.snapshot());
|
|
179
|
+
const parts = unzipSync(saved);
|
|
180
|
+
const path = Object.keys(parts).find(part => /^xl\/pivotTables\/pivotTable\d+\.xml$/u.test(part))!;
|
|
181
|
+
expect(strFromU8(parts[path]!)).toContain('dataPosition="3"');
|
|
182
|
+
const reopened = openXlsx("Grouped values", saved);
|
|
183
|
+
expect(reopened.restrictions).toEqual([]);
|
|
184
|
+
expect(reopened.snapshot.pivotTables?.[0]).toMatchObject({ valuesAxis: preference, dateGroups: [{ units: ["years", "quarters", "months"] }] });
|
|
185
|
+
} finally { await workbook.close(); }
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("reopens WPS-refreshed fixed bounds with period rows before both overflow buckets", async () => {
|
|
189
|
+
const file = openXlsx("January.xlsx", readFileSync(refreshedFixture));
|
|
190
|
+
expect(file.restrictions).toEqual([]);
|
|
191
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
192
|
+
try {
|
|
193
|
+
const table = workbook.pivotTables()[0]!;
|
|
194
|
+
expect(table.dateGroups).toMatchObject([{ field: 0, units: ["months"], start: "2026-01-01", end: "2026-01-31" }]);
|
|
195
|
+
await edit(workbook, { name: "setCells", target: parseWorkbookRange(table.source.sheetId, "B4"),
|
|
196
|
+
params: { cells: [[{ kind: "value", value: 40 }]] } },
|
|
197
|
+
{ name: "refreshPivotTable", target: table.output, params: { id: table.id } });
|
|
198
|
+
const reopened = openXlsx("January-refreshed.xlsx", file.write(workbook.snapshot()));
|
|
199
|
+
expect(reopened.restrictions).toEqual([]);
|
|
200
|
+
expect(reopened.snapshot.pivotTables?.[0]?.dateGroups).toEqual(table.dateGroups);
|
|
201
|
+
expect(reopened.snapshot.sheets[0]!.cells).toEqual(expect.arrayContaining([
|
|
202
|
+
{ row: 1, column: 3, input: { kind: "value", value: "1月" } },
|
|
203
|
+
{ row: 1, column: 4, input: { kind: "value", value: 45 } },
|
|
204
|
+
{ row: 2, column: 3, input: { kind: "value", value: "<2026/1/1" } },
|
|
205
|
+
{ row: 2, column: 4, input: { kind: "value", value: 20 } },
|
|
206
|
+
{ row: 4, column: 4, input: { kind: "value", value: 95 } }
|
|
207
|
+
]));
|
|
208
|
+
} finally { await workbook.close(); }
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it.each(["1900", "1904"] as const)("reopens native WPS clock groups and refreshes %s without shifting midnight", async dateSystem => {
|
|
212
|
+
const fixture = new URL("../../../test/fixtures/native-pivot-time-" + dateSystem + ".xlsx", import.meta.url);
|
|
213
|
+
const file = openXlsx("Native time.xlsx", readFileSync(fixture));
|
|
214
|
+
expect(file.restrictions).toEqual([]);
|
|
215
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
216
|
+
try {
|
|
217
|
+
const table = workbook.pivotTables()[0]!;
|
|
218
|
+
const group = { field: 0, units: ["hours", "minutes"], start: "00:00:00" };
|
|
219
|
+
expect(table).toMatchObject({ rowFields: [0], cache: { timeFields: [0] }, dateGroups: [group] });
|
|
220
|
+
expect(table.cache.dateFields).toBeUndefined();
|
|
221
|
+
expect(table.cache.records.map(row => row[0])).toEqual([0, 1, 899, 900, 33300, 35999, 43200, 86399].map(seconds => seconds / 86400));
|
|
222
|
+
const at = (row: number, column: number) => workbook.readCell({ sheetId: table.output.sheetId, row, column }).input;
|
|
223
|
+
expect(at(1, 2)).toEqual({ kind: "value", value: 3 });
|
|
224
|
+
expect(at(8, 2)).toEqual({ kind: "value", value: 255 });
|
|
225
|
+
await edit(workbook, { name: "setCells", target: parseWorkbookRange(table.source.sheetId, "B2"), params: { value: 11 } },
|
|
226
|
+
{ name: "refreshPivotTable", target: table.output, params: { id: table.id } });
|
|
227
|
+
expect(at(1, 2)).toEqual({ kind: "value", value: 13 });
|
|
228
|
+
expect(at(8, 2)).toEqual({ kind: "value", value: 265 });
|
|
229
|
+
const bytes = file.write(workbook.snapshot());
|
|
230
|
+
const saved = openXlsx("Refreshed time.xlsx", bytes);
|
|
231
|
+
expect(saved.restrictions).toEqual([]);
|
|
232
|
+
expect(saved.snapshot.pivotTables?.[0]).toMatchObject({ cache: { timeFields: [0] }, dateGroups: [group] });
|
|
233
|
+
const parts = unzipSync(bytes);
|
|
234
|
+
const path = Object.keys(parts).find(part => /^xl\/pivotCache\/pivotCacheDefinition\d+\.xml$/u.test(part))!;
|
|
235
|
+
const cache = strFromU8(parts[path]!);
|
|
236
|
+
const epoch = dateSystem === "1900" ? "1899-12-30" : "1904-01-01";
|
|
237
|
+
expect(cache).toContain('<d v="' + epoch + 'T00:00:00"/>');
|
|
238
|
+
expect(cache).toContain('endDate="' + epoch + 'T23:59:59"');
|
|
239
|
+
expect(cache).toContain('groupBy="hours"');
|
|
240
|
+
} finally { await workbook.close(); }
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("distinguishes 1904 origin-day dates, clock times and elapsed hours at the same serials", async () => {
|
|
244
|
+
const rows = [["Booked", "Time", "Elapsed", "Weight"], [0, 0, 0, 1], [0.5, 0.5, 0.5, 2]];
|
|
245
|
+
const workbook = await openWorkbook({ id: "origin-day", version: 1, revision: 0, name: "Origin day", dateSystem: "1904", sheets: [
|
|
246
|
+
{ id: "source", name: "Source", cells: rows.flatMap((row, index) => row.map((value, column) => ({
|
|
247
|
+
row: index, column, input: { kind: "value", value }
|
|
248
|
+
}))), formats: [1, 2].flatMap(row => ["yyyy-mm-dd hh:mm:ss", "hh:mm:ss", "[h]:mm:ss"].map((numberFormat, column) => ({
|
|
249
|
+
row, column, format: { numberFormat }
|
|
250
|
+
}))) },
|
|
251
|
+
{ id: "report", name: "Report", cells: [] }
|
|
252
|
+
] });
|
|
253
|
+
try {
|
|
254
|
+
const dateGroups = [{ field: 0, units: ["days", "hours"] }, { field: 1, units: ["hours"], end: "00:00:00" }];
|
|
255
|
+
await edit(workbook, { name: "setPivotTable", target: parseWorkbookRange("report", "A1"), params: { name: "Origin",
|
|
256
|
+
source: { sheetId: "source", range: "A1:D3" }, rowFields: [0, 2], columnFields: [1], filters: [], dateGroups,
|
|
257
|
+
numberGroups: [{ field: 2, interval: 0.25 }], values: [{ field: 3, aggregate: "sum" }] } });
|
|
258
|
+
await edit(workbook, { name: "setCellFormat", target: parseWorkbookRange("source", "B2:B3"), params: { numberFormat: "General" } });
|
|
259
|
+
const reopened = openXlsx("Origin day", createXlsx(workbook.snapshot()));
|
|
260
|
+
expect(reopened.restrictions).toEqual([]);
|
|
261
|
+
expect(reopened.snapshot.pivotTables?.[0]).toMatchObject({
|
|
262
|
+
cache: { dateFields: [0], timeFields: [1], dateSystem: "1904", records: rows.slice(1) },
|
|
263
|
+
dateGroups, numberGroups: [{ field: 2, interval: 0.25 }]
|
|
264
|
+
});
|
|
265
|
+
} finally { await workbook.close(); }
|
|
266
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
|
3
|
+
import { openWorkbook, parseWorkbookRange, type WorkbookCommandCall, type WorkbookPivotDisplay, type WorkbookSnapshot } from "@quirekit/workbook";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { createXlsx, openXlsx } from "../../index";
|
|
6
|
+
|
|
7
|
+
const source = [
|
|
8
|
+
["Region", "City", "Quarter", "Sales"],
|
|
9
|
+
["East", "Alpha", "Q1", 40], ["East", "Beta", "Q1", 10], ["East", "Alpha", "Q2", 30],
|
|
10
|
+
["West", "Gamma", "Q1", 20], ["West", "Gamma", "Q2", -30]
|
|
11
|
+
];
|
|
12
|
+
const snapshot: WorkbookSnapshot = { version: 1, id: "value-display", name: "Value display", revision: 0, sheets: [
|
|
13
|
+
{ id: "data", name: "Data", cells: source.flatMap((record, row) =>
|
|
14
|
+
record.map((value, column) => ({ row, column, input: { kind: "value", value } }))) },
|
|
15
|
+
{ id: "report", name: "Summary", cells: [] }
|
|
16
|
+
] };
|
|
17
|
+
const modes: readonly (WorkbookPivotDisplay | undefined)[] = [
|
|
18
|
+
undefined, { mode: "percentOfCol" }, { mode: "percentOfRow" }, { mode: "percentOfTotal" }, { mode: "percentOfParentRow" },
|
|
19
|
+
{ mode: "percentOfParentCol" }, { mode: "percentOfParent", baseField: 0 }, { mode: "index" }
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/** @returns XLSX with every calculation applied to an independent measure of the same field. */
|
|
23
|
+
async function writeValues(): Promise<Uint8Array> {
|
|
24
|
+
const workbook = await openWorkbook(snapshot);
|
|
25
|
+
try {
|
|
26
|
+
await workbook.commit(workbook.prepare({ operationId: "values-as", baseRevision: workbook.revision, commands: [
|
|
27
|
+
{ name: "setPivotTable", target: parseWorkbookRange("report", "A1"),
|
|
28
|
+
params: { name: "Values", source: { sheetId: "data", range: "A1:D6" }, rowFields: [0, 1], columnFields: [2], filters: [],
|
|
29
|
+
values: modes.map(display => ({ field: 3, aggregate: "sum", ...(display && { display }) })),
|
|
30
|
+
valuesAxis: { axis: "row", position: 2 } } }
|
|
31
|
+
] }).id);
|
|
32
|
+
return createXlsx(workbook.snapshot());
|
|
33
|
+
} finally { await workbook.close(); }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe("native PivotTable value display", () => {
|
|
37
|
+
it("writes legacy attributes, parent extensions and real worksheet percentage styles and errors", async () => {
|
|
38
|
+
const bytes = await writeValues();
|
|
39
|
+
const parts = unzipSync(bytes);
|
|
40
|
+
const definition = Object.keys(parts).find(path => /^xl\/pivotTables\/pivotTable\d+\.xml$/u.test(path))!;
|
|
41
|
+
const layout = strFromU8(parts[definition]!);
|
|
42
|
+
const report = strFromU8(parts["xl/worksheets/sheet2.xml"]!);
|
|
43
|
+
for (const mode of ["percentOfCol", "percentOfRow", "percentOfTotal", "index"]) {
|
|
44
|
+
expect(layout).toMatch(new RegExp('<dataField[^>]*baseField="0" baseItem="0"[^>]*showDataAs="' + mode + '"', "u"));
|
|
45
|
+
}
|
|
46
|
+
for (const mode of ["percentOfParent", "percentOfParentRow", "percentOfParentCol"]) {
|
|
47
|
+
expect(layout).toContain('pivotShowAs="' + mode + '"');
|
|
48
|
+
}
|
|
49
|
+
expect(layout).toContain('baseField="0" baseItem="0"');
|
|
50
|
+
expect(layout).toContain('numFmtId="10"');
|
|
51
|
+
expect(report).toMatch(/<c r="E4"[^>]+t="e"[^>]*><v>#DIV\/0!<\/v><\/c>/u);
|
|
52
|
+
const reopened = openXlsx("Value display", bytes);
|
|
53
|
+
expect(reopened.restrictions).toEqual([]);
|
|
54
|
+
expect(reopened.snapshot.pivotTables?.[0]?.values.map(value => value.display)).toEqual(modes);
|
|
55
|
+
const workbook = await openWorkbook(reopened.snapshot, { appearance: reopened.appearance });
|
|
56
|
+
const summaryId = workbook.worksheets()[1]!.id;
|
|
57
|
+
const dataId = workbook.worksheets()[0]!.id;
|
|
58
|
+
/** @param column - Value column. @returns Authored input, result, and effective native format. */
|
|
59
|
+
function summary(column: number) {
|
|
60
|
+
const cell = { sheetId: summaryId, row: 3, column };
|
|
61
|
+
return { ...workbook.readCell(cell), format: workbook.readFormat(cell) };
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
expect(summary(3)).toMatchObject({ result: { status: "value", value: 4 / 7 }, format: { numberFormat: "0.00%" } });
|
|
65
|
+
expect(summary(4)).toMatchObject({ input: { kind: "error", code: "#DIV/0!" }, result: { status: "error", code: "#DIV/0!" } });
|
|
66
|
+
const commands: WorkbookCommandCall[] = [
|
|
67
|
+
{ name: "setCells", target: parseWorkbookRange(dataId, "D6"), params: { value: -10 } },
|
|
68
|
+
{ name: "refreshPivotTable", target: parseWorkbookRange(summaryId, "A1"), params: { id: workbook.pivotTables()[0]!.id } }
|
|
69
|
+
];
|
|
70
|
+
await workbook.commit(workbook.prepare({ operationId: "refresh-values", baseRevision: workbook.revision, commands }).id);
|
|
71
|
+
expect(summary(4)).toMatchObject({ result: { status: "value", value: 1.5 }, format: { numberFormat: "0.00%" } });
|
|
72
|
+
const written = reopened.write(workbook.snapshot());
|
|
73
|
+
expect(openXlsx("Updated", written).restrictions).toEqual([]);
|
|
74
|
+
await workbook.undo("undo-refresh");
|
|
75
|
+
expect(summary(4)).toMatchObject({ result: { status: "error", code: "#DIV/0!" } });
|
|
76
|
+
} finally { await workbook.close(); }
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("opens the refreshed and saved WPS workbook with independently editable display settings", async () => {
|
|
80
|
+
const bytes = readFileSync(new URL("../../../test/fixtures/native-pivot-value-display.xlsx", import.meta.url));
|
|
81
|
+
const file = openXlsx("WPS Value Display", bytes);
|
|
82
|
+
expect(file.restrictions).toEqual([]);
|
|
83
|
+
expect(file.snapshot.pivotTables?.map(({ values }) => values[0]?.display)).toEqual([
|
|
84
|
+
{ mode: "percentOfCol" }, { mode: "percentOfParent", baseField: 0 }, { mode: "index" }
|
|
85
|
+
]);
|
|
86
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
87
|
+
const table = workbook.pivotTables().find(({ name }) => name === "percentTotals")!;
|
|
88
|
+
const { sheetId } = table.output;
|
|
89
|
+
try {
|
|
90
|
+
expect(workbook.readCell({ sheetId, row: 2, column: 2 }).result).toMatchObject({ status: "value", value: expect.closeTo(4 / 7) });
|
|
91
|
+
expect(workbook.readCell({ sheetId, row: 2, column: 3 }).result).toEqual({ status: "error", code: "#DIV/0!" });
|
|
92
|
+
await workbook.commit(workbook.prepare({ operationId: "edit-wps-values", baseRevision: workbook.revision, commands: [
|
|
93
|
+
{ name: "setCells", target: parseWorkbookRange(table.source.sheetId, "D2"), params: { value: 60 } },
|
|
94
|
+
{ name: "refreshPivotTable", target: parseWorkbookRange(sheetId, "A1"), params: { id: table.id } }
|
|
95
|
+
] }).id);
|
|
96
|
+
expect(workbook.readCell({ sheetId, row: 2, column: 2 }).result).toMatchObject({ value: expect.closeTo(2 / 3) });
|
|
97
|
+
const output = openXlsx("Edited WPS workbook", file.write(workbook.snapshot()));
|
|
98
|
+
expect(output.restrictions).toEqual([]);
|
|
99
|
+
expect(output.snapshot.pivotTables?.find(({ name }) => name === table.name)?.values[0]?.display).toEqual({ mode: "percentOfCol" });
|
|
100
|
+
} finally { await workbook.close(); }
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("round-trips a parent basis located on a generated grouping field", async () => {
|
|
104
|
+
const workbook = await openWorkbook(snapshot);
|
|
105
|
+
try {
|
|
106
|
+
await workbook.commit(workbook.prepare({ operationId: "grouped-parent-basis", baseRevision: workbook.revision, commands: [
|
|
107
|
+
{ name: "setPivotTable", target: parseWorkbookRange("report", "A1"), params: {
|
|
108
|
+
name: "Shares by group", source: { sheetId: "data", range: "A1:D6" }, rowFields: [0, 1], columnFields: [2], filters: [],
|
|
109
|
+
values: [{ field: 3, aggregate: "sum", display: { mode: "percentOfParent", baseField: 0 } }],
|
|
110
|
+
memberGroups: [{ field: 0, groups: [{ name: "Coast", members: ["East", "West"] }] }]
|
|
111
|
+
} }
|
|
112
|
+
] }).id);
|
|
113
|
+
const bytes = createXlsx(workbook.snapshot());
|
|
114
|
+
const parts = unzipSync(bytes);
|
|
115
|
+
const path = Object.keys(parts).find(part => /^xl\/pivotTables\/pivotTable\d+\.xml$/u.test(part))!;
|
|
116
|
+
expect(strFromU8(parts[path]!)).toContain('baseField="4" baseItem="0"');
|
|
117
|
+
const reopened = openXlsx("Grouped parent basis", bytes);
|
|
118
|
+
expect(reopened.restrictions).toEqual([]);
|
|
119
|
+
expect(reopened.snapshot.pivotTables?.[0]?.values[0]?.display).toEqual({ mode: "percentOfParent", baseField: 0 });
|
|
120
|
+
expect(reopened.snapshot.sheets[1]!.cells).toContainEqual({ row: 2, column: 3, input: { kind: "value", value: 4 / 7 } });
|
|
121
|
+
} finally { await workbook.close(); }
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("preserves the original bytes for an unmodeled display extension", async () => {
|
|
125
|
+
const parts = unzipSync(await writeValues());
|
|
126
|
+
const definition = Object.keys(parts).find(path => /^xl\/pivotTables\/pivotTable\d+\.xml$/u.test(path))!;
|
|
127
|
+
parts[definition] = strToU8(strFromU8(parts[definition]!).replace('pivotShowAs="percentOfParent"', 'pivotShowAs="rankAscending"'));
|
|
128
|
+
const bytes = zipSync(parts);
|
|
129
|
+
const file = openXlsx("Ranked", bytes);
|
|
130
|
+
expect(file.restrictions).toContain("未支持的数据透视表、缓存或工作表关系");
|
|
131
|
+
expect(file.write(file.snapshot)).toEqual(bytes);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { strFromU8, unzipSync } from "fflate";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { openWorkbook, parseWorkbookRange } from "@quirekit/workbook";
|
|
5
|
+
import { openXlsx } from "../../index";
|
|
6
|
+
|
|
7
|
+
it("keeps WPS axis member and label filters and rewrites native sort settings", async () => {
|
|
8
|
+
const bytes = readFileSync(new URL("../../../test/fixtures/wps-pivot-field-filters.xlsx", import.meta.url));
|
|
9
|
+
const file = openXlsx("Field filter samples", bytes);
|
|
10
|
+
expect(file.restrictions).toEqual([]);
|
|
11
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
12
|
+
try {
|
|
13
|
+
const [filtered, sorted] = workbook.pivotTables();
|
|
14
|
+
expect(filtered?.fieldSettings).toEqual([
|
|
15
|
+
{ field: 0, filter: { kind: "members", mode: "include", items: ["华东"] } },
|
|
16
|
+
{ field: 2, filter: { kind: "label", operator: "contains", first: "1" } },
|
|
17
|
+
{ field: 4, filter: { kind: "members", mode: "include", items: ["A"] } }
|
|
18
|
+
]);
|
|
19
|
+
expect(sorted?.fieldSettings).toEqual([{ field: 2, sort: "asc" }]);
|
|
20
|
+
const initial = openXlsx("Saved label filter", file.write(workbook.snapshot()));
|
|
21
|
+
expect(initial.restrictions).toEqual([]);
|
|
22
|
+
expect(initial.snapshot.pivotTables?.[0]?.fieldSettings).toEqual(filtered?.fieldSettings);
|
|
23
|
+
const { id, output: { sheetId }, source } = filtered!;
|
|
24
|
+
const target = parseWorkbookRange(sheetId, "A3");
|
|
25
|
+
expect(workbook.readCell({ sheetId, row: 8, column: 4 }).result).toMatchObject({ value: 10 });
|
|
26
|
+
await workbook.commit(workbook.prepare({ operationId: "filter-and-sort-axis", baseRevision: workbook.revision,
|
|
27
|
+
commands: [
|
|
28
|
+
{ name: "setPivotFieldSettings", target, params: { id, field: 2, filter: null, sort: "desc" } },
|
|
29
|
+
{ name: "setPivotFieldSettings", target, params: { id, field: 4, filter: { kind: "members", mode: "exclude", items: ["B"] } } }
|
|
30
|
+
]
|
|
31
|
+
}).id);
|
|
32
|
+
const selection = workbook.pivotTables()[0]!.fieldSettings!;
|
|
33
|
+
const { output } = workbook.pivotTables()[0]!;
|
|
34
|
+
expect(workbook.readCell({ sheetId, row: output.endRow, column: output.endColumn }).result).toMatchObject({ value: 70 });
|
|
35
|
+
|
|
36
|
+
const written = file.write(workbook.snapshot());
|
|
37
|
+
const definitions = unzipSync(written);
|
|
38
|
+
const native = Object.entries(definitions).filter(([path]) => /^xl\/pivotTables\/pivotTable\d+\.xml$/u.test(path))
|
|
39
|
+
.map(([, bytes]) => strFromU8(bytes)).find(xml => xml.includes('name="FilteredQuarter"'));
|
|
40
|
+
expect(native).toMatch(/sortType="descending"/u);
|
|
41
|
+
expect(native).toMatch(/includeNewItemsInFilter="1"/u);
|
|
42
|
+
expect(native).toMatch(/hideNewItems="1"/u);
|
|
43
|
+
expect(native?.match(/h="1"/gu)).toHaveLength(2);
|
|
44
|
+
const saved = openXlsx("Saved field filters", written);
|
|
45
|
+
expect(saved.restrictions).toEqual([]);
|
|
46
|
+
expect(saved.snapshot.pivotTables?.[0]?.fieldSettings).toEqual(selection);
|
|
47
|
+
expect(saved.snapshot.pivotTables?.[0]?.source).toEqual(source);
|
|
48
|
+
await workbook.commit(workbook.prepare({ operationId: "refresh-axis-filter", baseRevision: workbook.revision, commands: [
|
|
49
|
+
{ name: "setCells", target: parseWorkbookRange(source.sheetId, "O3"), params: { value: "C" } },
|
|
50
|
+
{ name: "refreshPivotTable", target, params: { id } }
|
|
51
|
+
] }).id);
|
|
52
|
+
const refreshed = workbook.pivotTables()[0]!.output;
|
|
53
|
+
expect(workbook.readCell({ sheetId, row: refreshed.endRow, column: refreshed.endColumn }).result).toMatchObject({ value: 100 });
|
|
54
|
+
expect(workbook.pivotTables()[1]?.cache.records).toEqual(sorted?.cache.records);
|
|
55
|
+
await workbook.undo("undo-axis-refresh");
|
|
56
|
+
await workbook.undo("undo-field-filters");
|
|
57
|
+
expect(workbook.pivotTables()[0]?.fieldSettings).toEqual(filtered?.fieldSettings);
|
|
58
|
+
} finally { await workbook.close(); }
|
|
59
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { strFromU8, unzipSync } from "fflate";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { openWorkbook, parseWorkbookRange } from "@quirekit/workbook";
|
|
5
|
+
import { openXlsx } from "../../index";
|
|
6
|
+
|
|
7
|
+
it("edits and refreshes native WPS compact and outline layouts with one cache", async () => {
|
|
8
|
+
const bytes = readFileSync(new URL("../../../test/fixtures/wps-pivot-report-layouts.xlsx", import.meta.url));
|
|
9
|
+
const file = openXlsx("Pivot layout samples", bytes);
|
|
10
|
+
expect(file.restrictions).toEqual([]);
|
|
11
|
+
expect(file.snapshot.pivotTables?.map(({ reportLayout }) => reportLayout)).toEqual([
|
|
12
|
+
{ form: "compact", repeatLabels: false }, { form: "compact", repeatLabels: false }, { form: "outline", repeatLabels: true }
|
|
13
|
+
]);
|
|
14
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
15
|
+
try {
|
|
16
|
+
const compact = workbook.pivotTables().find(({ name }) => name === "CompactQuarter")!;
|
|
17
|
+
const headings = workbook.pivotTables().find(({ name }) => name === "CompactHeadings")!;
|
|
18
|
+
const outline = workbook.pivotTables().find(({ name }) => name === "OutlineQuarter")!;
|
|
19
|
+
const { sheetId } = outline.output;
|
|
20
|
+
expect(workbook.readFormat({ sheetId: compact.output.sheetId, row: 6, column: 0 }).indent).toBe(1);
|
|
21
|
+
expect(workbook.readCell({ sheetId: headings.output.sheetId, row: 5, column: 5 }).input).toBeNull();
|
|
22
|
+
expect(workbook.readCell({ sheetId, row: 6, column: 0 }).result).toMatchObject({ value: "Q1" });
|
|
23
|
+
const target = parseWorkbookRange(sheetId, "A3");
|
|
24
|
+
const { id, name, cache, rowFields, columnFields, values, filters } = outline;
|
|
25
|
+
await workbook.commit(workbook.prepare({ operationId: "display-compact", baseRevision: workbook.revision,
|
|
26
|
+
commands: [{ name: "setPivotTable", target, params: { id, name, rowFields, columnFields, values, filters,
|
|
27
|
+
source: { sheetId: outline.source.sheetId, range: "K1:O7" }, reportLayout: { form: "compact", repeatLabels: true } } }]
|
|
28
|
+
}).id);
|
|
29
|
+
expect(workbook.readCell({ sheetId, row: 5, column: 7 }).result).toMatchObject({ value: 90 });
|
|
30
|
+
expect(workbook.readCell({ sheetId, row: 5, column: 8 }).input).toBeNull();
|
|
31
|
+
expect(workbook.readCell({ sheetId, row: 6, column: 0 }).result).toMatchObject({ value: "A" });
|
|
32
|
+
expect(workbook.readFormat({ sheetId, row: 6, column: 0 }).indent).toBe(1);
|
|
33
|
+
await workbook.commit(workbook.prepare({ operationId: "refresh-compact", baseRevision: workbook.revision, commands: [
|
|
34
|
+
{ name: "setCells", target: parseWorkbookRange(outline.source.sheetId, "N2"), params: { value: Number(cache.records[0]![3]) + 10 } },
|
|
35
|
+
{ name: "refreshPivotTable", target, params: { id } }
|
|
36
|
+
] }).id);
|
|
37
|
+
expect(workbook.readCell({ sheetId, row: 11, column: 7 }).result).toMatchObject({ value: 220 });
|
|
38
|
+
const written = file.write(workbook.snapshot());
|
|
39
|
+
const parts = unzipSync(written);
|
|
40
|
+
const definition = Object.keys(parts).filter(path => /^xl\/pivotTables\/pivotTable\d+\.xml$/u.test(path))
|
|
41
|
+
.map(path => strFromU8(parts[path]!)).find(text => text.includes('name="OutlineQuarter"'))!;
|
|
42
|
+
expect(definition).toContain('compact="1"');
|
|
43
|
+
expect(definition).toContain('firstDataCol="1"');
|
|
44
|
+
expect(definition).toContain('fillDownLabelsDefault="1"');
|
|
45
|
+
expect(strFromU8(parts["xl/styles.xml"]!)).toMatch(/<alignment[^>]*indent="1"/u);
|
|
46
|
+
const saved = openXlsx("Reopened report", written);
|
|
47
|
+
expect(saved.restrictions).toEqual([]);
|
|
48
|
+
expect(saved.snapshot.pivotTables?.find(table => table.name === name)?.reportLayout).toEqual({ form: "compact", repeatLabels: true });
|
|
49
|
+
await workbook.undo("undo-refresh");
|
|
50
|
+
await workbook.undo("undo-layout");
|
|
51
|
+
expect(workbook.readCell({ sheetId, row: 6, column: 0 }).result).toMatchObject({ value: "Q1" });
|
|
52
|
+
expect(workbook.readFormat({ sheetId, row: 6, column: 0 }).indent).toBeUndefined();
|
|
53
|
+
} finally { await workbook.close(); }
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("reads and rewrites WPS row and column groups with native fold state", async () => {
|
|
57
|
+
const bytes = readFileSync(new URL("../../../test/fixtures/wps-pivot-collapsed-groups.xlsx", import.meta.url));
|
|
58
|
+
const file = openXlsx("Folded report", bytes);
|
|
59
|
+
expect(file.restrictions).toEqual([]);
|
|
60
|
+
const workbook = await openWorkbook(file.snapshot, { appearance: file.appearance });
|
|
61
|
+
try {
|
|
62
|
+
const report = workbook.pivotTables()[0]!;
|
|
63
|
+
const { id, output: { sheetId } } = report;
|
|
64
|
+
const target = parseWorkbookRange(sheetId, "A3");
|
|
65
|
+
expect(report).toMatchObject({ output: parseWorkbookRange(sheetId, "A3:G10"), showExpandCollapse: false,
|
|
66
|
+
reportLayout: { form: "tabular", repeatLabels: false },
|
|
67
|
+
collapsedItems: [{ field: 0, items: ["华北"] }, { field: 2, items: ["Q1"] }] });
|
|
68
|
+
expect(workbook.readCell({ sheetId, row: 9, column: 2 }).result).toMatchObject({ value: 110 });
|
|
69
|
+
const written = file.write(workbook.snapshot());
|
|
70
|
+
const parts = unzipSync(written);
|
|
71
|
+
const definition = strFromU8(parts["xl/pivotTables/pivotTable1.xml"]!);
|
|
72
|
+
expect(definition).toContain('showDrill="0"');
|
|
73
|
+
expect(definition.match(/sd="0"/gu)).toHaveLength(2);
|
|
74
|
+
expect(openXlsx("Saved folded state", written).snapshot.pivotTables?.[0]).toMatchObject({
|
|
75
|
+
output: report.output, collapsedItems: report.collapsedItems, showExpandCollapse: false
|
|
76
|
+
});
|
|
77
|
+
await workbook.commit(workbook.prepare({ operationId: "open-groups", baseRevision: workbook.revision, commands: [
|
|
78
|
+
{ name: "setPivotItemExpanded", target, params: { id, field: 0, expanded: true } },
|
|
79
|
+
{ name: "setPivotItemExpanded", target, params: { id, field: 2, item: "Q1", expanded: true } }
|
|
80
|
+
] }).id);
|
|
81
|
+
expect(workbook.pivotTables()[0]?.output).toEqual(parseWorkbookRange(sheetId, "A3:I12"));
|
|
82
|
+
expect(workbook.readCell({ sheetId, row: 11, column: 4 }).result).toMatchObject({ value: 110 / 3 });
|
|
83
|
+
const reopened = openXlsx("Expanded result", file.write(workbook.snapshot()));
|
|
84
|
+
expect(reopened.restrictions).toEqual([]);
|
|
85
|
+
expect(reopened.snapshot.pivotTables?.[0]?.collapsedItems).toBeUndefined();
|
|
86
|
+
expect(reopened.snapshot.pivotTables?.[0]?.showExpandCollapse).toBe(false);
|
|
87
|
+
} finally { await workbook.close(); }
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("edits native WPS separators and captions without changing cached records", async () => {
|
|
91
|
+
const bytes = readFileSync(new URL("../../../test/fixtures/wps-pivot-result-presentation.xlsx", import.meta.url));
|
|
92
|
+
const original = openXlsx("Report display samples", bytes);
|
|
93
|
+
expect(original.restrictions).toEqual([]);
|
|
94
|
+
const workbook = await openWorkbook(original.snapshot, { appearance: original.appearance });
|
|
95
|
+
try {
|
|
96
|
+
const table = workbook.pivotTables().find(table => table.name === "ReviewQuarter")!;
|
|
97
|
+
const groups = workbook.pivotTables().find(table => table.name === "BlankAfterGroups")!;
|
|
98
|
+
const { sheetId } = table.output;
|
|
99
|
+
const target = parseWorkbookRange(sheetId, "A3");
|
|
100
|
+
const presentation = { blankRows: true, empty: { enabled: true, text: "待补" }, error: { enabled: true, text: "需核对" } };
|
|
101
|
+
expect(table.output).toEqual(parseWorkbookRange(sheetId, "A3:P15"));
|
|
102
|
+
expect(table.reportPresentation).toEqual(presentation);
|
|
103
|
+
expect(workbook.readCell({ sheetId, row: 6, column: 2 }).result).toMatchObject({ value: "待补" });
|
|
104
|
+
expect(workbook.readCell({ sheetId, row: 6, column: 3 }).result).toMatchObject({ value: "需核对" });
|
|
105
|
+
expect(workbook.readCell({ sheetId, row: 9, column: 3 }).input).toBeNull();
|
|
106
|
+
expect(workbook.readCell({ sheetId: groups.output.sheetId, row: 8, column: 4 }).result).toMatchObject({ value: 0 });
|
|
107
|
+
expect(groups.reportPresentation).toEqual({
|
|
108
|
+
blankRows: true, empty: { enabled: true, text: "00" }, error: { enabled: true, text: "" }
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const { id, name, rowFields, columnFields, values, filters } = table;
|
|
112
|
+
await workbook.commit(workbook.prepare({ operationId: "reveal-native-results", baseRevision: workbook.revision,
|
|
113
|
+
commands: [{ name: "setPivotTable", target, params: { id, name, rowFields, columnFields, values, filters,
|
|
114
|
+
source: { sheetId: table.source.sheetId, range: "K1:O7" }, reportPresentation: { blankRows: false,
|
|
115
|
+
empty: { enabled: false, text: "待补" }, error: { enabled: false, text: "需核对" } } } }]
|
|
116
|
+
}).id);
|
|
117
|
+
expect(workbook.pivotTables()[0]?.output).toEqual(parseWorkbookRange(sheetId, "A3:P13"));
|
|
118
|
+
expect(workbook.readCell({ sheetId, row: 6, column: 2 }).result).toMatchObject({ value: 0 });
|
|
119
|
+
expect(workbook.readCell({ sheetId, row: 6, column: 3 }).result).toEqual({ status: "error", code: "#DIV/0!" });
|
|
120
|
+
expect(workbook.readCell({ sheetId, row: 14, column: 14 }).input).toBeNull();
|
|
121
|
+
const { name: groupName, id: groupId, rowFields: groupRows, columnFields: groupColumns } = groups;
|
|
122
|
+
await workbook.commit(workbook.prepare({ operationId: "remove-unused-calculated-field", baseRevision: workbook.revision,
|
|
123
|
+
commands: [{ name: "setPivotTable", target: parseWorkbookRange(groups.output.sheetId, "A3"), params: {
|
|
124
|
+
id: groupId, name: groupName, rowFields: groupRows, columnFields: groupColumns, values: groups.values, filters: groups.filters,
|
|
125
|
+
source: { sheetId: groups.source.sheetId, range: "K1:O7" }, calculatedFields: [],
|
|
126
|
+
reportPresentation: { blankRows: [{ field: 4 }, { field: 2 }] }
|
|
127
|
+
} }]
|
|
128
|
+
}).id);
|
|
129
|
+
const written = original.write(workbook.snapshot());
|
|
130
|
+
const parts = unzipSync(written);
|
|
131
|
+
const definition = Object.keys(parts).filter(path => /^xl\/pivotTables\/pivotTable\d+\.xml$/u.test(path))
|
|
132
|
+
.map(path => strFromU8(parts[path]!)).find(text => text.includes('name="ReviewQuarter"'));
|
|
133
|
+
expect(definition).toContain('showMissing="0"');
|
|
134
|
+
expect(definition).toContain('errorCaption="需核对"');
|
|
135
|
+
expect(definition).not.toContain('t="blank"');
|
|
136
|
+
const reopened = openXlsx("Saved report display samples", written);
|
|
137
|
+
expect(reopened.restrictions).toEqual([]);
|
|
138
|
+
expect(reopened.snapshot.pivotTables?.[0]?.cache).toEqual(original.snapshot.pivotTables?.[0]?.cache);
|
|
139
|
+
expect(reopened.snapshot.pivotTables?.[1]?.reportPresentation).toEqual({
|
|
140
|
+
...groups.reportPresentation, blankRows: [{ field: 2 }, { field: 4 }]
|
|
141
|
+
});
|
|
142
|
+
expect(reopened.snapshot.pivotTables?.[1]?.calculatedFields).toBeUndefined();
|
|
143
|
+
await workbook.undo("undo-calculated-field-removal");
|
|
144
|
+
await workbook.undo("undo-presentation");
|
|
145
|
+
expect(workbook.pivotTables()[0]?.reportPresentation).toEqual(presentation);
|
|
146
|
+
expect(workbook.pivotTables()[0]?.output).toEqual(table.output);
|
|
147
|
+
} finally { await workbook.close(); }
|
|
148
|
+
});
|