@rosperitus/excelerate-reader 0.12.3 → 0.14.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.
@@ -109,6 +109,11 @@ for you - an indexed colour needs the palette of the file it came from, and a
109
109
  theme colour needs the workbook theme, which the reader keeps but does not
110
110
  interpret.
111
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
+
112
117
  ## Formulas
113
118
 
114
119
  A formula's **text** is here (`getFormula`), and so is the value the file was
@@ -127,6 +132,10 @@ package may unpack, which is what stops a zip bomb. It defaults to 512 MB; a
127
132
  real workbook can outgrow that - a 100 MB package unpacking to 560 MB is not
128
133
  unusual - so raise it when you know where the file came from.
129
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
+
130
139
  ## What is not here
131
140
 
132
141
  Writing, in any format - including painting a cell, writing a note, a link or
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 {
@@ -126,6 +153,22 @@ export interface SheetShape {
126
153
  * a theme colour carries its tint as `theme:4@-0.25`.
127
154
  */
128
155
  export type StyleColor = string | null;
156
+ /**
157
+ * What a run of formatted text changes about the cell's font; a field left
158
+ * out is the cell's own. `size` in points.
159
+ */
160
+ export interface RunFont {
161
+ name?: string;
162
+ size?: number;
163
+ bold?: boolean;
164
+ italic?: boolean;
165
+ underline?: string;
166
+ strike?: boolean;
167
+ color?: StyleColor;
168
+ script?: "superscript" | "subscript" | "baseline";
169
+ }
170
+ /** One run of formatted text, as `getRichText` returns it. */
171
+ export interface TextRun { text: string; font?: RunFont | null }
129
172
  /** One side of a cell's border. */
130
173
  export interface BorderSide { style: string; color: StyleColor }
131
174
  /** How a cell is painted, as `cellStyle` returns it. */
@@ -273,24 +316,24 @@ export class Book {
273
316
  * for. `sheet` is set on a name local to one sheet.
274
317
  */
275
318
  definedNames(): WorkbookName[];
319
+ /**
320
+ * What Excel shows under File > Info: every text field is a string or
321
+ * `null`, dates in ISO 8601. `custom` lists the user's own fields with
322
+ * their type: `text`, `integer`, `number`, `boolean` or `date`.
323
+ */
324
+ documentProperties(): DocumentProperties;
276
325
  /**
277
326
  * The other workbooks this one reads, in the order `[1]Sheet1!A1` counts
278
327
  * them. A path is `undefined` where the file does not name one.
279
328
  */
280
329
  externalBooks(): any[];
281
- /**
282
- * Reads an xlsx package from its bytes.
283
- */
284
- static fromXlsx(bytes: Uint8Array): Book;
285
330
  /**
286
331
  * The value at `address` on sheet `sheet`, as a JS number, string, boolean
287
332
  * or `null`. A formula cell gives its cached result, not its text.
288
333
  */
289
334
  get(sheet: number, address: string): CellValue;
290
335
  /**
291
- * The same by 1-based row and column, the numbers `ROW()` and `COLUMN()`
292
- * return: `getAt(0, 4, 2)` is `B4`. Saves formatting an address only to
293
- * parse it again.
336
+ * The same by 1-based row and column.
294
337
  */
295
338
  getAt(sheet: number, row: number, column: number): CellValue;
296
339
  /**
@@ -332,6 +375,16 @@ export class Book {
332
375
  * The same by numbers, as `getRangeAt` takes them.
333
376
  */
334
377
  getRangeStylesAt(sheet: number, row: number, column: number, rows: number, columns: number): RangeStyles;
378
+ /**
379
+ * The runs of a cell's formatted text: `{ text, font }` each, `font`
380
+ * naming only what the run changes about the cell's font, or `null` for
381
+ * a run in the cell's own. `null` for a cell without formatted text.
382
+ */
383
+ getRichText(sheet: number, address: string): TextRun[] | null;
384
+ /**
385
+ * The same by 1-based row and column.
386
+ */
387
+ getRichTextAt(sheet: number, row: number, column: number): TextRun[] | null;
335
388
  /**
336
389
  * A whole row in one crossing of the boundary: values, displayed text,
337
390
  * bold and indent, plus whether the row is hidden.
@@ -422,7 +475,7 @@ export class Book {
422
475
  * Writes a value: a number, boolean, or string. A string starting with `=`
423
476
  * becomes a formula.
424
477
  */
425
- set(index: number, address: string, value: CellValue): void;
478
+ set(sheet: number, address: string, value: CellValue): void;
426
479
  /**
427
480
  * Sets that tab.
428
481
  */
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,20 +314,6 @@ class Book {
304
314
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
305
315
  return v1;
306
316
  }
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
317
  /**
322
318
  * The value at `address` on sheet `sheet`, as a JS number, string, boolean
323
319
  * or `null`. A formula cell gives its cached result, not its text.
@@ -335,9 +331,7 @@ class Book {
335
331
  return takeFromExternrefTable0(ret[0]);
336
332
  }
337
333
  /**
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.
334
+ * The same by 1-based row and column.
341
335
  * @param {number} sheet
342
336
  * @param {number} row
343
337
  * @param {number} column
@@ -503,6 +497,37 @@ class Book {
503
497
  }
504
498
  return takeFromExternrefTable0(ret[0]);
505
499
  }
500
+ /**
501
+ * The runs of a cell's formatted text: `{ text, font }` each, `font`
502
+ * naming only what the run changes about the cell's font, or `null` for
503
+ * a run in the cell's own. `null` for a cell without formatted text.
504
+ * @param {number} sheet
505
+ * @param {string} address
506
+ * @returns {TextRun[] | null}
507
+ */
508
+ getRichText(sheet, address) {
509
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
510
+ const len0 = WASM_VECTOR_LEN;
511
+ const ret = wasm.book_getRichText(this.__wbg_ptr, sheet, ptr0, len0);
512
+ if (ret[2]) {
513
+ throw takeFromExternrefTable0(ret[1]);
514
+ }
515
+ return takeFromExternrefTable0(ret[0]);
516
+ }
517
+ /**
518
+ * The same by 1-based row and column.
519
+ * @param {number} sheet
520
+ * @param {number} row
521
+ * @param {number} column
522
+ * @returns {TextRun[] | null}
523
+ */
524
+ getRichTextAt(sheet, row, column) {
525
+ const ret = wasm.book_getRichTextAt(this.__wbg_ptr, sheet, row, column);
526
+ if (ret[2]) {
527
+ throw takeFromExternrefTable0(ret[1]);
528
+ }
529
+ return takeFromExternrefTable0(ret[0]);
530
+ }
506
531
  /**
507
532
  * A whole row in one crossing of the boundary: values, displayed text,
508
533
  * bold and indent, plus whether the row is hidden.
@@ -722,14 +747,14 @@ class Book {
722
747
  /**
723
748
  * Writes a value: a number, boolean, or string. A string starting with `=`
724
749
  * becomes a formula.
725
- * @param {number} index
750
+ * @param {number} sheet
726
751
  * @param {string} address
727
752
  * @param {CellValue} value
728
753
  */
729
- set(index, address, value) {
754
+ set(sheet, address, value) {
730
755
  const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
731
756
  const len0 = WASM_VECTOR_LEN;
732
- const ret = wasm.book_set(this.__wbg_ptr, index, ptr0, len0, value);
757
+ const ret = wasm.book_set(this.__wbg_ptr, sheet, ptr0, len0, value);
733
758
  if (ret[1]) {
734
759
  throw takeFromExternrefTable0(ret[0]);
735
760
  }
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.3",
4
+ "version": "0.14.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",