@rosperitus/excelerate 0.16.0 → 0.18.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
@@ -353,6 +353,9 @@ class Book {
353
353
  recalculateCell(sheet: number, address: string): boolean;
354
354
  recalculateFrom(sheet: number, address: string): number;
355
355
  recalculateFromMany(sheet: number, addresses: string[]): number;
356
+ circularReferences(): CircularCell[]; // { sheet, address } on each cycle
357
+ setIteration(settings: IterationSettings | null): void; // { maxIterations?, tolerance? }
358
+ iteration(): IterationSettings | null;
356
359
  goalSeek(sheet: number, set: string, target: number, changing: string, options?: GoalSeekOptions): GoalSeekResult;
357
360
 
358
361
  // Functions of your own, for names no built-in claims
@@ -440,6 +443,13 @@ missing sheet, a truncated package.
440
443
  evaluated, a range as a grid. A built-in name stays the built-in's, an
441
444
  unregistered one reads `#NAME?`, and a function that throws gives
442
445
  `#VALUE!` rather than an exception out of the formula.
446
+ - **Circular references.** A formula that reads itself through others
447
+ computes `#REF!`; `book.circularReferences()` lists them as
448
+ `[{ sheet, address }]`. `book.setIteration({ maxIterations: 100, tolerance:
449
+ 0.001 })` turns on Excel's iterative calculation, so `recalculate()` steps
450
+ each cycle until it settles; `setIteration(null)` turns it off, and
451
+ `iteration()` says what is set. The setting is saved with the workbook, and
452
+ a file saved with it on iterates as it is.
443
453
  - **Progress.** `Book.read`, `toXlsx` and `recalculate` take a callback last;
444
454
  it gets `{ stage, done, total, what, fraction }` per sheet, part or formula.
445
455
  `total` is `null` while a read has not reached the workbook part yet.
package/excelerate.d.ts CHANGED
@@ -417,6 +417,18 @@ export interface GoalSeekOptions {
417
417
  maxIterations?: number;
418
418
  tolerance?: number;
419
419
  }
420
+ /** Excel's iterative calculation, as `iteration` returns it and `setIteration` takes it. */
421
+ export interface IterationSettings {
422
+ /** Maximum Iterations: the most rounds a cycle is stepped. */
423
+ maxIterations?: number;
424
+ /** Maximum Change: rounds stop once no value moves by more. */
425
+ tolerance?: number;
426
+ }
427
+ /** A formula cell on a circular reference, as `circularReferences` lists it. */
428
+ export interface CircularCell {
429
+ sheet: number;
430
+ address: string;
431
+ }
420
432
  /** How `goalSeek` ended. */
421
433
  export interface GoalSeekResult {
422
434
  /** The value left in the changing cell: the best one tried. */
@@ -542,6 +554,17 @@ export class Book {
542
554
  * ```
543
555
  */
544
556
  checkValidation(sheet: number, address: string, value: CellValue): ValidationProblem | null;
557
+ /**
558
+ * The formula cells on a circular reference, as Excel lists them under
559
+ * Formulas - Error Checking - Circular References: each one reads itself
560
+ * through other formulas. A formula that only reads a cycle is not
561
+ * listed. Without iteration (`setIteration`) these cells compute `#REF!`.
562
+ *
563
+ * ```js
564
+ * for (const { sheet, address } of book.circularReferences()) console.log(sheet, address);
565
+ * ```
566
+ */
567
+ circularReferences(): CircularCell[];
545
568
  /**
546
569
  * Empties a cell, style and all.
547
570
  */
@@ -781,6 +804,11 @@ export class Book {
781
804
  * as Excel's Circle Invalid Data finds them: `["B3", "B9"]`.
782
805
  */
783
806
  invalidCells(sheet: number): string[];
807
+ /**
808
+ * Whether circular references are iterated, Excel's Enable iterative
809
+ * calculation, and with what limits; `null` when they are not.
810
+ */
811
+ iteration(): IterationSettings | null;
784
812
  /**
785
813
  * Merges a block of cells: `merge(0, "A1:C1")`.
786
814
  */
@@ -1074,6 +1102,18 @@ export class Book {
1074
1102
  * is a place in this workbook: `'Sheet 2'!A1`.
1075
1103
  */
1076
1104
  setHyperlink(sheet: number, range: string, target: string, inside?: boolean | null, display?: string | null, tooltip?: string | null): void;
1105
+ /**
1106
+ * Turns iteration of circular references on, or off with `null`. Left
1107
+ * out, `maxIterations` is 100 (at most 32,767, as in Excel) and
1108
+ * `tolerance`, Excel's Maximum Change, 0.001. The setting is saved with
1109
+ * the workbook and used by `recalculate` and `recalculateFrom`.
1110
+ *
1111
+ * ```js
1112
+ * book.setIteration({ maxIterations: 1000, tolerance: 1e-6 });
1113
+ * book.recalculate();
1114
+ * ```
1115
+ */
1116
+ setIteration(settings: IterationSettings | null): void;
1077
1117
  /**
1078
1118
  * Writes a rectangle of values with `at` as its top-left corner. Rows may
1079
1119
  * differ in length; a `null` leaves its cell empty.
package/excelerate.js CHANGED
@@ -256,6 +256,21 @@ class Book {
256
256
  }
257
257
  return takeFromExternrefTable0(ret[0]);
258
258
  }
259
+ /**
260
+ * The formula cells on a circular reference, as Excel lists them under
261
+ * Formulas - Error Checking - Circular References: each one reads itself
262
+ * through other formulas. A formula that only reads a cycle is not
263
+ * listed. Without iteration (`setIteration`) these cells compute `#REF!`.
264
+ *
265
+ * ```js
266
+ * for (const { sheet, address } of book.circularReferences()) console.log(sheet, address);
267
+ * ```
268
+ * @returns {CircularCell[]}
269
+ */
270
+ circularReferences() {
271
+ const ret = wasm.book_circularReferences(this.__wbg_ptr);
272
+ return ret;
273
+ }
259
274
  /**
260
275
  * Empties a cell, style and all.
261
276
  * @param {number} sheet
@@ -927,6 +942,15 @@ class Book {
927
942
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
928
943
  return v1;
929
944
  }
945
+ /**
946
+ * Whether circular references are iterated, Excel's Enable iterative
947
+ * calculation, and with what limits; `null` when they are not.
948
+ * @returns {IterationSettings | null}
949
+ */
950
+ iteration() {
951
+ const ret = wasm.book_iteration(this.__wbg_ptr);
952
+ return ret;
953
+ }
930
954
  /**
931
955
  * Merges a block of cells: `merge(0, "A1:C1")`.
932
956
  * @param {number} sheet
@@ -1655,6 +1679,24 @@ class Book {
1655
1679
  throw takeFromExternrefTable0(ret[0]);
1656
1680
  }
1657
1681
  }
1682
+ /**
1683
+ * Turns iteration of circular references on, or off with `null`. Left
1684
+ * out, `maxIterations` is 100 (at most 32,767, as in Excel) and
1685
+ * `tolerance`, Excel's Maximum Change, 0.001. The setting is saved with
1686
+ * the workbook and used by `recalculate` and `recalculateFrom`.
1687
+ *
1688
+ * ```js
1689
+ * book.setIteration({ maxIterations: 1000, tolerance: 1e-6 });
1690
+ * book.recalculate();
1691
+ * ```
1692
+ * @param {IterationSettings | null} settings
1693
+ */
1694
+ setIteration(settings) {
1695
+ const ret = wasm.book_setIteration(this.__wbg_ptr, settings);
1696
+ if (ret[1]) {
1697
+ throw takeFromExternrefTable0(ret[0]);
1698
+ }
1699
+ }
1658
1700
  /**
1659
1701
  * Writes a rectangle of values with `at` as its top-left corner. Rows may
1660
1702
  * differ in length; a `null` leaves its cell empty.
Binary file
package/index.d.ts CHANGED
@@ -139,10 +139,11 @@ type SheetQueryName =
139
139
  /** Every `Book` method without a sheet is a `Workbook` method, chaining the same way. */
140
140
  type BookActionName =
141
141
  | "moveSheet" | "protectWorkbook" | "registerFunction" | "setDefinedName"
142
- | "setDocumentProperties" | "setTableFilter" | "sortTable" | "unprotectWorkbook";
142
+ | "setDocumentProperties" | "setIteration" | "setTableFilter" | "sortTable"
143
+ | "unprotectWorkbook";
143
144
  type BookQueryName =
144
- | "activeSheet" | "definedNames" | "documentProperties" | "externalBooks"
145
- | "registeredFunctions" | "removeDefinedName" | "sheetIndex" | "sheetNames"
145
+ | "activeSheet" | "circularReferences" | "definedNames" | "documentProperties"
146
+ | "externalBooks" | "iteration" | "registeredFunctions" | "removeDefinedName" | "sheetIndex" | "sheetNames"
146
147
  | "toOds" | "toXls" | "unregisterFunction" | "workbookProtection";
147
148
 
148
149
  type SheetActions = {
package/index.js CHANGED
@@ -41,11 +41,12 @@ function build(Book) {
41
41
  ];
42
42
  const BOOK_ACTIONS = [
43
43
  "moveSheet", "protectWorkbook", "registerFunction", "setDefinedName",
44
- "setDocumentProperties", "setTableFilter", "sortTable", "unprotectWorkbook",
44
+ "setDocumentProperties", "setIteration", "setTableFilter", "sortTable",
45
+ "unprotectWorkbook",
45
46
  ];
46
47
  const BOOK_QUERIES = [
47
- "activeSheet", "definedNames", "documentProperties", "externalBooks",
48
- "registeredFunctions", "removeDefinedName", "sheetIndex", "sheetNames",
48
+ "activeSheet", "circularReferences", "definedNames", "documentProperties",
49
+ "externalBooks", "iteration", "registeredFunctions", "removeDefinedName", "sheetIndex", "sheetNames",
49
50
  "toOds", "toXls", "unregisterFunction", "workbookProtection",
50
51
  ];
51
52
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rosperitus/excelerate",
3
3
  "description": "Read, write and recalculate spreadsheets: xlsx, xls, ods, csv, html, and a 518-function formula engine",
4
- "version": "0.16.0",
4
+ "version": "0.18.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -417,6 +417,18 @@ export interface GoalSeekOptions {
417
417
  maxIterations?: number;
418
418
  tolerance?: number;
419
419
  }
420
+ /** Excel's iterative calculation, as `iteration` returns it and `setIteration` takes it. */
421
+ export interface IterationSettings {
422
+ /** Maximum Iterations: the most rounds a cycle is stepped. */
423
+ maxIterations?: number;
424
+ /** Maximum Change: rounds stop once no value moves by more. */
425
+ tolerance?: number;
426
+ }
427
+ /** A formula cell on a circular reference, as `circularReferences` lists it. */
428
+ export interface CircularCell {
429
+ sheet: number;
430
+ address: string;
431
+ }
420
432
  /** How `goalSeek` ended. */
421
433
  export interface GoalSeekResult {
422
434
  /** The value left in the changing cell: the best one tried. */
@@ -542,6 +554,17 @@ export class Book {
542
554
  * ```
543
555
  */
544
556
  checkValidation(sheet: number, address: string, value: CellValue): ValidationProblem | null;
557
+ /**
558
+ * The formula cells on a circular reference, as Excel lists them under
559
+ * Formulas - Error Checking - Circular References: each one reads itself
560
+ * through other formulas. A formula that only reads a cycle is not
561
+ * listed. Without iteration (`setIteration`) these cells compute `#REF!`.
562
+ *
563
+ * ```js
564
+ * for (const { sheet, address } of book.circularReferences()) console.log(sheet, address);
565
+ * ```
566
+ */
567
+ circularReferences(): CircularCell[];
545
568
  /**
546
569
  * Empties a cell, style and all.
547
570
  */
@@ -781,6 +804,11 @@ export class Book {
781
804
  * as Excel's Circle Invalid Data finds them: `["B3", "B9"]`.
782
805
  */
783
806
  invalidCells(sheet: number): string[];
807
+ /**
808
+ * Whether circular references are iterated, Excel's Enable iterative
809
+ * calculation, and with what limits; `null` when they are not.
810
+ */
811
+ iteration(): IterationSettings | null;
784
812
  /**
785
813
  * Merges a block of cells: `merge(0, "A1:C1")`.
786
814
  */
@@ -1074,6 +1102,18 @@ export class Book {
1074
1102
  * is a place in this workbook: `'Sheet 2'!A1`.
1075
1103
  */
1076
1104
  setHyperlink(sheet: number, range: string, target: string, inside?: boolean | null, display?: string | null, tooltip?: string | null): void;
1105
+ /**
1106
+ * Turns iteration of circular references on, or off with `null`. Left
1107
+ * out, `maxIterations` is 100 (at most 32,767, as in Excel) and
1108
+ * `tolerance`, Excel's Maximum Change, 0.001. The setting is saved with
1109
+ * the workbook and used by `recalculate` and `recalculateFrom`.
1110
+ *
1111
+ * ```js
1112
+ * book.setIteration({ maxIterations: 1000, tolerance: 1e-6 });
1113
+ * book.recalculate();
1114
+ * ```
1115
+ */
1116
+ setIteration(settings: IterationSettings | null): void;
1077
1117
  /**
1078
1118
  * Writes a rectangle of values with `at` as its top-left corner. Rows may
1079
1119
  * differ in length; a `null` leaves its cell empty.
@@ -1342,6 +1382,7 @@ export interface InitOutput {
1342
1382
  readonly book_cellStyleAt: (a: number, b: number, c: number, d: number) => [number, number, number];
1343
1383
  readonly book_charts: (a: number, b: number) => [number, number, number];
1344
1384
  readonly book_checkValidation: (a: number, b: number, c: number, d: number, e: any) => [number, number, number];
1385
+ readonly book_circularReferences: (a: number) => any;
1345
1386
  readonly book_clear: (a: number, b: number, c: number, d: number) => [number, number];
1346
1387
  readonly book_clearAt: (a: number, b: number, c: number, d: number) => [number, number];
1347
1388
  readonly book_columnLevel: (a: number, b: number, c: number, d: number) => [number, number, number];
@@ -1382,6 +1423,7 @@ export interface InitOutput {
1382
1423
  readonly book_insertRows: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
1383
1424
  readonly book_insertRowsMany: (a: number, b: number, c: any, d: number, e: number) => [number, number];
1384
1425
  readonly book_invalidCells: (a: number, b: number) => [number, number, number, number];
1426
+ readonly book_iteration: (a: number) => any;
1385
1427
  readonly book_merge: (a: number, b: number, c: number, d: number) => [number, number];
1386
1428
  readonly book_mergedRanges: (a: number, b: number) => [number, number, number, number];
1387
1429
  readonly book_mergedRangesAt: (a: number, b: number) => [number, number, number];
@@ -1428,6 +1470,7 @@ export interface InitOutput {
1428
1470
  readonly book_setDefinedName: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
1429
1471
  readonly book_setDocumentProperties: (a: number, b: any) => [number, number];
1430
1472
  readonly book_setHyperlink: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => [number, number];
1473
+ readonly book_setIteration: (a: number, b: any) => [number, number];
1431
1474
  readonly book_setRange: (a: number, b: number, c: number, d: number, e: any) => [number, number];
1432
1475
  readonly book_setRangeAt: (a: number, b: number, c: number, d: number, e: any) => [number, number];
1433
1476
  readonly book_setRangeStyle: (a: number, b: number, c: number, d: number, e: any) => [number, number];
package/web/excelerate.js CHANGED
@@ -256,6 +256,21 @@ export class Book {
256
256
  }
257
257
  return takeFromExternrefTable0(ret[0]);
258
258
  }
259
+ /**
260
+ * The formula cells on a circular reference, as Excel lists them under
261
+ * Formulas - Error Checking - Circular References: each one reads itself
262
+ * through other formulas. A formula that only reads a cycle is not
263
+ * listed. Without iteration (`setIteration`) these cells compute `#REF!`.
264
+ *
265
+ * ```js
266
+ * for (const { sheet, address } of book.circularReferences()) console.log(sheet, address);
267
+ * ```
268
+ * @returns {CircularCell[]}
269
+ */
270
+ circularReferences() {
271
+ const ret = wasm.book_circularReferences(this.__wbg_ptr);
272
+ return ret;
273
+ }
259
274
  /**
260
275
  * Empties a cell, style and all.
261
276
  * @param {number} sheet
@@ -927,6 +942,15 @@ export class Book {
927
942
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
928
943
  return v1;
929
944
  }
945
+ /**
946
+ * Whether circular references are iterated, Excel's Enable iterative
947
+ * calculation, and with what limits; `null` when they are not.
948
+ * @returns {IterationSettings | null}
949
+ */
950
+ iteration() {
951
+ const ret = wasm.book_iteration(this.__wbg_ptr);
952
+ return ret;
953
+ }
930
954
  /**
931
955
  * Merges a block of cells: `merge(0, "A1:C1")`.
932
956
  * @param {number} sheet
@@ -1655,6 +1679,24 @@ export class Book {
1655
1679
  throw takeFromExternrefTable0(ret[0]);
1656
1680
  }
1657
1681
  }
1682
+ /**
1683
+ * Turns iteration of circular references on, or off with `null`. Left
1684
+ * out, `maxIterations` is 100 (at most 32,767, as in Excel) and
1685
+ * `tolerance`, Excel's Maximum Change, 0.001. The setting is saved with
1686
+ * the workbook and used by `recalculate` and `recalculateFrom`.
1687
+ *
1688
+ * ```js
1689
+ * book.setIteration({ maxIterations: 1000, tolerance: 1e-6 });
1690
+ * book.recalculate();
1691
+ * ```
1692
+ * @param {IterationSettings | null} settings
1693
+ */
1694
+ setIteration(settings) {
1695
+ const ret = wasm.book_setIteration(this.__wbg_ptr, settings);
1696
+ if (ret[1]) {
1697
+ throw takeFromExternrefTable0(ret[0]);
1698
+ }
1699
+ }
1658
1700
  /**
1659
1701
  * Writes a rectangle of values with `at` as its top-left corner. Rows may
1660
1702
  * differ in length; a `null` leaves its cell empty.
Binary file
@@ -17,6 +17,7 @@ export const book_cellStyle: (a: number, b: number, c: number, d: number) => [nu
17
17
  export const book_cellStyleAt: (a: number, b: number, c: number, d: number) => [number, number, number];
18
18
  export const book_charts: (a: number, b: number) => [number, number, number];
19
19
  export const book_checkValidation: (a: number, b: number, c: number, d: number, e: any) => [number, number, number];
20
+ export const book_circularReferences: (a: number) => any;
20
21
  export const book_clear: (a: number, b: number, c: number, d: number) => [number, number];
21
22
  export const book_clearAt: (a: number, b: number, c: number, d: number) => [number, number];
22
23
  export const book_columnLevel: (a: number, b: number, c: number, d: number) => [number, number, number];
@@ -57,6 +58,7 @@ export const book_insertColumnsMany: (a: number, b: number, c: any, d: number, e
57
58
  export const book_insertRows: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
58
59
  export const book_insertRowsMany: (a: number, b: number, c: any, d: number, e: number) => [number, number];
59
60
  export const book_invalidCells: (a: number, b: number) => [number, number, number, number];
61
+ export const book_iteration: (a: number) => any;
60
62
  export const book_merge: (a: number, b: number, c: number, d: number) => [number, number];
61
63
  export const book_mergedRanges: (a: number, b: number) => [number, number, number, number];
62
64
  export const book_mergedRangesAt: (a: number, b: number) => [number, number, number];
@@ -103,6 +105,7 @@ export const book_setComment: (a: number, b: number, c: number, d: number, e: nu
103
105
  export const book_setDefinedName: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
104
106
  export const book_setDocumentProperties: (a: number, b: any) => [number, number];
105
107
  export const book_setHyperlink: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => [number, number];
108
+ export const book_setIteration: (a: number, b: any) => [number, number];
106
109
  export const book_setRange: (a: number, b: number, c: number, d: number, e: any) => [number, number];
107
110
  export const book_setRangeAt: (a: number, b: number, c: number, d: number, e: any) => [number, number];
108
111
  export const book_setRangeStyle: (a: number, b: number, c: number, d: number, e: any) => [number, number];
package/web/index.d.ts CHANGED
@@ -140,10 +140,11 @@ type SheetQueryName =
140
140
  /** Every `Book` method without a sheet is a `Workbook` method, chaining the same way. */
141
141
  type BookActionName =
142
142
  | "moveSheet" | "protectWorkbook" | "registerFunction" | "setDefinedName"
143
- | "setDocumentProperties" | "setTableFilter" | "sortTable" | "unprotectWorkbook";
143
+ | "setDocumentProperties" | "setIteration" | "setTableFilter" | "sortTable"
144
+ | "unprotectWorkbook";
144
145
  type BookQueryName =
145
- | "activeSheet" | "definedNames" | "documentProperties" | "externalBooks"
146
- | "registeredFunctions" | "removeDefinedName" | "sheetIndex" | "sheetNames"
146
+ | "activeSheet" | "circularReferences" | "definedNames" | "documentProperties"
147
+ | "externalBooks" | "iteration" | "registeredFunctions" | "removeDefinedName" | "sheetIndex" | "sheetNames"
147
148
  | "toOds" | "toXls" | "unregisterFunction" | "workbookProtection";
148
149
 
149
150
  type SheetActions = {
package/web/index.js CHANGED
@@ -42,11 +42,12 @@ function build(Book) {
42
42
  ];
43
43
  const BOOK_ACTIONS = [
44
44
  "moveSheet", "protectWorkbook", "registerFunction", "setDefinedName",
45
- "setDocumentProperties", "setTableFilter", "sortTable", "unprotectWorkbook",
45
+ "setDocumentProperties", "setIteration", "setTableFilter", "sortTable",
46
+ "unprotectWorkbook",
46
47
  ];
47
48
  const BOOK_QUERIES = [
48
- "activeSheet", "definedNames", "documentProperties", "externalBooks",
49
- "registeredFunctions", "removeDefinedName", "sheetIndex", "sheetNames",
49
+ "activeSheet", "circularReferences", "definedNames", "documentProperties",
50
+ "externalBooks", "iteration", "registeredFunctions", "removeDefinedName", "sheetIndex", "sheetNames",
50
51
  "toOds", "toXls", "unregisterFunction", "workbookProtection",
51
52
  ];
52
53