@rosperitus/excelerate 0.13.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 +137 -9
- package/excelerate.d.ts +264 -4
- package/excelerate.js +268 -4
- package/excelerate_bg.wasm +0 -0
- package/index.d.ts +159 -0
- package/index.js +409 -0
- package/package.json +25 -5
- package/web/excelerate.d.ts +1345 -0
- package/web/excelerate.js +2519 -0
- package/web/excelerate_bg.wasm +0 -0
- package/web/excelerate_bg.wasm.d.ts +153 -0
- package/web/index.d.ts +160 -0
- package/web/index.js +406 -0
- package/web/package.json +4 -0
package/README.md
CHANGED
|
@@ -11,7 +11,11 @@ npm install @rosperitus/excelerate
|
|
|
11
11
|
|
|
12
12
|
TypeScript declarations ship with the package. Only need to read? The
|
|
13
13
|
`@rosperitus/excelerate-reader` package has the reading half of the API in a
|
|
14
|
-
wasm file of 1.
|
|
14
|
+
wasm file of 1.4 MB instead of 3.9 MB (0.6 MB against 1.5 MB gzipped).
|
|
15
|
+
|
|
16
|
+
The examples use `import`: a project needs `"type": "module"` in its
|
|
17
|
+
`package.json` for that (`npm init -y` writes `"commonjs"`), or `require`
|
|
18
|
+
works the same - `const { Book } = require("@rosperitus/excelerate")`.
|
|
15
19
|
|
|
16
20
|
## Quick start
|
|
17
21
|
|
|
@@ -63,10 +67,101 @@ writeFileSync("report.xlsx", book.toXlsx());
|
|
|
63
67
|
Continue a series the way the fill handle does:
|
|
64
68
|
|
|
65
69
|
```ts
|
|
70
|
+
import { Book } from "@rosperitus/excelerate";
|
|
71
|
+
|
|
72
|
+
const book = new Book();
|
|
66
73
|
book.setRange(0, "F1", [["Jan", "Кв1", 1], [null, null, 3]]);
|
|
67
74
|
book.fillSeries(0, "F1:H6", "down"); // Feb..Jun, Кв2..Кв6, 5, 7, 9, 11
|
|
68
75
|
```
|
|
69
76
|
|
|
77
|
+
## In the browser
|
|
78
|
+
|
|
79
|
+
The package carries a second build for browsers and bundlers (Vite, webpack,
|
|
80
|
+
esbuild), and the same import picks it there. The one difference from Node:
|
|
81
|
+
the module has to be started first, which fetches the `.wasm`:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import init, { Book } from "@rosperitus/excelerate";
|
|
85
|
+
|
|
86
|
+
await init();
|
|
87
|
+
const file = document.querySelector("input[type=file]") as HTMLInputElement;
|
|
88
|
+
const book = Book.read(new Uint8Array(await file.files![0].arrayBuffer()));
|
|
89
|
+
const blob = new Blob([book.toXlsx()]);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The `.wasm` is fetched from beside the module, so the server should send it as
|
|
93
|
+
`application/wasm`; then the browser compiles it as it streams. Without a
|
|
94
|
+
bundler, an import map pointing at `@rosperitus/excelerate/web/index.js` does
|
|
95
|
+
the same. `@rosperitus/excelerate/web` names the browser build explicitly,
|
|
96
|
+
which also runs in Node given the bytes: `await init({ module_or_path: bytes })`.
|
|
97
|
+
|
|
98
|
+
## Objects and chains
|
|
99
|
+
|
|
100
|
+
`Book` is one flat class addressed by sheet index. Over it sit `Workbook`,
|
|
101
|
+
`Sheet`, `Table` and `SheetRange`: a workbook hands out sheets, a sheet hands
|
|
102
|
+
out tables and ranges, and every call that changes something returns its
|
|
103
|
+
object, so calls chain.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { Workbook } from "@rosperitus/excelerate";
|
|
107
|
+
import { writeFileSync } from "node:fs";
|
|
108
|
+
|
|
109
|
+
const wb = new Workbook();
|
|
110
|
+
const sales = wb
|
|
111
|
+
.addSheet("Sales") // a new workbook's first sheet, renamed
|
|
112
|
+
.addTableFromData("Sales", "A1", [
|
|
113
|
+
["Region", "Manager", "Amount"],
|
|
114
|
+
["North", "Ivanov", 120],
|
|
115
|
+
["South", "Petrov", 340],
|
|
116
|
+
["West", "Kozlov", 210],
|
|
117
|
+
["South", "Smirnov", 95],
|
|
118
|
+
])
|
|
119
|
+
.set(1, "Amount", 125) // data row 1, by header
|
|
120
|
+
.addFilter("Region", { values: ["South", "West"] })
|
|
121
|
+
.addFilter("Amount", { custom: [{ op: ">", value: 100 }] });
|
|
122
|
+
|
|
123
|
+
sales.records({ visible: true }); // [{ Region: "South", Manager: "Petrov", Amount: 340 }, ...]
|
|
124
|
+
sales.range().visibleValues(); // the same with the header, as a grid
|
|
125
|
+
sales.sheet.style("A1:C1", { font: { bold: true } }).width("B", 14);
|
|
126
|
+
writeFileSync("sales.xlsx", wb.toXlsx());
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
A filter is Excel's own: the criteria go into the table's `<autoFilter>`, and
|
|
130
|
+
the rows they reject are hidden in the file, so Excel opens it already
|
|
131
|
+
filtered. Criteria on several columns all have to hold. `{ values }` keeps
|
|
132
|
+
the rows whose cell shows one of them (`blank: true` adds the empty ones),
|
|
133
|
+
`{ custom }` takes one or two comparisons (`=`, `<>`, `>`, `>=`, `<`, `<=`;
|
|
134
|
+
`*` and `?` in `=` and `<>`; `and: true` to need both), `{ top: n }` and
|
|
135
|
+
`{ bottom: n }` the extremes, `percent: true` for a share. `clearFilter()`
|
|
136
|
+
takes them off.
|
|
137
|
+
|
|
138
|
+
Every `Book` method that takes the sheet first is a `Sheet` method without
|
|
139
|
+
it, and every one that takes no sheet a `Workbook` method: what `Book`
|
|
140
|
+
answers with nothing returns the object, so it chains, and the rest return
|
|
141
|
+
their answer. So the whole flat API is there:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const sheet = wb.sheet("Sales")
|
|
145
|
+
.setColumnWidth(2, 14)
|
|
146
|
+
.setRowHidden(5, true)
|
|
147
|
+
.insertRows(8, 2)
|
|
148
|
+
.setCellStyle("A1", { font: { bold: true } });
|
|
149
|
+
sheet.getRange("A1:C3"); // a query answers: CellGrid
|
|
150
|
+
sheet.columnWidth(2); // 14
|
|
151
|
+
wb.setDefinedName("Total", "Sales!$C$9").definedNames();
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
On top of that a few have their own shape: `write`, `range`, `style`,
|
|
155
|
+
`width`, `freeze`, `addTable`, `addTableFromData`, `table`, `rename`,
|
|
156
|
+
`activate`, `recalculate` and `remove` on a sheet; `sheet`, `addSheet` and
|
|
157
|
+
`Workbook.readCsv` on the workbook.
|
|
158
|
+
|
|
159
|
+
The objects are handles - a sheet index, a table name, an address - and work
|
|
160
|
+
through `workbook.book`. A
|
|
161
|
+
sheet removed or moved through the `Book` moves the indexes under them, as it
|
|
162
|
+
does for any index. `Workbook.read(bytes)` opens a file; `Book` and its flat
|
|
163
|
+
API are unchanged.
|
|
164
|
+
|
|
70
165
|
## API
|
|
71
166
|
|
|
72
167
|
```ts
|
|
@@ -146,6 +241,11 @@ class Book {
|
|
|
146
241
|
removeRows(sheet: number, at: number, count: number): void;
|
|
147
242
|
insertColumns(sheet: number, at: number, count: number, copyOrigin?: CopyOrigin): void; // 1-based
|
|
148
243
|
removeColumns(sheet: number, at: number, count: number): void;
|
|
244
|
+
// Many places in one pass: [at, count] pairs, numbered as before the call
|
|
245
|
+
insertRowsMany(sheet: number, places: [number, number][], copyOrigin?: CopyOrigin): void;
|
|
246
|
+
removeRowsMany(sheet: number, places: [number, number][]): void;
|
|
247
|
+
insertColumnsMany(sheet: number, places: [number, number][], copyOrigin?: CopyOrigin): void;
|
|
248
|
+
removeColumnsMany(sheet: number, places: [number, number][]): void;
|
|
149
249
|
copyRange(sheet: number, range: string, to: string, toSheet?: number): void; // formulas rewritten
|
|
150
250
|
moveRange(sheet: number, range: string, to: string, toSheet?: number): void; // formulas kept, references follow
|
|
151
251
|
insertCells(sheet: number, range: string, shift: "down" | "right", copyOrigin?: CopyOrigin): void;
|
|
@@ -163,10 +263,12 @@ class Book {
|
|
|
163
263
|
comments(sheet: number): SheetComment[];
|
|
164
264
|
hyperlinks(sheet: number): SheetHyperlink[];
|
|
165
265
|
tables(sheet: number): SheetTable[];
|
|
166
|
-
charts(sheet: number): SheetChart[];
|
|
266
|
+
charts(sheet: number): SheetChart[]; // with the chart and plot area fill and outline
|
|
167
267
|
images(sheet: number): SheetImage[]; // without the bytes
|
|
168
268
|
imageData(sheet: number, index: number): Uint8Array;
|
|
169
|
-
shapes(sheet: number): SheetShape[];
|
|
269
|
+
shapes(sheet: number): SheetShape[]; // rotation, flips, fill, line, font as Excel shows them
|
|
270
|
+
setShapeFormat(sheet: number, index: number, patch: ShapeFormatPatch): void; // fill, line, font, rotation, flips
|
|
271
|
+
setChartFormat(sheet: number, index: number, patch: ChartFormatPatch): void; // chart and plot area fill and outline
|
|
170
272
|
|
|
171
273
|
// Style: read whole, written as a patch over what the cell has
|
|
172
274
|
cellStyle(sheet: number, address: string): CellStyle; // numberFormat, font, fill, borders, alignment
|
|
@@ -174,6 +276,10 @@ class Book {
|
|
|
174
276
|
setCellStyle(sheet: number, address: string, patch: CellStylePatch): void;
|
|
175
277
|
setCellStyleAt(sheet: number, row: number, column: number, patch: CellStylePatch): void;
|
|
176
278
|
setRangeStyle(sheet: number, range: string, patch: CellStylePatch): void;
|
|
279
|
+
getRichText(sheet: number, address: string): TextRun[] | null; // [{ text, font }]
|
|
280
|
+
getRichTextAt(sheet: number, row: number, column: number): TextRun[] | null;
|
|
281
|
+
setRichText(sheet: number, address: string, runs: TextRun[]): void;
|
|
282
|
+
setRichTextAt(sheet: number, row: number, column: number, runs: TextRun[]): void;
|
|
177
283
|
|
|
178
284
|
// Notes, links, tables
|
|
179
285
|
setComment(sheet: number, address: string, author: string, text: string): void;
|
|
@@ -182,6 +288,7 @@ class Book {
|
|
|
182
288
|
removeHyperlink(sheet: number, range: string): boolean;
|
|
183
289
|
addTable(sheet: number, name: string, range: string, headerRow?: boolean): void;
|
|
184
290
|
removeTable(sheet: number, name: string): boolean;
|
|
291
|
+
setTableFilter(name: string, column: string | number, criteria: TableFilter | null): void; // hides the rows that fail
|
|
185
292
|
|
|
186
293
|
// The saved view
|
|
187
294
|
sheetView(sheet: number): SheetViewInfo;
|
|
@@ -194,6 +301,10 @@ class Book {
|
|
|
194
301
|
setDefinedName(name: string, formula: string, sheet?: number): void;
|
|
195
302
|
removeDefinedName(name: string, sheet?: number): boolean;
|
|
196
303
|
|
|
304
|
+
// File > Info: title, author, company, and fields of your own
|
|
305
|
+
documentProperties(): DocumentProperties;
|
|
306
|
+
setDocumentProperties(patch: DocumentPropertiesPatch): void; // null clears a field
|
|
307
|
+
|
|
197
308
|
// Rules a file states
|
|
198
309
|
dataValidations(sheet: number): SheetValidation[];
|
|
199
310
|
conditionalFormats(sheet: number): SheetConditionalFormat[];
|
|
@@ -259,6 +370,14 @@ missing sheet, a truncated package.
|
|
|
259
370
|
workbook, not one sheet: `$A$5` becomes `$A$6`, a range that lost cells
|
|
260
371
|
narrows, a deleted cell reads `#REF!`, and drawings and tables follow. The
|
|
261
372
|
cached result of a rewritten formula is dropped, so recalculate after.
|
|
373
|
+
An insert that would push a filled cell or a merge off the last row or
|
|
374
|
+
column throws and leaves the book as it was, as Excel refuses it.
|
|
375
|
+
- **Many rows at once.** Every edit walks the whole workbook, so a loop of
|
|
376
|
+
`insertRows` costs a walk per row. `insertRowsMany(0, [[5, 1], [9, 1],
|
|
377
|
+
[14, 1]])` does it in one: places are numbered as the sheet was before the
|
|
378
|
+
call, in any order. Subtotal rows under 4 000 groups of 40 000 rows took
|
|
379
|
+
73 s one at a time and take 29 ms this way. `removeRowsMany` and the column
|
|
380
|
+
pair work the same.
|
|
262
381
|
- **Style is a patch.** `setCellStyle(0, "A1", { font: { bold: true } })` keeps
|
|
263
382
|
the number format the cell had. Equal styles share one entry in the
|
|
264
383
|
workbook's table, so painting a column costs one style, not one per cell -
|
|
@@ -278,9 +397,18 @@ missing sheet, a truncated package.
|
|
|
278
397
|
- **Read and write formatting by the block.** `getRangeStyles` returns each
|
|
279
398
|
distinct style once and a grid of indexes into them; `setRangeStyles` takes
|
|
280
399
|
the same shape back, so copying a block's look is two calls.
|
|
281
|
-
- **Charts, pictures and shapes
|
|
282
|
-
`shapes` describe what a sheet carries
|
|
283
|
-
|
|
400
|
+
- **Charts, pictures and shapes travel byte for byte; their look is a patch.**
|
|
401
|
+
`charts`, `images` and `shapes` describe what a sheet carries, and an
|
|
402
|
+
untouched object goes back into the file as it came. A shape's `fill`,
|
|
403
|
+
`line` and `font` are what Excel shows, its style filling in what the shape
|
|
404
|
+
leaves out, and a colour comes resolved through the theme:
|
|
405
|
+
`{ type: "solid", color: "#FF4472C4" }`. `setShapeFormat(0, 2, { fill: {
|
|
406
|
+
type: "solid", color: "accent2" }, line: { width: 2 }, rotation: 15 })`
|
|
407
|
+
changes only what it names - `null` gives a fill or line back to the style -
|
|
408
|
+
and only those elements are rewritten; effects, other runs and dashes stay.
|
|
409
|
+
A colour to write is `#RRGGBB`, `#AARRGGBB` or a theme name (`accent1`,
|
|
410
|
+
`tx1`, `bg2`) that follows the theme. `setChartFormat` does the same for a
|
|
411
|
+
chart's chart area (`format`) and plot area (`plotFormat`).
|
|
284
412
|
- **Functions of your own.** `book.registerFunction("MYTOTAL", (range) =>
|
|
285
413
|
range.flat().reduce((a, b) => a + (b ?? 0), 0))` - arguments arrive
|
|
286
414
|
evaluated, a range as a grid. A built-in name stays the built-in's, an
|
|
@@ -316,19 +444,19 @@ This folder is both the published package's readme and the workspace that
|
|
|
316
444
|
builds and exercises it.
|
|
317
445
|
|
|
318
446
|
```
|
|
319
|
-
../
|
|
447
|
+
../build-npm.sh # wasm-pack --release --target nodejs -> npm/pkg
|
|
320
448
|
npm install && npm test # tests against the freshly built package
|
|
321
449
|
npm start # example.js: build a book, calculate, round-trip
|
|
322
450
|
npm run ts # typescript/basic.ts, no build step
|
|
323
451
|
npm run typecheck # tsc --strict over the TypeScript examples
|
|
324
452
|
npm run bench [iterations] # parse timings, median and best
|
|
325
|
-
../
|
|
453
|
+
../pack-npm.sh # pkg -> pkg-publish, then: cd pkg-publish && npm publish --otp=...
|
|
326
454
|
```
|
|
327
455
|
|
|
328
456
|
| Path | What it is |
|
|
329
457
|
|---|---|
|
|
330
458
|
| `pkg/` | build output for Node (git-ignored); `pkg-web/` and `pkg-bundler/` for the other targets |
|
|
331
|
-
| `pkg-publish/` | `
|
|
459
|
+
| `pkg-publish/` | `pack-npm.sh`: a copy of `pkg/` renamed to `@rosperitus/excelerate`, the folder `npm publish` runs in (git-ignored) |
|
|
332
460
|
| `example.js`, `test.js`, `bench.js` | JavaScript examples, tests, benchmark |
|
|
333
461
|
| `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 |
|
|
334
462
|
| `browser/` | the same API in a page: `index.html` over `pkg-web/` |
|
package/excelerate.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* What `setDocumentProperties` takes: a named field is set, `null` clears it,
|
|
6
|
+
* a missing one stays. `custom` replaces the whole list; `type` is optional.
|
|
7
|
+
*/
|
|
8
|
+
export type DocumentPropertiesPatch = Partial<
|
|
9
|
+
Record<Exclude<keyof DocumentProperties, "custom">, string | null>
|
|
10
|
+
> & {
|
|
11
|
+
custom?: { name: string; value: string | number | boolean; type?: CustomProperty["type"] }[];
|
|
12
|
+
};
|
|
4
13
|
/**
|
|
5
14
|
* A style to write, as `setCellStyle` takes it. Every field is optional and
|
|
6
15
|
* what is left out keeps the value the cell had, so `{ font: { bold: true } }`
|
|
@@ -54,6 +63,52 @@ export interface RangeStylesPatch {
|
|
|
54
63
|
styles: CellStylePatch[];
|
|
55
64
|
grid: (number | null)[][];
|
|
56
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* A colour to draw with: `#RRGGBB`, `#AARRGGBB` (the alpha is the opacity) or
|
|
68
|
+
* a theme colour by name - `accent1` to `accent6`, `tx1`, `tx2`, `bg1`,
|
|
69
|
+
* `bg2`, `hlink`, `folHlink` - which follows the workbook's theme.
|
|
70
|
+
*/
|
|
71
|
+
export type DrawingColorInput = string;
|
|
72
|
+
/** A fill to write: the form `shapes` reads, without `other`. */
|
|
73
|
+
export type DrawingFillInput =
|
|
74
|
+
| { type: "none" }
|
|
75
|
+
| { type: "solid"; color: DrawingColorInput }
|
|
76
|
+
| {
|
|
77
|
+
type: "gradient";
|
|
78
|
+
stops: { position: number; color: DrawingColorInput }[];
|
|
79
|
+
angle?: number | null;
|
|
80
|
+
path?: "shape" | "circle" | "rect" | null;
|
|
81
|
+
}
|
|
82
|
+
| { type: "pattern"; preset?: string | null; foreground?: DrawingColorInput; background?: DrawingColorInput };
|
|
83
|
+
/**
|
|
84
|
+
* Fill and outline to lay over an object's own: a field left out stays,
|
|
85
|
+
* `null` gives it back to the style. `line.width` is in points.
|
|
86
|
+
*/
|
|
87
|
+
export interface DrawingFormatPatch {
|
|
88
|
+
fill?: DrawingFillInput | null;
|
|
89
|
+
line?: { fill?: DrawingFillInput | null; width?: number | null } | null;
|
|
90
|
+
}
|
|
91
|
+
/** What `setShapeFormat` takes. `rotation` is in degrees clockwise. */
|
|
92
|
+
export interface ShapeFormatPatch extends DrawingFormatPatch {
|
|
93
|
+
font?: Pick<RunFont, "name" | "size" | "bold" | "italic" | "color">;
|
|
94
|
+
rotation?: number;
|
|
95
|
+
flipH?: boolean;
|
|
96
|
+
flipV?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* What a table column keeps, as `setTableFilter` takes it: the shown values,
|
|
100
|
+
* one or two comparisons, or the largest or smallest few.
|
|
101
|
+
*/
|
|
102
|
+
export type TableFilter =
|
|
103
|
+
| { values: (string | number)[]; blank?: boolean }
|
|
104
|
+
| { custom: { op: "=" | "<>" | ">" | ">=" | "<" | "<="; value: string | number }[]; and?: boolean }
|
|
105
|
+
| { top: number; percent?: boolean }
|
|
106
|
+
| { bottom: number; percent?: boolean };
|
|
107
|
+
/** What `setChartFormat` takes: the chart area and the plot area. */
|
|
108
|
+
export interface ChartFormatPatch {
|
|
109
|
+
format?: DrawingFormatPatch | null;
|
|
110
|
+
plotFormat?: DrawingFormatPatch | null;
|
|
111
|
+
}
|
|
57
112
|
|
|
58
113
|
|
|
59
114
|
|
|
@@ -88,6 +143,33 @@ export interface SheetViewInfo {
|
|
|
88
143
|
rightToLeft: boolean;
|
|
89
144
|
topLeftCell: string | null;
|
|
90
145
|
}
|
|
146
|
+
/** One of the user's own document properties. */
|
|
147
|
+
export interface CustomProperty {
|
|
148
|
+
name: string;
|
|
149
|
+
type: "text" | "integer" | "number" | "boolean" | "date";
|
|
150
|
+
value: string | number | boolean;
|
|
151
|
+
}
|
|
152
|
+
/** Title, author, dates and the user's fields, as `documentProperties` returns them. Dates are ISO 8601. */
|
|
153
|
+
export interface DocumentProperties {
|
|
154
|
+
title: string | null;
|
|
155
|
+
subject: string | null;
|
|
156
|
+
creator: string | null;
|
|
157
|
+
keywords: string | null;
|
|
158
|
+
description: string | null;
|
|
159
|
+
lastModifiedBy: string | null;
|
|
160
|
+
category: string | null;
|
|
161
|
+
contentStatus: string | null;
|
|
162
|
+
language: string | null;
|
|
163
|
+
identifier: string | null;
|
|
164
|
+
revision: string | null;
|
|
165
|
+
version: string | null;
|
|
166
|
+
created: string | null;
|
|
167
|
+
modified: string | null;
|
|
168
|
+
lastPrinted: string | null;
|
|
169
|
+
company: string | null;
|
|
170
|
+
manager: string | null;
|
|
171
|
+
custom: CustomProperty[];
|
|
172
|
+
}
|
|
91
173
|
/** A name that stands for a formula, as `definedNames` returns it. */
|
|
92
174
|
export interface WorkbookName {
|
|
93
175
|
name: string;
|
|
@@ -113,7 +195,7 @@ export interface SheetConditionalFormat {
|
|
|
113
195
|
/** The autofilter over a range, as `autoFilter` returns it. */
|
|
114
196
|
export interface SheetAutoFilter {
|
|
115
197
|
range: string;
|
|
116
|
-
columns: { colId: number; kind: "values" | "custom" | "dynamic" | "top10" | "none" }[];
|
|
198
|
+
columns: { colId: number; kind: "values" | "custom" | "dynamic" | "top10" | "color" | "icon" | "none" }[];
|
|
117
199
|
}
|
|
118
200
|
/** A pivot report on the sheet, as `pivotTables` returns it. */
|
|
119
201
|
export interface SheetPivotTable {
|
|
@@ -158,6 +240,10 @@ export interface SheetChart {
|
|
|
158
240
|
kinds: string[];
|
|
159
241
|
seriesCount: number;
|
|
160
242
|
anchor: ObjectAnchor;
|
|
243
|
+
/** The chart area's fill and outline; `null` leaves them to the chart style. */
|
|
244
|
+
format: DrawingFormat | null;
|
|
245
|
+
/** The plot area's, the same way. */
|
|
246
|
+
plotFormat: DrawingFormat | null;
|
|
161
247
|
}
|
|
162
248
|
/** A picture on the sheet, as `images` returns it. Bytes come from `imageData`. */
|
|
163
249
|
export interface SheetImage {
|
|
@@ -174,6 +260,45 @@ export interface SheetShape {
|
|
|
174
260
|
geometry: string | null;
|
|
175
261
|
text: string;
|
|
176
262
|
anchor: ObjectAnchor;
|
|
263
|
+
/** Degrees clockwise about the centre. */
|
|
264
|
+
rotation: number;
|
|
265
|
+
/** Mirrored left to right, before it is turned. */
|
|
266
|
+
flipH: boolean;
|
|
267
|
+
/** Mirrored top to bottom, before it is turned. */
|
|
268
|
+
flipV: boolean;
|
|
269
|
+
/** What Excel fills it with: its own, else its style's. */
|
|
270
|
+
fill: DrawingFill;
|
|
271
|
+
/** Its outline, the same way. */
|
|
272
|
+
line: DrawingLine;
|
|
273
|
+
/** The font of its text as the first run states it, the colour from the style if not. */
|
|
274
|
+
font: RunFont;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* A colour of a drawing, resolved through the workbook theme to `#AARRGGBB` (`FF` for opaque);
|
|
278
|
+
* `null` for one no theme defines.
|
|
279
|
+
*/
|
|
280
|
+
export type DrawingColor = string | null;
|
|
281
|
+
/** How a drawing object or chart area is filled. `position` is in percent, `angle` in degrees. */
|
|
282
|
+
export type DrawingFill =
|
|
283
|
+
| { type: "none" }
|
|
284
|
+
| { type: "solid"; color: DrawingColor }
|
|
285
|
+
| {
|
|
286
|
+
type: "gradient";
|
|
287
|
+
stops: { position: number; color: DrawingColor }[];
|
|
288
|
+
angle: number | null;
|
|
289
|
+
path: "shape" | "circle" | "rect" | null;
|
|
290
|
+
}
|
|
291
|
+
| { type: "pattern"; preset: string | null; foreground: DrawingColor; background: DrawingColor }
|
|
292
|
+
| { type: "other" };
|
|
293
|
+
/** An outline: `fill` is `null` and `width` (points) is `null` where the file is silent. */
|
|
294
|
+
export interface DrawingLine {
|
|
295
|
+
fill: DrawingFill | null;
|
|
296
|
+
width: number | null;
|
|
297
|
+
}
|
|
298
|
+
/** The fill and outline an element states; `null` in either leaves it to the style. */
|
|
299
|
+
export interface DrawingFormat {
|
|
300
|
+
fill: DrawingFill | null;
|
|
301
|
+
line: DrawingLine | null;
|
|
177
302
|
}
|
|
178
303
|
/**
|
|
179
304
|
* A colour as the file states it: `null` when the file leaves it to the
|
|
@@ -182,6 +307,22 @@ export interface SheetShape {
|
|
|
182
307
|
* a theme colour carries its tint as `theme:4@-0.25`.
|
|
183
308
|
*/
|
|
184
309
|
export type StyleColor = string | null;
|
|
310
|
+
/**
|
|
311
|
+
* What a run of formatted text changes about the cell's font; a field left
|
|
312
|
+
* out is the cell's own. `size` in points.
|
|
313
|
+
*/
|
|
314
|
+
export interface RunFont {
|
|
315
|
+
name?: string;
|
|
316
|
+
size?: number;
|
|
317
|
+
bold?: boolean;
|
|
318
|
+
italic?: boolean;
|
|
319
|
+
underline?: string;
|
|
320
|
+
strike?: boolean;
|
|
321
|
+
color?: StyleColor;
|
|
322
|
+
script?: "superscript" | "subscript" | "baseline";
|
|
323
|
+
}
|
|
324
|
+
/** One run of formatted text, as `getRichText` returns it. */
|
|
325
|
+
export interface TextRun { text: string; font?: RunFont | null }
|
|
185
326
|
/** One side of a cell's border. */
|
|
186
327
|
export interface BorderSide { style: string; color: StyleColor }
|
|
187
328
|
/** How a cell is painted, as `cellStyle` returns it. */
|
|
@@ -346,6 +487,12 @@ export class Book {
|
|
|
346
487
|
* for. `sheet` is set on a name local to one sheet.
|
|
347
488
|
*/
|
|
348
489
|
definedNames(): WorkbookName[];
|
|
490
|
+
/**
|
|
491
|
+
* What Excel shows under File > Info: every text field is a string or
|
|
492
|
+
* `null`, dates in ISO 8601. `custom` lists the user's own fields with
|
|
493
|
+
* their type: `text`, `integer`, `number`, `boolean` or `date`.
|
|
494
|
+
*/
|
|
495
|
+
documentProperties(): DocumentProperties;
|
|
349
496
|
/**
|
|
350
497
|
* Evaluates a formula (with or without the leading `=`) as if it sat in
|
|
351
498
|
* `address` of `sheet`, and returns its result.
|
|
@@ -373,6 +520,19 @@ export class Book {
|
|
|
373
520
|
* last cells.
|
|
374
521
|
*/
|
|
375
522
|
fillSeries(sheet: number, range: string, direction: "down" | "right" | "up" | "left"): void;
|
|
523
|
+
/**
|
|
524
|
+
* Reads a workbook and hands sheet `sheet` over row by row, without
|
|
525
|
+
* building its grid: `callback(row, data)` gets the 1-based row number
|
|
526
|
+
* and what `getRowAt` would answer for it, and the row is dropped once
|
|
527
|
+
* the callback returns.
|
|
528
|
+
*
|
|
529
|
+
* The workbook comes back whole but for that sheet's cells. Only xlsx
|
|
530
|
+
* streams; any other format is read whole and then handed over the same
|
|
531
|
+
* way, so the callback sees the same rows but nothing is saved.
|
|
532
|
+
* A callback that throws is not called again, and what it threw comes
|
|
533
|
+
* out of `forEachRow` once the read is over.
|
|
534
|
+
*/
|
|
535
|
+
static forEachRow(bytes: Uint8Array, name: string | null | undefined, sheet: number, callback: Function, formatted?: boolean | null): Book;
|
|
376
536
|
/**
|
|
377
537
|
* Freezes the first `rows` rows and `columns` columns, so they stay put
|
|
378
538
|
* while the rest scrolls. `freezePanes(0, 1, 0)` pins the header row;
|
|
@@ -427,6 +587,16 @@ export class Book {
|
|
|
427
587
|
* The same by numbers, as `getRangeAt` takes them.
|
|
428
588
|
*/
|
|
429
589
|
getRangeStylesAt(sheet: number, row: number, column: number, rows: number, columns: number): RangeStyles;
|
|
590
|
+
/**
|
|
591
|
+
* The runs of a cell's formatted text: `{ text, font }` each, `font`
|
|
592
|
+
* naming only what the run changes about the cell's font, or `null` for
|
|
593
|
+
* a run in the cell's own. `null` for a cell without formatted text.
|
|
594
|
+
*/
|
|
595
|
+
getRichText(sheet: number, address: string): TextRun[] | null;
|
|
596
|
+
/**
|
|
597
|
+
* The same by 1-based row and column.
|
|
598
|
+
*/
|
|
599
|
+
getRichTextAt(sheet: number, row: number, column: number): TextRun[] | null;
|
|
430
600
|
/**
|
|
431
601
|
* A whole row in one crossing of the boundary: values, displayed text,
|
|
432
602
|
* bold and indent, plus whether the row is hidden.
|
|
@@ -465,6 +635,10 @@ export class Book {
|
|
|
465
635
|
* `copyOrigin` works as in `insertRows`, with left and right.
|
|
466
636
|
*/
|
|
467
637
|
insertColumns(sheet: number, at: number, count: number, copyOrigin?: "before" | "after" | "none"): void;
|
|
638
|
+
/**
|
|
639
|
+
* `insertRowsMany` for columns.
|
|
640
|
+
*/
|
|
641
|
+
insertColumnsMany(sheet: number, places: [number, number][], copyOrigin?: "before" | "after" | "none"): void;
|
|
468
642
|
/**
|
|
469
643
|
* Inserts `count` rows above row `at`, moving everything below down.
|
|
470
644
|
* `copyOrigin` - `"before"` (the row above), `"after"` (the row below)
|
|
@@ -476,6 +650,18 @@ export class Book {
|
|
|
476
650
|
* a user sees.
|
|
477
651
|
*/
|
|
478
652
|
insertRows(sheet: number, at: number, count: number, copyOrigin?: "before" | "after" | "none"): void;
|
|
653
|
+
/**
|
|
654
|
+
* Inserts rows at many places in one pass: `places` is `[at, count]`
|
|
655
|
+
* pairs, numbered as the sheet is before the call, in any order.
|
|
656
|
+
* `book.insertRowsMany(0, [[5, 1], [9, 1]])` puts a row above each of
|
|
657
|
+
* rows 5 and 9 - the old row 9, now row 10. Each new block takes its
|
|
658
|
+
* formatting from its own neighbour, as `copyOrigin` says.
|
|
659
|
+
*
|
|
660
|
+
* The result is that of the single inserts made from the bottom up, but
|
|
661
|
+
* the workbook is walked once rather than once per place: four thousand
|
|
662
|
+
* subtotal rows into forty thousand take milliseconds, not a minute.
|
|
663
|
+
*/
|
|
664
|
+
insertRowsMany(sheet: number, places: [number, number][], copyOrigin?: "before" | "after" | "none"): void;
|
|
479
665
|
/**
|
|
480
666
|
* Merges a block of cells: `merge(0, "A1:C1")`.
|
|
481
667
|
*/
|
|
@@ -537,9 +723,11 @@ export class Book {
|
|
|
537
723
|
*
|
|
538
724
|
* `name` is the file name they came from, if the caller has one: it
|
|
539
725
|
* settles what the bytes cannot say (a `.csv` against a `.html`) and names
|
|
540
|
-
* the sheet of a SYLK file.
|
|
726
|
+
* the sheet of a SYLK file. `password` opens a workbook saved with a
|
|
727
|
+
* password to open; without it only one encrypted to be opened
|
|
728
|
+
* read-only reads.
|
|
541
729
|
*/
|
|
542
|
-
static read(bytes: Uint8Array, name?: string | null, max_expanded?: number | null, on_progress?: Function | null): Book;
|
|
730
|
+
static read(bytes: Uint8Array, name?: string | null, max_expanded?: number | null, on_progress?: Function | null, password?: string | null): Book;
|
|
543
731
|
/**
|
|
544
732
|
* Reads CSV with the guesses overridden: the delimiter, whether a row
|
|
545
733
|
* that produced no cell is skipped, whether an empty field becomes an
|
|
@@ -621,6 +809,10 @@ export class Book {
|
|
|
621
809
|
* Removes `count` columns from column `at`, 1-based.
|
|
622
810
|
*/
|
|
623
811
|
removeColumns(sheet: number, at: number, count: number): void;
|
|
812
|
+
/**
|
|
813
|
+
* `removeRowsMany` for columns.
|
|
814
|
+
*/
|
|
815
|
+
removeColumnsMany(sheet: number, places: [number, number][]): void;
|
|
624
816
|
/**
|
|
625
817
|
* Takes a note off a cell. Answers whether there was one.
|
|
626
818
|
*/
|
|
@@ -638,6 +830,11 @@ export class Book {
|
|
|
638
830
|
* cell reads `#REF!` afterwards.
|
|
639
831
|
*/
|
|
640
832
|
removeRows(sheet: number, at: number, count: number): void;
|
|
833
|
+
/**
|
|
834
|
+
* Removes rows at many places in one pass: `[at, count]` pairs, numbered
|
|
835
|
+
* as the sheet is before the call. Blocks that overlap are merged.
|
|
836
|
+
*/
|
|
837
|
+
removeRowsMany(sheet: number, places: [number, number][]): void;
|
|
641
838
|
/**
|
|
642
839
|
* Removes a sheet. References to it from anywhere in the workbook become
|
|
643
840
|
* `#REF!`, the way Excel writes them, and the sheets after it shift down
|
|
@@ -702,6 +899,13 @@ export class Book {
|
|
|
702
899
|
* The same by 1-based row and column.
|
|
703
900
|
*/
|
|
704
901
|
setCellStyleAt(sheet: number, row: number, column: number, patch: CellStylePatch): void;
|
|
902
|
+
/**
|
|
903
|
+
* Changes the fill and outline of a chart's chart area (`format`) and
|
|
904
|
+
* plot area (`plotFormat`), by its position in `charts`; each takes
|
|
905
|
+
* `{ fill, line }` as `setShapeFormat` does, or `null` to leave the area
|
|
906
|
+
* to the chart style.
|
|
907
|
+
*/
|
|
908
|
+
setChartFormat(sheet: number, index: number, patch: ChartFormatPatch): void;
|
|
705
909
|
/**
|
|
706
910
|
* Hides a column, or shows it again. `column` is 1-based.
|
|
707
911
|
*/
|
|
@@ -724,6 +928,13 @@ export class Book {
|
|
|
724
928
|
* name local to that sheet instead of the workbook.
|
|
725
929
|
*/
|
|
726
930
|
setDefinedName(name: string, formula: string, sheet?: number | null): void;
|
|
931
|
+
/**
|
|
932
|
+
* Changes the fields the patch names and leaves the rest: a string sets
|
|
933
|
+
* one, `null` clears it. `custom`, when given, replaces the list; a
|
|
934
|
+
* field's type is taken from `type` or else from the value (a whole
|
|
935
|
+
* number is an integer).
|
|
936
|
+
*/
|
|
937
|
+
setDocumentProperties(patch: DocumentPropertiesPatch): void;
|
|
727
938
|
/**
|
|
728
939
|
* Puts a link over a cell or a block of them.
|
|
729
940
|
*
|
|
@@ -758,6 +969,16 @@ export class Book {
|
|
|
758
969
|
* The same with the corner given as 1-based row and column.
|
|
759
970
|
*/
|
|
760
971
|
setRangeStylesAt(sheet: number, row: number, column: number, styles: RangeStylesPatch): void;
|
|
972
|
+
/**
|
|
973
|
+
* Writes formatted text: runs as `getRichText` returns them, each with
|
|
974
|
+
* its own text and the part of the font it changes (`font` may be left
|
|
975
|
+
* out or `null` for the cell's own).
|
|
976
|
+
*/
|
|
977
|
+
setRichText(sheet: number, address: string, runs: TextRun[]): void;
|
|
978
|
+
/**
|
|
979
|
+
* The same by 1-based row and column.
|
|
980
|
+
*/
|
|
981
|
+
setRichTextAt(sheet: number, row: number, column: number, runs: TextRun[]): void;
|
|
761
982
|
/**
|
|
762
983
|
* Sets the height of a row in points, or gives it back to the sheet
|
|
763
984
|
* default with `undefined`. `row` is the number a user sees.
|
|
@@ -767,6 +988,26 @@ export class Book {
|
|
|
767
988
|
* Hides a row, or shows it again.
|
|
768
989
|
*/
|
|
769
990
|
setRowHidden(sheet: number, row: number, hidden: boolean): void;
|
|
991
|
+
/**
|
|
992
|
+
* Changes how a shape looks, by its position in `shapes`:
|
|
993
|
+
*
|
|
994
|
+
* ```js
|
|
995
|
+
* book.setShapeFormat(0, 2, {
|
|
996
|
+
* fill: { type: "solid", color: "accent2" },
|
|
997
|
+
* line: { width: 2 },
|
|
998
|
+
* font: { bold: true, color: "#FFFFFFFF" },
|
|
999
|
+
* rotation: 15,
|
|
1000
|
+
* });
|
|
1001
|
+
* ```
|
|
1002
|
+
*
|
|
1003
|
+
* `fill`, `line`, `font`, `rotation` (degrees clockwise), `flipH` and
|
|
1004
|
+
* `flipV`; a field left out stays as it was, `null` for `fill` or `line`
|
|
1005
|
+
* gives it back to the shape's style. A colour is `#RRGGBB`,
|
|
1006
|
+
* `#AARRGGBB` or a theme colour by name (`accent1`, `tx1`, `bg2`), which
|
|
1007
|
+
* follows the theme. The rest of the shape - effects, other runs, the
|
|
1008
|
+
* outline's dashes - stays in the file as it was.
|
|
1009
|
+
*/
|
|
1010
|
+
setShapeFormat(sheet: number, index: number, patch: ShapeFormatPatch): void;
|
|
770
1011
|
/**
|
|
771
1012
|
* Gives a sheet a tab or takes it away: `"visible"`, `"hidden"` or
|
|
772
1013
|
* `"veryHidden"`.
|
|
@@ -781,13 +1022,32 @@ export class Book {
|
|
|
781
1022
|
* `headers`.
|
|
782
1023
|
*/
|
|
783
1024
|
setShowGridLines(sheet: number, show: boolean, headers?: boolean | null): void;
|
|
1025
|
+
/**
|
|
1026
|
+
* Filters a table by one of its columns, named by its header or
|
|
1027
|
+
* numbered from 1, and hides the data rows the table's criteria reject,
|
|
1028
|
+
* as Excel does. `null` takes the column's criterion off.
|
|
1029
|
+
*
|
|
1030
|
+
* ```js
|
|
1031
|
+
* book.setTableFilter("Sales", "Region", { values: ["South", "West"] });
|
|
1032
|
+
* book.setTableFilter("Sales", "Amount", { custom: [{ op: ">", value: 100 }] });
|
|
1033
|
+
* book.setTableFilter("Sales", 3, { top: 5 }); // or { bottom: 10, percent: true }
|
|
1034
|
+
* ```
|
|
1035
|
+
*
|
|
1036
|
+
* `values` keeps a row whose cell shows one of them, `blank: true` the
|
|
1037
|
+
* empty ones too; `custom` takes one or two comparisons (`=`, `<>`, `>`,
|
|
1038
|
+
* `>=`, `<`, `<=`; `*` and `?` in `=` and `<>`), joined by `or` unless
|
|
1039
|
+
* `and` is set. Criteria on several columns all have to hold.
|
|
1040
|
+
*/
|
|
1041
|
+
setTableFilter(name: string, column: string | number, criteria: TableFilter | null): void;
|
|
784
1042
|
/**
|
|
785
1043
|
* The zoom a reader opens the sheet at, in percent; `undefined` gives it
|
|
786
1044
|
* back to 100.
|
|
787
1045
|
*/
|
|
788
1046
|
setZoom(sheet: number, percent?: number | null): void;
|
|
789
1047
|
/**
|
|
790
|
-
* The drawn shapes of a sheet, text and all
|
|
1048
|
+
* The drawn shapes of a sheet, text and all, with the look Excel shows:
|
|
1049
|
+
* fill, outline and font are the shape's own with its style filling in
|
|
1050
|
+
* the rest, colours resolved through the workbook theme.
|
|
791
1051
|
*/
|
|
792
1052
|
shapes(sheet: number): SheetShape[];
|
|
793
1053
|
/**
|