@rosperitus/excelerate-reader 0.12.0 → 0.13.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
@@ -5,8 +5,8 @@ Gnumeric and SpreadsheetML 2003 - and read how their cells are painted. Rust
5
5
  compiled to WebAssembly, no native module to build and nothing to install
6
6
  alongside it.
7
7
 
8
- This is the reading half of [excelerate](https://www.npmjs.com/package/excelerate).
9
- The full package also writes files back out and carries a 443-function formula
8
+ This is the reading half of [excelerate](https://www.npmjs.com/package/@rosperitus/excelerate).
9
+ The full package also writes files back out and carries a 518-function formula
10
10
  engine; if you need either, use that one. Here they are not compiled in at all,
11
11
  which is the point: a reader that cannot write cannot be made to write, and the
12
12
  binary is the smaller for it.
@@ -56,8 +56,9 @@ book.sheetVisibility(0); // "visible" | "hidden" | "veryHidden"
56
56
  call takes is the sheet's position in the workbook, and skipping the hidden
57
57
  ones would shift it.
58
58
 
59
- `usedRangeHint` answers the same question as `usedRange` without walking the
60
- cells - it repeats what the file says about its own shape - and `columnWidth`
59
+ `usedRangeHint` answers the same question as `usedRange` without ever walking
60
+ the rows (`usedRange` walks them only after a cell in an edge column was
61
+ removed, and the hint may then be wider), and `columnWidth`
61
62
  and `rowHeight` come back `undefined` where the sheet leaves them to the
62
63
  default.
63
64
 
@@ -108,6 +109,11 @@ for you - an indexed colour needs the palette of the file it came from, and a
108
109
  theme colour needs the workbook theme, which the reader keeps but does not
109
110
  interpret.
110
111
 
112
+ For a block of cells, `getRangeStyles(sheet, "A1:H40")` answers `{ styles,
113
+ grid }`: each distinct style once and a grid of indexes into them, which is
114
+ one crossing instead of a `cellStyle` per cell. `cellStyleAt` and
115
+ `getRangeStylesAt` take 1-based numbers instead of an address.
116
+
111
117
  ## Formulas
112
118
 
113
119
  A formula's **text** is here (`getFormula`), and so is the value the file was
@@ -126,6 +132,10 @@ package may unpack, which is what stops a zip bomb. It defaults to 512 MB; a
126
132
  real workbook can outgrow that - a 100 MB package unpacking to 560 MB is not
127
133
  unusual - so raise it when you know where the file came from.
128
134
 
135
+ A callback as the fourth argument hears about each sheet as it is read:
136
+ `{ stage, done, total, what, fraction }`, with `total` `null` until the
137
+ workbook part says how many sheets there are.
138
+
129
139
  ## What is not here
130
140
 
131
141
  Writing, in any format - including painting a cell, writing a note, a link or
package/excelerate.d.ts CHANGED
@@ -156,6 +156,14 @@ export interface CellStyle {
156
156
  textRotation: number;
157
157
  };
158
158
  }
159
+ /**
160
+ * The styles of a rectangle, as `getRangeStyles` returns them: each distinct
161
+ * style once in `styles`, and `grid` - row by row - pointing into it.
162
+ */
163
+ export interface RangeStyles {
164
+ styles: CellStyle[];
165
+ grid: number[][];
166
+ }
159
167
 
160
168
 
161
169
 
@@ -270,19 +278,13 @@ export class Book {
270
278
  * them. A path is `undefined` where the file does not name one.
271
279
  */
272
280
  externalBooks(): any[];
273
- /**
274
- * Reads an xlsx package from its bytes.
275
- */
276
- static fromXlsx(bytes: Uint8Array): Book;
277
281
  /**
278
282
  * The value at `address` on sheet `sheet`, as a JS number, string, boolean
279
283
  * or `null`. A formula cell gives its cached result, not its text.
280
284
  */
281
285
  get(sheet: number, address: string): CellValue;
282
286
  /**
283
- * The same by 1-based row and column, the numbers `ROW()` and `COLUMN()`
284
- * return: `getAt(0, 4, 2)` is `B4`. Saves formatting an address only to
285
- * parse it again.
287
+ * The same by 1-based row and column.
286
288
  */
287
289
  getAt(sheet: number, row: number, column: number): CellValue;
288
290
  /**
@@ -313,6 +315,17 @@ export class Book {
313
315
  * to take. `getRangeAt(0, 1, 1, 3, 2)` is `A1:B3`.
314
316
  */
315
317
  getRangeAt(sheet: number, row: number, column: number, rows: number, columns: number): CellGrid;
318
+ /**
319
+ * The styles of a rectangle in one call: each distinct style once, and a
320
+ * grid of indexes into them. `cellStyle` per cell costs a crossing and a
321
+ * whole style object per cell; a formatted table of ten thousand cells
322
+ * usually has a dozen styles.
323
+ */
324
+ getRangeStyles(sheet: number, range: string): RangeStyles;
325
+ /**
326
+ * The same by numbers, as `getRangeAt` takes them.
327
+ */
328
+ getRangeStylesAt(sheet: number, row: number, column: number, rows: number, columns: number): RangeStyles;
316
329
  /**
317
330
  * A whole row in one crossing of the boundary: values, displayed text,
318
331
  * bold and indent, plus whether the row is hidden.
@@ -403,7 +416,7 @@ export class Book {
403
416
  * Writes a value: a number, boolean, or string. A string starting with `=`
404
417
  * becomes a formula.
405
418
  */
406
- set(index: number, address: string, value: CellValue): void;
419
+ set(sheet: number, address: string, value: CellValue): void;
407
420
  /**
408
421
  * Sets that tab.
409
422
  */
@@ -460,12 +473,12 @@ export class Book {
460
473
  */
461
474
  usedRange(sheet: number): string | undefined;
462
475
  /**
463
- * The used range of a sheet as `"A1:D20"`, taken from what the file says
464
- * rather than from walking the cells; `undefined` when it says nothing.
476
+ * The used range of a sheet as `"A1:D20"` without walking the rows;
477
+ * `undefined` for an empty sheet.
465
478
  *
466
- * A reader that only needs the shape of a sheet pays nothing for it;
467
- * `usedRange` walks every cell and answers for a sheet built in memory
468
- * too, where the file has nothing to say.
479
+ * Rows are exact, columns an upper bound: removing a cell never narrows
480
+ * them. `usedRange` answers the same until a cell in an edge column is
481
+ * removed, and walks the rows after that to give the exact rectangle.
469
482
  */
470
483
  usedRangeHint(sheet: number): string | undefined;
471
484
  /**
package/excelerate.js CHANGED
@@ -304,20 +304,6 @@ class Book {
304
304
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
305
305
  return v1;
306
306
  }
307
- /**
308
- * Reads an xlsx package from its bytes.
309
- * @param {Uint8Array} bytes
310
- * @returns {Book}
311
- */
312
- static fromXlsx(bytes) {
313
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
314
- const len0 = WASM_VECTOR_LEN;
315
- const ret = wasm.book_fromXlsx(ptr0, len0);
316
- if (ret[2]) {
317
- throw takeFromExternrefTable0(ret[1]);
318
- }
319
- return Book.__wrap(ret[0]);
320
- }
321
307
  /**
322
308
  * The value at `address` on sheet `sheet`, as a JS number, string, boolean
323
309
  * or `null`. A formula cell gives its cached result, not its text.
@@ -335,9 +321,7 @@ class Book {
335
321
  return takeFromExternrefTable0(ret[0]);
336
322
  }
337
323
  /**
338
- * The same by 1-based row and column, the numbers `ROW()` and `COLUMN()`
339
- * return: `getAt(0, 4, 2)` is `B4`. Saves formatting an address only to
340
- * parse it again.
324
+ * The same by 1-based row and column.
341
325
  * @param {number} sheet
342
326
  * @param {number} row
343
327
  * @param {number} column
@@ -469,6 +453,40 @@ class Book {
469
453
  }
470
454
  return takeFromExternrefTable0(ret[0]);
471
455
  }
456
+ /**
457
+ * The styles of a rectangle in one call: each distinct style once, and a
458
+ * grid of indexes into them. `cellStyle` per cell costs a crossing and a
459
+ * whole style object per cell; a formatted table of ten thousand cells
460
+ * usually has a dozen styles.
461
+ * @param {number} sheet
462
+ * @param {string} range
463
+ * @returns {RangeStyles}
464
+ */
465
+ getRangeStyles(sheet, range) {
466
+ const ptr0 = passStringToWasm0(range, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
467
+ const len0 = WASM_VECTOR_LEN;
468
+ const ret = wasm.book_getRangeStyles(this.__wbg_ptr, sheet, ptr0, len0);
469
+ if (ret[2]) {
470
+ throw takeFromExternrefTable0(ret[1]);
471
+ }
472
+ return takeFromExternrefTable0(ret[0]);
473
+ }
474
+ /**
475
+ * The same by numbers, as `getRangeAt` takes them.
476
+ * @param {number} sheet
477
+ * @param {number} row
478
+ * @param {number} column
479
+ * @param {number} rows
480
+ * @param {number} columns
481
+ * @returns {RangeStyles}
482
+ */
483
+ getRangeStylesAt(sheet, row, column, rows, columns) {
484
+ const ret = wasm.book_getRangeStylesAt(this.__wbg_ptr, sheet, row, column, rows, columns);
485
+ if (ret[2]) {
486
+ throw takeFromExternrefTable0(ret[1]);
487
+ }
488
+ return takeFromExternrefTable0(ret[0]);
489
+ }
472
490
  /**
473
491
  * A whole row in one crossing of the boundary: values, displayed text,
474
492
  * bold and indent, plus whether the row is hidden.
@@ -688,14 +706,14 @@ class Book {
688
706
  /**
689
707
  * Writes a value: a number, boolean, or string. A string starting with `=`
690
708
  * becomes a formula.
691
- * @param {number} index
709
+ * @param {number} sheet
692
710
  * @param {string} address
693
711
  * @param {CellValue} value
694
712
  */
695
- set(index, address, value) {
713
+ set(sheet, address, value) {
696
714
  const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
697
715
  const len0 = WASM_VECTOR_LEN;
698
- const ret = wasm.book_set(this.__wbg_ptr, index, ptr0, len0, value);
716
+ const ret = wasm.book_set(this.__wbg_ptr, sheet, ptr0, len0, value);
699
717
  if (ret[1]) {
700
718
  throw takeFromExternrefTable0(ret[0]);
701
719
  }
@@ -864,12 +882,12 @@ class Book {
864
882
  return v1;
865
883
  }
866
884
  /**
867
- * The used range of a sheet as `"A1:D20"`, taken from what the file says
868
- * rather than from walking the cells; `undefined` when it says nothing.
885
+ * The used range of a sheet as `"A1:D20"` without walking the rows;
886
+ * `undefined` for an empty sheet.
869
887
  *
870
- * A reader that only needs the shape of a sheet pays nothing for it;
871
- * `usedRange` walks every cell and answers for a sheet built in memory
872
- * too, where the file has nothing to say.
888
+ * Rows are exact, columns an upper bound: removing a cell never narrows
889
+ * them. `usedRange` answers the same until a cell in an edge column is
890
+ * removed, and walks the rows after that to give the exact rectangle.
873
891
  * @param {number} sheet
874
892
  * @returns {string | undefined}
875
893
  */
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
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.12.0",
4
+ "version": "0.13.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",