@univerjs-pro/exchange-node 1.4.0 → 1.6.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/README.md CHANGED
@@ -17,6 +17,15 @@ pnpm add @univerjs-pro/exchange-node
17
17
 
18
18
  Native Binding dependencies allow same-minor patches from the version paired with the SDK; the application lock controls the installed patch.
19
19
 
20
+ Office native builds containing the integer-period PV correction can change trailing digits in recalculated
21
+ `PV` results and dependent balances: `PV(0.05/12,4,-3000)` changes from `11876.034121502425` to
22
+ `11876.03412150258`. This applies to nonzero rates and integer period counts with absolute value at most
23
+ `2147483647`; other PV inputs retain their existing calculation paths. Update the Office binding and request
24
+ formula recalculation to apply it; cached values and older native builds are not rewritten by a Wrapper update.
25
+ API, protocol and snapshot formats require no migration. Release identities remain to be selected;
26
+ native Formula and Pro comparison tests pass, but a new published Office package and Excel round trip have
27
+ not been validated for this correction.
28
+
20
29
  ## Import
21
30
 
22
31
  ```ts
@@ -59,6 +68,55 @@ const xlsxBuffer = await exportToBuffer(workbook, {
59
68
 
60
69
  Sheet export defaults to `FormulaCalculationMode.WHEN_EMPTY`: missing cached formula values are calculated, while existing cached values are preserved. Pass `FormulaCalculationMode.NO` to disable calculation.
61
70
 
71
+ Either mode uses the external-link values saved in the workbook snapshot. A saved OOXML cache is used even when its `freshness` marker is `stale` (the value both import and export always write), and a `<sheetData refreshError="1">` marker does not invalidate it: both are resource metadata, matching Excel opening the file without refreshing its links. Import and export calculations therefore agree for the same workbook; the in-session Rust formula engine keeps asking the host for live external data instead.
72
+
73
+ ### XLSX implicit intersection formulas
74
+
75
+ XLSX export uses the existing `ft` (formula type), `si` (shared group), `ref` (range)
76
+ and `fd` (fixed/dynamic array) cell metadata. Normal (`ft: 0`) and shared formulas
77
+ (`ft: 1`, or a shared `si` group) restore intersections already implied by legacy
78
+ calculation. Explicit intersections in array-consuming arguments remain explicit:
79
+ `SUM(@A1:A5)` becomes `SUM(_xlfn.SINGLE(A1:A5))`, preserving its scalar result.
80
+ A retained outer intersection also preserves inner intersections in its array
81
+ operand: `@(A1:A5+@B1:B5)` keeps both `SINGLE` calls.
82
+ Array formulas (`ft: 2`) and formulas without type/shared metadata also store explicit
83
+ intersection as `_xlfn.SINGLE(...)`. When type/shared/range metadata is absent, actual
84
+ runtime `@`/`#` operators also derive a single-cell array anchor using the existing
85
+ `ref` mechanism. This preserves Formula2 evaluation inside nested expressions;
86
+ declared normal/shared metadata remains authoritative. Spill references such as `A1#` use Excel's
87
+ `_xlfn.ANCHORARRAY(A1)` file spelling. Strings, sheet names and Table references keep
88
+ their literal `@` characters, including escaped Table headers.
89
+
90
+ Previously, export could write runtime unary `@` directly into worksheet `<f>` text.
91
+ The corrected Office native binding normalizes the file representation without
92
+ changing the supplied snapshot or recalculating cached values. When a LET/LAMBDA
93
+ binding shares a built-in function name, import retains the built-in's `_xlfn.`
94
+ qualification so a later export cannot turn it into a local function call.
95
+
96
+ Older snapshots without formula-type/shared metadata use `SINGLE` to retain explicit
97
+ intersection; reimport the original XLSX when its original formula kind and array
98
+ range are required. Reimporting an untyped operator expression can expose the
99
+ inferred array type and range. Consumers that compare formula strings or snapshots
100
+ must allow these equivalent representations. The JS API and snapshot schema are
101
+ unchanged; updating only the wrapper cannot fix an older native binding. A new native
102
+ artifact is required; release identities remain to be selected.
103
+
104
+ ### Read editable PivotTables from imported XLSX snapshots
105
+
106
+ Editable PivotTables are stored in the snapshot's PivotTable resource. Load the snapshot in a compatible Univer frontend to read the rendered results. The worksheet cells retain ordinary data, and import-time formula calculation can still use the report values. Re-import the original XLSX to remove static copies left by earlier imports. Preserve the raw PivotTable resource and use a matching native binding when exporting these snapshots. The default XLSX export writes static report values for spreadsheet readers that do not refresh PivotTables.
107
+
108
+ Unchanged imported reports replay their saved values and merged headers while retaining current worksheet cell styles. Reports with changed PivotTable configuration and deleted reports do not replay their old output or merges. The raw PivotTable resource v2 stores saved cells in `worksheetOutputCells` and saved merges in `worksheetOutputMerges`; preserve both through frontend saves and export with a native binding that reads both fields. Older exporters ignore the merge archive and cannot preserve this round trip. Snapshots that already lost merge information must be re-imported from the original XLSX. Rebuilding the Office binding or CLI is required; updating only the JavaScript wrapper does not apply these fixes. Release artifacts and desktop Excel refresh still require validation.
109
+
110
+ ### Defer eligible XLSX PivotTable calculations to Excel
111
+
112
+ Pass `deferPivotCalculation: true` to a Sheet XLSX export to leave eligible PivotTable results for Excel to calculate. The option works with `exportToBuffer`, `exportToFile`, `exportSnapshotToBuffer`, and `exportSnapshotToFile`. Omission or `false` keeps the usual export behavior. Formula calculation is controlled separately.
113
+
114
+ The eligible profile is a single new PivotTable with one unfiltered, unsorted text row field, one numeric SUM measure, and grand totals. It uses a populated two-column source range on a different sheet with distinct worksheet headers that match the PivotTable source fields. Excel receives the PivotTable definition, source cache, a two-row starting range, and the refresh-on-open setting. The worksheet result cells are initially empty. Open the file in desktop Excel and refresh the PivotTable if it has not refreshed on open.
115
+
116
+ Export rejects an eligible PivotTable if its maximum refresh range contains worksheet data. Workbooks with formulas, named ranges, charts, slicers, existing raw PivotTables, or grouped fields continue through the usual export path. Use the default for files that must expose static results to readers without Excel refresh support.
117
+
118
+ This option requires an Office native binding that supports `deferPivotCalculation`. An older binding rejects the opt-in option. The wrapper omits the native option for both `false` and the default, so existing calls require no changes. The snapshot format is unchanged.
119
+
62
120
  ### XLSX worksheet default styles
