@justybase/spreadsheet-tasks 2.0.0 → 2.1.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.
@@ -167,7 +167,6 @@ declare class XlsxReader extends ExcelReaderAbstract {
167
167
  open(path: string, readSharedStrings?: boolean): Promise<void>;
168
168
  close(): Promise<void>;
169
169
  private _readZipEntryContent;
170
- private _unescapeXml;
171
170
  private _parseSharedStrings;
172
171
  private _parseStyles;
173
172
  getSheetNames(): string[];
@@ -175,7 +174,6 @@ declare class XlsxReader extends ExcelReaderAbstract {
175
174
  private _initSheet;
176
175
  private _readNextRow;
177
176
  private _parseRowByIndex;
178
- private _columnLetterToIndex;
179
177
  getValue(i: number): CellValue;
180
178
  }
181
179
 
@@ -351,6 +349,168 @@ declare class XlsxWriter {
351
349
  private _writeRels;
352
350
  }
353
351
 
352
+ /**
353
+ * Options for {@link XlsxUpdater.replaceSheetData}.
354
+ */
355
+ interface ReplaceSheetDataOptions$1 {
356
+ /**
357
+ * Optional header row written into row 1 of the target sheet.
358
+ * When omitted, row 1 is filled with the data rows.
359
+ */
360
+ headers?: string[];
361
+ /**
362
+ * Style strategy for the new cells:
363
+ * - `'inherit'` (default): reuse the dominant cell style of each column from the
364
+ * existing data (and the original header style for row 1), so date/number
365
+ * formatting of the sheet is preserved. Falls back to General (0).
366
+ * - `'general'`: all new cells use style 0 (General).
367
+ */
368
+ styleFallback?: 'inherit' | 'general';
369
+ }
370
+ /**
371
+ * Update the data of a worksheet inside an existing XLSX file without rebuilding
372
+ * the workbook. Everything outside the target sheet's cell data — pivot tables
373
+ * and their caches, other sheets, styles, themes, defined names — is preserved
374
+ * byte-for-byte. This makes it possible to refresh a data sheet that other
375
+ * Excel features (pivot tables, charts, formulas) are wired to.
376
+ *
377
+ * ```ts
378
+ * const updater = new XlsxUpdater('report.xlsx');
379
+ * updater.replaceSheetData('data1', rows, { headers: ['ID', 'NAME', 'AMOUNT'] });
380
+ * updater.save('report_new.xlsx'); // or updater.save() to overwrite in place
381
+ * ```
382
+ */
383
+ declare class XlsxUpdater {
384
+ private readonly zip;
385
+ private readonly sourcePath;
386
+ private sheetNameToPath;
387
+ private pivotCacheDefs;
388
+ private pivotTableDefPaths;
389
+ private sharedStringsXml;
390
+ private sharedStringsValues;
391
+ private sharedStringsOriginalLength;
392
+ private sharedStringsCount;
393
+ private stringIndexMap;
394
+ private readonly _oaEpoch;
395
+ /**
396
+ * @param path Path to an existing `.xlsx` file.
397
+ */
398
+ constructor(path: string);
399
+ /** Worksheet names in workbook order. */
400
+ getSheetNames(): string[];
401
+ /**
402
+ * Clear the entire cell data of the target sheet and write new rows in its place.
403
+ * All other parts of the workbook (pivot tables, other sheets, styles, …) are preserved.
404
+ *
405
+ * @param sheetName Name of the worksheet to replace.
406
+ * @param rows New data rows (`CellValue` cells; null/undefined = blank).
407
+ * @param options See {@link ReplaceSheetDataOptions}.
408
+ */
409
+ replaceSheetData(sheetName: string, rows: CellValue[][], options?: ReplaceSheetDataOptions$1): void;
410
+ /**
411
+ * Write the updated workbook to disk.
412
+ * @param outputPath Destination path; defaults to the source file (overwrites in place).
413
+ */
414
+ save(outputPath?: string): void;
415
+ /** The updated workbook as an in-memory ZIP buffer. */
416
+ toBuffer(): Buffer;
417
+ private _loadWorkbookStructure;
418
+ private _ensureSharedStringsLoaded;
419
+ private _commitSharedStrings;
420
+ private _collectExistingStyles;
421
+ private _findDateStyleIndex;
422
+ private _buildSheetData;
423
+ private _valueCell;
424
+ private _stringCell;
425
+ private _patchSheetXml;
426
+ private _updatePivotCaches;
427
+ private _addRefreshOnLoadToPivotTables;
428
+ }
429
+
430
+ /**
431
+ * Options for {@link XlsbUpdater.replaceSheetData}.
432
+ */
433
+ interface ReplaceSheetDataOptions {
434
+ /**
435
+ * Optional header row written into row 1 of the target sheet.
436
+ * When omitted, row 1 is filled with the data rows.
437
+ */
438
+ headers?: string[];
439
+ /**
440
+ * Style strategy for the new cells:
441
+ * - `'inherit'` (default): reuse the dominant cell style (xf) of each column from the
442
+ * existing data (and the original header style for row 1), so date/number
443
+ * formatting of the sheet is preserved. Falls back to General (0).
444
+ * - `'general'`: all new cells use xf 0 (General).
445
+ */
446
+ styleFallback?: 'inherit' | 'general';
447
+ }
448
+ /**
449
+ * Update the data of a worksheet inside an existing XLSB file without rebuilding
450
+ * the workbook. Everything outside the target sheet's rows — pivot tables and
451
+ * their caches, other sheets, styles, column widths, views — is preserved.
452
+ * This makes it possible to refresh a data sheet that pivot tables are wired to.
453
+ *
454
+ * ```ts
455
+ * const updater = new XlsbUpdater('report.xlsb');
456
+ * updater.replaceSheetData('data1', rows, { headers: ['ID', 'NAME', 'AMOUNT'] });
457
+ * updater.save('report_new.xlsb'); // or updater.save() to overwrite in place
458
+ * ```
459
+ */
460
+ declare class XlsbUpdater {
461
+ private readonly zip;
462
+ private readonly sourcePath;
463
+ private sheetNameToPath;
464
+ private pivotCacheDefPaths;
465
+ private sharedStringsBuf;
466
+ private sharedStringsValues;
467
+ private sharedStringsTotal;
468
+ private sharedStringsUnique;
469
+ private sharedStringsEndSst;
470
+ private stringIndexMap;
471
+ private readonly _oaEpoch;
472
+ /**
473
+ * @param path Path to an existing `.xlsb` file.
474
+ */
475
+ constructor(path: string);
476
+ /** Worksheet names in workbook order. */
477
+ getSheetNames(): string[];
478
+ /**
479
+ * Clear the entire cell data of the target sheet and write new rows in its place.
480
+ * All other parts of the workbook (pivot tables, other sheets, styles, …) are preserved.
481
+ *
482
+ * @param sheetName Name of the worksheet to replace.
483
+ * @param rows New data rows (`CellValue` cells; null/undefined = blank).
484
+ * @param options See {@link ReplaceSheetDataOptions}.
485
+ */
486
+ replaceSheetData(sheetName: string, rows: CellValue[][], options?: ReplaceSheetDataOptions): void;
487
+ /**
488
+ * Write the updated workbook to disk.
489
+ * @param outputPath Destination path; defaults to the source file (overwrites in place).
490
+ */
491
+ save(outputPath?: string): void;
492
+ /** The updated workbook as an in-memory ZIP buffer. */
493
+ toBuffer(): Buffer;
494
+ private _loadWorkbookStructure;
495
+ private _appendCount;
496
+ private _ensureSharedStringsLoaded;
497
+ private _commitSharedStrings;
498
+ private _collectStyles;
499
+ private _findDateXf;
500
+ private _buildRows;
501
+ private _valueCellBytes;
502
+ private _stringCellBytes;
503
+ private _findRowsRegion;
504
+ /**
505
+ * Keep the sheet dimension record (0x98) in sync with the new data.
506
+ * Excel uses its rwLast (payload offset 24) and colLast (payload offset 32)
507
+ * fields to read the full row range; stale values make the last written row
508
+ * invisible to Excel (and drop it from pivot refreshes).
509
+ */
510
+ private _patchDimension;
511
+ private _patchPivotCaches;
512
+ }
513
+
354
514
  /** Excel sheet name characters that must be replaced. */
355
515
  declare const INVALID_SHEET_NAME_CHARS: RegExp;
356
516
  /**
@@ -396,4 +556,4 @@ declare class StreamingSheetState {
396
556
  end(): void;
397
557
  }
398
558
 
399
- export { BiffReaderWriter, BigBuffer, type CellValue, ExcelReaderAbstract, F, type FormattedCell, INVALID_SHEET_NAME_CHARS, type PrimitiveCellValue, ReaderFactory, StreamingSheetState, XlsbReader, XlsbWriter, XlsxReader, XlsxWriter, applyHeaderWidths, defaultColWidth, getFormat, initColWidths, isFormattedCell, sanitizeSheetName, unwrapCell, updateColWidthsFromRows };
559
+ export { BiffReaderWriter, BigBuffer, type CellValue, ExcelReaderAbstract, F, type FormattedCell, INVALID_SHEET_NAME_CHARS, type PrimitiveCellValue, ReaderFactory, type ReplaceSheetDataOptions$1 as ReplaceSheetDataOptions, StreamingSheetState, XlsbReader, type ReplaceSheetDataOptions as XlsbReplaceSheetDataOptions, XlsbUpdater, XlsbWriter, XlsxReader, XlsxUpdater, XlsxWriter, applyHeaderWidths, defaultColWidth, getFormat, initColWidths, isFormattedCell, sanitizeSheetName, unwrapCell, updateColWidthsFromRows };