@casualoffice/sheets 0.9.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 +200 -0
- package/dist/embed/embed-runtime.js +537 -0
- package/dist/embed/embed.html +29 -0
- package/dist/embed/parser.worker.js +48474 -0
- package/dist/embed.cjs +225 -0
- package/dist/embed.cjs.map +1 -0
- package/dist/embed.d.cts +100 -0
- package/dist/embed.d.ts +100 -0
- package/dist/embed.js +204 -0
- package/dist/embed.js.map +1 -0
- package/dist/index.cjs +1549 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1530 -0
- package/dist/index.js.map +1 -0
- package/dist/parser.worker.cjs +48469 -0
- package/dist/parser.worker.cjs.map +1 -0
- package/dist/parser.worker.js +48474 -0
- package/dist/parser.worker.js.map +1 -0
- package/dist/protocol--KyBQUjU.d.cts +171 -0
- package/dist/protocol-cEzy7S0i.d.ts +171 -0
- package/dist/sheets.cjs +677 -0
- package/dist/sheets.cjs.map +1 -0
- package/dist/sheets.d.cts +177 -0
- package/dist/sheets.d.ts +177 -0
- package/dist/sheets.js +658 -0
- package/dist/sheets.js.map +1 -0
- package/dist/signing.cjs +706 -0
- package/dist/signing.cjs.map +1 -0
- package/dist/signing.d.cts +141 -0
- package/dist/signing.d.ts +141 -0
- package/dist/signing.js +683 -0
- package/dist/signing.js.map +1 -0
- package/dist/styles.cjs +10 -0
- package/dist/styles.cjs.map +1 -0
- package/dist/styles.d.cts +2 -0
- package/dist/styles.d.ts +2 -0
- package/dist/styles.js +8 -0
- package/dist/styles.js.map +1 -0
- package/dist/types-s_O0u6Cg.d.cts +90 -0
- package/dist/types-s_O0u6Cg.d.ts +90 -0
- package/dist/univer.cjs +220 -0
- package/dist/univer.cjs.map +1 -0
- package/dist/univer.d.cts +60 -0
- package/dist/univer.d.ts +60 -0
- package/dist/univer.js +187 -0
- package/dist/univer.js.map +1 -0
- package/dist/xlsx.cjs +3388 -0
- package/dist/xlsx.cjs.map +1 -0
- package/dist/xlsx.d.cts +383 -0
- package/dist/xlsx.d.ts +383 -0
- package/dist/xlsx.js +3383 -0
- package/dist/xlsx.js.map +1 -0
- package/package.json +293 -0
- package/src/embed/EmbedHostTransport.ts +226 -0
- package/src/embed/EmbedTransport.ts +323 -0
- package/src/embed/EmbedTransport.unit.test.ts +161 -0
- package/src/embed/index.ts +40 -0
- package/src/embed/protocol.ts +258 -0
- package/src/embed-runtime/embed.html +29 -0
- package/src/embed-runtime/index.tsx +440 -0
- package/src/index.ts +16 -0
- package/src/sheets/CasualSheets.tsx +319 -0
- package/src/sheets/CasualSheetsIframe.tsx +220 -0
- package/src/sheets/api.ts +108 -0
- package/src/sheets/index.ts +11 -0
- package/src/signing/SigningPane.tsx +374 -0
- package/src/signing/SigningProvider.tsx +126 -0
- package/src/signing/captures.tsx +316 -0
- package/src/signing/controller.ts +151 -0
- package/src/signing/controller.unit.test.ts +133 -0
- package/src/signing/index.ts +44 -0
- package/src/signing/types.ts +89 -0
- package/src/styles.ts +16 -0
- package/src/univer/index.ts +17 -0
- package/src/univer/lazy-plugins.ts +280 -0
- package/src/xlsx/_perf.ts +14 -0
- package/src/xlsx/_snapshot-constants.ts +15 -0
- package/src/xlsx/comments-resource.ts +209 -0
- package/src/xlsx/constants.ts +9 -0
- package/src/xlsx/data-validation-resource.ts +219 -0
- package/src/xlsx/import.ts +35 -0
- package/src/xlsx/index.ts +40 -0
- package/src/xlsx/page-setup-resource.ts +205 -0
- package/src/xlsx/parse-impl.ts +418 -0
- package/src/xlsx/parse-in-worker.ts +82 -0
- package/src/xlsx/parser.worker.ts +39 -0
- package/src/xlsx/passthrough-resource.ts +175 -0
- package/src/xlsx/pivot-passthrough.ts +359 -0
- package/src/xlsx/style-mapping.ts +171 -0
- package/src/xlsx/tables-resource.ts +211 -0
package/dist/xlsx.d.cts
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { IWorkbookData, IStyleData, IRange } from '@univerjs/core';
|
|
2
|
+
import * as ExcelJS from 'exceljs';
|
|
3
|
+
import ExcelJS__default from 'exceljs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Public entry point for xlsx import. The actual ExcelJS work lives in a
|
|
7
|
+
* Web Worker (`parser.worker.ts` → `parse-impl.ts`) so the main thread
|
|
8
|
+
* stays responsive while a multi-MB workbook is being parsed. This file
|
|
9
|
+
* stays type-only on the main bundle — ExcelJS doesn't get pulled in
|
|
10
|
+
* here.
|
|
11
|
+
*
|
|
12
|
+
* Fidelity scope (MVP):
|
|
13
|
+
* - Values + formulas (cell.value / cell.formula)
|
|
14
|
+
* - Font (family, size, bold, italic, underline, color)
|
|
15
|
+
* - Fill (solid background)
|
|
16
|
+
* - Alignment (horizontal, vertical, wrap)
|
|
17
|
+
* - Number format
|
|
18
|
+
* - Borders (thin, per side, color preserved)
|
|
19
|
+
* - Merges
|
|
20
|
+
* - Sheet order + names
|
|
21
|
+
*
|
|
22
|
+
* Accepts loss: charts, drawings, pivots, validation, conditional formatting,
|
|
23
|
+
* data tables, comments, hyperlinks, advanced borders (dashed/double), themes.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Workbook data ready to mount. Stage 5 of the pipeline folded
|
|
27
|
+
* hyperlinks into `cell.p.body.customRanges` inline, so no more
|
|
28
|
+
* `__pendingHyperlinks` side-channel — the snapshot is self-contained.
|
|
29
|
+
*/
|
|
30
|
+
type ImportedWorkbook = IWorkbookData;
|
|
31
|
+
declare function xlsxToWorkbookData(buffer: ArrayBuffer): Promise<ImportedWorkbook>;
|
|
32
|
+
|
|
33
|
+
declare function excelStyleToUniver(cell: ExcelJS.Cell): IStyleData | undefined;
|
|
34
|
+
declare function univerStyleToExcel(style: IStyleData): Partial<ExcelJS.Style>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Name of a hidden worksheet we use to stash JSON we can't represent
|
|
38
|
+
* natively in xlsx (Univer plugin state — e.g. table definitions, outline
|
|
39
|
+
* groups). On open we recognize and consume it, never showing it to the
|
|
40
|
+
* user. Defined in its own module so both the parser worker and the
|
|
41
|
+
* exporter worker can import it without dragging the other one's
|
|
42
|
+
* ExcelJS code into their bundle.
|
|
43
|
+
*/
|
|
44
|
+
declare const RESOURCES_SHEET = "__casual_sheets_resources__";
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* xlsx-native `cell.note` ⇄ Univer `thread-comment` resource bridge.
|
|
48
|
+
*
|
|
49
|
+
* Comments in xlsx live on the cell itself (`xl/comments<N>.xml`).
|
|
50
|
+
* Univer's thread-comment plugin stores them in a workbook-level
|
|
51
|
+
* resource keyed by sheet id under the name below — same
|
|
52
|
+
* registration pattern as defined-names. Each side of the round-trip
|
|
53
|
+
* has to translate to the shape the other one expects:
|
|
54
|
+
*
|
|
55
|
+
* xlsx cell.note (string | { texts: [{ text }] })
|
|
56
|
+
* ⇅
|
|
57
|
+
* { dataStream: "<text>\r\n" } (Univer IDocumentBody minimal form)
|
|
58
|
+
*
|
|
59
|
+
* Why this exists separately from the parser/exporter modules:
|
|
60
|
+
* 1. Two-sided code lives next to itself so the inverse stays
|
|
61
|
+
* obvious. The audit test fails the moment one side drifts.
|
|
62
|
+
* 2. The `IThreadComment` row builder is non-trivial and reused
|
|
63
|
+
* verbatim on both sides — extracting it keeps parse-impl and
|
|
64
|
+
* export-impl from carrying near-duplicate shape definitions.
|
|
65
|
+
*/
|
|
66
|
+
declare const THREAD_COMMENT_RESOURCE = "SHEET_UNIVER_THREAD_COMMENT_PLUGIN";
|
|
67
|
+
type SynthComment = {
|
|
68
|
+
id: string;
|
|
69
|
+
threadId: string;
|
|
70
|
+
ref: string;
|
|
71
|
+
dT: string;
|
|
72
|
+
personId: string;
|
|
73
|
+
text: {
|
|
74
|
+
dataStream: string;
|
|
75
|
+
};
|
|
76
|
+
unitId: string;
|
|
77
|
+
subUnitId: string;
|
|
78
|
+
children?: never[];
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Walk every worksheet and collect xlsx-native `cell.note` entries
|
|
82
|
+
* into a Univer thread-comment resource payload. The synthesised IDs
|
|
83
|
+
* and dates aren't stable — re-opening the same file produces new
|
|
84
|
+
* ones — which is fine for the use cases we care about (comments
|
|
85
|
+
* survive the round-trip; nobody is referring to them by id).
|
|
86
|
+
*/
|
|
87
|
+
declare function readCommentsFromXlsx(wb: ExcelJS__default.Workbook, unitId: string, sheetIdForExcel: (excelId: number) => string): Record<string, SynthComment[]>;
|
|
88
|
+
/**
|
|
89
|
+
* Merge a synthesised comment payload into the workbook's `resources`
|
|
90
|
+
* array. Skipped when the workbook already carries a thread-comment
|
|
91
|
+
* resource from our hidden sidecar (`__casual_sheets_resources__`) —
|
|
92
|
+
* that one has the full plugin shape; we shouldn't clobber it with a
|
|
93
|
+
* lossy xlsx-native re-derivation.
|
|
94
|
+
*/
|
|
95
|
+
declare function mergeCommentsIntoResources(resources: IWorkbookData['resources'], comments: Record<string, SynthComment[]>): IWorkbookData['resources'];
|
|
96
|
+
/**
|
|
97
|
+
* Read the thread-comment resource off a snapshot. Tolerant of older
|
|
98
|
+
* / missing / malformed payloads — those cases return `{}` so the
|
|
99
|
+
* exporter just skips writing notes rather than throwing on save.
|
|
100
|
+
*/
|
|
101
|
+
declare function readCommentsFromSnapshot(data: IWorkbookData): Record<string, SynthComment[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Extract the plain string from a Univer comment body. Strips the
|
|
104
|
+
* trailing `\r\n` (or `\n`) that the body convention appends so the
|
|
105
|
+
* xlsx-side note doesn't show as a blank line below the text in
|
|
106
|
+
* Excel's pop-up.
|
|
107
|
+
*/
|
|
108
|
+
declare function commentBodyToString(body: SynthComment['text']): string;
|
|
109
|
+
/**
|
|
110
|
+
* Parse an "A1"-style ref back to a zero-based (row, col). Falls back
|
|
111
|
+
* to (-1, -1) on malformed input — exporter callers should skip in
|
|
112
|
+
* that case.
|
|
113
|
+
*/
|
|
114
|
+
declare function refToRowCol(ref: string): {
|
|
115
|
+
row: number;
|
|
116
|
+
column: number;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Passthrough preservation for xlsx-native page-setup chrome —
|
|
121
|
+
* orientation, paper size, margins, header/footer text. Univer
|
|
122
|
+
* doesn't model any of this; the print dialog uses a per-user
|
|
123
|
+
* localStorage slot. Without a passthrough, opening an xlsx that
|
|
124
|
+
* was authored to print landscape and saving it again silently
|
|
125
|
+
* resets to portrait.
|
|
126
|
+
*
|
|
127
|
+
* The round-trip stays inside our own resource sidecar
|
|
128
|
+
* (`__casual_sheets_page_setup__`) — the data never reaches Univer
|
|
129
|
+
* for editing; the parser stashes it on `IWorkbookData.resources`
|
|
130
|
+
* and the exporter reads it back and applies to ExcelJS's native
|
|
131
|
+
* `worksheet.pageSetup` + `worksheet.headerFooter`.
|
|
132
|
+
*
|
|
133
|
+
* If/when we add an in-app Page Setup editor, this resource is the
|
|
134
|
+
* authoritative store — the localStorage fallback is per-user and
|
|
135
|
+
* can't survive Save → Open in another tab.
|
|
136
|
+
*/
|
|
137
|
+
declare const PAGE_SETUP_RESOURCE = "__casual_sheets_page_setup__";
|
|
138
|
+
type SheetPageSetupV1 = {
|
|
139
|
+
orientation?: 'landscape' | 'portrait';
|
|
140
|
+
paperSize?: number;
|
|
141
|
+
fitToPage?: boolean;
|
|
142
|
+
fitToWidth?: number;
|
|
143
|
+
fitToHeight?: number;
|
|
144
|
+
scale?: number;
|
|
145
|
+
printArea?: string;
|
|
146
|
+
margins?: {
|
|
147
|
+
top?: number;
|
|
148
|
+
bottom?: number;
|
|
149
|
+
left?: number;
|
|
150
|
+
right?: number;
|
|
151
|
+
header?: number;
|
|
152
|
+
footer?: number;
|
|
153
|
+
};
|
|
154
|
+
headerFooter?: {
|
|
155
|
+
oddHeader?: string;
|
|
156
|
+
oddFooter?: string;
|
|
157
|
+
evenHeader?: string;
|
|
158
|
+
evenFooter?: string;
|
|
159
|
+
differentFirst?: boolean;
|
|
160
|
+
differentOddEven?: boolean;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Walk the xlsx worksheets and pull each one's page-setup + header
|
|
165
|
+
* /footer into a sidecar payload. Empty entries are dropped so the
|
|
166
|
+
* resource isn't written for files that didn't carry any chrome.
|
|
167
|
+
*/
|
|
168
|
+
declare function readPageSetupFromXlsx(wb: ExcelJS__default.Workbook, sheetIdForExcel: (excelId: number) => string): Record<string, SheetPageSetupV1>;
|
|
169
|
+
/** Merge a synthesised page-setup map into the snapshot resources. */
|
|
170
|
+
declare function mergePageSetupIntoResources(resources: IWorkbookData['resources'], payload: Record<string, SheetPageSetupV1>): IWorkbookData['resources'];
|
|
171
|
+
/** Read the page-setup resource off a snapshot. Tolerant of older /
|
|
172
|
+
* missing / malformed payloads. */
|
|
173
|
+
declare function readPageSetupFromSnapshot(data: IWorkbookData): Record<string, SheetPageSetupV1>;
|
|
174
|
+
/** Apply a per-sheet entry onto an ExcelJS worksheet. */
|
|
175
|
+
declare function applyPageSetupToXlsxWorksheet(ws: any, entry: SheetPageSetupV1): void;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* xlsx-native `worksheet.dataValidations` ⇄ Univer
|
|
179
|
+
* `SHEET_DATA_VALIDATION_PLUGIN` resource bridge.
|
|
180
|
+
*
|
|
181
|
+
* Data-validation rules live on the worksheet in xlsx (`xl/worksheets/
|
|
182
|
+
* sheetN.xml` `<dataValidations>` element). Univer's data-validation
|
|
183
|
+
* plugin keeps them in a resource keyed by sheet id under the name
|
|
184
|
+
* below — same registration pattern as defined-names and
|
|
185
|
+
* thread-comments. We mirror in both directions so:
|
|
186
|
+
*
|
|
187
|
+
* - a file authored in real Excel keeps its list / whole / date /
|
|
188
|
+
* decimal constraints when opened here (parser fall-back)
|
|
189
|
+
* - our save round-trip preserves the rule even when the exporter
|
|
190
|
+
* is called without the live `extras` from the running app — eg.
|
|
191
|
+
* the audit harness drives `parse → snapshot → export` only.
|
|
192
|
+
*
|
|
193
|
+
* Resource name matches Univer's plugin (`vendor/univer/packages/
|
|
194
|
+
* data-validation/src/controllers/dv-resource.controller.ts:23`) so
|
|
195
|
+
* the rules live-load into the plugin on re-open instead of just
|
|
196
|
+
* sitting in our sidecar — bonus on top of the round-trip.
|
|
197
|
+
*/
|
|
198
|
+
declare const DATA_VALIDATION_RESOURCE = "SHEET_DATA_VALIDATION_PLUGIN";
|
|
199
|
+
type SynthDvRule = {
|
|
200
|
+
uid: string;
|
|
201
|
+
type: string;
|
|
202
|
+
ranges: IRange[];
|
|
203
|
+
formula1?: string;
|
|
204
|
+
formula2?: string;
|
|
205
|
+
operator?: string;
|
|
206
|
+
allowBlank?: boolean;
|
|
207
|
+
error?: string;
|
|
208
|
+
errorTitle?: string;
|
|
209
|
+
showErrorMessage?: boolean;
|
|
210
|
+
errorStyle?: string;
|
|
211
|
+
prompt?: string;
|
|
212
|
+
promptTitle?: string;
|
|
213
|
+
showInputMessage?: boolean;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Walk every worksheet and lift its `dataValidations.model` into the
|
|
217
|
+
* synthesised plugin shape. ExcelJS stores rules keyed by a range
|
|
218
|
+
* string that may be space-separated when a single rule covers
|
|
219
|
+
* multiple ranges; we expand those into the `ranges` array.
|
|
220
|
+
*/
|
|
221
|
+
declare function readDataValidationFromXlsx(wb: ExcelJS__default.Workbook, sheetIdForExcel: (excelId: number) => string): Record<string, SynthDvRule[]>;
|
|
222
|
+
/**
|
|
223
|
+
* Merge a synthesised DV map into the workbook's `resources` array.
|
|
224
|
+
* Skipped when the workbook already carries the plugin resource (from
|
|
225
|
+
* our hidden sidecar) — that one came through Univer's model and has
|
|
226
|
+
* the full rule shape; xlsx-derived rules are a strict subset.
|
|
227
|
+
*/
|
|
228
|
+
declare function mergeDataValidationIntoResources(resources: IWorkbookData['resources'], payload: Record<string, SynthDvRule[]>): IWorkbookData['resources'];
|
|
229
|
+
/** Read the DV resource off a snapshot. Tolerant of older / missing /
|
|
230
|
+
* malformed payloads. */
|
|
231
|
+
declare function readDataValidationFromSnapshot(data: IWorkbookData): Record<string, SynthDvRule[]>;
|
|
232
|
+
/** Apply a per-sheet rule set onto an ExcelJS worksheet. */
|
|
233
|
+
declare function applyDataValidationToXlsxWorksheet(ws: any, rules: SynthDvRule[]): void;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Passthrough preservation for xlsx ListObjects (a.k.a. Excel Tables).
|
|
237
|
+
* Univer doesn't model tables as first-class objects — autofilters and
|
|
238
|
+
* structured-reference parsing aren't there yet — so without a
|
|
239
|
+
* passthrough, opening an xlsx that ships a defined table and saving
|
|
240
|
+
* it again would silently strip the table back to plain cells.
|
|
241
|
+
*
|
|
242
|
+
* Data lives in our own sidecar (`__casual_sheets_tables__`); on
|
|
243
|
+
* export we replay `ws.addTable(...)` so the saved file shows the
|
|
244
|
+
* table to any reader (real Excel, gsheets, LibreOffice).
|
|
245
|
+
*
|
|
246
|
+
* When/if Univer grows native table support, this resource is the
|
|
247
|
+
* place to switch from sidecar to plugin shape — readers of older
|
|
248
|
+
* files keep working because the sidecar is forward-compatible.
|
|
249
|
+
*/
|
|
250
|
+
declare const TABLES_RESOURCE = "__casual_sheets_tables__";
|
|
251
|
+
type SynthTableColumn = {
|
|
252
|
+
name: string;
|
|
253
|
+
filterButton?: boolean;
|
|
254
|
+
totalsRowFunction?: string;
|
|
255
|
+
totalsRowLabel?: string;
|
|
256
|
+
totalsRowFormula?: string;
|
|
257
|
+
style?: any;
|
|
258
|
+
};
|
|
259
|
+
type SynthTableV1 = {
|
|
260
|
+
name: string;
|
|
261
|
+
ref: string;
|
|
262
|
+
displayName?: string;
|
|
263
|
+
headerRow?: boolean;
|
|
264
|
+
totalsRow?: boolean;
|
|
265
|
+
style?: {
|
|
266
|
+
theme?: string;
|
|
267
|
+
name?: string;
|
|
268
|
+
showRowStripes?: boolean;
|
|
269
|
+
showColumnStripes?: boolean;
|
|
270
|
+
showFirstColumn?: boolean;
|
|
271
|
+
showLastColumn?: boolean;
|
|
272
|
+
};
|
|
273
|
+
columns: SynthTableColumn[];
|
|
274
|
+
rows: unknown[][];
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Walk every worksheet and lift any defined tables into the sidecar
|
|
278
|
+
* payload. ExcelJS stores tables on `ws.tables` keyed by table name;
|
|
279
|
+
* each value is a Table *instance* whose actual fields hang off
|
|
280
|
+
* `t.model` (`node_modules/exceljs/lib/doc/table.js:275`). Two
|
|
281
|
+
* gotchas the parser must handle:
|
|
282
|
+
*
|
|
283
|
+
* 1. After `xlsx.load`, the model uses `tableRef` (full range) and
|
|
284
|
+
* drops `ref` (the original top-left author hint). We coalesce
|
|
285
|
+
* onto `ref` as a single canonical full-range string.
|
|
286
|
+
* 2. The loaded model never carries `rows` — table cell data is
|
|
287
|
+
* already on the worksheet. We don't need rows to round-trip.
|
|
288
|
+
*/
|
|
289
|
+
declare function readTablesFromXlsx(wb: ExcelJS__default.Workbook, sheetIdForExcel: (excelId: number) => string): Record<string, SynthTableV1[]>;
|
|
290
|
+
/** Merge a synthesised table map into the snapshot resources. */
|
|
291
|
+
declare function mergeTablesIntoResources(resources: IWorkbookData['resources'], payload: Record<string, SynthTableV1[]>): IWorkbookData['resources'];
|
|
292
|
+
/** Read the tables resource off a snapshot. */
|
|
293
|
+
declare function readTablesFromSnapshot(data: IWorkbookData): Record<string, SynthTableV1[]>;
|
|
294
|
+
/**
|
|
295
|
+
* Apply a per-sheet table set onto an ExcelJS worksheet.
|
|
296
|
+
*
|
|
297
|
+
* Why this bypasses `ws.addTable(...)`:
|
|
298
|
+
*
|
|
299
|
+
* `Table.validate()` (`node_modules/exceljs/lib/doc/table.js:129`)
|
|
300
|
+
* throws when `table.rows` is missing — but our round-trip case
|
|
301
|
+
* doesn't carry rows (cell data already lives in `cellData`). And
|
|
302
|
+
* `Table.store()` would *re-write* every cell from the rows
|
|
303
|
+
* array, clobbering whatever the user had set after the table was
|
|
304
|
+
* created. So instead of going through `addTable`, we attach the
|
|
305
|
+
* load-shape model directly the same way ExcelJS's worksheet xform
|
|
306
|
+
* setter does on load (`node_modules/exceljs/lib/doc/worksheet.js:
|
|
307
|
+
* 917`). The serializer then walks `Object.values(ws.tables).map(t
|
|
308
|
+
* => t.model)` (`worksheet.js:856`) and writes the table parts —
|
|
309
|
+
* `target` + `id` are filled in by `xlsx.js:632` during prepare.
|
|
310
|
+
*/
|
|
311
|
+
declare function applyTablesToXlsxWorksheet(ws: any, tables: SynthTableV1[]): void;
|
|
312
|
+
|
|
313
|
+
type PivotPassthroughPayload = {
|
|
314
|
+
/** Every captured part — pivotCaches/**, pivotTables/**, and any
|
|
315
|
+
* per-part `.rels` files — keyed by zip path; base64 contents. */
|
|
316
|
+
parts: Record<string, string>;
|
|
317
|
+
/** The raw `<pivotCaches>…</pivotCaches>` block extracted from
|
|
318
|
+
* `xl/workbook.xml` at parse time. The `r:id` refs inside get
|
|
319
|
+
* remapped at inject time. */
|
|
320
|
+
workbookPivotCachesXml: string;
|
|
321
|
+
/** Workbook-level pivotCacheDefinition relationships. `origId` is
|
|
322
|
+
* the captured rId — used to remap the `r:id` references inside
|
|
323
|
+
* `workbookPivotCachesXml`. */
|
|
324
|
+
workbookCacheRels: Array<{
|
|
325
|
+
origId: string;
|
|
326
|
+
target: string;
|
|
327
|
+
}>;
|
|
328
|
+
/** Pivot tables, grouped by the sheet they belong to. Sheets are
|
|
329
|
+
* identified by NAME (not rId) because ExcelJS may reorder files. */
|
|
330
|
+
perSheet: Array<{
|
|
331
|
+
sheetName: string;
|
|
332
|
+
/** sheet's pivotTable rels. `origId` is the captured rId in the
|
|
333
|
+
* ORIGINAL sheet rels file; we assign fresh rIds at inject time. */
|
|
334
|
+
pivotTableRels: Array<{
|
|
335
|
+
origId: string;
|
|
336
|
+
target: string;
|
|
337
|
+
}>;
|
|
338
|
+
}>;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Sidecar resource that carries raw OOXML parts ExcelJS silently drops.
|
|
343
|
+
*
|
|
344
|
+
* Today we passthrough:
|
|
345
|
+
* - `xl/vbaProject.bin` — `.xlsm` macros round-trip byte-equal.
|
|
346
|
+
* - `xl/pivotCaches/**` + `xl/pivotTables/**` — pivot definitions
|
|
347
|
+
* survive a round-trip so Excel still sees the file as having
|
|
348
|
+
* pivot tables (the materialised cells already survive via the
|
|
349
|
+
* normal cell pipeline; this re-instates the metadata Excel
|
|
350
|
+
* needs to render filter dropdowns, refresh, etc).
|
|
351
|
+
*
|
|
352
|
+
* We never execute VBA. The pivot OOXML is treated as opaque bytes —
|
|
353
|
+
* Univer doesn't render pivots from the OOXML, only the cells; this
|
|
354
|
+
* preserves the metadata for Excel's benefit.
|
|
355
|
+
*/
|
|
356
|
+
declare const XLSX_PASSTHROUGH_RESOURCE = "__casual_sheets_xlsx_passthrough__";
|
|
357
|
+
type XlsxPassthroughPayload = {
|
|
358
|
+
/** base64-encoded contents of xl/vbaProject.bin */
|
|
359
|
+
vba?: {
|
|
360
|
+
binBase64: string;
|
|
361
|
+
};
|
|
362
|
+
/** raw OOXML pivot machinery — see pivot-passthrough.ts */
|
|
363
|
+
pivots?: PivotPassthroughPayload;
|
|
364
|
+
};
|
|
365
|
+
declare const XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
366
|
+
declare const XLSM_MIME = "application/vnd.ms-excel.sheet.macroEnabled.12";
|
|
367
|
+
declare function mimeForPassthrough(payload: XlsxPassthroughPayload | undefined): string;
|
|
368
|
+
declare function extensionForPassthrough(payload: XlsxPassthroughPayload | undefined): 'xlsx' | 'xlsm';
|
|
369
|
+
declare function capturePassthroughFromBuffer(buffer: ArrayBuffer): Promise<XlsxPassthroughPayload | undefined>;
|
|
370
|
+
declare function mergePassthroughIntoResources(resources: IWorkbookData['resources'], payload: XlsxPassthroughPayload | undefined): IWorkbookData['resources'];
|
|
371
|
+
declare function readPassthroughFromSnapshot(data: IWorkbookData): XlsxPassthroughPayload | undefined;
|
|
372
|
+
/**
|
|
373
|
+
* Re-inject every captured OOXML payload into the ExcelJS-written
|
|
374
|
+
* buffer in one pass. VBA + pivots share a single JSZip session so
|
|
375
|
+
* the [Content_Types].xml + workbook.xml.rels patches compose cleanly
|
|
376
|
+
* (each patch sees the previous step's writes).
|
|
377
|
+
*
|
|
378
|
+
* The input buffer is read but not mutated; a fresh ArrayBuffer is
|
|
379
|
+
* returned. No-op when the payload is empty.
|
|
380
|
+
*/
|
|
381
|
+
declare function applyPassthroughToXlsxBuffer(excelJsBuffer: ArrayBuffer | Uint8Array, payload: XlsxPassthroughPayload | undefined): Promise<ArrayBuffer>;
|
|
382
|
+
|
|
383
|
+
export { DATA_VALIDATION_RESOURCE, type ImportedWorkbook, PAGE_SETUP_RESOURCE, RESOURCES_SHEET, type SheetPageSetupV1, type SynthComment, type SynthDvRule, type SynthTableColumn, type SynthTableV1, TABLES_RESOURCE, THREAD_COMMENT_RESOURCE, XLSM_MIME, XLSX_MIME, XLSX_PASSTHROUGH_RESOURCE, type XlsxPassthroughPayload, applyDataValidationToXlsxWorksheet, applyPageSetupToXlsxWorksheet, applyPassthroughToXlsxBuffer, applyTablesToXlsxWorksheet, capturePassthroughFromBuffer, commentBodyToString, excelStyleToUniver, extensionForPassthrough, mergeCommentsIntoResources, mergeDataValidationIntoResources, mergePageSetupIntoResources, mergePassthroughIntoResources, mergeTablesIntoResources, mimeForPassthrough, readCommentsFromSnapshot, readCommentsFromXlsx, readDataValidationFromSnapshot, readDataValidationFromXlsx, readPageSetupFromSnapshot, readPageSetupFromXlsx, readPassthroughFromSnapshot, readTablesFromSnapshot, readTablesFromXlsx, refToRowCol, univerStyleToExcel, xlsxToWorkbookData };
|