63
121
 
64
122
  XLSX has no worksheet-level equivalent of Univer's `sheet.defaultStyle`. The Office native exporter passes the complete default-style object, or the object resolved from its workbook style ID, through the same style conversion used for cells. Column defaults and the necessary composed row/cell styles preserve supported font properties, RGB text and fill colors, borders, number formats, alignment, wrapping, shrink-to-fit, rotation, text direction and left indent. The projection does not filter the input to a list of font fields. Unspecified attributes retain the existing workbook export base; column, row and cell attributes override the default by property, including explicit `0` and `null` clearing values. This also applies to `FWorksheet.setDefaultStyle()` followed by `workbook.save()` and to complete snapshot exports. The workbook's existing Normal style is retained.
@@ -102,6 +160,14 @@ interface ISnapshotWithBlocks {
102
160
 
103
161
  Sheet and Base snapshots must include every referenced sheet block. Doc, Slide and Board snapshots normally use an empty `sheetBlocks` array.
104
162
 
163
+ Office native builds containing the empty-block compatibility fix accept a `workbook.blockMeta`
164
+ entry with omitted `blocks` (or legacy `Blocks`) as an empty list, matching protobuf JSON's
165
+ omission of empty repeated fields. Older native builds reject that input; updating only this
166
+ JavaScript wrapper does not fix them. Explicit non-array values, invalid block IDs and missing
167
+ referenced blocks still fail. Existing snapshots need no migration; until the native fix is
168
+ available, producers can emit `blocks: []` for empty entries. This requires a new Office binding
169
+ patch or rebuilt CLI/FFI; release identities remain to be selected.
170
+
105
171
  Snapshot APIs materialize the complete aggregate in memory. They do not call a Snapshot Server or stream blocks to storage.
106
172
 
107
173
  ## Board export
@@ -315,6 +381,8 @@ The following table compares quota queries and actual exports. Both APIs return
315
381
  Applications may derive expiry reminders from `licenseStatus` and `expiresAt`. No separate notice list or automatic logging is emitted. Supplied invalid credentials reject configuration, queries and exports with `LICENSE_INVALID`. If usage processing fails, do not infer whether a count was consumed from the error alone; preserve the complete error for support.
316
382
  ESM and CommonJS share configuration within the same JavaScript context. Each `worker_threads` Worker must configure itself or initialize from its environment; Workers share the export quota, not their configuration. Exports capture configuration when the public method is called; a later configuration change applies to subsequently started exports. A failed explicit configuration leaves the previous configuration in effect.
317
383
 
384
+ The Office Node Binding supports loading in successive short-lived Workers. Published Linux GNU Binding 1.0.6 and 1.1.0 can crash the entire process when the first loading Worker exits and a later Worker loads the addon again. The correction upgrades the bundled mimalloc v3.3.2 allocator to Microsoft's v3.6.1 release, using its official Rust bindings and C sources pinned to one release commit. It requires an updated native Binding artifact; the JS wrapper alone cannot repair an older binary. API signatures and the configuration protocol are unchanged. The Exchange CLI shares the allocator dependency and also uses the official v3.6.1 implementation when rebuilt; the independent Formula addon and Go PDF runtime do not switch allocators. The Office Node Binding and CLI use the upstream allocator defaults. Mimalloc can retain freed pages for reuse by subsequent conversions; upgrade validation includes peak RSS across repeated calls. Upstream `MIMALLOC_*` environment controls can be set before the first native load. Source builds fetch the pinned public Git dependency through Cargo; users of prebuilt npm Binding packages do not need to fetch it. Worker threads share a process address space and do not isolate fatal native failures; use separate processes when that isolation is required. Automated lifecycle checks exercise loading, repeated Worker teardown, and completed conversions; terminating a conversion while native work is in flight is not covered by those checks.
385
+
318
386
  ## Advanced packaging
319
387
 
320
388
  Standard npm installation is recommended. `UNIVER_NODE_SDK_RUNTIME_DIR_OVERRIDE` is an escape hatch for external packagers; our own build and runtime flows do not set it.
package/lib/cjs/index.cjs CHANGED
@@ -455,7 +455,8 @@ function nativeExportOptions(options) {
455
455
  } : void 0,
456
456
  formulaCalculation: "formulaCalculation" in options ? options.formulaCalculation : void 0,
457
457
  ole: options.ole !== void 0 ? { attachmentSource: options.ole.attachmentSource ?? "original" } : void 0,
458
- files: options.files !== void 0 || void 0
458
+ files: options.files !== void 0 || void 0,
459
+ deferPivotCalculation: "deferPivotCalculation" in options && options.deferPivotCalculation === !0 ? !0 : void 0
459
460
  };
