@rosperitus/excelerate 0.8.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/LICENSE +21 -0
- package/README.md +186 -0
- package/excelerate.d.ts +359 -0
- package/excelerate.js +1152 -0
- package/excelerate_bg.wasm +0 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yuri Rubtsov (aka rosperitus)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# excelerate
|
|
2
|
+
|
|
3
|
+
Read, write and recalculate spreadsheets in Node - xlsx, xls, ods, csv, html
|
|
4
|
+
and more - with a real formula engine (443 Excel functions). Rust compiled to
|
|
5
|
+
WebAssembly, so there is no native module to build, no Python, no headless
|
|
6
|
+
Office.
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm install @rosperitus/excelerate
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
TypeScript declarations ship with the package; nothing extra to install.
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { Book } from "@rosperitus/excelerate";
|
|
18
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
19
|
+
|
|
20
|
+
// The format is detected from the bytes. The file name is optional and only
|
|
21
|
+
// settles the ambiguous cases (a .csv against an .html).
|
|
22
|
+
const book = Book.read(readFileSync("report.xlsx"), "report.xlsx");
|
|
23
|
+
|
|
24
|
+
console.log(book.sheetNames()); // ["Sheet1", "Data"]
|
|
25
|
+
console.log(book.get(0, "B4")); // number | string | boolean | null
|
|
26
|
+
|
|
27
|
+
book.set(0, "B4", 42);
|
|
28
|
+
book.recalculateFrom(0, "B4"); // only what depends on B4
|
|
29
|
+
|
|
30
|
+
writeFileSync("out.xlsx", book.toXlsx());
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Build one from scratch:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { Book } from "@rosperitus/excelerate";
|
|
37
|
+
|
|
38
|
+
const book = new Book();
|
|
39
|
+
book.set(0, "A1", "Item");
|
|
40
|
+
book.set(0, "B1", "Price");
|
|
41
|
+
book.set(0, "A2", "Bolt");
|
|
42
|
+
book.set(0, "B2", 7.5);
|
|
43
|
+
book.set(0, "A3", "Total");
|
|
44
|
+
book.set(0, "B3", "=SUM(B2:B2)"); // a string starting with = is a formula
|
|
45
|
+
|
|
46
|
+
book.recalculate();
|
|
47
|
+
console.log(book.toCsv(0));
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
type CellValue = number | string | boolean | null;
|
|
54
|
+
type CellGrid = CellValue[][];
|
|
55
|
+
|
|
56
|
+
class Book {
|
|
57
|
+
constructor();
|
|
58
|
+
static fromXlsx(bytes: Uint8Array): Book;
|
|
59
|
+
static read(bytes: Uint8Array, name?: string | null, maxExpanded?: number | null): Book;
|
|
60
|
+
|
|
61
|
+
// Sheets
|
|
62
|
+
sheetNames(): string[];
|
|
63
|
+
sheetIndex(name: string): number | undefined; // case-insensitive, as Excel compares
|
|
64
|
+
addSheet(title: string): number;
|
|
65
|
+
renameSheet(sheet: number, title: string): void;
|
|
66
|
+
activeSheet(): number;
|
|
67
|
+
setActiveSheet(sheet: number): void;
|
|
68
|
+
cellCount(sheet?: number | null): number;
|
|
69
|
+
usedRange(sheet: number): string | undefined; // "A1:D9"
|
|
70
|
+
|
|
71
|
+
// Cells, by address
|
|
72
|
+
get(sheet: number, address: string): CellValue;
|
|
73
|
+
set(sheet: number, address: string, value: CellValue): void;
|
|
74
|
+
clear(sheet: number, address: string): void;
|
|
75
|
+
getFormula(sheet: number, address: string): string | undefined;
|
|
76
|
+
getFormatted(sheet: number, address: string): string; // through the number format
|
|
77
|
+
getRange(sheet: number, range: string): CellGrid; // one call, not one per cell
|
|
78
|
+
setRange(sheet: number, at: string, values: CellGrid): void;
|
|
79
|
+
|
|
80
|
+
// Cells, by 1-based row and column - no address to build and re-parse
|
|
81
|
+
getAt(sheet: number, row: number, column: number): CellValue;
|
|
82
|
+
setAt(sheet: number, row: number, column: number, value: CellValue): void;
|
|
83
|
+
clearAt(sheet: number, row: number, column: number): void;
|
|
84
|
+
getFormulaAt(sheet: number, row: number, column: number): string | undefined;
|
|
85
|
+
getFormattedAt(sheet: number, row: number, column: number): string;
|
|
86
|
+
getRangeAt(sheet: number, row: number, column: number, rows: number, columns: number): CellGrid;
|
|
87
|
+
setRangeAt(sheet: number, row: number, column: number, values: CellGrid): void;
|
|
88
|
+
recalculateCellAt(sheet: number, row: number, column: number): boolean;
|
|
89
|
+
recalculateFromAt(sheet: number, row: number, column: number): number;
|
|
90
|
+
|
|
91
|
+
// Layout
|
|
92
|
+
cellIndent(sheet: number, address: string): number; // indent steps, 0 when none
|
|
93
|
+
cellIndentAt(sheet: number, row: number, column: number): number;
|
|
94
|
+
cellBold(sheet: number, address: string): boolean; // the one flag, without the whole style
|
|
95
|
+
cellBoldAt(sheet: number, row: number, column: number): boolean;
|
|
96
|
+
rowLevel(sheet: number, row: number): number; // outline depth, 0 when ungrouped
|
|
97
|
+
columnLevel(sheet: number, column: string): number; // by letters: "C"
|
|
98
|
+
rowHidden(sheet: number, row: number): boolean;
|
|
99
|
+
sheetVisibility(sheet: number): "visible" | "hidden" | "veryHidden";
|
|
100
|
+
mergedRanges(sheet: number): string[]; // ["A1:C1", ...]
|
|
101
|
+
mergedRangesAt(sheet: number): Uint32Array; // [r1, c1, r2, c2] per area
|
|
102
|
+
getRowAt(sheet: number, row: number, formatted?: boolean): SheetRow;
|
|
103
|
+
|
|
104
|
+
// Calculation
|
|
105
|
+
evaluate(sheet: number, address: string, formula: string): CellValue;
|
|
106
|
+
recalculate(sheet?: number | null): number;
|
|
107
|
+
recalculateCell(sheet: number, address: string): boolean;
|
|
108
|
+
recalculateFrom(sheet: number, address: string): number;
|
|
109
|
+
recalculateFromMany(sheet: number, addresses: string[]): number;
|
|
110
|
+
|
|
111
|
+
// Output
|
|
112
|
+
toXlsx(): Uint8Array;
|
|
113
|
+
toOds(): Uint8Array;
|
|
114
|
+
toXls(): Uint8Array;
|
|
115
|
+
toHtml(sheet?: number | null, fragment?: boolean | null): string;
|
|
116
|
+
toCsv(sheet: number): string;
|
|
117
|
+
|
|
118
|
+
free(): void;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Every method that can fail throws an `Error` with the reason - a bad address, a
|
|
123
|
+
missing sheet, a truncated package.
|
|
124
|
+
|
|
125
|
+
## Notes worth reading once
|
|
126
|
+
|
|
127
|
+
- **`free()` / `using`.** The workbook lives in wasm memory. Node's GC will get
|
|
128
|
+
to it eventually, but in a loop over many files, release it deliberately:
|
|
129
|
+
`book.free()`, or `using book = Book.read(...)` with explicit resource
|
|
130
|
+
management.
|
|
131
|
+
- **Numbers or addresses, your call.** Every cell method has an `...At` twin
|
|
132
|
+
taking 1-based `row` and `column` - the numbers `ROW()` and `COLUMN()`
|
|
133
|
+
return. Looping over a grid, they save building an address string only to
|
|
134
|
+
have it parsed straight back.
|
|
135
|
+
- **Move rectangles, not cells.** `getRange`/`setRange` cross the wasm
|
|
136
|
+
boundary once for the whole block; a loop of `get` crosses once per cell.
|
|
137
|
+
- **Batch your edits.** `recalculateFromMany(sheet, ["A1", "B7", ...])` runs one
|
|
138
|
+
pass for the whole batch. Calling `recalculateFrom` in a loop runs one pass
|
|
139
|
+
per cell - on a 20k-formula workbook that is roughly 20x the work.
|
|
140
|
+
- **Big files.** Zip expansion is capped at 512 MB to stop a zip bomb. Real
|
|
141
|
+
workbooks do exceed it (a 100 MB package can expand to 560 MB), so pass a
|
|
142
|
+
larger `maxExpanded` third argument to `Book.read` when you know the source.
|
|
143
|
+
- **Cached results.** A formula cell read from a file carries whatever the app
|
|
144
|
+
that saved it computed. Call `recalculate()` before relying on those numbers.
|
|
145
|
+
|
|
146
|
+
## Formats
|
|
147
|
+
|
|
148
|
+
| Format | Read | Write |
|
|
149
|
+
|---|:--:|:--:|
|
|
150
|
+
| xlsx | ✅ | ✅ (`toXlsx`) |
|
|
151
|
+
| xls (BIFF8) | ✅ | ✅ (`toXls`) |
|
|
152
|
+
| ods | ✅ | ✅ (`toOds`) |
|
|
153
|
+
| CSV | ✅ | ✅ (`toCsv`) |
|
|
154
|
+
| HTML | ✅ | ✅ (`toHtml`) |
|
|
155
|
+
| SYLK, Gnumeric, SpreadsheetML 2003 | ✅ | - |
|
|
156
|
+
|
|
157
|
+
SYLK, Gnumeric and SpreadsheetML are read-only in the Rust crate too - there is
|
|
158
|
+
nothing to bind.
|
|
159
|
+
|
|
160
|
+
One catch on `toXls`: BIFF8 cannot store a formula as text, so every formula
|
|
161
|
+
goes out as its last computed value. Call `recalculate()` first.
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
This folder is both the published package's readme and the workspace that
|
|
166
|
+
builds and exercises it.
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
../tools/build-npm.sh # wasm-pack --release --target nodejs -> npm/pkg
|
|
170
|
+
npm install && npm test # tests against the freshly built package
|
|
171
|
+
npm start # example.js: build a book, calculate, round-trip
|
|
172
|
+
npm run ts # typescript/basic.ts, no build step
|
|
173
|
+
npm run typecheck # tsc --strict over the TypeScript examples
|
|
174
|
+
npm run bench [iterations] # parse timings, median and best
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
| Path | What it is |
|
|
178
|
+
|---|---|
|
|
179
|
+
| `pkg/` | build output, published as-is (git-ignored) |
|
|
180
|
+
| `example.js`, `test.js`, `bench.js` | JavaScript examples, tests, benchmark |
|
|
181
|
+
| `typescript/` | TypeScript examples, run from here: `node typescript/basic.ts` (Node 22.6+). No node_modules of their own - they resolve the package from this folder |
|
|
182
|
+
| `files/` | workbooks the benchmark and tests use (git-ignored except `gen.xlsx`) |
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
MIT
|
package/excelerate.d.ts
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/** What a cell can hold on the JS side. An error cell reads as its code, `#DIV/0!`. */
|
|
5
|
+
export type CellValue = number | string | boolean | null;
|
|
6
|
+
/** A rectangle of cells, row by row, as `getRange` returns it. */
|
|
7
|
+
export type CellGrid = CellValue[][];
|
|
8
|
+
/**
|
|
9
|
+
* One row with its styling, as `getRowAt` returns it. `formatted` is `null`
|
|
10
|
+
* when the call asked for values alone. `bold` is one byte per cell, 0 or 1.
|
|
11
|
+
*/
|
|
12
|
+
export interface SheetRow {
|
|
13
|
+
values: CellValue[];
|
|
14
|
+
formatted: string[] | null;
|
|
15
|
+
bold: Uint8Array;
|
|
16
|
+
indent: Uint32Array;
|
|
17
|
+
hidden: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A colour as the file states it: `null` when the file leaves it to the
|
|
21
|
+
* reader, `#AARRGGBB` when it names one outright, and `indexed:N` or
|
|
22
|
+
* `theme:N` when it points into the legacy palette or the workbook theme -
|
|
23
|
+
* a theme colour carries its tint as `theme:4@-0.25`.
|
|
24
|
+
*/
|
|
25
|
+
export type StyleColor = string | null;
|
|
26
|
+
/** One side of a cell's border. */
|
|
27
|
+
export interface BorderSide { style: string; color: StyleColor }
|
|
28
|
+
/** How a cell is painted, as `cellStyle` returns it. */
|
|
29
|
+
export interface CellStyle {
|
|
30
|
+
numberFormat: string;
|
|
31
|
+
font: {
|
|
32
|
+
name: string;
|
|
33
|
+
size: number;
|
|
34
|
+
bold: boolean;
|
|
35
|
+
italic: boolean;
|
|
36
|
+
underline: string;
|
|
37
|
+
strike: boolean;
|
|
38
|
+
color: StyleColor;
|
|
39
|
+
};
|
|
40
|
+
fill: { pattern: string; foreground: StyleColor; background: StyleColor };
|
|
41
|
+
borders: {
|
|
42
|
+
left: BorderSide;
|
|
43
|
+
right: BorderSide;
|
|
44
|
+
top: BorderSide;
|
|
45
|
+
bottom: BorderSide;
|
|
46
|
+
};
|
|
47
|
+
alignment: {
|
|
48
|
+
horizontal: string | null;
|
|
49
|
+
vertical: string | null;
|
|
50
|
+
wrapText: boolean;
|
|
51
|
+
shrinkToFit: boolean;
|
|
52
|
+
indent: number;
|
|
53
|
+
textRotation: number;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A workbook.
|
|
61
|
+
*/
|
|
62
|
+
export class Book {
|
|
63
|
+
free(): void;
|
|
64
|
+
[Symbol.dispose](): void;
|
|
65
|
+
/**
|
|
66
|
+
* The tab a reader opens the workbook on.
|
|
67
|
+
*/
|
|
68
|
+
activeSheet(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Appends a sheet and returns its index.
|
|
71
|
+
*/
|
|
72
|
+
addSheet(title: string): number;
|
|
73
|
+
/**
|
|
74
|
+
* Whether a cell is bold.
|
|
75
|
+
*
|
|
76
|
+
* The one flag, without building the rest of the style: a parser that
|
|
77
|
+
* looks for a header row asks this of every cell, and `cellStyle` would
|
|
78
|
+
* make it pay for the font, fill and four borders it never reads.
|
|
79
|
+
*/
|
|
80
|
+
cellBold(sheet: number, address: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The same by 1-based row and column.
|
|
83
|
+
*/
|
|
84
|
+
cellBoldAt(sheet: number, row: number, column: number): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* How many non-empty cells the workbook holds, or one sheet of it.
|
|
87
|
+
*/
|
|
88
|
+
cellCount(sheet?: number | null): number;
|
|
89
|
+
/**
|
|
90
|
+
* The indent of a cell, in Excel's indent steps (0 when it has none).
|
|
91
|
+
*
|
|
92
|
+
* Indent lives on the cell's style, and a spreadsheet only honours it for
|
|
93
|
+
* left, right and distributed alignment - but the number is returned as
|
|
94
|
+
* the file states it, whatever the alignment.
|
|
95
|
+
*/
|
|
96
|
+
cellIndent(sheet: number, address: string): number;
|
|
97
|
+
/**
|
|
98
|
+
* The same by 1-based row and column.
|
|
99
|
+
*/
|
|
100
|
+
cellIndentAt(sheet: number, row: number, column: number): number;
|
|
101
|
+
/**
|
|
102
|
+
* How a cell is painted: number format, font, fill, borders and text
|
|
103
|
+
* placement, as the file states them.
|
|
104
|
+
*
|
|
105
|
+
* A cell the file says nothing about answers with Excel's defaults, which
|
|
106
|
+
* is what Excel itself shows for it.
|
|
107
|
+
*/
|
|
108
|
+
cellStyle(sheet: number, address: string): CellStyle;
|
|
109
|
+
/**
|
|
110
|
+
* The same by 1-based row and column.
|
|
111
|
+
*/
|
|
112
|
+
cellStyleAt(sheet: number, row: number, column: number): CellStyle;
|
|
113
|
+
/**
|
|
114
|
+
* Empties a cell, style and all.
|
|
115
|
+
*/
|
|
116
|
+
clear(sheet: number, address: string): void;
|
|
117
|
+
/**
|
|
118
|
+
* The same by 1-based row and column.
|
|
119
|
+
*/
|
|
120
|
+
clearAt(sheet: number, row: number, column: number): void;
|
|
121
|
+
/**
|
|
122
|
+
* The same for a column, named by its letters: `columnLevel(0, "C")`.
|
|
123
|
+
*/
|
|
124
|
+
columnLevel(sheet: number, column: string): number;
|
|
125
|
+
/**
|
|
126
|
+
* Evaluates a formula (with or without the leading `=`) as if it sat in
|
|
127
|
+
* `address` of `sheet`, and returns its result.
|
|
128
|
+
*/
|
|
129
|
+
evaluate(sheet: number, address: string, formula: string): CellValue;
|
|
130
|
+
/**
|
|
131
|
+
* Reads an xlsx package from its bytes.
|
|
132
|
+
*/
|
|
133
|
+
static fromXlsx(bytes: Uint8Array): Book;
|
|
134
|
+
/**
|
|
135
|
+
* The value at `address` on sheet `sheet`, as a JS number, string, boolean
|
|
136
|
+
* or `null`. A formula cell gives its cached result, not its text.
|
|
137
|
+
*/
|
|
138
|
+
get(sheet: number, address: string): CellValue;
|
|
139
|
+
/**
|
|
140
|
+
* The same by 1-based row and column, the numbers `ROW()` and `COLUMN()`
|
|
141
|
+
* return: `getAt(0, 4, 2)` is `B4`. Saves formatting an address only to
|
|
142
|
+
* parse it again.
|
|
143
|
+
*/
|
|
144
|
+
getAt(sheet: number, row: number, column: number): CellValue;
|
|
145
|
+
/**
|
|
146
|
+
* The cell as a spreadsheet would display it: the value run through its
|
|
147
|
+
* number format, so `0.256` under `0.0%` reads `25.6%`.
|
|
148
|
+
*/
|
|
149
|
+
getFormatted(sheet: number, address: string): string;
|
|
150
|
+
/**
|
|
151
|
+
* The same by 1-based row and column.
|
|
152
|
+
*/
|
|
153
|
+
getFormattedAt(sheet: number, row: number, column: number): string;
|
|
154
|
+
/**
|
|
155
|
+
* The formula text of a cell without its leading `=`, or `undefined` when
|
|
156
|
+
* the cell holds a plain value.
|
|
157
|
+
*/
|
|
158
|
+
getFormula(sheet: number, address: string): string | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* The same by 1-based row and column.
|
|
161
|
+
*/
|
|
162
|
+
getFormulaAt(sheet: number, row: number, column: number): string | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* A rectangle of cells, row by row. One call across the boundary instead
|
|
165
|
+
* of one per cell, which is what makes reading a sheet worth doing.
|
|
166
|
+
*/
|
|
167
|
+
getRange(sheet: number, range: string): CellGrid;
|
|
168
|
+
/**
|
|
169
|
+
* The same by numbers: the top-left cell, then how many rows and columns
|
|
170
|
+
* to take. `getRangeAt(0, 1, 1, 3, 2)` is `A1:B3`.
|
|
171
|
+
*/
|
|
172
|
+
getRangeAt(sheet: number, row: number, column: number, rows: number, columns: number): CellGrid;
|
|
173
|
+
/**
|
|
174
|
+
* A whole row in one crossing of the boundary: values, displayed text,
|
|
175
|
+
* bold and indent, plus whether the row is hidden.
|
|
176
|
+
*
|
|
177
|
+
* The arrays run from column 1 to the last column this row has a cell in,
|
|
178
|
+
* so a row of ten cells costs one call rather than forty.
|
|
179
|
+
*
|
|
180
|
+
* `formatted` is what the number format makes of each value, and building
|
|
181
|
+
* it allocates a string per cell - which a caller reading values does not
|
|
182
|
+
* want to pay half a sheet over. Pass `false` and the field comes back
|
|
183
|
+
* `null`; `getFormattedAt` still answers for the cells that need it.
|
|
184
|
+
*/
|
|
185
|
+
getRowAt(sheet: number, row: number, formatted?: boolean | null): SheetRow;
|
|
186
|
+
/**
|
|
187
|
+
* The merged areas of a sheet, as `"A1:C1"` strings in the order the file
|
|
188
|
+
* lists them.
|
|
189
|
+
*/
|
|
190
|
+
mergedRanges(sheet: number): string[];
|
|
191
|
+
/**
|
|
192
|
+
* The merged areas of a sheet as numbers: four per area, `[r1, c1, r2,
|
|
193
|
+
* c2]`, rows and columns 1-based.
|
|
194
|
+
*
|
|
195
|
+
* One typed array instead of a JS string per area, which is what a sheet
|
|
196
|
+
* carrying three hundred thousand of them needs.
|
|
197
|
+
*/
|
|
198
|
+
mergedRangesAt(sheet: number): Uint32Array;
|
|
199
|
+
/**
|
|
200
|
+
* A new workbook with one empty sheet.
|
|
201
|
+
*/
|
|
202
|
+
constructor();
|
|
203
|
+
/**
|
|
204
|
+
* Reads a workbook of any format this crate supports, working the format
|
|
205
|
+
* out from the bytes themselves.
|
|
206
|
+
*
|
|
207
|
+
* `name` is the file name they came from, if the caller has one: it
|
|
208
|
+
* settles what the bytes cannot say (a `.csv` against a `.html`) and names
|
|
209
|
+
* the sheet of a SYLK file.
|
|
210
|
+
*/
|
|
211
|
+
static read(bytes: Uint8Array, name?: string | null, max_expanded?: number | null, on_progress?: Function | null): Book;
|
|
212
|
+
/**
|
|
213
|
+
* Recomputes every formula and stores the results beside them, so that
|
|
214
|
+
* `get` and `toCsv` show this engine's answers rather than the cache the
|
|
215
|
+
* file was saved with. Returns how many formulas were computed.
|
|
216
|
+
*
|
|
217
|
+
* With no argument the whole workbook is recomputed; with a sheet index,
|
|
218
|
+
* only that sheet's formulas are - though they still read the whole
|
|
219
|
+
* workbook, as a cross-sheet reference must.
|
|
220
|
+
*/
|
|
221
|
+
recalculate(sheet?: number | null, on_progress?: Function | null): number;
|
|
222
|
+
/**
|
|
223
|
+
* Recomputes the formula in one cell and stores its result. Returns
|
|
224
|
+
* whether there was a formula there.
|
|
225
|
+
*
|
|
226
|
+
* Not the same as `recalculateFrom`, which recomputes the formulas
|
|
227
|
+
* *reading* this cell and leaves the cell itself alone.
|
|
228
|
+
*/
|
|
229
|
+
recalculateCell(sheet: number, address: string): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* The same by 1-based row and column.
|
|
232
|
+
*/
|
|
233
|
+
recalculateCellAt(sheet: number, row: number, column: number): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Recomputes only what depends on one cell that changed - the formulas
|
|
236
|
+
* reading it, the formulas reading those, and so on. Returns how many were
|
|
237
|
+
* computed. This is the pass to run after `set`.
|
|
238
|
+
*
|
|
239
|
+
* For a batch of edits use `recalculateFromMany`, which answers them all
|
|
240
|
+
* in one pass.
|
|
241
|
+
*/
|
|
242
|
+
recalculateFrom(sheet: number, address: string): number;
|
|
243
|
+
/**
|
|
244
|
+
* The same by 1-based row and column.
|
|
245
|
+
*/
|
|
246
|
+
recalculateFromAt(sheet: number, row: number, column: number): number;
|
|
247
|
+
/**
|
|
248
|
+
* The same for a batch of cells, all on sheet `sheet`, answered in one
|
|
249
|
+
* pass: editing a hundred cells costs one walk of the workbook, not a
|
|
250
|
+
* hundred.
|
|
251
|
+
*
|
|
252
|
+
* The index of what reads what is built on the first call and kept, so a
|
|
253
|
+
* run of edits parses the formulas only once. `set` keeps it in step.
|
|
254
|
+
*/
|
|
255
|
+
recalculateFromMany(sheet: number, addresses: string[]): number;
|
|
256
|
+
/**
|
|
257
|
+
* Registers a function of your own, callable from any formula in the
|
|
258
|
+
* workbook by that name.
|
|
259
|
+
*
|
|
260
|
+
* The function is handed the arguments already computed - a range arrives
|
|
261
|
+
* as an array of arrays - and whatever it returns becomes the value. A
|
|
262
|
+
* name a built-in claims stays the built-in's: a workbook where `SUM`
|
|
263
|
+
* means something else is a workbook nobody else can read.
|
|
264
|
+
*
|
|
265
|
+
* ```js
|
|
266
|
+
* book.registerFunction("MYRATE", (base) => base * 1.5 + 0.5);
|
|
267
|
+
* book.evaluate(0, "A1", "=MYRATE(10)"); // 15.5
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
registerFunction(name: string, _function: Function): void;
|
|
271
|
+
/**
|
|
272
|
+
* The names registered, in no particular order.
|
|
273
|
+
*/
|
|
274
|
+
registeredFunctions(): string[];
|
|
275
|
+
/**
|
|
276
|
+
* Renames a sheet.
|
|
277
|
+
*/
|
|
278
|
+
renameSheet(sheet: number, title: string): void;
|
|
279
|
+
/**
|
|
280
|
+
* Whether a row is hidden. `row` is the number a user sees.
|
|
281
|
+
*/
|
|
282
|
+
rowHidden(sheet: number, row: number): boolean;
|
|
283
|
+
/**
|
|
284
|
+
* How deeply a row is grouped: 0 when it is not, 1 for the outermost
|
|
285
|
+
* group, and so on. `row` is the number a user sees.
|
|
286
|
+
*/
|
|
287
|
+
rowLevel(sheet: number, row: number): number;
|
|
288
|
+
/**
|
|
289
|
+
* Writes a value: a number, boolean, or string. A string starting with `=`
|
|
290
|
+
* becomes a formula.
|
|
291
|
+
*/
|
|
292
|
+
set(index: number, address: string, value: CellValue): void;
|
|
293
|
+
/**
|
|
294
|
+
* Sets that tab.
|
|
295
|
+
*/
|
|
296
|
+
setActiveSheet(sheet: number): void;
|
|
297
|
+
/**
|
|
298
|
+
* The same by 1-based row and column.
|
|
299
|
+
*/
|
|
300
|
+
setAt(sheet: number, row: number, column: number, value: CellValue): void;
|
|
301
|
+
/**
|
|
302
|
+
* Writes a rectangle of values with `at` as its top-left corner. Rows may
|
|
303
|
+
* differ in length; a `null` leaves its cell empty.
|
|
304
|
+
*/
|
|
305
|
+
setRange(sheet: number, at: string, values: CellGrid): void;
|
|
306
|
+
/**
|
|
307
|
+
* The same with the corner given as 1-based row and column.
|
|
308
|
+
*/
|
|
309
|
+
setRangeAt(sheet: number, row: number, column: number, values: CellGrid): void;
|
|
310
|
+
/**
|
|
311
|
+
* The tab index of a sheet by name, or `undefined` when there is none.
|
|
312
|
+
* Names are compared the way Excel does, ignoring case.
|
|
313
|
+
*/
|
|
314
|
+
sheetIndex(name: string): number | undefined;
|
|
315
|
+
/**
|
|
316
|
+
* Sheet titles, in tab order.
|
|
317
|
+
*/
|
|
318
|
+
sheetNames(): string[];
|
|
319
|
+
/**
|
|
320
|
+
* Whether a sheet has a tab: `"visible"`, `"hidden"` or `"veryHidden"`.
|
|
321
|
+
*
|
|
322
|
+
* `sheetNames` lists every sheet, hidden ones included, because that is
|
|
323
|
+
* what the index of every other call counts.
|
|
324
|
+
*/
|
|
325
|
+
sheetVisibility(sheet: number): string;
|
|
326
|
+
/**
|
|
327
|
+
* One sheet as CSV.
|
|
328
|
+
*/
|
|
329
|
+
toCsv(sheet: number): string;
|
|
330
|
+
/**
|
|
331
|
+
* The workbook as an HTML page, or one sheet of it. `fragment` leaves out
|
|
332
|
+
* the `<html>` wrapper, for embedding in a page that already has one.
|
|
333
|
+
*/
|
|
334
|
+
toHtml(sheet?: number | null, fragment?: boolean | null): string;
|
|
335
|
+
/**
|
|
336
|
+
* The workbook as an `OpenDocument` spreadsheet.
|
|
337
|
+
*/
|
|
338
|
+
toOds(): Uint8Array;
|
|
339
|
+
/**
|
|
340
|
+
* The workbook as a BIFF8 `.xls` file.
|
|
341
|
+
*
|
|
342
|
+
* The format cannot hold a formula as text, so every formula is written
|
|
343
|
+
* as its last computed value; call `recalculate` first if that matters.
|
|
344
|
+
*/
|
|
345
|
+
toXls(): Uint8Array;
|
|
346
|
+
/**
|
|
347
|
+
* The workbook as an xlsx package.
|
|
348
|
+
*/
|
|
349
|
+
toXlsx(on_progress?: Function | null): Uint8Array;
|
|
350
|
+
/**
|
|
351
|
+
* Forgets a function registered earlier; answers whether there was one.
|
|
352
|
+
*/
|
|
353
|
+
unregisterFunction(name: string): boolean;
|
|
354
|
+
/**
|
|
355
|
+
* The used range of a sheet as `A1:D9`, or `undefined` if it holds
|
|
356
|
+
* nothing. This is the rectangle to walk; the sheet itself is sparse.
|
|
357
|
+
*/
|
|
358
|
+
usedRange(sheet: number): string | undefined;
|
|
359
|
+
}
|