@alosha/xlsx 0.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.
@@ -0,0 +1,825 @@
1
+ declare enum CellType {
2
+ Null = 0,
3
+ Number = 1,
4
+ String = 2,
5
+ Boolean = 3,
6
+ Date = 4,
7
+ Error = 5,
8
+ RichText = 6,
9
+ Hyperlink = 7,
10
+ Formula = 8,
11
+ Merge = 9,
12
+ SharedString = 10
13
+ }
14
+ declare enum FormulaType {
15
+ None = 0,
16
+ Master = 1,
17
+ Shared = 2
18
+ }
19
+ type ErrorCode = "#N/A" | "#REF!" | "#NAME?" | "#DIV/0!" | "#NULL!" | "#VALUE!" | "#NUM!";
20
+
21
+ interface Color {
22
+ argb?: string;
23
+ theme?: number;
24
+ indexed?: number;
25
+ }
26
+ interface Font {
27
+ name?: string;
28
+ size?: number;
29
+ family?: number;
30
+ scheme?: "minor" | "major" | "none";
31
+ charset?: number;
32
+ color?: Color;
33
+ bold?: boolean;
34
+ italic?: boolean;
35
+ underline?: boolean | "none" | "single" | "double" | "singleAccounting" | "doubleAccounting";
36
+ vertAlign?: "superscript" | "subscript";
37
+ strike?: boolean;
38
+ outline?: boolean;
39
+ }
40
+ type FillPattern = "none" | "solid" | "darkVertical" | "darkHorizontal" | "darkGrid" | "darkTrellis" | "darkDown" | "darkUp" | "lightVertical" | "lightHorizontal" | "lightGrid" | "lightTrellis" | "lightDown" | "lightUp" | "darkGray" | "mediumGray" | "lightGray" | "gray125" | "gray0625";
41
+ interface GradientStop {
42
+ position: number;
43
+ color: Color;
44
+ }
45
+ type Fill = {
46
+ type: "pattern";
47
+ pattern: FillPattern;
48
+ fgColor?: Color;
49
+ bgColor?: Color;
50
+ } | {
51
+ type: "gradient";
52
+ gradient: "angle";
53
+ degree: number;
54
+ stops: GradientStop[];
55
+ } | {
56
+ type: "gradient";
57
+ gradient: "path";
58
+ center: {
59
+ left: number;
60
+ top: number;
61
+ };
62
+ stops: GradientStop[];
63
+ };
64
+ type BorderStyle = "thin" | "dotted" | "hair" | "medium" | "double" | "thick" | "dashed" | "dashDot" | "dashDotDot" | "slantDashDot" | "mediumDashed" | "mediumDashDotDot" | "mediumDashDot";
65
+ interface Border {
66
+ style?: BorderStyle;
67
+ color?: Color;
68
+ }
69
+ interface BorderDiagonal extends Border {
70
+ up?: boolean;
71
+ down?: boolean;
72
+ }
73
+ interface Borders {
74
+ top?: Border;
75
+ left?: Border;
76
+ bottom?: Border;
77
+ right?: Border;
78
+ diagonal?: BorderDiagonal;
79
+ }
80
+ interface Alignment {
81
+ horizontal?: "left" | "center" | "right" | "fill" | "justify" | "centerContinuous" | "distributed";
82
+ vertical?: "top" | "middle" | "bottom" | "distributed" | "justify";
83
+ wrapText?: boolean;
84
+ shrinkToFit?: boolean;
85
+ indent?: number;
86
+ readingOrder?: "rtl" | "ltr";
87
+ textRotation?: number | "vertical";
88
+ }
89
+ interface Protection {
90
+ locked?: boolean;
91
+ hidden?: boolean;
92
+ }
93
+ interface Style {
94
+ numFmt?: string;
95
+ font?: Font;
96
+ alignment?: Alignment;
97
+ protection?: Protection;
98
+ border?: Borders;
99
+ fill?: Fill;
100
+ }
101
+ /**
102
+ * Resolve a cell's effective style: row default and column default merged field-by-field — row
103
+ * wins over column — then the cell's own style overrides both (see docs/API-AUDIT.md §4's
104
+ * `_mergeStyle` precedence note). `fill` is a discriminated union so it is replaced wholesale
105
+ * rather than merged (mixing a `pattern` fill's fields with a `gradient` fill's would be
106
+ * incoherent). Returns a new object; never mutates any input.
107
+ */
108
+ declare function resolveCellStyle(rowStyle?: Style, colStyle?: Style, cellStyle?: Style): Style;
109
+
110
+ interface RichTextRun {
111
+ text: string;
112
+ font?: Font;
113
+ }
114
+ interface RichText {
115
+ richText: RichTextRun[];
116
+ }
117
+ interface Hyperlink {
118
+ text: string;
119
+ hyperlink: string;
120
+ tooltip?: string;
121
+ }
122
+ interface CellError {
123
+ error: ErrorCode;
124
+ }
125
+ interface CellFormula {
126
+ formula?: string;
127
+ sharedFormula?: string;
128
+ ref?: string;
129
+ shareType?: "shared" | "array";
130
+ result?: number | string | boolean | Date | CellError;
131
+ }
132
+ /** What callers pass to `cell.value = …` and read back. */
133
+ type CellValue = null | number | string | boolean | Date | CellError | RichText | Hyperlink | CellFormula;
134
+ /** Internal normalized storage on the cell model (discriminated on `type`). */
135
+ type StoredValue = {
136
+ type: CellType.Null;
137
+ } | {
138
+ type: CellType.Number;
139
+ value: number;
140
+ } | {
141
+ type: CellType.String;
142
+ value: string;
143
+ } | {
144
+ type: CellType.Boolean;
145
+ value: boolean;
146
+ } | {
147
+ type: CellType.Date;
148
+ value: Date;
149
+ } | {
150
+ type: CellType.Error;
151
+ value: CellError;
152
+ } | {
153
+ type: CellType.RichText;
154
+ value: RichText;
155
+ } | {
156
+ type: CellType.Hyperlink;
157
+ value: Hyperlink;
158
+ } | {
159
+ type: CellType.Formula;
160
+ value: CellFormula;
161
+ } | {
162
+ type: CellType.Merge;
163
+ master: string;
164
+ } | {
165
+ type: CellType.SharedString;
166
+ value: number;
167
+ };
168
+ /**
169
+ * Duck-type a `CellValue` into a `CellType`, mirroring ExcelJS's `Value.getType` check order:
170
+ * null → string → number → boolean → date → hyperlink (`text`&`hyperlink`) → formula
171
+ * (`formula`|`sharedFormula`) → richText → error. Throws {@link InvalidCellValueError} for
172
+ * anything else.
173
+ */
174
+ declare function detectType(v: CellValue): CellType;
175
+ /** Normalizes an ergonomic `CellValue` into its discriminated `StoredValue` form. */
176
+ declare function toStored(v: CellValue): StoredValue;
177
+ /**
178
+ * Recovers the ergonomic `CellValue` from a `StoredValue`. `Merge` (resolved via the master cell)
179
+ * and `SharedString` (resolved via the shared-strings pool, Stage 1.3) have no `CellValue`
180
+ * equivalent of their own and read back as `null`.
181
+ */
182
+ declare function fromStored(s: StoredValue): CellValue;
183
+ /** For a formula cell, the type of its cached `result`; else the cell's own type. */
184
+ declare function effectiveType(s: StoredValue): CellType;
185
+ /** Display string for a stored value (no number-format application — that's Stage 1.3). */
186
+ declare function toText(s: StoredValue): string;
187
+ /** CSV-escaped rendering of a stored value: quotes the field and doubles internal quotes when it
188
+ * contains a comma, quote, or newline. */
189
+ declare function toCsv(s: StoredValue): string;
190
+
191
+ /** A row's cell values: a contiguous/sparse array, a column-key-keyed object, or absent. */
192
+ type RowValues = CellValue[] | {
193
+ [key: string]: CellValue;
194
+ } | undefined | null;
195
+
196
+ interface RowModel {
197
+ number: number;
198
+ cells: CellModel[];
199
+ height?: number;
200
+ hidden?: boolean;
201
+ outlineLevel?: number;
202
+ style?: Style;
203
+ }
204
+ type EachCellCb$1 = (cell: Cell, colNumber: number) => void;
205
+ declare class Row {
206
+ readonly worksheet: WorksheetHost;
207
+ readonly number: number;
208
+ height?: number;
209
+ hidden: boolean;
210
+ outlineLevel: number;
211
+ /** Sparse, 1-indexed by column number; index 0 is never assigned. */
212
+ private _cells;
213
+ private _style;
214
+ constructor(worksheet: WorksheetHost, number: number);
215
+ get collapsed(): boolean;
216
+ private resolveColNumber;
217
+ getCell(col: number | string): Cell;
218
+ findCell(col: number): Cell | undefined;
219
+ eachCell(cb: EachCellCb$1): void;
220
+ eachCell(opts: {
221
+ includeEmpty: boolean;
222
+ }, cb: EachCellCb$1): void;
223
+ get hasValues(): boolean;
224
+ get cellCount(): number;
225
+ get actualCellCount(): number;
226
+ get dimensions(): {
227
+ min: number;
228
+ max: number;
229
+ } | null;
230
+ get values(): RowValues;
231
+ set values(v: RowValues);
232
+ splice(start: number, count: number, ...inserts: CellValue[]): void;
233
+ private applyToCells;
234
+ get style(): Style;
235
+ set style(s: Style);
236
+ get numFmt(): string | undefined;
237
+ set numFmt(v: string | undefined);
238
+ get font(): Font | undefined;
239
+ set font(v: Font | undefined);
240
+ get alignment(): Alignment | undefined;
241
+ set alignment(v: Alignment | undefined);
242
+ get border(): Borders | undefined;
243
+ set border(v: Borders | undefined);
244
+ get fill(): Fill | undefined;
245
+ set fill(v: Fill | undefined);
246
+ get protection(): Protection | undefined;
247
+ set protection(v: Protection | undefined);
248
+ get model(): RowModel;
249
+ set model(m: RowModel);
250
+ }
251
+
252
+ interface WorksheetHost {
253
+ getColumn(col: number | string): Column;
254
+ getColumnKey(key: string): Column | undefined;
255
+ getRow(row: number): Row;
256
+ eachRow(cb: (row: Row, n: number) => void): void;
257
+ eachRow(opts: {
258
+ includeEmpty: boolean;
259
+ }, cb: (row: Row, n: number) => void): void;
260
+ readonly properties: {
261
+ outlineLevelCol: number;
262
+ outlineLevelRow: number;
263
+ } & Record<string, unknown>;
264
+ }
265
+
266
+ declare const DEFAULT_COLUMN_WIDTH = 9;
267
+ interface ColumnDefn {
268
+ key?: string;
269
+ header?: string | string[];
270
+ width?: number;
271
+ hidden?: boolean;
272
+ outlineLevel?: number;
273
+ style?: Style;
274
+ }
275
+ /** Run-length range as compressed by `Column.toModel` — OOXML `<col min max .../>` attributes only. */
276
+ interface ColumnRange {
277
+ min: number;
278
+ max: number;
279
+ width?: number;
280
+ hidden?: boolean;
281
+ outlineLevel?: number;
282
+ style?: Style;
283
+ }
284
+ type EachCellCb = (cell: Cell, rowNumber: number) => void;
285
+ declare class Column {
286
+ private readonly host;
287
+ readonly number: number;
288
+ key?: string;
289
+ width?: number;
290
+ hidden: boolean;
291
+ outlineLevel: number;
292
+ private _header;
293
+ private _style;
294
+ constructor(host: WorksheetHost, number: number, defn?: Partial<ColumnDefn> | false);
295
+ get letter(): string;
296
+ get collapsed(): boolean;
297
+ get isCustomWidth(): boolean;
298
+ get isDefault(): boolean;
299
+ get header(): string | string[] | undefined;
300
+ /** Writes the header text(s) into this column's top cell(s): row 1 for a string, rows 1..N
301
+ * for a string array (SPEC §6 — "header assignment writes the top row cells' values"). */
302
+ set header(h: string | string[] | undefined);
303
+ get values(): CellValue[];
304
+ set values(vals: CellValue[]);
305
+ eachCell(cb: EachCellCb): void;
306
+ eachCell(opts: {
307
+ includeEmpty: boolean;
308
+ }, cb: EachCellCb): void;
309
+ private applyToCells;
310
+ get style(): Style;
311
+ set style(s: Style);
312
+ get numFmt(): string | undefined;
313
+ set numFmt(v: string | undefined);
314
+ get font(): Font | undefined;
315
+ set font(v: Font | undefined);
316
+ get alignment(): Alignment | undefined;
317
+ set alignment(v: Alignment | undefined);
318
+ get border(): Borders | undefined;
319
+ set border(v: Borders | undefined);
320
+ get fill(): Fill | undefined;
321
+ set fill(v: Fill | undefined);
322
+ get protection(): Protection | undefined;
323
+ set protection(v: Protection | undefined);
324
+ get defn(): ColumnDefn;
325
+ set defn(d: ColumnDefn);
326
+ /** Whether two columns share the same OOXML-relevant attributes (used to compress runs). */
327
+ equivalentTo(other: Column): boolean;
328
+ private static rangeOf;
329
+ /** Run-length compress an array of Columns into `<col min max>` ranges. */
330
+ static toModel(columns: Column[]): ColumnRange[] | undefined;
331
+ /** Expands `<col min max>` ranges back into individual Columns. */
332
+ static fromModel(host: WorksheetHost, cols: ColumnRange[]): Column[] | null;
333
+ }
334
+
335
+ interface CellModel {
336
+ address: string;
337
+ type: CellType;
338
+ value?: unknown;
339
+ formula?: string;
340
+ result?: unknown;
341
+ style?: Style;
342
+ }
343
+ declare class Cell {
344
+ private readonly rowRef;
345
+ private readonly columnRef;
346
+ readonly address: string;
347
+ private _stored;
348
+ private _style;
349
+ private _master;
350
+ constructor(rowRef: Row, columnRef: Column, address: string);
351
+ get row(): number;
352
+ get col(): number;
353
+ get $col$row(): string;
354
+ /** The stored value this cell resolves through: itself, or (if merged) its master. */
355
+ private get resolvedStored();
356
+ get value(): CellValue;
357
+ set value(v: CellValue);
358
+ /** This cell's own marker type — `Merge` for a slave, even though `value`/`text` delegate. */
359
+ get type(): CellType;
360
+ get effectiveType(): CellType;
361
+ get text(): string;
362
+ toString(): string;
363
+ toCsvString(): string;
364
+ get isMerged(): boolean;
365
+ /** The master cell of this cell's merge region; itself if unmerged. */
366
+ get master(): Cell;
367
+ merge(master: Cell, ignoreStyle?: boolean): void;
368
+ unmerge(): void;
369
+ get formula(): string | undefined;
370
+ get result(): unknown;
371
+ get formulaType(): FormulaType;
372
+ get style(): Style;
373
+ set style(s: Style);
374
+ get numFmt(): string | undefined;
375
+ set numFmt(v: string | undefined);
376
+ get font(): Font | undefined;
377
+ set font(v: Font | undefined);
378
+ get alignment(): Alignment | undefined;
379
+ set alignment(v: Alignment | undefined);
380
+ get border(): Borders | undefined;
381
+ set border(v: Borders | undefined);
382
+ get fill(): Fill | undefined;
383
+ set fill(v: Fill | undefined);
384
+ get protection(): Protection | undefined;
385
+ set protection(v: Protection | undefined);
386
+ get model(): CellModel;
387
+ set model(m: CellModel);
388
+ }
389
+
390
+ /** 1-based rows/cols everywhere in this module's public surface. */
391
+ interface Decoded {
392
+ row: number;
393
+ col: number;
394
+ address: string;
395
+ }
396
+ /** `decodeEx` result: adds the absolute `$col$row` form and an optional sheet qualifier. */
397
+ interface DecodedEx extends Decoded {
398
+ $col$row: string;
399
+ sheetName?: string;
400
+ }
401
+ /** 'A'->1, 'Z'->26, 'AA'->27. Throws {@link InvalidAddressError} on non-letters. */
402
+ declare function colLetterToNumber(letter: string): number;
403
+ /** 1->'A', 27->'AA'. */
404
+ declare function colNumberToLetter(col: number): string;
405
+ /** (row=1,col=2) -> 'B1'. */
406
+ declare function encodeAddress(row: number, col: number): string;
407
+ /** 'B1' -> { row:1, col:2, address:'B1' }. Cached. */
408
+ declare function decodeAddress(address: string): Decoded;
409
+ /** Handles '$B$1', "'Sheet 1'!B1", Sheet1!B1, absolute/relative `$` markers. */
410
+ declare function decodeEx(address: string): DecodedEx;
411
+ /** Throws {@link InvalidAddressError} if not a well-formed A1 cell address. */
412
+ declare function validateAddress(address: string): void;
413
+
414
+ type RangeSource = string | [string, string] | [number, number, number, number] | Range | Decoded;
415
+ /** A normalized bounding box (`top<=bottom`, `left<=right`) over 1-based cell addresses. */
416
+ declare class Range {
417
+ top: number;
418
+ left: number;
419
+ bottom: number;
420
+ right: number;
421
+ sheetName?: string;
422
+ constructor(source?: RangeSource);
423
+ constructor(top: number, left: number, bottom: number, right: number);
424
+ /** Top-left address, e.g. 'A1'. */
425
+ get tl(): string;
426
+ /** Bottom-right address, e.g. 'B2'. */
427
+ get br(): string;
428
+ /** 'A1:B2'. */
429
+ get range(): string;
430
+ /** Total cell count covered by the box. */
431
+ get count(): number;
432
+ /** Grows the box to include the given box (union of bounds). */
433
+ expand(top: number, left: number, bottom: number, right: number): void;
434
+ /** Whether the given address falls within this box. */
435
+ contains(address: string): boolean;
436
+ /** Whether this box overlaps another box. */
437
+ intersects(other: Range): boolean;
438
+ /** Visits every address in the box, row-major (row-by-row, left-to-right within a row). */
439
+ forEachAddress(cb: (address: string, row: number, col: number) => void): void;
440
+ }
441
+
442
+ /** Sheet properties. `outlineLevelCol`/`outlineLevelRow` back the `collapsed` derivation on
443
+ * Column/Row; the rest is plain round-tripped data. */
444
+ interface WorksheetProperties {
445
+ tabColor?: Color;
446
+ outlineLevelCol: number;
447
+ outlineLevelRow: number;
448
+ defaultRowHeight: number;
449
+ defaultColWidth?: number;
450
+ dyDescent: number;
451
+ showGridLines?: boolean;
452
+ [key: string]: unknown;
453
+ }
454
+ /** Freeze/split panes, zoom, gridlines — stored as plain data (round-trips through the model). */
455
+ interface WorksheetView {
456
+ state?: "normal" | "frozen" | "split";
457
+ showGridLines?: boolean;
458
+ zoomScale?: number;
459
+ [key: string]: unknown;
460
+ }
461
+ /** Options accepted by `Workbook.addWorksheet`. */
462
+ interface AddWorksheetOptions {
463
+ state: "visible" | "hidden" | "veryHidden";
464
+ properties: Partial<WorksheetProperties>;
465
+ views: WorksheetView[];
466
+ pageSetup: unknown;
467
+ headerFooter: unknown;
468
+ }
469
+ /** Replaces ExcelJS's cryptic `'i' | 'o' | 'i+' | 'o+' | 'n'` style DSL (API-AUDIT §2). */
470
+ type RowInheritOption = {
471
+ inheritFrom?: "above" | "below";
472
+ includeEmpty?: boolean;
473
+ } | undefined;
474
+ /** The serializable snapshot of a worksheet. */
475
+ interface WorksheetModel {
476
+ id: number;
477
+ name: string;
478
+ orderNo: number;
479
+ state: "visible" | "hidden" | "veryHidden";
480
+ properties: WorksheetProperties;
481
+ views: WorksheetView[];
482
+ columns?: ColumnRange[];
483
+ rows: RowModel[];
484
+ merges: string[];
485
+ pageSetup?: unknown;
486
+ headerFooter?: unknown;
487
+ }
488
+ type EachRowCb = (row: Row, n: number) => void;
489
+ type RowData = CellValue[] | Record<string, CellValue>;
490
+ declare class Worksheet implements WorksheetHost {
491
+ orderNo: number;
492
+ state: "visible" | "hidden" | "veryHidden";
493
+ readonly workbook: Workbook;
494
+ properties: WorksheetProperties;
495
+ views: WorksheetView[];
496
+ pageSetup?: unknown;
497
+ headerFooter?: unknown;
498
+ private _id;
499
+ private _name;
500
+ private readonly _rows;
501
+ private readonly _columns;
502
+ private readonly _columnsByKey;
503
+ /** Active merge regions keyed by their master (top-left) cell address. */
504
+ private readonly _merges;
505
+ constructor(workbook: Workbook, id: number, name: string, orderNo: number);
506
+ get id(): number;
507
+ get name(): string;
508
+ set name(value: string);
509
+ getRow(row: number): Row;
510
+ getRows(start: number, length: number): Row[] | undefined;
511
+ findRow(row: number): Row | undefined;
512
+ addRow(data: RowData, options?: RowInheritOption): Row;
513
+ addRows(rows: RowData[], options?: RowInheritOption): Row[];
514
+ insertRow(pos: number, value: RowData, options?: RowInheritOption): Row;
515
+ private applyInheritance;
516
+ duplicateRow(rowNum: number, count: number, insert?: boolean): void;
517
+ spliceRows(start: number, count: number, ...inserts: RowData[]): void;
518
+ private snapshotRow;
519
+ private restoreRow;
520
+ eachRow(cb: EachRowCb): void;
521
+ eachRow(opts: {
522
+ includeEmpty: boolean;
523
+ }, cb: EachRowCb): void;
524
+ getSheetValues(): RowValues[];
525
+ get rowCount(): number;
526
+ get actualRowCount(): number;
527
+ get lastRow(): Row | undefined;
528
+ get columns(): Column[];
529
+ set columns(defns: Partial<ColumnDefn>[]);
530
+ getColumn(idOrKey: number | string): Column;
531
+ private getOrCreateColumn;
532
+ get columnCount(): number;
533
+ get actualColumnCount(): number;
534
+ get lastColumn(): Column | undefined;
535
+ spliceColumns(start: number, count: number, ...inserts: CellValue[][]): void;
536
+ getColumnKey(key: string): Column | undefined;
537
+ setColumnKey(key: string, column: Column): void;
538
+ deleteColumnKey(key: string): void;
539
+ eachColumnKey(cb: (column: Column, key: string) => void): void;
540
+ getCell(r: number | string, c?: number | string): Cell;
541
+ findCell(r: number | string, c?: number | string): Cell | undefined;
542
+ private toColNumber;
543
+ mergeCells(...cells: unknown[]): void;
544
+ unMergeCells(...cells: unknown[]): void;
545
+ /** Links the slave cells of `range` to its top-left master and records the region. */
546
+ private applyMerge;
547
+ get hasMerges(): boolean;
548
+ get dimensions(): Range;
549
+ get model(): WorksheetModel;
550
+ set model(m: WorksheetModel);
551
+ }
552
+
553
+ /** Workbook-wide flags — notably the 1904 date system. */
554
+ interface WorkbookProperties {
555
+ date1904?: boolean;
556
+ [key: string]: unknown;
557
+ }
558
+ /** Calculation chain flags (e.g. `fullCalcOnLoad`). */
559
+ interface CalculationProperties {
560
+ fullCalcOnLoad?: boolean;
561
+ [key: string]: unknown;
562
+ }
563
+ /** Window layout / active-tab state — stored as plain data (round-trips through the model). */
564
+ interface WorkbookView {
565
+ x?: number;
566
+ y?: number;
567
+ width?: number;
568
+ height?: number;
569
+ activeTab?: number;
570
+ visibility?: string;
571
+ [key: string]: unknown;
572
+ }
573
+ /** The serializable snapshot of a workbook. */
574
+ interface WorkbookModel {
575
+ creator?: string;
576
+ lastModifiedBy?: string;
577
+ created: Date;
578
+ modified: Date;
579
+ lastPrinted?: Date;
580
+ title?: string;
581
+ subject?: string;
582
+ keywords?: string;
583
+ category?: string;
584
+ description?: string;
585
+ company?: string;
586
+ manager?: string;
587
+ properties: WorkbookProperties;
588
+ calcProperties: CalculationProperties;
589
+ views: WorkbookView[];
590
+ sheets: WorksheetModel[];
591
+ nextId: number;
592
+ }
593
+ declare class Workbook {
594
+ creator?: string;
595
+ lastModifiedBy?: string;
596
+ created: Date;
597
+ modified: Date;
598
+ lastPrinted?: Date;
599
+ title?: string;
600
+ subject?: string;
601
+ keywords?: string;
602
+ category?: string;
603
+ description?: string;
604
+ company?: string;
605
+ manager?: string;
606
+ properties: WorkbookProperties;
607
+ calcProperties: CalculationProperties;
608
+ views: WorkbookView[];
609
+ private readonly _byId;
610
+ private _sheets;
611
+ private _nextId;
612
+ constructor();
613
+ /** Ordered, O(n). A fresh copy so callers cannot mutate the backing order. */
614
+ get worksheets(): Worksheet[];
615
+ addWorksheet(name?: string, options?: Partial<AddWorksheetOptions>): Worksheet;
616
+ private uniqueSheetName;
617
+ getWorksheet(idOrName?: number | string): Worksheet | undefined;
618
+ removeWorksheet(idOrName: number | string): void;
619
+ /** Keeps `orderNo` equal to array position after a removal. */
620
+ private reindex;
621
+ eachSheet(cb: (ws: Worksheet, id: number) => void): void;
622
+ get model(): WorkbookModel;
623
+ set model(m: WorkbookModel);
624
+ }
625
+
626
+ /** Convert a `Date` to its Excel day serial (fractional part carries the time of day). */
627
+ declare function dateToSerial(d: Date, date1904?: boolean): number;
628
+ /** Convert an Excel day serial back to a `Date` (UTC-based instant). */
629
+ declare function serialToDate(serial: number, date1904?: boolean): Date;
630
+
631
+ /** Reserved for future read options (e.g. `ignoreStyles`). None are required for v1. */
632
+ interface ReadOptions {
633
+ }
634
+ /** Parse a buffered `.xlsx` into a `Workbook`. Environment-agnostic (no `fs`); see `readWorkbookFile`. */
635
+ declare function readWorkbookBuffer(bytes: Uint8Array, _options?: ReadOptions): Workbook;
636
+ /** Node-only convenience: read and parse a `.xlsx` from disk. Isolated here so browser bundles that
637
+ * only use {@link readWorkbookBuffer} never pull in `node:fs`. */
638
+ declare function readWorkbookFile(path: string, options?: ReadOptions): Promise<Workbook>;
639
+
640
+ interface SharedStrings {
641
+ /** Intern a plain string or rich text; returns its 0-based index. Repeated values return the same
642
+ * index (but still count as a reference). */
643
+ add(value: string | RichText): number;
644
+ /** Total references added (the sum of `add` calls). */
645
+ readonly count: number;
646
+ /** Distinct entries in the pool. */
647
+ readonly uniqueCount: number;
648
+ /** Render xl/sharedStrings.xml, or `undefined` when the pool is empty (the part is then omitted). */
649
+ toXml(): string | undefined;
650
+ }
651
+ declare function createSharedStrings(): SharedStrings;
652
+
653
+ interface Styles {
654
+ /** Intern a resolved cell Style; returns its cellXf index (the value for a cell's `s=""` attr). A cell
655
+ * with no style — or a structurally-default one — returns 0, the seeded default cellXf. */
656
+ addStyle(style: Style | undefined): number;
657
+ /** Render the complete xl/styles.xml. Always non-empty (the baseline seeds are always present). */
658
+ toXml(): string;
659
+ }
660
+ declare function createStyles(): Styles;
661
+
662
+ interface WriteOptions {
663
+ /** Emit a shared-string table (string cells store an index). When `false`, strings render inline.
664
+ * Default `true`. */
665
+ useSharedStrings?: boolean;
666
+ /** Intern cell/row/column styles into styles.xml. When `false`, cells render unstyled (`s` omitted)
667
+ * and styles.xml carries only the mandatory baseline. Default `true`. */
668
+ useStyles?: boolean;
669
+ }
670
+ /** Serialize a workbook to `.xlsx` bytes. Environment-agnostic (no `fs`); see `writeWorkbookFile`. */
671
+ declare function writeWorkbookBuffer(wb: Workbook, options?: WriteOptions): Uint8Array;
672
+ /** Node-only convenience: serialize and write to disk. Isolated here so browser bundles that only
673
+ * use {@link writeWorkbookBuffer} never pull in `node:fs`. */
674
+ declare function writeWorkbookFile(wb: Workbook, path: string, options?: WriteOptions): Promise<void>;
675
+
676
+ /**
677
+ * Typed error hierarchy for @alosha/xlsx.
678
+ *
679
+ * Every error thrown by the library extends {@link AloshaXlsxError}, so callers can do:
680
+ *
681
+ * try { ws.name = 'a/b'; }
682
+ * catch (e) {
683
+ * if (e instanceof AloshaXlsxError) console.log(e.code); // stable, minify-safe
684
+ * }
685
+ *
686
+ * The `code` string is the stable programmatic handle (safe across bundling/minification, unlike
687
+ * `name`/`instanceof` across realms). Prefer switching on `code`. Design goal (see docs/API-AUDIT.md §5):
688
+ * replace ExcelJS's `console.warn`/`console.trace` side effects with thrown, inspectable errors.
689
+ */
690
+ type AloshaXlsxErrorCode = "INVALID_ADDRESS" | "INVALID_RANGE" | "INVALID_WORKSHEET_NAME" | "RESERVED_WORKSHEET_NAME" | "DUPLICATE_WORKSHEET_NAME" | "WORKSHEET_NAME_TOO_LONG" | "MERGE_CONFLICT" | "INVALID_ROW_NUMBER" | "INVALID_CELL_VALUE" | "UNSUPPORTED_FEATURE" | "INVALID_PACKAGE";
691
+ /**
692
+ * Base class for all library errors. Abstract — never thrown directly; always a concrete subclass.
693
+ * Sets `name` from the concrete class and repairs the prototype chain so `instanceof` holds even when
694
+ * compiled to older targets.
695
+ */
696
+ declare abstract class AloshaXlsxError extends Error {
697
+ /** Stable, machine-readable discriminator. Prefer this over `name`/`instanceof`. */
698
+ abstract readonly code: AloshaXlsxErrorCode;
699
+ constructor(message: string);
700
+ }
701
+ /** Narrowing type guard for library errors. */
702
+ declare function isAloshaXlsxError(e: unknown): e is AloshaXlsxError;
703
+ /** A cell address or column letter could not be parsed (e.g. `''`, `'A0'`, `'1A'`, `'@'`). */
704
+ declare class InvalidAddressError extends AloshaXlsxError {
705
+ readonly address: string;
706
+ readonly code: "INVALID_ADDRESS";
707
+ constructor(address: string);
708
+ }
709
+ /** A range could not be parsed from the supplied source (e.g. `'A1:'`, malformed tuple). */
710
+ declare class InvalidRangeError extends AloshaXlsxError {
711
+ readonly range: unknown;
712
+ readonly code: "INVALID_RANGE";
713
+ constructor(range: unknown);
714
+ }
715
+ /** Why a worksheet name was rejected (illegal-character/empty/edge-quote cases). */
716
+ type InvalidWorksheetNameReason = "empty" | "illegal-characters" | "edge-quote";
717
+ /** Worksheet name is empty, contains `* ? : / \ [ ]`, or starts/ends with a single quote. */
718
+ declare class InvalidWorksheetNameError extends AloshaXlsxError {
719
+ readonly worksheetName: string;
720
+ readonly reason: InvalidWorksheetNameReason;
721
+ readonly code: "INVALID_WORKSHEET_NAME";
722
+ constructor(worksheetName: string, reason: InvalidWorksheetNameReason);
723
+ private static messageFor;
724
+ }
725
+ /** Worksheet name uses a reserved word (Excel reserves `"History"`). */
726
+ declare class ReservedWorksheetNameError extends AloshaXlsxError {
727
+ readonly worksheetName: string;
728
+ readonly code: "RESERVED_WORKSHEET_NAME";
729
+ constructor(worksheetName: string);
730
+ }
731
+ /** A worksheet with this name already exists in the workbook (comparison is case-insensitive). */
732
+ declare class DuplicateWorksheetNameError extends AloshaXlsxError {
733
+ readonly worksheetName: string;
734
+ readonly code: "DUPLICATE_WORKSHEET_NAME";
735
+ constructor(worksheetName: string);
736
+ }
737
+ /**
738
+ * Worksheet name exceeds Excel's limit. Unlike ExcelJS (which warns + silently truncates), the model
739
+ * throws so the caller decides — see docs/STAGE-1.2-SPEC.md §7.
740
+ */
741
+ declare class WorksheetNameTooLongError extends AloshaXlsxError {
742
+ readonly worksheetName: string;
743
+ readonly maxLength: number;
744
+ readonly code: "WORKSHEET_NAME_TOO_LONG";
745
+ /** Excel's hard cap on sheet-name length. */
746
+ static readonly MAX_LENGTH = 31;
747
+ constructor(worksheetName: string, maxLength?: number);
748
+ }
749
+ /** Attempted to merge a region that overlaps an existing merge (merges are atomic — API-AUDIT §2). */
750
+ declare class MergeConflictError extends AloshaXlsxError {
751
+ readonly range: string;
752
+ readonly code: "MERGE_CONFLICT";
753
+ constructor(range: string);
754
+ }
755
+ /** A row model's `number` does not match the row it is being assigned to (model round-trip guard). */
756
+ declare class InvalidRowNumberError extends AloshaXlsxError {
757
+ readonly expected: number;
758
+ readonly actual: number;
759
+ readonly code: "INVALID_ROW_NUMBER";
760
+ constructor(expected: number, actual: number);
761
+ }
762
+ /** A value passed to `cell.value` is not a supported {@link import('./model/cell-value').CellValue}. */
763
+ declare class InvalidCellValueError extends AloshaXlsxError {
764
+ readonly value: unknown;
765
+ readonly code: "INVALID_CELL_VALUE";
766
+ constructor(value: unknown);
767
+ private static describe;
768
+ }
769
+ /**
770
+ * A feature not implemented in the current stage was invoked (pivot tables, conditional formatting,
771
+ * drawings, tables, data validation, comments, protection — deferred to Stage 2; see STAGE-1.2-SPEC §9).
772
+ * Use to fail loudly on stubs instead of silently no-op'ing.
773
+ */
774
+ declare class UnsupportedFeatureError extends AloshaXlsxError {
775
+ readonly feature: string;
776
+ readonly code: "UNSUPPORTED_FEATURE";
777
+ constructor(feature: string);
778
+ }
779
+ /**
780
+ * The `.xlsx` package's OPC structure (zip / rels / parts) is missing or malformed: a truncated/corrupt
781
+ * zip, a missing `_rels/.rels` or workbook part, or a relationship that cannot be resolved. Thrown by
782
+ * `openPackage` before any SpreadsheetML parsing begins.
783
+ */
784
+ declare class InvalidPackageError extends AloshaXlsxError {
785
+ readonly reason: string;
786
+ readonly code: "INVALID_PACKAGE";
787
+ constructor(reason: string);
788
+ }
789
+
790
+ /**
791
+ * @alosha/xlsx — a modern TypeScript library for reading and writing XLSX
792
+ * spreadsheets, inspired by exceljs.
793
+ *
794
+ * This is the public entry point: the Stage 1.2 document model plus the Stage 1.3 OOXML writer. The
795
+ * writer is exposed two ways — the free functions from `./xlsx` (the environment-agnostic core) and
796
+ * an ExcelJS-style `workbook.xlsx.writeBuffer/writeFile` accessor attached here at the composition
797
+ * root, so the model layer keeps no dependency on the serializer.
798
+ */
799
+
800
+ /** A source of chunks for {@link XlsxAccessor.read}; a Node `Readable` satisfies this structurally. */
801
+ type ByteStream = AsyncIterable<Uint8Array>;
802
+ /** The ExcelJS-compatible read/write surface reached via `workbook.xlsx`. `load`/`readFile`/`read`
803
+ * mutate the receiving workbook in place and return it, matching ExcelJS. */
804
+ interface XlsxAccessor {
805
+ /** Serialize the workbook to `.xlsx` bytes. Async to mirror ExcelJS; wraps the sync core. */
806
+ writeBuffer(options?: WriteOptions): Promise<Uint8Array>;
807
+ /** Node-only: serialize and write to `path`. */
808
+ writeFile(path: string, options?: WriteOptions): Promise<void>;
809
+ /** Parse `.xlsx` bytes into this workbook (replaces its contents), returning it. */
810
+ load(data: Uint8Array, options?: ReadOptions): Promise<Workbook>;
811
+ /** Node-only: read and parse a `.xlsx` from `path` into this workbook, returning it. */
812
+ readFile(path: string, options?: ReadOptions): Promise<Workbook>;
813
+ /** Drain a byte stream (e.g. a Node `Readable`) and parse it into this workbook, returning it. */
814
+ read(stream: ByteStream, options?: ReadOptions): Promise<Workbook>;
815
+ }
816
+ declare module "./model/workbook.js" {
817
+ interface Workbook {
818
+ /** ExcelJS-style read/write accessor (see {@link XlsxAccessor}). */
819
+ readonly xlsx: XlsxAccessor;
820
+ }
821
+ }
822
+ /** The semantic version of the library. */
823
+ declare const version = "0.0.0";
824
+
825
+ export { type AddWorksheetOptions, type Alignment, AloshaXlsxError, type AloshaXlsxErrorCode, type Border, type BorderDiagonal, type BorderStyle, type Borders, type CalculationProperties, Cell, type CellError, type CellFormula, type CellModel, CellType, type CellValue, type Color, Column, type ColumnDefn, type ColumnRange, DEFAULT_COLUMN_WIDTH, type Decoded, type DecodedEx, DuplicateWorksheetNameError, type ErrorCode, type Fill, type FillPattern, type Font, FormulaType, type GradientStop, type Hyperlink, InvalidAddressError, InvalidCellValueError, InvalidPackageError, InvalidRangeError, InvalidRowNumberError, InvalidWorksheetNameError, type InvalidWorksheetNameReason, MergeConflictError, type Protection, Range, type RangeSource, type ReadOptions, ReservedWorksheetNameError, type RichText, type RichTextRun, Row, type RowInheritOption, type RowModel, type RowValues, type SharedStrings, type StoredValue, type Style, type Styles, UnsupportedFeatureError, Workbook, type WorkbookModel, type WorkbookProperties, type WorkbookView, Worksheet, type WorksheetHost, type WorksheetModel, WorksheetNameTooLongError, type WorksheetProperties, type WorksheetView, type WriteOptions, type XlsxAccessor, colLetterToNumber, colNumberToLetter, createSharedStrings, createStyles, dateToSerial, decodeAddress, decodeEx, detectType, effectiveType, encodeAddress, fromStored, isAloshaXlsxError, readWorkbookBuffer, readWorkbookFile, resolveCellStyle, serialToDate, toCsv, toStored, toText, validateAddress, version, writeWorkbookBuffer, writeWorkbookFile };