460
461
  }
461
462
  async function importSnapshot(input, options, fileName, files) {
@@ -682,7 +683,10 @@ async function importBufferToSnapshot(input, options) {
682
683
  async function exportResult(data, options, isSnapshot, captured) {
683
684
  let result;
684
685
  try {
685
- let config = await captured, { files, ole } = validateExportResources(options), adapter = pdfAdapter(options.type, options.format);
686
+ let config = await captured;
687
+ if ("deferPivotCalculation" in options && options.deferPivotCalculation !== void 0 && (options.type !== import_core.UniverInstanceType.UNIVER_SHEET || options.format !== "xlsx" /* XLSX */ || typeof options.deferPivotCalculation != "boolean"))
688
+ throw invalidArgument("deferPivotCalculation must be a boolean for Sheet XLSX export");
689
+ let { files, ole } = validateExportResources(options), adapter = pdfAdapter(options.type, options.format);
686
690
  if (adapter) {
687
691
  let unit = isSnapshot ? adapter.fromSnapshot(data) : data;
688
692
  result = await adapter.export(
@@ -279,6 +279,8 @@ interface ISheetExportConfig {
279
279
  }
280
280
  export type ISheetExportOptions = ISheetExportConfig & ((IExportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.XLSX> & {
281
281
  csv?: never;
282
+ /** Leave eligible PivotTable results for Excel to calculate on refresh. Defaults to false. */
283
+ deferPivotCalculation?: boolean;
282
284
  }) | (IExportOptionsBase<UniverInstanceType.UNIVER_SHEET, ExchangeFormat.CSV | ExchangeFormat.TSV> & {
283
285
  csv: ICsvExportOptions;
284
286
  files?: never;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
3
3
  "dependencies": {
4
- "@univerjs-pro/boards": "1.4.0",
5
- "@univerjs-pro/collaboration": "1.4.0",
6
- "@univerjs-pro/exchange-node-binding": "~1.1.0",
7
- "@univerjs-pro/pdfs": "1.4.0",
8
- "@univerjs-pro/slides": "1.4.0",
9
- "@univerjs/core": "1.4.0",
10
- "@univerjs/protocol": "1.4.0"
4
+ "@univerjs-pro/boards": "1.6.0",
5
+ "@univerjs-pro/collaboration": "1.6.0",
6
+ "@univerjs-pro/exchange-node-binding": "~1.3.0",
7
+ "@univerjs-pro/pdfs": "1.6.0",
8
+ "@univerjs-pro/slides": "1.6.0",
9
+ "@univerjs/core": "1.6.0",
10
+ "@univerjs/protocol": "1.6.0"
11
11
  },
12
12
  "description": "Node.js SDK for converting between Office formats, Univer unit data, and snapshots",
13
13
  "files": [
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "name": "@univerjs-pro/exchange-node",
18
18
  "peerDependencies": {
19
- "@univerjs-pro/exchange-pdf-node-binding": "~1.1.0"
19
+ "@univerjs-pro/exchange-pdf-node-binding": "~1.2.0"
20
20
  },
21
21
  "peerDependenciesMeta": {
22
22
  "@univerjs-pro/exchange-pdf-node-binding": {
@@ -32,7 +32,7 @@
32
32
  "./lib/cjs/mermaid.cjs"
33
33
  ],
34
34
  "type": "module",
35
- "version": "1.4.0",
35
+ "version": "1.6.0",
36
36
  "main": "./lib/cjs/index.cjs",
37
37
  "module": "./lib/es/index.js",
38
38
  "types": "./lib/types/index.d.ts",