@rosperitus/excelerate-reader 0.13.0 → 0.15.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
@@ -38,6 +38,44 @@ book.getRowAt(0, 3, false); // the same without the displayed text, which is
38
38
  // a string per cell nobody asked for
39
39
  ```
40
40
 
41
+ ## In the browser
42
+
43
+ The package carries a second build for browsers and bundlers, and the same
44
+ import picks it there. The module has to be started first, which fetches the
45
+ `.wasm`; the rest is the same as in Node:
46
+
47
+ ```js
48
+ import init, { Book } from "@rosperitus/excelerate-reader";
49
+
50
+ await init();
51
+ const book = Book.read(new Uint8Array(await file.arrayBuffer()), file.name);
52
+ ```
53
+
54
+ The server should send the `.wasm` as `application/wasm`. Without a bundler,
55
+ an import map pointing at `@rosperitus/excelerate-reader/web/excelerate.js` does the same.
56
+
57
+ ## Reading a big sheet without holding it
58
+
59
+ `forEachRow` reads the file and hands one sheet over row by row instead of
60
+ building its grid: each row goes to the callback and is then dropped.
61
+
62
+ ```js
63
+ const book = Book.forEachRow(bytes, "report.xlsx", 0, (row, data) => {
64
+ // data is what getRowAt returns: values, formatted, bold, indent, hidden
65
+ if (data.bold[0]) console.log(row, data.values[0]);
66
+ }, false); // false: skip the displayed text, a string per cell
67
+
68
+ book.sheetNames(); // the workbook still comes back - every sheet is in it,
69
+ // the streamed one with everything except its cells
70
+ ```
71
+
72
+ On a million-row file of 70 MB that is 588 MB peak and 13.9 s, against
73
+ 863 MB and 14.4 s for `read` plus `getRowAt` on every row; on 882 thousand
74
+ rows of 39 MB, 344 MB and 7.1 s against 547 MB and 8.4 s. A callback that
75
+ throws is not called again, and its error comes out of `forEachRow`. Only
76
+ xlsx streams; any other format is read whole first and then handed over the
77
+ same way, so the callback sees the same rows but nothing is saved.
78
+
41
79
  ## Layout
42
80
 
43
81
  Reading a sheet usually means asking the same few things of every row, so each
package/excelerate.d.ts CHANGED
@@ -32,6 +32,33 @@ export interface SheetViewInfo {
32
32
  rightToLeft: boolean;
33
33
  topLeftCell: string | null;
34
34
  }
35
+ /** One of the user's own document properties. */
36
+ export interface CustomProperty {
37
+ name: string;
38
+ type: "text" | "integer" | "number" | "boolean" | "date";
39
+ value: string | number | boolean;
40
+ }
41
+ /** Title, author, dates and the user's fields, as `documentProperties` returns them. Dates are ISO 8601. */
42
+ export interface DocumentProperties {
43
+ title: string | null;
44
+ subject: string | null;
45
+ creator: string | null;
46
+ keywords: string | null;
47
+ description: string | null;
48
+ lastModifiedBy: string | null;
49
+ category: string | null;
50
+ contentStatus: string | null;
51
+ language: string | null;
52
+ identifier: string | null;
53
+ revision: string | null;
54
+ version: string | null;
55
+ created: string | null;
56
+ modified: string | null;
57
+ lastPrinted: string | null;
58
+ company: string | null;
59
+ manager: string | null;
60
+ custom: CustomProperty[];
61
+ }
35
62
  /** A name that stands for a formula, as `definedNames` returns it. */
36
63
  export interface WorkbookName {
37
64
  name: string;
@@ -57,7 +84,7 @@ export interface SheetConditionalFormat {
57
84
  /** The autofilter over a range, as `autoFilter` returns it. */
58
85
  export interface SheetAutoFilter {
59
86
  range: string;
60
- columns: { colId: number; kind: "values" | "custom" | "dynamic" | "top10" | "none" }[];
87
+ columns: { colId: number; kind: "values" | "custom" | "dynamic" | "top10" | "color" | "icon" | "none" }[];
61
88
  }
62
89
  /** A pivot report on the sheet, as `pivotTables` returns it. */
63
90
  export interface SheetPivotTable {
@@ -102,6 +129,10 @@ export interface SheetChart {
102
129
  kinds: string[];
103
130
  seriesCount: number;
104
131
  anchor: ObjectAnchor;
132
+ /** The chart area's fill and outline; `null` leaves them to the chart style. */
133
+ format: DrawingFormat | null;
134
+ /** The plot area's, the same way. */
135
+ plotFormat: DrawingFormat | null;
105
136
  }
106
137
  /** A picture on the sheet, as `images` returns it. Bytes come from `imageData`. */
107
138
  export interface SheetImage {
@@ -118,6 +149,45 @@ export interface SheetShape {
118
149
  geometry: string | null;
119
150
  text: string;
120
151
  anchor: ObjectAnchor;
152
+ /** Degrees clockwise about the centre. */
153
+ rotation: number;
154
+ /** Mirrored left to right, before it is turned. */
155
+ flipH: boolean;
156
+ /** Mirrored top to bottom, before it is turned. */
157
+ flipV: boolean;
158
+ /** What Excel fills it with: its own, else its style's. */
159
+ fill: DrawingFill;
160
+ /** Its outline, the same way. */
161
+ line: DrawingLine;
162
+ /** The font of its text as the first run states it, the colour from the style if not. */
163
+ font: RunFont;
164
+ }
165
+ /**
166
+ * A colour of a drawing, resolved through the workbook theme to `#AARRGGBB` (`FF` for opaque);
167
+ * `null` for one no theme defines.
168
+ */
169
+ export type DrawingColor = string | null;
170
+ /** How a drawing object or chart area is filled. `position` is in percent, `angle` in degrees. */
171
+ export type DrawingFill =
172
+ | { type: "none" }
173
+ | { type: "solid"; color: DrawingColor }
174
+ | {
175
+ type: "gradient";
176
+ stops: { position: number; color: DrawingColor }[];
177
+ angle: number | null;
178
+ path: "shape" | "circle" | "rect" | null;
179
+ }
180
+ | { type: "pattern"; preset: string | null; foreground: DrawingColor; background: DrawingColor }
181
+ | { type: "other" };
182
+ /** An outline: `fill` is `null` and `width` (points) is `null` where the file is silent. */
183
+ export interface DrawingLine {
184
+ fill: DrawingFill | null;
185
+ width: number | null;
186
+ }
187
+ /** The fill and outline an element states; `null` in either leaves it to the style. */
188
+ export interface DrawingFormat {
189
+ fill: DrawingFill | null;
190
+ line: DrawingLine | null;
121
191
  }
