@rosperitus/excelerate 0.14.0 → 0.16.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 +161 -9
- package/excelerate.d.ts +339 -8
- package/excelerate.js +343 -4
- package/excelerate_bg.wasm +0 -0
- package/index.d.ts +161 -0
- package/index.js +411 -0
- package/package.json +25 -5
- package/web/excelerate.d.ts +1508 -0
- package/web/excelerate.js +2681 -0
- package/web/excelerate_bg.wasm +0 -0
- package/web/excelerate_bg.wasm.d.ts +160 -0
- package/web/index.d.ts +162 -0
- package/web/index.js +408 -0
- package/web/package.json +4 -0
package/excelerate.js
CHANGED
|
@@ -28,6 +28,27 @@ class Book {
|
|
|
28
28
|
const ret = wasm.book_activeSheet(this.__wbg_ptr);
|
|
29
29
|
return ret >>> 0;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Adds a data validation rule to a sheet, as Data - Data Validation
|
|
33
|
+
* does: `type` is `"whole"`, `"decimal"`, `"list"`, `"date"`, `"time"`,
|
|
34
|
+
* `"textLength"` or `"custom"`, `operator` one of `"between"` (the
|
|
35
|
+
* default), `"notBetween"`, `"equal"`, `"notEqual"`, `"greaterThan"`,
|
|
36
|
+
* `"lessThan"`, `"greaterThanOrEqual"`, `"lessThanOrEqual"`. Formulas are
|
|
37
|
+
* written for the first cell of `sqref`; a list is `"\"Yes,No\""` or a
|
|
38
|
+
* range such as `"$E$1:$E$5"`.
|
|
39
|
+
*
|
|
40
|
+
* ```js
|
|
41
|
+
* book.addDataValidation(0, { sqref: "B2:B100", type: "list", formula1: "\"Yes,No\"" });
|
|
42
|
+
* ```
|
|
43
|
+
* @param {number} sheet
|
|
44
|
+
* @param {NewDataValidation} rule
|
|
45
|
+
*/
|
|
46
|
+
addDataValidation(sheet, rule) {
|
|
47
|
+
const ret = wasm.book_addDataValidation(this.__wbg_ptr, sheet, rule);
|
|
48
|
+
if (ret[1]) {
|
|
49
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
31
52
|
/**
|
|
32
53
|
* Appends a sheet and returns its index.
|
|
33
54
|
* @param {string} title
|
|
@@ -212,6 +233,29 @@ class Book {
|
|
|
212
233
|
}
|
|
213
234
|
return takeFromExternrefTable0(ret[0]);
|
|
214
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Whether `value` would be accepted in a cell under its data validation
|
|
238
|
+
* rule: `null` when it would (or there is no rule), otherwise what Excel
|
|
239
|
+
* would report, `{ style, title, message, sqref }`.
|
|
240
|
+
*
|
|
241
|
+
* ```js
|
|
242
|
+
* const problem = book.checkValidation(0, "B5", 150);
|
|
243
|
+
* if (problem) alert(problem.message || "Not allowed");
|
|
244
|
+
* ```
|
|
245
|
+
* @param {number} sheet
|
|
246
|
+
* @param {string} address
|
|
247
|
+
* @param {CellValue} value
|
|
248
|
+
* @returns {ValidationProblem | null}
|
|
249
|
+
*/
|
|
250
|
+
checkValidation(sheet, address, value) {
|
|
251
|
+
const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
252
|
+
const len0 = WASM_VECTOR_LEN;
|
|
253
|
+
const ret = wasm.book_checkValidation(this.__wbg_ptr, sheet, ptr0, len0, value);
|
|
254
|
+
if (ret[2]) {
|
|
255
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
256
|
+
}
|
|
257
|
+
return takeFromExternrefTable0(ret[0]);
|
|
258
|
+
}
|
|
215
259
|
/**
|
|
216
260
|
* Empties a cell, style and all.
|
|
217
261
|
* @param {number} sheet
|
|
@@ -423,6 +467,35 @@ class Book {
|
|
|
423
467
|
throw takeFromExternrefTable0(ret[0]);
|
|
424
468
|
}
|
|
425
469
|
}
|
|
470
|
+
/**
|
|
471
|
+
* Reads a workbook and hands sheet `sheet` over row by row, without
|
|
472
|
+
* building its grid: `callback(row, data)` gets the 1-based row number
|
|
473
|
+
* and what `getRowAt` would answer for it, and the row is dropped once
|
|
474
|
+
* the callback returns.
|
|
475
|
+
*
|
|
476
|
+
* The workbook comes back whole but for that sheet's cells. Only xlsx
|
|
477
|
+
* streams; any other format is read whole and then handed over the same
|
|
478
|
+
* way, so the callback sees the same rows but nothing is saved.
|
|
479
|
+
* A callback that throws is not called again, and what it threw comes
|
|
480
|
+
* out of `forEachRow` once the read is over.
|
|
481
|
+
* @param {Uint8Array} bytes
|
|
482
|
+
* @param {string | null | undefined} name
|
|
483
|
+
* @param {number} sheet
|
|
484
|
+
* @param {Function} callback
|
|
485
|
+
* @param {boolean | null} [formatted]
|
|
486
|
+
* @returns {Book}
|
|
487
|
+
*/
|
|
488
|
+
static forEachRow(bytes, name, sheet, callback, formatted) {
|
|
489
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
490
|
+
const len0 = WASM_VECTOR_LEN;
|
|
491
|
+
var ptr1 = isLikeNone(name) ? 0 : passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
492
|
+
var len1 = WASM_VECTOR_LEN;
|
|
493
|
+
const ret = wasm.book_forEachRow(ptr0, len0, ptr1, len1, sheet, callback, isLikeNone(formatted) ? 0xFFFFFF : formatted ? 1 : 0);
|
|
494
|
+
if (ret[2]) {
|
|
495
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
496
|
+
}
|
|
497
|
+
return Book.__wrap(ret[0]);
|
|
498
|
+
}
|
|
426
499
|
/**
|
|
427
500
|
* Freezes the first `rows` rows and `columns` columns, so they stay put
|
|
428
501
|
* while the rest scrolls. `freezePanes(0, 1, 0)` pins the header row;
|
|
@@ -674,6 +747,35 @@ class Book {
|
|
|
674
747
|
}
|
|
675
748
|
return takeFromExternrefTable0(ret[0]);
|
|
676
749
|
}
|
|
750
|
+
/**
|
|
751
|
+
* Finds the value of `changing` that makes the formula in `set` compute
|
|
752
|
+
* `target`, as Excel's Goal Seek does, both cells on `sheet`. The best
|
|
753
|
+
* value found is left in `changing` and what reads it is recomputed.
|
|
754
|
+
* `options.maxIterations` and `options.tolerance` default to the
|
|
755
|
+
* workbook's own iteration settings (100 and 0.001 unless it says
|
|
756
|
+
* otherwise). Returns `{ value, result, iterations, converged }`.
|
|
757
|
+
*
|
|
758
|
+
* ```js
|
|
759
|
+
* const { value, converged } = book.goalSeek(0, "B4", 300, "B1");
|
|
760
|
+
* ```
|
|
761
|
+
* @param {number} sheet
|
|
762
|
+
* @param {string} set
|
|
763
|
+
* @param {number} target
|
|
764
|
+
* @param {string} changing
|
|
765
|
+
* @param {GoalSeekOptions} [options]
|
|
766
|
+
* @returns {GoalSeekResult}
|
|
767
|
+
*/
|
|
768
|
+
goalSeek(sheet, set, target, changing, options) {
|
|
769
|
+
const ptr0 = passStringToWasm0(set, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
770
|
+
const len0 = WASM_VECTOR_LEN;
|
|
771
|
+
const ptr1 = passStringToWasm0(changing, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
772
|
+
const len1 = WASM_VECTOR_LEN;
|
|
773
|
+
const ret = wasm.book_goalSeek(this.__wbg_ptr, sheet, ptr0, len0, target, ptr1, len1, options);
|
|
774
|
+
if (ret[2]) {
|
|
775
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
776
|
+
}
|
|
777
|
+
return takeFromExternrefTable0(ret[0]);
|
|
778
|
+
}
|
|
677
779
|
/**
|
|
678
780
|
* The hyperlinks of a sheet. `external` tells a URL from a jump inside
|
|
679
781
|
* the workbook.
|
|
@@ -752,6 +854,20 @@ class Book {
|
|
|
752
854
|
throw takeFromExternrefTable0(ret[0]);
|
|
753
855
|
}
|
|
754
856
|
}
|
|
857
|
+
/**
|
|
858
|
+
* `insertRowsMany` for columns.
|
|
859
|
+
* @param {number} sheet
|
|
860
|
+
* @param {[number, number][]} places
|
|
861
|
+
* @param {"before" | "after" | "none"} [copyOrigin]
|
|
862
|
+
*/
|
|
863
|
+
insertColumnsMany(sheet, places, copyOrigin) {
|
|
864
|
+
var ptr0 = isLikeNone(copyOrigin) ? 0 : passStringToWasm0(copyOrigin, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
865
|
+
var len0 = WASM_VECTOR_LEN;
|
|
866
|
+
const ret = wasm.book_insertColumnsMany(this.__wbg_ptr, sheet, places, ptr0, len0);
|
|
867
|
+
if (ret[1]) {
|
|
868
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
755
871
|
/**
|
|
756
872
|
* Inserts `count` rows above row `at`, moving everything below down.
|
|
757
873
|
* `copyOrigin` - `"before"` (the row above), `"after"` (the row below)
|
|
@@ -774,6 +890,43 @@ class Book {
|
|
|
774
890
|
throw takeFromExternrefTable0(ret[0]);
|
|
775
891
|
}
|
|
776
892
|
}
|
|
893
|
+
/**
|
|
894
|
+
* Inserts rows at many places in one pass: `places` is `[at, count]`
|
|
895
|
+
* pairs, numbered as the sheet is before the call, in any order.
|
|
896
|
+
* `book.insertRowsMany(0, [[5, 1], [9, 1]])` puts a row above each of
|
|
897
|
+
* rows 5 and 9 - the old row 9, now row 10. Each new block takes its
|
|
898
|
+
* formatting from its own neighbour, as `copyOrigin` says.
|
|
899
|
+
*
|
|
900
|
+
* The result is that of the single inserts made from the bottom up, but
|
|
901
|
+
* the workbook is walked once rather than once per place: four thousand
|
|
902
|
+
* subtotal rows into forty thousand take milliseconds, not a minute.
|
|
903
|
+
* @param {number} sheet
|
|
904
|
+
* @param {[number, number][]} places
|
|
905
|
+
* @param {"before" | "after" | "none"} [copyOrigin]
|
|
906
|
+
*/
|
|
907
|
+
insertRowsMany(sheet, places, copyOrigin) {
|
|
908
|
+
var ptr0 = isLikeNone(copyOrigin) ? 0 : passStringToWasm0(copyOrigin, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
909
|
+
var len0 = WASM_VECTOR_LEN;
|
|
910
|
+
const ret = wasm.book_insertRowsMany(this.__wbg_ptr, sheet, places, ptr0, len0);
|
|
911
|
+
if (ret[1]) {
|
|
912
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* The cells of a sheet whose values break their data validation rule,
|
|
917
|
+
* as Excel's Circle Invalid Data finds them: `["B3", "B9"]`.
|
|
918
|
+
* @param {number} sheet
|
|
919
|
+
* @returns {string[]}
|
|
920
|
+
*/
|
|
921
|
+
invalidCells(sheet) {
|
|
922
|
+
const ret = wasm.book_invalidCells(this.__wbg_ptr, sheet);
|
|
923
|
+
if (ret[3]) {
|
|
924
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
925
|
+
}
|
|
926
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
|
|
927
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
928
|
+
return v1;
|
|
929
|
+
}
|
|
777
930
|
/**
|
|
778
931
|
* Merges a block of cells: `merge(0, "A1:C1")`.
|
|
779
932
|
* @param {number} sheet
|
|
@@ -913,19 +1066,24 @@ class Book {
|
|
|
913
1066
|
*
|
|
914
1067
|
* `name` is the file name they came from, if the caller has one: it
|
|
915
1068
|
* settles what the bytes cannot say (a `.csv` against a `.html`) and names
|
|
916
|
-
* the sheet of a SYLK file.
|
|
1069
|
+
* the sheet of a SYLK file. `password` opens a workbook saved with a
|
|
1070
|
+
* password to open; without it only one encrypted to be opened
|
|
1071
|
+
* read-only reads.
|
|
917
1072
|
* @param {Uint8Array} bytes
|
|
918
1073
|
* @param {string | null} [name]
|
|
919
1074
|
* @param {number | null} [max_expanded]
|
|
920
1075
|
* @param {Function | null} [on_progress]
|
|
1076
|
+
* @param {string | null} [password]
|
|
921
1077
|
* @returns {Book}
|
|
922
1078
|
*/
|
|
923
|
-
static read(bytes, name, max_expanded, on_progress) {
|
|
1079
|
+
static read(bytes, name, max_expanded, on_progress, password) {
|
|
924
1080
|
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
925
1081
|
const len0 = WASM_VECTOR_LEN;
|
|
926
1082
|
var ptr1 = isLikeNone(name) ? 0 : passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
927
1083
|
var len1 = WASM_VECTOR_LEN;
|
|
928
|
-
|
|
1084
|
+
var ptr2 = isLikeNone(password) ? 0 : passStringToWasm0(password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1085
|
+
var len2 = WASM_VECTOR_LEN;
|
|
1086
|
+
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);
|
|
929
1087
|
if (ret[2]) {
|
|
930
1088
|
throw takeFromExternrefTable0(ret[1]);
|
|
931
1089
|
}
|
|
@@ -1114,6 +1272,17 @@ class Book {
|
|
|
1114
1272
|
throw takeFromExternrefTable0(ret[0]);
|
|
1115
1273
|
}
|
|
1116
1274
|
}
|
|
1275
|
+
/**
|
|
1276
|
+
* `removeRowsMany` for columns.
|
|
1277
|
+
* @param {number} sheet
|
|
1278
|
+
* @param {[number, number][]} places
|
|
1279
|
+
*/
|
|
1280
|
+
removeColumnsMany(sheet, places) {
|
|
1281
|
+
const ret = wasm.book_removeColumnsMany(this.__wbg_ptr, sheet, places);
|
|
1282
|
+
if (ret[1]) {
|
|
1283
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1117
1286
|
/**
|
|
1118
1287
|
* Takes a note off a cell. Answers whether there was one.
|
|
1119
1288
|
* @param {number} sheet
|
|
@@ -1141,6 +1310,31 @@ class Book {
|
|
|
1141
1310
|
const ret = wasm.book_removeDefinedName(this.__wbg_ptr, ptr0, len0, isLikeNone(sheet) ? Number.MAX_SAFE_INTEGER : (sheet) >>> 0);
|
|
1142
1311
|
return ret !== 0;
|
|
1143
1312
|
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Removes the rows of a range that repeat a row above them, as Excel's
|
|
1315
|
+
* Remove Duplicates does: cells are compared by the text they show,
|
|
1316
|
+
* without regard to case. `options.columns` are the 1-based sheet
|
|
1317
|
+
* columns compared (all of the range when left out), and
|
|
1318
|
+
* `options.header` keeps the first row out of it. Returns
|
|
1319
|
+
* `{ removed, remaining }`.
|
|
1320
|
+
*
|
|
1321
|
+
* ```js
|
|
1322
|
+
* book.removeDuplicates(0, "A1:C500", { columns: [1, 3], header: true });
|
|
1323
|
+
* ```
|
|
1324
|
+
* @param {number} sheet
|
|
1325
|
+
* @param {string} range
|
|
1326
|
+
* @param {RemoveDuplicatesOptions} [options]
|
|
1327
|
+
* @returns {DuplicatesRemoved}
|
|
1328
|
+
*/
|
|
1329
|
+
removeDuplicates(sheet, range, options) {
|
|
1330
|
+
const ptr0 = passStringToWasm0(range, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1331
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1332
|
+
const ret = wasm.book_removeDuplicates(this.__wbg_ptr, sheet, ptr0, len0, options);
|
|
1333
|
+
if (ret[2]) {
|
|
1334
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
1335
|
+
}
|
|
1336
|
+
return takeFromExternrefTable0(ret[0]);
|
|
1337
|
+
}
|
|
1144
1338
|
/**
|
|
1145
1339
|
* Takes the link off a range. Answers whether there was one.
|
|
1146
1340
|
* @param {number} sheet
|
|
@@ -1169,6 +1363,18 @@ class Book {
|
|
|
1169
1363
|
throw takeFromExternrefTable0(ret[0]);
|
|
1170
1364
|
}
|
|
1171
1365
|
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Removes rows at many places in one pass: `[at, count]` pairs, numbered
|
|
1368
|
+
* as the sheet is before the call. Blocks that overlap are merged.
|
|
1369
|
+
* @param {number} sheet
|
|
1370
|
+
* @param {[number, number][]} places
|
|
1371
|
+
*/
|
|
1372
|
+
removeRowsMany(sheet, places) {
|
|
1373
|
+
const ret = wasm.book_removeRowsMany(this.__wbg_ptr, sheet, places);
|
|
1374
|
+
if (ret[1]) {
|
|
1375
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1172
1378
|
/**
|
|
1173
1379
|
* Removes a sheet. References to it from anywhere in the workbook become
|
|
1174
1380
|
* `#REF!`, the way Excel writes them, and the sheets after it shift down
|
|
@@ -1330,6 +1536,21 @@ class Book {
|
|
|
1330
1536
|
throw takeFromExternrefTable0(ret[0]);
|
|
1331
1537
|
}
|
|
1332
1538
|
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Changes the fill and outline of a chart's chart area (`format`) and
|
|
1541
|
+
* plot area (`plotFormat`), by its position in `charts`; each takes
|
|
1542
|
+
* `{ fill, line }` as `setShapeFormat` does, or `null` to leave the area
|
|
1543
|
+
* to the chart style.
|
|
1544
|
+
* @param {number} sheet
|
|
1545
|
+
* @param {number} index
|
|
1546
|
+
* @param {ChartFormatPatch} patch
|
|
1547
|
+
*/
|
|
1548
|
+
setChartFormat(sheet, index, patch) {
|
|
1549
|
+
const ret = wasm.book_setChartFormat(this.__wbg_ptr, sheet, index, patch);
|
|
1550
|
+
if (ret[1]) {
|
|
1551
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1333
1554
|
/**
|
|
1334
1555
|
* Hides a column, or shows it again. `column` is 1-based.
|
|
1335
1556
|
* @param {number} sheet
|
|
@@ -1563,6 +1784,34 @@ class Book {
|
|
|
1563
1784
|
throw takeFromExternrefTable0(ret[0]);
|
|
1564
1785
|
}
|
|
1565
1786
|
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Changes how a shape looks, by its position in `shapes`:
|
|
1789
|
+
*
|
|
1790
|
+
* ```js
|
|
1791
|
+
* book.setShapeFormat(0, 2, {
|
|
1792
|
+
* fill: { type: "solid", color: "accent2" },
|
|
1793
|
+
* line: { width: 2 },
|
|
1794
|
+
* font: { bold: true, color: "#FFFFFFFF" },
|
|
1795
|
+
* rotation: 15,
|
|
1796
|
+
* });
|
|
1797
|
+
* ```
|
|
1798
|
+
*
|
|
1799
|
+
* `fill`, `line`, `font`, `rotation` (degrees clockwise), `flipH` and
|
|
1800
|
+
* `flipV`; a field left out stays as it was, `null` for `fill` or `line`
|
|
1801
|
+
* gives it back to the shape's style. A colour is `#RRGGBB`,
|
|
1802
|
+
* `#AARRGGBB` or a theme colour by name (`accent1`, `tx1`, `bg2`), which
|
|
1803
|
+
* follows the theme. The rest of the shape - effects, other runs, the
|
|
1804
|
+
* outline's dashes - stays in the file as it was.
|
|
1805
|
+
* @param {number} sheet
|
|
1806
|
+
* @param {number} index
|
|
1807
|
+
* @param {ShapeFormatPatch} patch
|
|
1808
|
+
*/
|
|
1809
|
+
setShapeFormat(sheet, index, patch) {
|
|
1810
|
+
const ret = wasm.book_setShapeFormat(this.__wbg_ptr, sheet, index, patch);
|
|
1811
|
+
if (ret[1]) {
|
|
1812
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1566
1815
|
/**
|
|
1567
1816
|
* Gives a sheet a tab or takes it away: `"visible"`, `"hidden"` or
|
|
1568
1817
|
* `"veryHidden"`.
|
|
@@ -1594,6 +1843,33 @@ class Book {
|
|
|
1594
1843
|
throw takeFromExternrefTable0(ret[0]);
|
|
1595
1844
|
}
|
|
1596
1845
|
}
|
|
1846
|
+
/**
|
|
1847
|
+
* Filters a table by one of its columns, named by its header or
|
|
1848
|
+
* numbered from 1, and hides the data rows the table's criteria reject,
|
|
1849
|
+
* as Excel does. `null` takes the column's criterion off.
|
|
1850
|
+
*
|
|
1851
|
+
* ```js
|
|
1852
|
+
* book.setTableFilter("Sales", "Region", { values: ["South", "West"] });
|
|
1853
|
+
* book.setTableFilter("Sales", "Amount", { custom: [{ op: ">", value: 100 }] });
|
|
1854
|
+
* book.setTableFilter("Sales", 3, { top: 5 }); // or { bottom: 10, percent: true }
|
|
1855
|
+
* ```
|
|
1856
|
+
*
|
|
1857
|
+
* `values` keeps a row whose cell shows one of them, `blank: true` the
|
|
1858
|
+
* empty ones too; `custom` takes one or two comparisons (`=`, `<>`, `>`,
|
|
1859
|
+
* `>=`, `<`, `<=`; `*` and `?` in `=` and `<>`), joined by `or` unless
|
|
1860
|
+
* `and` is set. Criteria on several columns all have to hold.
|
|
1861
|
+
* @param {string} name
|
|
1862
|
+
* @param {string | number} column
|
|
1863
|
+
* @param {TableFilter | null} criteria
|
|
1864
|
+
*/
|
|
1865
|
+
setTableFilter(name, column, criteria) {
|
|
1866
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1867
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1868
|
+
const ret = wasm.book_setTableFilter(this.__wbg_ptr, ptr0, len0, column, criteria);
|
|
1869
|
+
if (ret[1]) {
|
|
1870
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1597
1873
|
/**
|
|
1598
1874
|
* The zoom a reader opens the sheet at, in percent; `undefined` gives it
|
|
1599
1875
|
* back to 100.
|
|
@@ -1607,7 +1883,9 @@ class Book {
|
|
|
1607
1883
|
}
|
|
1608
1884
|
}
|
|
1609
1885
|
/**
|
|
1610
|
-
* The drawn shapes of a sheet, text and all
|
|
1886
|
+
* The drawn shapes of a sheet, text and all, with the look Excel shows:
|
|
1887
|
+
* fill, outline and font are the shape's own with its style filling in
|
|
1888
|
+
* the rest, colours resolved through the workbook theme.
|
|
1611
1889
|
* @param {number} sheet
|
|
1612
1890
|
* @returns {SheetShape[]}
|
|
1613
1891
|
*/
|
|
@@ -1741,6 +2019,37 @@ class Book {
|
|
|
1741
2019
|
}
|
|
1742
2020
|
return takeFromExternrefTable0(ret[0]);
|
|
1743
2021
|
}
|
|
2022
|
+
/**
|
|
2023
|
+
* Splits the text of each cell in the first column of `range` across
|
|
2024
|
+
* the columns to its right, as Excel's Text to Columns does. Pieces that
|
|
2025
|
+
* read as numbers, booleans or errors become them. Returns how many
|
|
2026
|
+
* columns the widest row took.
|
|
2027
|
+
*
|
|
2028
|
+
* `options.delimiters` is a string of delimiter characters (`";"`,
|
|
2029
|
+
* `",\t"`), or `options.widths` the character positions to cut before
|
|
2030
|
+
* for fixed width; `mergeConsecutive` treats a run of delimiters as one,
|
|
2031
|
+
* `qualifier` is the quote (`"` unless given; `null` for none), and
|
|
2032
|
+
* `destination` is the first cell written (the range's own when left
|
|
2033
|
+
* out).
|
|
2034
|
+
*
|
|
2035
|
+
* ```js
|
|
2036
|
+
* book.textToColumns(0, "A2:A100", { delimiters: ";" });
|
|
2037
|
+
* book.textToColumns(0, "A2:A100", { widths: [4, 10], destination: "C2" });
|
|
2038
|
+
* ```
|
|
2039
|
+
* @param {number} sheet
|
|
2040
|
+
* @param {string} range
|
|
2041
|
+
* @param {TextToColumnsOptions} options
|
|
2042
|
+
* @returns {number}
|
|
2043
|
+
*/
|
|
2044
|
+
textToColumns(sheet, range, options) {
|
|
2045
|
+
const ptr0 = passStringToWasm0(range, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2046
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2047
|
+
const ret = wasm.book_textToColumns(this.__wbg_ptr, sheet, ptr0, len0, options);
|
|
2048
|
+
if (ret[2]) {
|
|
2049
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
2050
|
+
}
|
|
2051
|
+
return ret[0] >>> 0;
|
|
2052
|
+
}
|
|
1744
2053
|
/**
|
|
1745
2054
|
* One sheet as CSV, comma-separated unless `options.delimiter` says
|
|
1746
2055
|
* otherwise - a semicolon for a locale where the comma is the decimal
|
|
@@ -1915,6 +2224,24 @@ class Book {
|
|
|
1915
2224
|
}
|
|
1916
2225
|
return v1;
|
|
1917
2226
|
}
|
|
2227
|
+
/**
|
|
2228
|
+
* The choices of the drop-down list on a cell, as Excel shows them; an
|
|
2229
|
+
* empty array when the cell has no list rule.
|
|
2230
|
+
* @param {number} sheet
|
|
2231
|
+
* @param {string} address
|
|
2232
|
+
* @returns {string[]}
|
|
2233
|
+
*/
|
|
2234
|
+
validationList(sheet, address) {
|
|
2235
|
+
const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2236
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2237
|
+
const ret = wasm.book_validationList(this.__wbg_ptr, sheet, ptr0, len0);
|
|
2238
|
+
if (ret[3]) {
|
|
2239
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
2240
|
+
}
|
|
2241
|
+
var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]);
|
|
2242
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
2243
|
+
return v2;
|
|
2244
|
+
}
|
|
1918
2245
|
/**
|
|
1919
2246
|
* Whether that password unlocks the sheet. `false` for a sheet with no
|
|
1920
2247
|
* password on it, and for a hash this crate cannot check.
|
|
@@ -1993,6 +2320,10 @@ function __wbg_get_imports() {
|
|
|
1993
2320
|
const ret = Reflect.apply(arg0, arg1, arg2);
|
|
1994
2321
|
return ret;
|
|
1995
2322
|
}, arguments); },
|
|
2323
|
+
__wbg_call_0f2a9af232c18fd2: function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
2324
|
+
const ret = arg0.call(arg1, arg2, arg3);
|
|
2325
|
+
return ret;
|
|
2326
|
+
}, arguments); },
|
|
1996
2327
|
__wbg_call_35dba3c747ad7521: function() { return handleError(function (arg0, arg1, arg2) {
|
|
1997
2328
|
const ret = arg0.call(arg1, arg2);
|
|
1998
2329
|
return ret;
|
|
@@ -2012,6 +2343,10 @@ function __wbg_get_imports() {
|
|
|
2012
2343
|
const ret = Reflect.get(arg0, arg1);
|
|
2013
2344
|
return ret;
|
|
2014
2345
|
}, arguments); },
|
|
2346
|
+
__wbg_get_c0c8f8d7da0c03dd: function(arg0, arg1) {
|
|
2347
|
+
const ret = arg0[arg1 >>> 0];
|
|
2348
|
+
return ret;
|
|
2349
|
+
},
|
|
2015
2350
|
__wbg_get_unchecked_e20b893aeafc3fca: function(arg0, arg1) {
|
|
2016
2351
|
const ret = arg0[arg1 >>> 0];
|
|
2017
2352
|
return ret;
|
|
@@ -2024,6 +2359,10 @@ function __wbg_get_imports() {
|
|
|
2024
2359
|
const ret = arg0.length;
|
|
2025
2360
|
return ret;
|
|
2026
2361
|
},
|
|
2362
|
+
__wbg_message_c141d5e68716b595: function(arg0) {
|
|
2363
|
+
const ret = arg0.message;
|
|
2364
|
+
return ret;
|
|
2365
|
+
},
|
|
2027
2366
|
__wbg_new_0_f117d868b403dc07: function() {
|
|
2028
2367
|
const ret = new Date();
|
|
2029
2368
|
return ret;
|
package/excelerate_bg.wasm
CHANGED
|
Binary file
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
export * from "./excelerate";
|
|
2
|
+
import type { Book, CellValue, CellGrid, CellStylePatch, SheetTable, SortKeys, TableFilter, CsvOptions } from "./excelerate";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Objects over `Book`, whose changing methods return themselves so calls chain:
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* const wb = new Workbook();
|
|
9
|
+
* const sales = wb.addSheet("Sales")
|
|
10
|
+
* .addTableFromData("Sales", "A1", [["Region", "Amount"], ["North", 120], ["South", 340]])
|
|
11
|
+
* .set(1, "Amount", 125)
|
|
12
|
+
* .addFilter("Region", { values: ["South"] });
|
|
13
|
+
* sales.records({ visible: true }); // [{ Region: "South", Amount: 340 }]
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Each object is a handle - a sheet index, a table name, an address - and
|
|
17
|
+
* works through `workbook.book`, which is there for everything not wrapped.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Workbook {
|
|
20
|
+
/** A new workbook, or one over a `Book` already in hand. */
|
|
21
|
+
constructor(book?: Book);
|
|
22
|
+
readonly book: Book;
|
|
23
|
+
/** Reads any format `Book.read` reads. */
|
|
24
|
+
static read(bytes: Uint8Array, name?: string, maxExpanded?: number, onProgress?: Function, password?: string): Workbook;
|
|
25
|
+
static readCsv(bytes: Uint8Array, options: CsvOptions): Workbook;
|
|
26
|
+
/** Hands one sheet over row by row without keeping its grid; the rest of the workbook comes back. */
|
|
27
|
+
static forEachRow(bytes: Uint8Array, name: string | null | undefined, sheet: number, callback: Function, formatted?: boolean | null): Workbook;
|
|
28
|
+
/** A sheet by position (from 0) or by name. */
|
|
29
|
+
sheet(which: number | string): Sheet;
|
|
30
|
+
sheets(): Sheet[];
|
|
31
|
+
/** Adds a sheet at the end. On a new workbook the first call takes over its empty "Sheet1". */
|
|
32
|
+
addSheet(name?: string): Sheet;
|
|
33
|
+
recalculate(onProgress?: Function): this;
|
|
34
|
+
toXlsx(onProgress?: Function): Uint8Array;
|
|
35
|
+
free(): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export declare class Sheet {
|
|
39
|
+
readonly workbook: Workbook;
|
|
40
|
+
/** The tab position the sheet had when it was handed out. */
|
|
41
|
+
readonly index: number;
|
|
42
|
+
readonly book: Book;
|
|
43
|
+
readonly name: string;
|
|
44
|
+
rename(name: string): this;
|
|
45
|
+
/** What the cell shows, through its number format. */
|
|
46
|
+
text(address: string): string;
|
|
47
|
+
/** A block of values whose top left corner lands on `at`. */
|
|
48
|
+
write(at: string, rows: CellGrid): this;
|
|
49
|
+
range(address: string): SheetRange;
|
|
50
|
+
style(address: string, patch: CellStylePatch): this;
|
|
51
|
+
/** Column width in characters; the column is a letter or a number from 1. */
|
|
52
|
+
width(column: string | number, characters?: number): this;
|
|
53
|
+
/** Freezes the rows above and the columns to the left; zeros unfreeze. */
|
|
54
|
+
freeze(rows: number, columns?: number): this;
|
|
55
|
+
/** A table over a range already filled. */
|
|
56
|
+
addTable(name: string, address: string, options?: { header?: boolean }): Table;
|
|
57
|
+
/** Writes `rows` from `at` - the first is the header - and draws a table over them. */
|
|
58
|
+
addTableFromData(name: string, at: string, rows: CellGrid): Table;
|
|
59
|
+
table(name: string): Table;
|
|
60
|
+
tables(): Table[];
|
|
61
|
+
/** Makes this the sheet a workbook opens on. */
|
|
62
|
+
activate(): this;
|
|
63
|
+
/** Recalculates the formulas of this sheet. */
|
|
64
|
+
recalculate(onProgress?: Function): this;
|
|
65
|
+
/** Removes the sheet; handles to the sheets after it go stale. */
|
|
66
|
+
remove(): Workbook;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export declare class Table {
|
|
70
|
+
readonly sheet: Sheet;
|
|
71
|
+
readonly name: string;
|
|
72
|
+
readonly book: Book;
|
|
73
|
+
readonly columns: string[];
|
|
74
|
+
info(): SheetTable;
|
|
75
|
+
/** The whole table, header and totals included; with an address, a range of the sheet. */
|
|
76
|
+
range(address?: string): SheetRange;
|
|
77
|
+
/** The data rows, without the header and totals. */
|
|
78
|
+
data(): SheetRange;
|
|
79
|
+
/** The sheet address of a data cell: `row` from 1, `column` a header or a number from 1. */
|
|
80
|
+
address(row: number, column: string | number): string;
|
|
81
|
+
columnIndex(header: string): number;
|
|
82
|
+
set(row: number, column: string | number, value: CellValue): this;
|
|
83
|
+
get(row: number, column: string | number): CellValue;
|
|
84
|
+
/** Filters by a column and hides the rows that fail, as Excel does. */
|
|
85
|
+
addFilter(column: string | number, criteria: TableFilter): this;
|
|
86
|
+
/** Takes the criterion off one column, or off all of them. */
|
|
87
|
+
clearFilter(column?: string | number): this;
|
|
88
|
+
/** `["Region", "-Amount"]`: a minus sorts largest first. */
|
|
89
|
+
sort(keys: SortKeys): this;
|
|
90
|
+
/** The data rows keyed by header; `visible` leaves out hidden rows. */
|
|
91
|
+
records(options?: { visible?: boolean }): Record<string, CellValue>[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export declare class SheetRange {
|
|
95
|
+
readonly sheet: Sheet;
|
|
96
|
+
readonly address: string;
|
|
97
|
+
readonly book: Book;
|
|
98
|
+
values(): CellGrid;
|
|
99
|
+
/** The values of the rows a filter or a user has not hidden. */
|
|
100
|
+
visibleValues(): CellGrid;
|
|
101
|
+
/** Writes a block from the top left corner of the range. */
|
|
102
|
+
set(rows: CellGrid): this;
|
|
103
|
+
style(patch: CellStylePatch): this;
|
|
104
|
+
merge(): this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Every `Book` method that takes the sheet first is a `Sheet` method without
|
|
109
|
+
* it; one that answers with nothing returns the sheet, so it chains.
|
|
110
|
+
* `sheet.setColumnWidth(2, 14).setRowHidden(5, true).getRange("A1:C3")`.
|
|
111
|
+
*/
|
|
112
|
+
type SheetActionName =
|
|
113
|
+
| "addDataValidation" | "clear" | "clearAt" | "copyRange" | "fillDown"
|
|
114
|
+
| "fillRight" | "fillSeries" | "freezePanes" | "insertCells" | "insertColumns"
|
|
115
|
+
| "insertColumnsMany" | "insertRows" | "insertRowsMany" | "merge"
|
|
116
|
+
| "moveRange" | "protectSheet" | "removeCells" | "removeColumns"
|
|
117
|
+
| "removeColumnsMany" | "removeRows" | "removeRowsMany" | "set" | "setAt"
|
|
118
|
+
| "setCellStyle" | "setCellStyleAt" | "setChartFormat" | "setColumnHidden"
|
|
119
|
+
| "setColumnWidth" | "setComment" | "setHyperlink" | "setRange" | "setRangeAt"
|
|
120
|
+
| "setRangeStyle" | "setRangeStyles" | "setRangeStylesAt" | "setRichText"
|
|
121
|
+
| "setRichTextAt" | "setRowHeight" | "setRowHidden" | "setShapeFormat"
|
|
122
|
+
| "setSheetVisibility" | "setShowGridLines" | "setZoom" | "sortRange"
|
|
123
|
+
| "unprotectSheet";
|
|
124
|
+
type SheetQueryName =
|
|
125
|
+
| "arrayFormulas" | "autoFilter" | "cellBold" | "cellBoldAt" | "cellCount"
|
|
126
|
+
| "cellIndent" | "cellIndentAt" | "cellStyle" | "cellStyleAt" | "charts"
|
|
127
|
+
| "checkValidation" | "columnLevel" | "columnWidth" | "comments"
|
|
128
|
+
| "conditionalFormats" | "dataValidations" | "evaluate" | "get" | "getAt"
|
|
129
|
+
| "getFormatted" | "getFormattedAt" | "getFormula" | "getFormulaAt"
|
|
130
|
+
| "getRange" | "getRangeAt" | "getRangeStyles" | "getRangeStylesAt"
|
|
131
|
+
| "getRichText" | "getRichTextAt" | "getRowAt" | "goalSeek" | "hyperlinks"
|
|
132
|
+
| "imageData" | "images" | "invalidCells" | "mergedRanges" | "mergedRangesAt"
|
|
133
|
+
| "pivotTables" | "recalculateCell" | "recalculateCellAt" | "recalculateFrom"
|
|
134
|
+
| "recalculateFromAt" | "recalculateFromMany" | "removeComment"
|
|
135
|
+
| "removeDuplicates" | "removeHyperlink" | "removeTable" | "rowHeight"
|
|
136
|
+
| "rowHidden" | "rowLevel" | "shapes" | "sheetProtection" | "sheetView"
|
|
137
|
+
| "sheetVisibility" | "textToColumns" | "toCsv" | "toHtml" | "unmerge"
|
|
138
|
+
| "usedRange" | "usedRangeHint" | "validationList" | "verifySheetPassword";
|
|
139
|
+
/** Every `Book` method without a sheet is a `Workbook` method, chaining the same way. */
|
|
140
|
+
type BookActionName =
|
|
141
|
+
| "moveSheet" | "protectWorkbook" | "registerFunction" | "setDefinedName"
|
|
142
|
+
| "setDocumentProperties" | "setTableFilter" | "sortTable" | "unprotectWorkbook";
|
|
143
|
+
type BookQueryName =
|
|
144
|
+
| "activeSheet" | "definedNames" | "documentProperties" | "externalBooks"
|
|
145
|
+
| "registeredFunctions" | "removeDefinedName" | "sheetIndex" | "sheetNames"
|
|
146
|
+
| "toOds" | "toXls" | "unregisterFunction" | "workbookProtection";
|
|
147
|
+
|
|
148
|
+
type SheetActions = {
|
|
149
|
+
[P in SheetActionName]: Book[P] extends (sheet: any, ...rest: infer A) => any ? (...rest: A) => Sheet : never;
|
|
150
|
+
};
|
|
151
|
+
type SheetQueries = {
|
|
152
|
+
[P in SheetQueryName]: Book[P] extends (sheet: any, ...rest: infer A) => infer R ? (...rest: A) => R : never;
|
|
153
|
+
};
|
|
154
|
+
type BookActions = {
|
|
155
|
+
[P in BookActionName]: Book[P] extends (...args: infer A) => any ? (...args: A) => Workbook : never;
|
|
156
|
+
};
|
|
157
|
+
type BookQueries = {
|
|
158
|
+
[P in BookQueryName]: Book[P] extends (...args: infer A) => infer R ? (...args: A) => R : never;
|
|
159
|
+
};
|
|
160
|
+
export interface Sheet extends SheetActions, SheetQueries {}
|
|
161
|
+
export interface Workbook extends BookActions, BookQueries {}
|