@rosperitus/excelerate 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -9
- package/excelerate.d.ts +183 -8
- package/excelerate.js +181 -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
|
|
@@ -175,7 +277,9 @@ class Book {
|
|
|
175
277
|
setCellStyleAt(sheet: number, row: number, column: number, patch: CellStylePatch): void;
|
|
176
278
|
setRangeStyle(sheet: number, range: string, patch: CellStylePatch): void;
|
|
177
279
|
getRichText(sheet: number, address: string): TextRun[] | null; // [{ text, font }]
|
|
280
|
+
getRichTextAt(sheet: number, row: number, column: number): TextRun[] | null;
|
|
178
281
|
setRichText(sheet: number, address: string, runs: TextRun[]): void;
|
|
282
|
+
setRichTextAt(sheet: number, row: number, column: number, runs: TextRun[]): void;
|
|
179
283
|
|
|
180
284
|
// Notes, links, tables
|
|
181
285
|
setComment(sheet: number, address: string, author: string, text: string): void;
|
|
@@ -184,6 +288,7 @@ class Book {
|
|
|
184
288
|
removeHyperlink(sheet: number, range: string): boolean;
|
|
185
289
|
addTable(sheet: number, name: string, range: string, headerRow?: boolean): void;
|
|
186
290
|
removeTable(sheet: number, name: string): boolean;
|
|
291
|
+
setTableFilter(name: string, column: string | number, criteria: TableFilter | null): void; // hides the rows that fail
|
|
187
292
|
|
|
188
293
|
// The saved view
|
|
189
294
|
sheetView(sheet: number): SheetViewInfo;
|
|
@@ -196,6 +301,10 @@ class Book {
|
|
|
196
301
|
setDefinedName(name: string, formula: string, sheet?: number): void;
|
|
197
302
|
removeDefinedName(name: string, sheet?: number): boolean;
|
|
198
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
|
+
|
|
199
308
|
// Rules a file states
|
|
200
309
|
dataValidations(sheet: number): SheetValidation[];
|
|
201
310
|
conditionalFormats(sheet: number): SheetConditionalFormat[];
|
|
@@ -261,6 +370,14 @@ missing sheet, a truncated package.
|
|
|
261
370
|
workbook, not one sheet: `$A$5` becomes `$A$6`, a range that lost cells
|
|
262
371
|
narrows, a deleted cell reads `#REF!`, and drawings and tables follow. The
|
|
263
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.
|
|
264
381
|
- **Style is a patch.** `setCellStyle(0, "A1", { font: { bold: true } })` keeps
|
|
265
382
|
the number format the cell had. Equal styles share one entry in the
|
|
266
383
|
workbook's table, so painting a column costs one style, not one per cell -
|
|
@@ -280,9 +397,18 @@ missing sheet, a truncated package.
|
|
|
280
397
|
- **Read and write formatting by the block.** `getRangeStyles` returns each
|
|
281
398
|
distinct style once and a grid of indexes into them; `setRangeStyles` takes
|
|
282
399
|
the same shape back, so copying a block's look is two calls.
|
|
283
|
-
- **Charts, pictures and shapes
|
|
284
|
-
`shapes` describe what a sheet carries
|
|
285
|
-
|
|
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`).
|
|
286
412
|
- **Functions of your own.** `book.registerFunction("MYTOTAL", (range) =>
|
|
287
413
|
range.flat().reduce((a, b) => a + (b ?? 0), 0))` - arguments arrive
|
|
288
414
|
evaluated, a range as a grid. A built-in name stays the built-in's, an
|
|
@@ -318,19 +444,19 @@ This folder is both the published package's readme and the workspace that
|
|
|
318
444
|
builds and exercises it.
|
|
319
445
|
|
|
320
446
|
```
|
|
321
|
-
../
|
|
447
|
+
../build-npm.sh # wasm-pack --release --target nodejs -> npm/pkg
|
|
322
448
|
npm install && npm test # tests against the freshly built package
|
|
323
449
|
npm start # example.js: build a book, calculate, round-trip
|
|
324
450
|
npm run ts # typescript/basic.ts, no build step
|
|
325
451
|
npm run typecheck # tsc --strict over the TypeScript examples
|
|
326
452
|
npm run bench [iterations] # parse timings, median and best
|
|
327
|
-
../
|
|
453
|
+
../pack-npm.sh # pkg -> pkg-publish, then: cd pkg-publish && npm publish --otp=...
|
|
328
454
|
```
|
|
329
455
|
|
|
330
456
|
| Path | What it is |
|
|
331
457
|
|---|---|
|
|
332
458
|
| `pkg/` | build output for Node (git-ignored); `pkg-web/` and `pkg-bundler/` for the other targets |
|
|
333
|
-
| `pkg-publish/` | `
|
|
459
|
+
| `pkg-publish/` | `pack-npm.sh`: a copy of `pkg/` renamed to `@rosperitus/excelerate`, the folder `npm publish` runs in (git-ignored) |
|
|
334
460
|
| `example.js`, `test.js`, `bench.js` | JavaScript examples, tests, benchmark |
|
|
335
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 |
|
|
336
462
|
| `browser/` | the same API in a page: `index.html` over `pkg-web/` |
|
package/excelerate.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* A style to write, as `setCellStyle` takes it. Every field is optional and
|
|
6
|
-
* what is left out keeps the value the cell had, so `{ font: { bold: true } }`
|
|
7
|
-
* makes a cell bold without touching its number format.
|
|
8
|
-
*/
|
|
9
4
|
/**
|
|
10
5
|
* What `setDocumentProperties` takes: a named field is set, `null` clears it,
|
|
11
6
|
* a missing one stays. `custom` replaces the whole list; `type` is optional.
|
|
@@ -15,6 +10,11 @@ Record<Exclude<keyof DocumentProperties, "custom">, string | null>
|
|
|
15
10
|
> & {
|
|
16
11
|
custom?: { name: string; value: string | number | boolean; type?: CustomProperty["type"] }[];
|
|
17
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* A style to write, as `setCellStyle` takes it. Every field is optional and
|
|
15
|
+
* what is left out keeps the value the cell had, so `{ font: { bold: true } }`
|
|
16
|
+
* makes a cell bold without touching its number format.
|
|
17
|
+
*/
|
|
18
18
|
export interface CellStylePatch {
|
|
19
19
|
numberFormat?: string;
|
|
20
20
|
font?: Partial<{
|
|
@@ -63,6 +63,52 @@ export interface RangeStylesPatch {
|
|
|
63
63
|
styles: CellStylePatch[];
|
|
64
64
|
grid: (number | null)[][];
|
|
65
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
|
+
}
|
|
66
112
|
|
|
67
113
|
|
|
68
114
|
|
|
@@ -194,6 +240,10 @@ export interface SheetChart {
|
|
|
194
240
|
kinds: string[];
|
|
195
241
|
seriesCount: number;
|
|
196
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;
|
|
197
247
|
}
|
|
198
248
|
/** A picture on the sheet, as `images` returns it. Bytes come from `imageData`. */
|
|
199
249
|
export interface SheetImage {
|
|
@@ -210,6 +260,45 @@ export interface SheetShape {
|
|
|
210
260
|
geometry: string | null;
|
|
211
261
|
text: string;
|
|
212
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;
|
|
213
302
|
}
|
|
214
303
|
/**
|
|
215
304
|
* A colour as the file states it: `null` when the file leaves it to the
|
|
@@ -431,6 +520,19 @@ export class Book {
|
|
|
431
520
|
* last cells.
|
|
432
521
|
*/
|
|
433
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;
|
|
434
536
|
/**
|
|
435
537
|
* Freezes the first `rows` rows and `columns` columns, so they stay put
|
|
436
538
|
* while the rest scrolls. `freezePanes(0, 1, 0)` pins the header row;
|
|
@@ -533,6 +635,10 @@ export class Book {
|
|
|
533
635
|
* `copyOrigin` works as in `insertRows`, with left and right.
|
|
534
636
|
*/
|
|
535
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;
|
|
536
642
|
/**
|
|
537
643
|
* Inserts `count` rows above row `at`, moving everything below down.
|
|
538
644
|
* `copyOrigin` - `"before"` (the row above), `"after"` (the row below)
|
|
@@ -544,6 +650,18 @@ export class Book {
|
|
|
544
650
|
* a user sees.
|
|
545
651
|
*/
|
|
546
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;
|
|
547
665
|
/**
|
|
548
666
|
* Merges a block of cells: `merge(0, "A1:C1")`.
|
|
549
667
|
*/
|
|
@@ -605,9 +723,11 @@ export class Book {
|
|
|
605
723
|
*
|
|
606
724
|
* `name` is the file name they came from, if the caller has one: it
|
|
607
725
|
* settles what the bytes cannot say (a `.csv` against a `.html`) and names
|
|
608
|
-
* 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.
|
|
609
729
|
*/
|
|
610
|
-
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;
|
|
611
731
|
/**
|
|
612
732
|
* Reads CSV with the guesses overridden: the delimiter, whether a row
|
|
613
733
|
* that produced no cell is skipped, whether an empty field becomes an
|
|
@@ -689,6 +809,10 @@ export class Book {
|
|
|
689
809
|
* Removes `count` columns from column `at`, 1-based.
|
|
690
810
|
*/
|
|
691
811
|
removeColumns(sheet: number, at: number, count: number): void;
|
|
812
|
+
/**
|
|
813
|
+
* `removeRowsMany` for columns.
|
|
814
|
+
*/
|
|
815
|
+
removeColumnsMany(sheet: number, places: [number, number][]): void;
|
|
692
816
|
/**
|
|
693
817
|
* Takes a note off a cell. Answers whether there was one.
|
|
694
818
|
*/
|
|
@@ -706,6 +830,11 @@ export class Book {
|
|
|
706
830
|
* cell reads `#REF!` afterwards.
|
|
707
831
|
*/
|
|
708
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;
|
|
709
838
|
/**
|
|
710
839
|
* Removes a sheet. References to it from anywhere in the workbook become
|
|
711
840
|
* `#REF!`, the way Excel writes them, and the sheets after it shift down
|
|
@@ -770,6 +899,13 @@ export class Book {
|
|
|
770
899
|
* The same by 1-based row and column.
|
|
771
900
|
*/
|
|
772
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;
|
|
773
909
|
/**
|
|
774
910
|
* Hides a column, or shows it again. `column` is 1-based.
|
|
775
911
|
*/
|
|
@@ -852,6 +988,26 @@ export class Book {
|
|
|
852
988
|
* Hides a row, or shows it again.
|
|
853
989
|
*/
|
|
854
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;
|
|
855
1011
|
/**
|
|
856
1012
|
* Gives a sheet a tab or takes it away: `"visible"`, `"hidden"` or
|
|
857
1013
|
* `"veryHidden"`.
|
|
@@ -866,13 +1022,32 @@ export class Book {
|
|
|
866
1022
|
* `headers`.
|
|
867
1023
|
*/
|
|
868
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;
|
|
869
1042
|
/**
|
|
870
1043
|
* The zoom a reader opens the sheet at, in percent; `undefined` gives it
|
|
871
1044
|
* back to 100.
|
|
872
1045
|
*/
|
|
873
1046
|
setZoom(sheet: number, percent?: number | null): void;
|
|
874
1047
|
/**
|
|
875
|
-
* 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.
|
|
876
1051
|
*/
|
|
877
1052
|
shapes(sheet: number): SheetShape[];
|
|
878
1053
|
/**
|