@rosperitus/excelerate-reader 0.14.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 +38 -0
- package/excelerate.d.ts +63 -3
- package/excelerate.js +48 -4
- package/excelerate_bg.wasm +0 -0
- package/package.json +21 -3
- package/web/excelerate.d.ts +724 -0
- package/web/excelerate.js +1381 -0
- package/web/excelerate_bg.wasm +0 -0
- package/web/excelerate_bg.wasm.d.ts +86 -0
- package/web/package.json +4 -0
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
|
@@ -129,6 +129,10 @@ export interface SheetChart {
|
|
|
129
129
|
kinds: string[];
|
|
130
130
|
seriesCount: number;
|
|
131
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;
|
|
132
136
|
}
|
|
133
137
|
/** A picture on the sheet, as `images` returns it. Bytes come from `imageData`. */
|
|
134
138
|
export interface SheetImage {
|
|
@@ -145,6 +149,45 @@ export interface SheetShape {
|
|
|
145
149
|
geometry: string | null;
|
|
146
150
|
text: string;
|
|
147
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;
|
|
148
191
|
}
|
|
149
192
|
/**
|
|
150
193
|
* A colour as the file states it: `null` when the file leaves it to the
|
|
@@ -327,6 +370,19 @@ export class Book {
|
|
|
327
370
|
* them. A path is `undefined` where the file does not name one.
|
|
328
371
|
*/
|
|
329
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;
|
|
330
386
|
/**
|
|
331
387
|
* The value at `address` on sheet `sheet`, as a JS number, string, boolean
|
|
332
388
|
* or `null`. A formula cell gives its cached result, not its text.
|
|
@@ -441,9 +497,11 @@ export class Book {
|
|
|
441
497
|
*
|
|
442
498
|
* `name` is the file name they came from, if the caller has one: it
|
|
443
499
|
* settles what the bytes cannot say (a `.csv` against a `.html`) and names
|
|
444
|
-
* 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.
|
|
445
503
|
*/
|
|
446
|
-
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;
|
|
447
505
|
/**
|
|
448
506
|
* Reads CSV with the guesses overridden: the delimiter, whether a row
|
|
449
507
|
* that produced no cell is skipped, whether an empty field becomes an
|
|
@@ -494,7 +552,9 @@ export class Book {
|
|
|
494
552
|
*/
|
|
495
553
|
setRangeAt(sheet: number, row: number, column: number, values: CellGrid): void;
|
|
496
554
|
/**
|
|
497
|
-
* 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.
|
|
498
558
|
*/
|
|
499
559
|
shapes(sheet: number): SheetShape[];
|
|
500
560
|
/**
|
package/excelerate.js
CHANGED
|
@@ -314,6 +314,35 @@ class Book {
|
|
|
314
314
|
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
315
315
|
return v1;
|
|
316
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
|
+
}
|
|
317
346
|
/**
|
|
318
347
|
* The value at `address` on sheet `sheet`, as a JS number, string, boolean
|
|
319
348
|
* or `null`. A formula cell gives its cached result, not its text.
|
|
@@ -652,19 +681,24 @@ class Book {
|
|
|
652
681
|
*
|
|
653
682
|
* `name` is the file name they came from, if the caller has one: it
|
|
654
683
|
* settles what the bytes cannot say (a `.csv` against a `.html`) and names
|
|
655
|
-
* 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.
|
|
656
687
|
* @param {Uint8Array} bytes
|
|
657
688
|
* @param {string | null} [name]
|
|
658
689
|
* @param {number | null} [max_expanded]
|
|
659
690
|
* @param {Function | null} [on_progress]
|
|
691
|
+
* @param {string | null} [password]
|
|
660
692
|
* @returns {Book}
|
|
661
693
|
*/
|
|
662
|
-
static read(bytes, name, max_expanded, on_progress) {
|
|
694
|
+
static read(bytes, name, max_expanded, on_progress, password) {
|
|
663
695
|
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
664
696
|
const len0 = WASM_VECTOR_LEN;
|
|
665
697
|
var ptr1 = isLikeNone(name) ? 0 : passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
666
698
|
var len1 = WASM_VECTOR_LEN;
|
|
667
|
-
|
|
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);
|
|
668
702
|
if (ret[2]) {
|
|
669
703
|
throw takeFromExternrefTable0(ret[1]);
|
|
670
704
|
}
|
|
@@ -811,7 +845,9 @@ class Book {
|
|
|
811
845
|
}
|
|
812
846
|
}
|
|
813
847
|
/**
|
|
814
|
-
* 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.
|
|
815
851
|
* @param {number} sheet
|
|
816
852
|
* @returns {SheetShape[]}
|
|
817
853
|
*/
|
|
@@ -1013,6 +1049,10 @@ function __wbg_get_imports() {
|
|
|
1013
1049
|
__wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
|
|
1014
1050
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
1015
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); },
|
|
1016
1056
|
__wbg_call_35dba3c747ad7521: function() { return handleError(function (arg0, arg1, arg2) {
|
|
1017
1057
|
const ret = arg0.call(arg1, arg2);
|
|
1018
1058
|
return ret;
|
|
@@ -1033,6 +1073,10 @@ function __wbg_get_imports() {
|
|
|
1033
1073
|
const ret = arg0.length;
|
|
1034
1074
|
return ret;
|
|
1035
1075
|
},
|
|
1076
|
+
__wbg_message_c141d5e68716b595: function(arg0) {
|
|
1077
|
+
const ret = arg0.message;
|
|
1078
|
+
return ret;
|
|
1079
|
+
},
|
|
1036
1080
|
__wbg_new_116be93542d39019: function() {
|
|
1037
1081
|
const ret = new Array();
|
|
1038
1082
|
return ret;
|
package/excelerate_bg.wasm
CHANGED
|
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.
|
|
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
|
-
"
|
|
11
|
+
"excelerate.d.ts",
|
|
12
12
|
"excelerate.js",
|
|
13
|
-
"
|
|
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
|
}
|