@justybase/spreadsheet-tasks 2.1.0 → 2.2.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/CHANGELOG.md +22 -0
- package/README.md +46 -2
- package/dist/cjs/index.d.ts +71 -3
- package/dist/cjs/index.js +1204 -89
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1201 -89
- package/dist/esm/index.js.map +1 -1
- package/docs/API.md +83 -2
- package/package.json +3 -2
package/docs/API.md
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
- [XlsbReader](#xlsbreader)
|
|
8
8
|
- [XlsxReader](#xlsxreader)
|
|
9
9
|
- [XlsxUpdater](#xlsxupdater)
|
|
10
|
+
- [XlsmUpdater](#xlsmupdater)
|
|
10
11
|
- [XlsbUpdater](#xlsbupdater)
|
|
12
|
+
- [Excel conversion](#excel-conversion)
|
|
11
13
|
- [ReaderFactory](#readerfactory)
|
|
12
14
|
- [Types](#types)
|
|
13
15
|
|
|
@@ -243,8 +245,9 @@ new XlsxUpdater(filePath: string)
|
|
|
243
245
|
**Parameters:**
|
|
244
246
|
- `filePath` - Path to an existing `.xlsx` file
|
|
245
247
|
|
|
246
|
-
Throws if the file does not exist, is not a valid XLSX, or is an XLSB
|
|
247
|
-
|
|
248
|
+
Throws if the file does not exist, is not a valid XLSX package, or is an XLSB.
|
|
249
|
+
Macro-enabled `.xlsm` packages can use the explicit [XlsmUpdater](#xlsmupdater)
|
|
250
|
+
alias; unknown VBA members are preserved.
|
|
248
251
|
|
|
249
252
|
**Example:**
|
|
250
253
|
```typescript
|
|
@@ -298,10 +301,28 @@ updater.save('report_new.xlsx');
|
|
|
298
301
|
Writes the updated workbook to disk. When `outputPath` is omitted, the source
|
|
299
302
|
file is overwritten in place.
|
|
300
303
|
|
|
304
|
+
#### `replaceSheetDataStream(sheetName: string, rows: RowSource, options?: ReplaceSheetDataOptions): Promise<void>`
|
|
305
|
+
|
|
306
|
+
Replaces worksheet rows from a synchronous or asynchronous one-pass row source.
|
|
307
|
+
The row source is processed incrementally and is not collected into a complete
|
|
308
|
+
2D array. Use `saveStreaming()` to also avoid materialising the final ZIP buffer.
|
|
309
|
+
|
|
310
|
+
#### `saveStreaming(outputPath?: string): Promise<void>`
|
|
311
|
+
|
|
312
|
+
Writes the updated package through a temporary file and installs it atomically.
|
|
313
|
+
Staged worksheet parts are streamed; `save()` remains the simpler synchronous
|
|
314
|
+
buffering path.
|
|
315
|
+
|
|
301
316
|
#### `toBuffer(): Buffer`
|
|
302
317
|
|
|
303
318
|
Returns the updated workbook as an in-memory ZIP buffer.
|
|
304
319
|
|
|
320
|
+
## XlsmUpdater
|
|
321
|
+
|
|
322
|
+
`XlsmUpdater` is an explicit alias of `XlsxUpdater` for macro-enabled `.xlsm`
|
|
323
|
+
packages. It has the same API as `XlsxUpdater` and preserves VBA parts without
|
|
324
|
+
parsing or modifying them.
|
|
325
|
+
|
|
305
326
|
---
|
|
306
327
|
|
|
307
328
|
## XlsbUpdater
|
|
@@ -382,6 +403,56 @@ Returns the updated workbook as an in-memory ZIP buffer.
|
|
|
382
403
|
|
|
383
404
|
---
|
|
384
405
|
|
|
406
|
+
## Excel conversion
|
|
407
|
+
|
|
408
|
+
Excel conversion uses the installed desktop Microsoft Excel through COM. It is
|
|
409
|
+
available in the Node.js build on Windows only; the browser build does not
|
|
410
|
+
expose these functions.
|
|
411
|
+
|
|
412
|
+
### `ExcelConversionOptions`
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
interface ExcelConversionOptions {
|
|
416
|
+
overwrite?: boolean;
|
|
417
|
+
}
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
`overwrite` defaults to `false`. Existing destination files are rejected unless
|
|
421
|
+
it is explicitly set to `true`.
|
|
422
|
+
|
|
423
|
+
### `convertXlsbToXlsx`
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
convertXlsbToXlsx(
|
|
427
|
+
inputPath: string,
|
|
428
|
+
outputPath: string,
|
|
429
|
+
options?: ExcelConversionOptions
|
|
430
|
+
): Promise<void>
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
Converts an existing `.xlsb` file to `.xlsx` using Excel `SaveAs` format 51.
|
|
434
|
+
|
|
435
|
+
### `convertXlsxToXlsb`
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
convertXlsxToXlsb(
|
|
439
|
+
inputPath: string,
|
|
440
|
+
outputPath: string,
|
|
441
|
+
options?: ExcelConversionOptions
|
|
442
|
+
): Promise<void>
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
Converts an existing `.xlsx` file to `.xlsb` using Excel `SaveAs` format 50.
|
|
446
|
+
|
|
447
|
+
Both functions reject invalid extensions, missing files, protected
|
|
448
|
+
destinations, unavailable COM automation, and Excel errors. The source is
|
|
449
|
+
opened read-only and the destination is first written to a temporary file.
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
await convertXlsbToXlsx('report.xlsb', 'report.xlsx');
|
|
453
|
+
await convertXlsxToXlsb('report.xlsx', 'report.xlsb', { overwrite: true });
|
|
454
|
+
```
|
|
455
|
+
|
|
385
456
|
## ReaderFactory
|
|
386
457
|
|
|
387
458
|
Factory class for creating appropriate reader based on file extension.
|
|
@@ -418,6 +489,16 @@ await reader.open('data.xlsb');
|
|
|
418
489
|
| `Date` | Date Serial Number |
|
|
419
490
|
| `null` / `undefined` | Empty Cell |
|
|
420
491
|
|
|
492
|
+
### `RowSource`
|
|
493
|
+
|
|
494
|
+
```typescript
|
|
495
|
+
type RowSource =
|
|
496
|
+
| Iterable<ReadonlyArray<CellValue>>
|
|
497
|
+
| AsyncIterable<ReadonlyArray<CellValue>>;
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
Used by `replaceSheetDataStream()` in both updater classes.
|
|
501
|
+
|
|
421
502
|
### Sheet Name Restrictions
|
|
422
503
|
|
|
423
504
|
Sheet names have the following restrictions:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justybase/spreadsheet-tasks",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "High-performance TypeScript library for reading and writing Excel files in XLSB and XLSX formats. XLSB is 3.3x faster to write and 2.3x faster to read than XLSX.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -29,9 +29,10 @@
|
|
|
29
29
|
"typecheck": "tsc --noEmit",
|
|
30
30
|
"test": "npm run typecheck && npm run test:smoke && npm run test:unit && npm run test:integration && npm run test:dist",
|
|
31
31
|
"test:smoke": "npx ts-node tests/smoke.test.ts",
|
|
32
|
-
"test:unit": "npx ts-node tests/unit/bigbuffer.test.ts && npx ts-node tests/unit/biff-reader-writer.test.ts && npx ts-node tests/unit/xlsb-writer.test.ts",
|
|
32
|
+
"test:unit": "npx ts-node tests/unit/bigbuffer.test.ts && npx ts-node tests/unit/biff-reader-writer.test.ts && npx ts-node tests/unit/xlsb-writer.test.ts && npx ts-node tests/unit/excel-converter.test.ts && npx ts-node tests/unit/updater-streaming.test.ts",
|
|
33
33
|
"test:integration": "npx ts-node tests/integration/xlsb-writer.test.ts && npx ts-node tests/integration/xlsx-writer.test.ts && npx ts-node tests/integration/xlsx-updater.test.ts && npx ts-node tests/integration/xlsb-updater.test.ts",
|
|
34
34
|
"test:dist": "npm run build && npx ts-node tests/dist-surface.test.ts",
|
|
35
|
+
"test:excel-conversion": "npm run build && npx ts-node tests/excel-compat/conversion.ts",
|
|
35
36
|
"test:xlsb": "npx ts-node tests/integration/xlsb-writer.test.ts && npx ts-node tests/integration/xlsb-updater.test.ts",
|
|
36
37
|
"test:xlsx": "npx ts-node tests/integration/xlsx-writer.test.ts",
|
|
37
38
|
"benchmark": "npm run build && npx ts-node benchmarks/performance.bench.ts",
|