122
192
  /**
123
193
  * A colour as the file states it: `null` when the file leaves it to the
@@ -126,6 +196,22 @@ export interface SheetShape {
126
196
  * a theme colour carries its tint as `theme:4@-0.25`.
127
197
  */
128
198
  export type StyleColor = string | null;
199
+ /**
200
+ * What a run of formatted text changes about the cell's font; a field left
201
+ * out is the cell's own. `size` in points.
202
+ */
203
+ export interface RunFont {
204
+ name?: string;
205
+ size?: number;
206
+ bold?: boolean;
207
+ italic?: boolean;
208
+ underline?: string;
209
+ strike?: boolean;
210
+ color?: StyleColor;
211
+ script?: "superscript" | "subscript" | "baseline";
212
+ }
213
+ /** One run of formatted text, as `getRichText` returns it. */
214
+ export interface TextRun { text: string; font?: RunFont | null }
129
215
  /** One side of a cell's border. */
130
216
  export interface BorderSide { style: string; color: StyleColor }
131
217
  /** How a cell is painted, as `cellStyle` returns it. */
@@ -273,11 +359,30 @@ export class Book {
273
359
  * for. `sheet` is set on a name local to one sheet.
274
360
  */
275
361
  definedNames(): WorkbookName[];
362
+ /**
363
+ * What Excel shows under File > Info: every text field is a string or
364
+ * `null`, dates in ISO 8601. `custom` lists the user's own fields with
365
+ * their type: `text`, `integer`, `number`, `boolean` or `date`.
366
+ */
367
+ documentProperties(): DocumentProperties;
276
368
  /**
277
369
  * The other workbooks this one reads, in the order `[1]Sheet1!A1` counts
278
370
  * them. A path is `undefined` where the file does not name one.
279
371
  */
280
372
  externalBooks(): any[];
373
+ /**
374
+ * Reads a workbook and hands sheet `sheet` over row by row, without
375
+ * building its grid: `callback(row, data)` gets the 1-based row number
376
+ * and what `getRowAt` would answer for it, and the row is dropped once
377
+ * the callback returns.
378
+ *
379
+ * The workbook comes back whole but for that sheet's cells. Only xlsx
380
+ * streams; any other format is read whole and then handed over the same
381
+ * way, so the callback sees the same rows but nothing is saved.
382
+ * A callback that throws is not called again, and what it threw comes
383
+ * out of `forEachRow` once the read is over.
384
+ */
385
+ static forEachRow(bytes: Uint8Array, name: string | null | undefined, sheet: number, callback: Function, formatted?: boolean | null): Book;
281
386
  /**
282
387
  * The value at `address` on sheet `sheet`, as a JS number, string, boolean
283
388
  * or `null`. A formula cell gives its cached result, not its text.
@@ -326,6 +431,16 @@ export class Book {
326
431
  * The same by numbers, as `getRangeAt` takes them.
327
432
  */
328
433
  getRangeStylesAt(sheet: number, row: number, column: number, rows: number, columns: number): RangeStyles;
434
+ /**
435
+ * The runs of a cell's formatted text: `{ text, font }` each, `font`
436
+ * naming only what the run changes about the cell's font, or `null` for
437
+ * a run in the cell's own. `null` for a cell without formatted text.
438
+ */
439
+ getRichText(sheet: number, address: string): TextRun[] | null;
440
+ /**
441
+ * The same by 1-based row and column.
442
+ */
443
+ getRichTextAt(sheet: number, row: number, column: number): TextRun[] | null;
329
444
  /**
330
445
  * A whole row in one crossing of the boundary: values, displayed text,
331
446
  * bold and indent, plus whether the row is hidden.
@@ -382,9 +497,11 @@ export class Book {
382
497
  *
383
498
  * `name` is the file name they came from, if the caller has one: it
384
499
  * settles what the bytes cannot say (a `.csv` against a `.html`) and names
385
- * the sheet of a SYLK file.
500
+ * the sheet of a SYLK file. `password` opens a workbook saved with a
501
+ * password to open; without it only one encrypted to be opened
502
+ * read-only reads.
386
503
  */
387
- static read(bytes: Uint8Array, name?: string | null, max_expanded?: number | null, on_progress?: Function | null): Book;
504
+ static read(bytes: Uint8Array, name?: string | null, max_expanded?: number | null, on_progress?: Function | null, password?: string | null): Book;
388
505
  /**
389
506
  * Reads CSV with the guesses overridden: the delimiter, whether a row
390
507
  * that produced no cell is skipped, whether an empty field becomes an
@@ -435,7 +552,9 @@ export class Book {
435
552
  */
436
553
  setRangeAt(sheet: number, row: number, column: number, values: CellGrid): void;
437
554
  /**
438
- * The drawn shapes of a sheet, text and all.
555
+ * The drawn shapes of a sheet, text and all, with the look Excel shows:
556
+ * fill, outline and font are the shape's own with its style filling in
557
+ * the rest, colours resolved through the workbook theme.
439
558
  */
440
559
  shapes(sheet: number): SheetShape[];
441
560
  /**
package/excelerate.js CHANGED
@@ -293,6 +293,16 @@ class Book {
293
293
  const ret = wasm.book_definedNames(this.__wbg_ptr);
294
294
  return ret;
295
295
  }
296
+ /**
297
+ * What Excel shows under File > Info: every text field is a string or
298
+ * `null`, dates in ISO 8601. `custom` lists the user's own fields with
299
+ * their type: `text`, `integer`, `number`, `boolean` or `date`.
300
+ * @returns {DocumentProperties}
301
+ */
302
+ documentProperties() {
303
+ const ret = wasm.book_documentProperties(this.__wbg_ptr);
304
+ return ret;
305
+ }
296
306
  /**
297
307
  * The other workbooks this one reads, in the order `[1]Sheet1!A1` counts
298
308
  * them. A path is `undefined` where the file does not name one.
@@ -304,6 +314,35 @@ class Book {
304
314
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
305
315
  return v1;
306
316
  }
317
+ /**
318
+ * Reads a workbook and hands sheet `sheet` over row by row, without
319
+ * building its grid: `callback(row, data)` gets the 1-based row number
320
+ * and what `getRowAt` would answer for it, and the row is dropped once
321
+ * the callback returns.
322
+ *
323
+ * The workbook comes back whole but for that sheet's cells. Only xlsx
324
+ * streams; any other format is read whole and then handed over the same
325
+ * way, so the callback sees the same rows but nothing is saved.
326
+ * A callback that throws is not called again, and what it threw comes
327
+ * out of `forEachRow` once the read is over.
328
+ * @param {Uint8Array} bytes
329
+ * @param {string | null | undefined} name
330
+ * @param {number} sheet
331
+ * @param {Function} callback
332
+ * @param {boolean | null} [formatted]
333
+ * @returns {Book}
334
+ */
335
+ static forEachRow(bytes, name, sheet, callback, formatted) {
336
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
337
+ const len0 = WASM_VECTOR_LEN;
338
+ var ptr1 = isLikeNone(name) ? 0 : passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
339
+ var len1 = WASM_VECTOR_LEN;
340
+ const ret = wasm.book_forEachRow(ptr0, len0, ptr1, len1, sheet, callback, isLikeNone(formatted) ? 0xFFFFFF : formatted ? 1 : 0);
341
+ if (ret[2]) {
342
+ throw takeFromExternrefTable0(ret[1]);
343
+ }
344
+ return Book.__wrap(ret[0]);
345
+ }
307
346
  /**
308
347
  * The value at `address` on sheet `sheet`, as a JS number, string, boolean
309
348
  * or `null`. A formula cell gives its cached result, not its text.
@@ -487,6 +526,37 @@ class Book {
487
526
  }
488
527
  return takeFromExternrefTable0(ret[0]);
489
528
  }
529
+ /**
530
+ * The runs of a cell's formatted text: `{ text, font }` each, `font`
531
+ * naming only what the run changes about the cell's font, or `null` for
532
+ * a run in the cell's own. `null` for a cell without formatted text.
533
+ * @param {number} sheet
534
+ * @param {string} address
535
+ * @returns {TextRun[] | null}
536
+ */
537
+ getRichText(sheet, address) {
538
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
539
+ const len0 = WASM_VECTOR_LEN;
540
+ const ret = wasm.book_getRichText(this.__wbg_ptr, sheet, ptr0, len0);
541
+ if (ret[2]) {
542
+ throw takeFromExternrefTable0(ret[1]);
543
+ }
544
+ return takeFromExternrefTable0(ret[0]);
545
+ }
546
+ /**
547
+ * The same by 1-based row and column.
548
+ * @param {number} sheet
549
+ * @param {number} row
550
+ * @param {number} column
551
+ * @returns {TextRun[] | null}
552
+ */
553
+ getRichTextAt(sheet, row, column) {
554
+ const ret = wasm.book_getRichTextAt(this.__wbg_ptr, sheet, row, column);
555
+ if (ret[2]) {
556
+ throw takeFromExternrefTable0(ret[1]);
557
+ }
558
+ return takeFromExternrefTable0(ret[0]);
559
+ }
490
560
  /**
491
561
  * A whole row in one crossing of the boundary: values, displayed text,
492
562
  * bold and indent, plus whether the row is hidden.
@@ -611,19 +681,24 @@ class Book {
611
681
  *
612
682
  * `name` is the file name they came from, if the caller has one: it
613
683
  * settles what the bytes cannot say (a `.csv` against a `.html`) and names
614
- * the sheet of a SYLK file.
684
+ * the sheet of a SYLK file. `password` opens a workbook saved with a
685
+ * password to open; without it only one encrypted to be opened
686
+ * read-only reads.
615
687
  * @param {Uint8Array} bytes
616
688
  * @param {string | null} [name]
617
689
  * @param {number | null} [max_expanded]
618
690
  * @param {Function | null} [on_progress]
691
+ * @param {string | null} [password]
619
692
  * @returns {Book}
620
693
  */
621
- static read(bytes, name, max_expanded, on_progress) {
694
+ static read(bytes, name, max_expanded, on_progress, password) {
622
695
  const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
623
696
  const len0 = WASM_VECTOR_LEN;
624
697
  var ptr1 = isLikeNone(name) ? 0 : passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
625
698
  var len1 = WASM_VECTOR_LEN;
626
- const ret = wasm.book_read(ptr0, len0, ptr1, len1, !isLikeNone(max_expanded), isLikeNone(max_expanded) ? 0 : max_expanded, isLikeNone(on_progress) ? 0 : addToExternrefTable0(on_progress));
699
+ var ptr2 = isLikeNone(password) ? 0 : passStringToWasm0(password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
700
+ var len2 = WASM_VECTOR_LEN;
701
+ const ret = wasm.book_read(ptr0, len0, ptr1, len1, !isLikeNone(max_expanded), isLikeNone(max_expanded) ? 0 : max_expanded, isLikeNone(on_progress) ? 0 : addToExternrefTable0(on_progress), ptr2, len2);
627
702
  if (ret[2]) {
628
703
  throw takeFromExternrefTable0(ret[1]);
629
704
  }
@@ -770,7 +845,9 @@ class Book {
770
845
  }
771
846
  }
772
847
  /**
773
- * The drawn shapes of a sheet, text and all.
848
+ * The drawn shapes of a sheet, text and all, with the look Excel shows:
849
+ * fill, outline and font are the shape's own with its style filling in
850
+ * the rest, colours resolved through the workbook theme.
774
851
  * @param {number} sheet
775
852
  * @returns {SheetShape[]}
776
853
  */
@@ -972,6 +1049,10 @@ function __wbg_get_imports() {
972
1049
  __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
973
1050
  throw new Error(getStringFromWasm0(arg0, arg1));
974
1051
  },
1052
+ __wbg_call_0f2a9af232c18fd2: function() { return handleError(function (arg0, arg1, arg2, arg3) {
1053
+ const ret = arg0.call(arg1, arg2, arg3);
1054
+ return ret;
1055
+ }, arguments); },
975
1056
  __wbg_call_35dba3c747ad7521: function() { return handleError(function (arg0, arg1, arg2) {
976
1057
  const ret = arg0.call(arg1, arg2);
977
1058
  return ret;
@@ -992,6 +1073,10 @@ function __wbg_get_imports() {
992
1073
  const ret = arg0.length;
993
1074
  return ret;
994
1075
  },
1076
+ __wbg_message_c141d5e68716b595: function(arg0) {
1077
+ const ret = arg0.message;
1078
+ return ret;
1079
+ },
995
1080
  __wbg_new_116be93542d39019: function() {
996
1081
  const ret = new Array();
997
1082
  return ret;
Binary file
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@rosperitus/excelerate-reader",
3
3
  "description": "Read spreadsheets in the browser or Node: xlsx, xls, ods, csv, html, SYLK, Gnumeric and SpreadsheetML, with cell styles. Reading only.",
4
- "version": "0.13.0",
4
+ "version": "0.15.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/rosperitus/excelerate"
9
9
  },
10
10
  "files": [
11
- "excelerate_bg.wasm",
11
+ "excelerate.d.ts",
12
12
  "excelerate.js",
13
- "excelerate.d.ts"
13
+ "excelerate_bg.wasm",
14
+ "web"
14
15
  ],
15
16
  "main": "excelerate.js",
16
17
  "homepage": "https://github.com/rosperitus/excelerate",
@@ -24,5 +25,22 @@
24
25
  ],
25
26
  "publishConfig": {
26
27
  "access": "public"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "node": {
32
+ "types": "./excelerate.d.ts",
33
+ "default": "./excelerate.js"
34
+ },
35
+ "default": {
36
+ "types": "./web/excelerate.d.ts",
37
+ "default": "./web/excelerate.js"
38
+ }
39
+ },
40
+ "./web": {
41
+ "types": "./web/excelerate.d.ts",
42
+ "default": "./web/excelerate.js"
43
+ },
44
+ "./package.json": "./package.json"
27
45
  }
28
46
  }