@niicojs/excel 0.2.3 → 0.2.4

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/dist/index.d.ts CHANGED
@@ -13,6 +13,10 @@ type ErrorType = '#NULL!' | '#DIV/0!' | '#VALUE!' | '#REF!' | '#NAME?' | '#NUM!'
13
13
  * Discriminator for cell content type
14
14
  */
15
15
  type CellType = 'number' | 'string' | 'boolean' | 'date' | 'error' | 'empty';
16
+ /**
17
+ * Date handling strategy when serializing cell values.
18
+ */
19
+ type DateHandling = 'jsDate' | 'excelSerial' | 'isoString';
16
20
  /**
17
21
  * Style definition for cells
18
22
  */
@@ -83,6 +87,17 @@ interface CellData {
83
87
  * Pivot table aggregation functions
84
88
  */
85
89
  type AggregationType = 'sum' | 'count' | 'average' | 'min' | 'max';
90
+ /**
91
+ * Sort order for pivot fields.
92
+ */
93
+ type PivotSortOrder = 'asc' | 'desc';
94
+ /**
95
+ * Filter configuration for pivot fields.
96
+ */
97
+ interface PivotFieldFilter {
98
+ include?: string[];
99
+ exclude?: string[];
100
+ }
86
101
  /**
87
102
  * Configuration for a value field in a pivot table
88
103
  */
@@ -200,6 +215,10 @@ interface SheetToJsonConfig {
200
215
  * If true, stop reading when an empty row is encountered. Defaults to true.
201
216
  */
202
217
  stopOnEmptyRow?: boolean;
218
+ /**
219
+ * How to serialize Date values. Defaults to 'jsDate'.
220
+ */
221
+ dateHandling?: DateHandling;
203
222
  }
204
223
 
205
224
  /**
@@ -315,6 +334,12 @@ declare class Range {
315
334
  * Get all values in the range as a 2D array
316
335
  */
317
336
  get values(): CellValue[][];
337
+ /**
338
+ * Get all values in the range as a 2D array with options
339
+ */
340
+ getValues(options?: {
341
+ createMissing?: boolean;
342
+ }): CellValue[][];
318
343
  /**
319
344
  * Set values in the range from a 2D array
320
345
  */
@@ -356,6 +381,11 @@ declare class Worksheet {
356
381
  private _dirty;
357
382
  private _mergedCells;
358
383
  private _sheetData;
384
+ private _columnWidths;
385
+ private _rowHeights;
386
+ private _frozenPane;
387
+ private _dataBoundsCache;
388
+ private _boundsDirty;
359
389
  constructor(workbook: Workbook, name: string);
360
390
  /**
361
391
  * Get the workbook this sheet belongs to
@@ -385,6 +415,10 @@ declare class Worksheet {
385
415
  * Get a cell by address or row/col
386
416
  */
387
417
  cell(rowOrAddress: number | string, col?: number): Cell;
418
+ /**
419
+ * Get an existing cell without creating it.
420
+ */
421
+ getCellIfExists(rowOrAddress: number | string, col?: number): Cell | undefined;
388
422
  /**
389
423
  * Get a range of cells
390
424
  */
@@ -410,6 +444,33 @@ declare class Worksheet {
410
444
  * Get all cells in the worksheet
411
445
  */
412
446
  get cells(): Map<string, Cell>;
447
+ /**
448
+ * Set a column width (0-based index or column letter)
449
+ */
450
+ setColumnWidth(col: number | string, width: number): void;
451
+ /**
452
+ * Get a column width if set
453
+ */
454
+ getColumnWidth(col: number | string): number | undefined;
455
+ /**
456
+ * Set a row height (0-based index)
457
+ */
458
+ setRowHeight(row: number, height: number): void;
459
+ /**
460
+ * Get a row height if set
461
+ */
462
+ getRowHeight(row: number): number | undefined;
463
+ /**
464
+ * Freeze panes at a given row/column split (counts from top-left)
465
+ */
466
+ freezePane(rowSplit: number, colSplit: number): void;
467
+ /**
468
+ * Get current frozen pane configuration
469
+ */
470
+ getFrozenPane(): {
471
+ row: number;
472
+ col: number;
473
+ } | null;
413
474
  /**
414
475
  * Convert sheet data to an array of JSON objects.
415
476
  *
@@ -429,6 +490,7 @@ declare class Worksheet {
429
490
  * ```
430
491
  */
431
492
  toJson<T = Record<string, CellValue>>(config?: SheetToJsonConfig): T[];
493
+ private _serializeDate;
432
494
  /**
433
495
  * Get the bounds of data in the sheet (min/max row and column with data)
434
496
  */
@@ -495,6 +557,14 @@ declare class Styles {
495
557
  private _xmlNodes;
496
558
  private _dirty;
497
559
  private _styleCache;
560
+ private _styleObjectCache;
561
+ /**
562
+ * Generate a deterministic cache key for a style object.
563
+ * More efficient than JSON.stringify as it avoids the overhead of
564
+ * full JSON serialization and produces a consistent key regardless
565
+ * of property order.
566
+ */
567
+ private _getStyleKey;
498
568
  /**
499
569
  * Parse styles from XML content
500
570
  */
@@ -517,6 +587,10 @@ declare class Styles {
517
587
  * Uses caching to deduplicate identical styles
518
588
  */
519
589
  createStyle(style: CellStyle): number;
590
+ /**
591
+ * Clone an existing style by index, optionally overriding fields.
592
+ */
593
+ cloneStyle(index: number, overrides?: Partial<CellStyle>): number;
520
594
  private _findOrCreateFont;
521
595
  private _findOrCreateFill;
522
596
  private _findOrCreateBorder;
@@ -547,6 +621,7 @@ declare class PivotCache {
547
621
  private _records;
548
622
  private _recordCount;
549
623
  private _refreshOnLoad;
624
+ private _dateGrouping;
550
625
  constructor(cacheId: number, sourceSheet: string, sourceRange: string);
551
626
  /**
552
627
  * Get the cache ID
@@ -618,6 +693,7 @@ declare class PivotTable {
618
693
  private _columnFields;
619
694
  private _valueFields;
620
695
  private _filterFields;
696
+ private _fieldAssignments;
621
697
  private _pivotTableIndex;
622
698
  constructor(name: string, cache: PivotCache, targetSheet: string, targetCell: string, targetRow: number, targetCol: number, pivotTableIndex: number);
623
699
  /**
@@ -662,6 +738,14 @@ declare class PivotTable {
662
738
  * @param fieldName - Name of the source field (column header)
663
739
  */
664
740
  addFilterField(fieldName: string): this;
741
+ /**
742
+ * Set a sort order for a row/column field
743
+ */
744
+ sortField(fieldName: string, order: PivotSortOrder): this;
745
+ /**
746
+ * Filter items for a field (include or exclude list)
747
+ */
748
+ filterField(fieldName: string, filter: PivotFieldFilter): this;
665
749
  /**
666
750
  * Generate the pivotTableDefinition XML
667
751
  */
@@ -670,6 +754,7 @@ declare class PivotTable {
670
754
  * Build a pivotField node for a given field index
671
755
  */
672
756
  private _buildPivotFieldNode;
757
+ private _resolveItemFilter;
673
758
  /**
674
759
  * Build row items based on unique values in row fields
675
760
  */
@@ -710,6 +795,7 @@ declare class Workbook {
710
795
  private _pivotTables;
711
796
  private _pivotCaches;
712
797
  private _nextCacheId;
798
+ private _dateHandling;
713
799
  private constructor();
714
800
  /**
715
801
  * Load a workbook from a file path
@@ -739,6 +825,14 @@ declare class Workbook {
739
825
  * Get styles
740
826
  */
741
827
  get styles(): Styles;
828
+ /**
829
+ * Get the workbook date handling strategy.
830
+ */
831
+ get dateHandling(): DateHandling;
832
+ /**
833
+ * Set the workbook date handling strategy.
834
+ */
835
+ set dateHandling(value: DateHandling);
742
836
  /**
743
837
  * Get a worksheet by name or index
744
838
  */
@@ -865,6 +959,18 @@ declare class Workbook {
865
959
  private _updatePivotTableFiles;
866
960
  }
867
961
 
962
+ /**
963
+ * Converts a column index (0-based) to Excel column letters (A, B, ..., Z, AA, AB, ...)
964
+ * @param col - 0-based column index
965
+ * @returns Column letter(s)
966
+ */
967
+ declare const colToLetter: (col: number) => string;
968
+ /**
969
+ * Converts Excel column letters to a 0-based column index
970
+ * @param letters - Column letter(s) like 'A', 'B', 'AA'
971
+ * @returns 0-based column index
972
+ */
973
+ declare const letterToCol: (letters: string) => number;
868
974
  /**
869
975
  * Parses an Excel cell address (e.g., 'A1', '$B$2') to row/col indices
870
976
  * @param address - Cell address string
@@ -890,7 +996,15 @@ declare const parseRange: (range: string) => RangeAddress;
890
996
  * @returns Range string like 'A1:B10'
891
997
  */
892
998
  declare const toRange: (range: RangeAddress) => string;
999
+ /**
1000
+ * Normalizes a range so start is always top-left and end is bottom-right
1001
+ */
1002
+ declare const normalizeRange: (range: RangeAddress) => RangeAddress;
1003
+ /**
1004
+ * Checks if an address is within a range
1005
+ */
1006
+ declare const isInRange: (addr: CellAddress, range: RangeAddress) => boolean;
893
1007
 
894
- export { Cell, PivotCache, PivotTable, Range, SharedStrings, Styles, Workbook, Worksheet, parseAddress, parseRange, toAddress, toRange };
895
- export type { AggregationType, Alignment, BorderStyle, BorderType, CellAddress, CellError, CellStyle, CellType, CellValue, ColumnConfig, ErrorType, PivotFieldAxis, PivotTableConfig, PivotValueConfig, RangeAddress, RichCellValue, SheetFromDataConfig, SheetToJsonConfig };
1008
+ export { Cell, PivotCache, PivotTable, Range, SharedStrings, Styles, Workbook, Worksheet, colToLetter, isInRange, letterToCol, normalizeRange, parseAddress, parseRange, toAddress, toRange };
1009
+ export type { AggregationType, Alignment, BorderStyle, BorderType, CellAddress, CellError, CellStyle, CellType, CellValue, ColumnConfig, DateHandling, ErrorType, PivotFieldAxis, PivotFieldFilter, PivotSortOrder, PivotTableConfig, PivotValueConfig, RangeAddress, RichCellValue, SheetFromDataConfig, SheetToJsonConfig };
896
1010
  //# sourceMappingURL=index.d.ts.map