javascript-excel 2.0.0-alpha.1 → 2.0.0-alpha.3

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.
Files changed (71) hide show
  1. package/README.md +164 -15
  2. package/dist/address-DUn7-5OS.js +75 -0
  3. package/dist/address-DZBHchLv.cjs +122 -0
  4. package/dist/{auto-width-2oBzjeNG.d.cts → auto-width-DRHsPKNk.d.cts} +1 -1
  5. package/dist/cells-CPXU722t.cjs +33 -0
  6. package/dist/cells-CrMF8h_t.js +28 -0
  7. package/dist/colors-B8Nf_xTx.js +114 -0
  8. package/dist/colors-oBpjx97l.cjs +119 -0
  9. package/dist/csv-DyVH9y7S.cjs +647 -0
  10. package/dist/csv-pXfaputs.js +618 -0
  11. package/dist/csv.cjs +6 -622
  12. package/dist/csv.d.cts +4 -1
  13. package/dist/csv.d.ts +4 -1
  14. package/dist/csv.js +1 -618
  15. package/dist/dataset-KeMzHCGl.js +664 -0
  16. package/dist/dataset-UUZCzsi3.cjs +687 -0
  17. package/dist/dates-BXcSWf9_.js +64 -0
  18. package/dist/dates-CA1dCizp.cjs +75 -0
  19. package/dist/dom.cjs +7 -28
  20. package/dist/dom.d.cts +5 -2
  21. package/dist/dom.d.ts +4 -1
  22. package/dist/dom.js +6 -27
  23. package/dist/{numfmt-B-TlCgr7.cjs → dos-time-FZ7-1tot.cjs} +36 -199
  24. package/dist/{numfmt-DEm0sYBJ.js → dos-time-dD0z1YWU.js} +36 -181
  25. package/dist/format.cjs +1264 -0
  26. package/dist/format.d.cts +59 -0
  27. package/dist/format.d.ts +59 -0
  28. package/dist/format.js +1262 -0
  29. package/dist/import.cjs +10 -0
  30. package/dist/import.d.cts +10 -0
  31. package/dist/import.d.ts +10 -0
  32. package/dist/import.js +1 -0
  33. package/dist/index.cjs +28 -1408
  34. package/dist/index.d.cts +149 -8
  35. package/dist/index.d.ts +148 -7
  36. package/dist/index.js +11 -1395
  37. package/dist/iso-date-3TY1OlGd.cjs +57 -0
  38. package/dist/iso-date-CXnn-9mT.js +46 -0
  39. package/dist/{warnings-C_12PT4t.d.cts → model-0JikLfuM.d.cts} +1 -41
  40. package/dist/{warnings-DXJKe1lx.d.ts → model-0JikLfuM.d.ts} +1 -41
  41. package/dist/numfmt-BmEbm78Y.cjs +125 -0
  42. package/dist/numfmt-DCDrX9P1.js +114 -0
  43. package/dist/pipeline-BAJtzBdW.js +1085 -0
  44. package/dist/pipeline-Bnf7EU3X.cjs +1132 -0
  45. package/dist/pipeline-CctEa86r.d.cts +186 -0
  46. package/dist/pipeline-I8SLmV9S.d.ts +186 -0
  47. package/dist/read-CZEWV4rK.cjs +3096 -0
  48. package/dist/read-LWti17lz.js +3073 -0
  49. package/dist/read.cjs +5 -2898
  50. package/dist/read.d.cts +13 -12
  51. package/dist/read.d.ts +13 -12
  52. package/dist/read.js +1 -2895
  53. package/dist/render.cjs +751 -0
  54. package/dist/render.d.cts +215 -0
  55. package/dist/render.d.ts +215 -0
  56. package/dist/render.js +732 -0
  57. package/dist/{sheet-names-CDsVK15c.js → sheet-names-7p-joVsG.js} +4 -102
  58. package/dist/{sheet-names-Cm-IhbBk.cjs → sheet-names-B8U5RAW0.cjs} +16 -168
  59. package/dist/warnings-B1v58nCZ.d.cts +41 -0
  60. package/dist/warnings-B1v58nCZ.d.ts +41 -0
  61. package/dist/worker.cjs +244 -7
  62. package/dist/worker.d.cts +68 -5
  63. package/dist/worker.d.ts +68 -5
  64. package/dist/worker.js +243 -7
  65. package/dist/{write-CYpLGuzl.d.ts → write-DM6ieuQY.d.ts} +2 -1
  66. package/dist/write-DjgWy1PK.js +1473 -0
  67. package/dist/{write-C5JgeIar.d.cts → write-DtjfdIFm.d.cts} +2 -1
  68. package/dist/write-f9kcYf5K.cjs +1490 -0
  69. package/package.json +77 -12
  70. package/dist/iso-date-B22IvwL1.js +0 -21
  71. package/dist/iso-date-BSUsPSWO.cjs +0 -26
package/dist/index.d.cts CHANGED
@@ -4,11 +4,14 @@
4
4
  * This entry exports the workbook model types (docs/api.md §3), the error
5
5
  * classes (§7), the xlsx writer (§5.1) and the address, date and style
6
6
  * helpers (§4). Builders land in later pull requests.
7
+ *
8
+ * @module javascript-excel
7
9
  */
8
- import { A as RichTextRun, C as GradientFill, D as PatternType, E as PatternFill, F as Theme, I as Workbook, M as Sheet, N as SheetView, O as PrintSetup, P as Style, S as Font, T as NumFmt, _ as ColumnWidth, a as BlobType, b as ErrorCode, c as BorderSide, d as CellErrorValue, f as CellInput, g as ColumnProps, h as Color, i as BlobLike, j as RowProps, k as RichText, l as BorderStyle, m as CellValue, n as ExcelWarningCode, o as Alignment, p as CellType, r as BinaryInput, s as Border, t as ExcelWarning, u as Cell, v as DefinedName, w as Hyperlink, x as Fill, y as DocProperties } from "./warnings-C_12PT4t.cjs";
9
- import { a as toUint8Array, i as toBlob, n as WriteOptions, r as XLSX_MIME, t as Progress } from "./write-C5JgeIar.cjs";
10
+ import { A as Theme, C as PrintSetup, D as Sheet, E as RowProps, O as SheetView, S as PatternType, T as RichTextRun, _ as Font, a as Cell, b as NumFmt, c as CellType, d as ColumnProps, f as ColumnWidth, g as Fill, h as ErrorCode, i as BorderStyle, j as Workbook, k as Style, l as CellValue, m as DocProperties, n as Border, o as CellErrorValue, p as DefinedName, r as BorderSide, s as CellInput, t as Alignment, u as Color, v as GradientFill, w as RichText, x as PatternFill, y as Hyperlink } from "./model-0JikLfuM.cjs";
11
+ import { a as toUint8Array, i as toBlob, n as WriteOptions, r as XLSX_MIME, t as Progress } from "./write-DtjfdIFm.cjs";
12
+ import { a as BlobType, i as BlobLike, n as ExcelWarningCode, r as BinaryInput, t as ExcelWarning } from "./warnings-B1v58nCZ.cjs";
10
13
  import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.cjs";
11
- import { t as AutoWidthOptions } from "./auto-width-2oBzjeNG.cjs";
14
+ import { t as AutoWidthOptions } from "./auto-width-DRHsPKNk.cjs";
12
15
  /**
13
16
  * Typed errors (docs/api.md §7).
14
17
  *
@@ -16,7 +19,7 @@ import { t as AutoWidthOptions } from "./auto-width-2oBzjeNG.cjs";
16
19
  * app ends up with both the ESM and the CJS build, each has its own classes.
17
20
  */
18
21
  /** Every error code the library throws. */
19
- type ExcelErrorCode = "NO_SHEETS" | "INVALID_SHEET_NAME" | "DUPLICATE_SHEET_NAME" | "INVALID_ACTIVE_SHEET" | "INVALID_REF" | "OUT_OF_BOUNDS" | "INVALID_CELL" | "INVALID_NUMBER" | "INVALID_DATE" | "STRING_TOO_LONG" | "INVALID_STYLE" | "INVALID_NUMFMT" | "INVALID_HYPERLINK" | "OVERLAPPING_MERGE" | "INVALID_COLUMN" | "TOO_MANY_STYLES" | "ZIP64_REQUIRED" | "INVALID_PROPERTY" | "INVALID_SHEET_PROPERTY" | "INVALID_DEFINED_NAME" | "UNSUPPORTED_FORMAT" | "NOT_XLSX" | "ZIP_INVALID" | "ZIP_UNSUPPORTED_METHOD" | "ZIP_ENCRYPTED" | "ZIP_CRC_MISMATCH" | "XML_MALFORMED" | "XML_DTD_FORBIDDEN" | "LIMIT_EXCEEDED" | "CSV_MALFORMED" | "ENVIRONMENT_UNSUPPORTED";
22
+ type ExcelErrorCode = "NO_SHEETS" | "INVALID_SHEET_NAME" | "DUPLICATE_SHEET_NAME" | "INVALID_ACTIVE_SHEET" | "INVALID_REF" | "OUT_OF_BOUNDS" | "INVALID_CELL" | "INVALID_NUMBER" | "INVALID_DATE" | "STRING_TOO_LONG" | "INVALID_STYLE" | "INVALID_NUMFMT" | "INVALID_HYPERLINK" | "OVERLAPPING_MERGE" | "INVALID_COLUMN" | "TOO_MANY_STYLES" | "ZIP64_REQUIRED" | "INVALID_PROPERTY" | "INVALID_SHEET_PROPERTY" | "INVALID_DEFINED_NAME" | "SHEET_NOT_FOUND" | "VALIDATION_FAILED" | "UNSUPPORTED_FORMAT" | "NOT_XLSX" | "ZIP_INVALID" | "ZIP_UNSUPPORTED_METHOD" | "ZIP_ENCRYPTED" | "ZIP_CRC_MISMATCH" | "XML_MALFORMED" | "XML_DTD_FORBIDDEN" | "LIMIT_EXCEEDED" | "CSV_MALFORMED" | "ENVIRONMENT_UNSUPPORTED";
20
23
  /** Options accepted by every error constructor. */
21
24
  interface ExcelErrorOptions {
22
25
  cause?: unknown;
@@ -50,7 +53,8 @@ interface DateOptions {
50
53
  /**
51
54
  * Converts a Date to an Excel serial number.
52
55
  * Throws `INVALID_DATE` for an invalid Date or one outside the date system's
53
- * range (1900-01-01 or 1904-01-01 to 9999-12-31).
56
+ * range: 1899-12-31 (Excel's day 0, where time-only values live, as serials
57
+ * 0 to <1; serialToDate returns those) or 1904-01-01, to 9999-12-31.
54
58
  */
55
59
  export declare function dateToSerial(d: Date, options?: DateOptions): number;
56
60
  /**
@@ -70,6 +74,18 @@ export declare function serialToDate(serial: number, options?: DateOptions): Dat
70
74
  * The inputs are not modified.
71
75
  */
72
76
  export declare function mergeStyles(...styles: Array<Style | undefined>): Style;
77
+ /** Context for `resolveColor`: the workbook's `theme` and `indexedColors`. */
78
+ interface ColorContext {
79
+ theme?: Theme | undefined;
80
+ indexedColors?: readonly string[] | undefined;
81
+ }
82
+ /**
83
+ * Resolves any `Color` to ARGB ('FFRRGGBB'). Theme colours use the file's
84
+ * theme and apply the tint (ECMA-376 §18.8.19, on HSL luminance); indexed
85
+ * colours use the file's palette. Without them, the defaults are used.
86
+ * Automatic colour and anything unreadable give black.
87
+ */
88
+ export declare function resolveColor(color: Color, ctx?: ColorContext): string;
73
89
  /** Options for `cellText`. */
74
90
  interface CellTextOptions {
75
91
  /** Fields used for dates. Default 'local'. */
@@ -82,6 +98,131 @@ interface CellTextOptions {
82
98
  * Number formats are not applied.
83
99
  */
84
100
  export declare function cellText(cell: CellInput, options?: CellTextOptions): string;
101
+ /** A dataset: column definitions and rows (objects or arrays). */
102
+ interface Dataset<T> {
103
+ /** Falsy entries are skipped (conditional columns). Omitted: inferred from the keys of the first object row. */
104
+ columns?: Array<ColumnDef<T> | null | false | undefined> | undefined;
105
+ /** Objects (picked by key, path or value) or arrays (picked by index). */
106
+ data: readonly T[];
107
+ }
108
+ /** A column definition: a leaf (one sheet column) or a header group. */
109
+ type ColumnDef<T> = LeafColumn<T> | GroupColumn<T>;
110
+ /** A header group: its title spans its leaf columns (a merged header cell). */
111
+ interface GroupColumn<T> {
112
+ title: string | RichText | Cell;
113
+ headerStyle?: Style | undefined;
114
+ children: Array<ColumnDef<T> | null | false | undefined>;
115
+ }
116
+ /** What a totals cell may be: a built-in, a fixed cell, or a function of the column's data. */
117
+ type ColumnTotal = "sum" | "average" | "count" | "min" | "max" | CellInput | ((ctx: {
118
+ range: string;
119
+ values: CellValue[];
120
+ }) => CellInput);
121
+ /** A leaf column: one sheet column. */
122
+ interface LeafColumn<T> {
123
+ /** Header cell. Default: the key or path, or '' for value/index accessors. */
124
+ title?: string | RichText | Cell | undefined;
125
+ /** Own property name, taken literally ('a.b' is a key containing a dot). */
126
+ key?: string | undefined;
127
+ /** Path into nested data: 'a.b', 'items[0].name', "a['x.y']". */
128
+ path?: string | undefined;
129
+ /** Computed value. */
130
+ value?: ((row: T, ctx: {
131
+ rowIndex: number;
132
+ }) => CellInput) | undefined;
133
+ /** Array rows: index into the row. */
134
+ index?: number | undefined;
135
+ /** Coerce data cells. Default 'auto': take values as they are. */
136
+ type?: "auto" | "string" | "number" | "boolean" | "date" | "datetime" | undefined;
137
+ numFmt?: NumFmt | undefined;
138
+ /** Style of this column's data cells. */
139
+ style?: Style | undefined;
140
+ /** Merged over options.headerStyle. */
141
+ headerStyle?: Style | undefined;
142
+ width?: ColumnWidth | undefined;
143
+ hidden?: boolean | undefined;
144
+ /** Totals row entry for this column. */
145
+ total?: ColumnTotal | undefined;
146
+ }
147
+ /** Options for `fromDataset` and `fromDatasets`. */
148
+ interface DatasetOptions<T> {
149
+ /** Sheet name, default 'Sheet1'. An invalid name throws INVALID_SHEET_NAME (§12 Q19). */
150
+ name?: string | undefined;
151
+ /** Top-left cell of the block, default 'A1'. */
152
+ origin?: string | undefined;
153
+ /** Write header rows, default true. */
154
+ header?: boolean | undefined;
155
+ /** Default { font: { bold: true } }. */
156
+ headerStyle?: Style | undefined;
157
+ /** Freeze all header rows. */
158
+ freezeHeader?: boolean | undefined;
159
+ /** Autofilter from the last header row through the last data row (totals excluded). */
160
+ autoFilter?: boolean | undefined;
161
+ /** Estimate column widths from the text. Columns with their own width keep it. */
162
+ autoWidth?: boolean | AutoWidthOptions | undefined;
163
+ rightToLeft?: boolean | undefined;
164
+ /** Totals row label (in the first leaf column, if it has no total) and style. */
165
+ totals?: {
166
+ label?: string | undefined;
167
+ style?: Style | undefined;
168
+ } | undefined;
169
+ rowStyle?: ((row: T, rowIndex: number) => Style | undefined) | undefined;
170
+ /** COERCION_FAILED and NON_FINITE_NUMBER. */
171
+ onWarning?: ((w: ExcelWarning) => void) | undefined;
172
+ }
173
+ /** A block for `fromDatasets`, optionally offset from the previous one. */
174
+ type DatasetBlock<T> = Dataset<T> & {
175
+ offset?: {
176
+ rows?: number | undefined;
177
+ cols?: number | undefined;
178
+ } | undefined;
179
+ };
180
+ /** Builds a sheet from `{ columns, data }`. */
181
+ export declare function fromDataset<T>(dataset: Dataset<T>, options?: DatasetOptions<T>): Sheet;
182
+ /**
183
+ * Stacks several datasets on one sheet (replaces the old xSteps/ySteps).
184
+ * Each block starts `gap` empty rows (default 1) below the previous one, or
185
+ * `offset.rows` rows when given, and `offset.cols` columns right of the
186
+ * origin. Freeze and filter apply to the first block with header rows.
187
+ */
188
+ export declare function fromDatasets(blocks: Array<DatasetBlock<any>>, options?: DatasetOptions<any> & {
189
+ gap?: number | undefined;
190
+ }): Sheet;
191
+ /** Options for `toDataset`. */
192
+ interface ToDatasetOptions {
193
+ /** Zero-based header row, default 0; false = no header, keys are column letters. */
194
+ headerRow?: number | false | undefined;
195
+ /** Range to read, e.g. 'A1:F100'. Default: sheet.dimension, else the used range. */
196
+ range?: string | undefined;
197
+ /** 'value' (default): each field is the cell's value; 'cell': the whole Cell. */
198
+ values?: "value" | "cell" | undefined;
199
+ /**
200
+ * Drop a totals row at the end. 'auto' (default): drop the last row when it
201
+ * has at least one formula and all its formulas are SUBTOTAL(...), as
202
+ * fromDataset writes them (a label such as "Total" may sit next to them).
203
+ * true: always drop the last row. false: keep it.
204
+ */
205
+ skipTotals?: "auto" | boolean | undefined;
206
+ /** Header rows from `headerRow` on, flattened into one title per column (merged cells expanded). Default 1. */
207
+ headerRows?: number | undefined;
208
+ /** Joins the parts of a multi-row title. Default ' / '. */
209
+ join?: string | undefined;
210
+ }
211
+ /** The result of `toDataset`. Rows are null-prototype objects. */
212
+ interface DatasetResult {
213
+ columns: Array<{
214
+ title: string;
215
+ key: string;
216
+ }>;
217
+ data: Array<Record<string, unknown>>;
218
+ }
219
+ /**
220
+ * Reads a sheet back into `{ columns, data }` (import direction). Keys come
221
+ * from the header text, deduplicated with _2, _3...; an empty header gives the
222
+ * column letter. Empty rows are skipped. Rows are null-prototype objects, so
223
+ * a header named __proto__ in an untrusted file is just a key.
224
+ */
225
+ export declare function toDataset(sheet: Sheet<Cell> | Sheet, options?: ToDatasetOptions): DatasetResult;
85
226
  /**
86
227
  * Sheet-name rules (docs/api.md §3.3, §4.6).
87
228
  *
@@ -135,6 +276,6 @@ export declare function decodeCell(ref: string): CellAddress;
135
276
  export declare function encodeRange(r: RangeAddress): string;
136
277
  /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
137
278
  export declare function decodeRange(ref: string): RangeAddress;
138
- /** Package version. Kept in sync with package.json by a unit test. */
139
- export declare const VERSION = "2.0.0-alpha.1";
140
- export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColumnProps, type ColumnWidth, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type Hyperlink, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };
279
+ /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
280
+ export declare const VERSION = "2.0.0-alpha.3";
281
+ export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColorContext, type ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type GroupColumn, type Hyperlink, type LeafColumn, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type ToDatasetOptions, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };
package/dist/index.d.ts CHANGED
@@ -4,9 +4,12 @@
4
4
  * This entry exports the workbook model types (docs/api.md §3), the error
5
5
  * classes (§7), the xlsx writer (§5.1) and the address, date and style
6
6
  * helpers (§4). Builders land in later pull requests.
7
+ *
8
+ * @module javascript-excel
7
9
  */
8
- import { A as SheetView, C as PatternFill, D as RichTextRun, E as RichText, F as BlobLike, I as BlobType, M as Theme, N as Workbook, O as RowProps, P as BinaryInput, S as NumFmt, T as PrintSetup, _ as ErrorCode, a as BorderSide, b as GradientFill, c as CellErrorValue, d as CellValue, f as Color, g as DocProperties, h as DefinedName, i as Border, j as Style, k as Sheet, l as CellInput, m as ColumnWidth, n as ExcelWarningCode, o as BorderStyle, p as ColumnProps, r as Alignment, s as Cell, t as ExcelWarning, u as CellType, v as Fill, w as PatternType, x as Hyperlink, y as Font } from "./warnings-DXJKe1lx.js";
9
- import { a as toUint8Array, i as toBlob, n as WriteOptions, r as XLSX_MIME, t as Progress } from "./write-CYpLGuzl.js";
10
+ import { A as Theme, C as PrintSetup, D as Sheet, E as RowProps, O as SheetView, S as PatternType, T as RichTextRun, _ as Font, a as Cell, b as NumFmt, c as CellType, d as ColumnProps, f as ColumnWidth, g as Fill, h as ErrorCode, i as BorderStyle, j as Workbook, k as Style, l as CellValue, m as DocProperties, n as Border, o as CellErrorValue, p as DefinedName, r as BorderSide, s as CellInput, t as Alignment, u as Color, v as GradientFill, w as RichText, x as PatternFill, y as Hyperlink } from "./model-0JikLfuM.js";
11
+ import { a as toUint8Array, i as toBlob, n as WriteOptions, r as XLSX_MIME, t as Progress } from "./write-DM6ieuQY.js";
12
+ import { a as BlobType, i as BlobLike, n as ExcelWarningCode, r as BinaryInput, t as ExcelWarning } from "./warnings-B1v58nCZ.js";
10
13
  import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.js";
11
14
  import { t as AutoWidthOptions } from "./auto-width-CT-BihTW.js";
12
15
  /**
@@ -16,7 +19,7 @@ import { t as AutoWidthOptions } from "./auto-width-CT-BihTW.js";
16
19
  * app ends up with both the ESM and the CJS build, each has its own classes.
17
20
  */
18
21
  /** Every error code the library throws. */
19
- type ExcelErrorCode = "NO_SHEETS" | "INVALID_SHEET_NAME" | "DUPLICATE_SHEET_NAME" | "INVALID_ACTIVE_SHEET" | "INVALID_REF" | "OUT_OF_BOUNDS" | "INVALID_CELL" | "INVALID_NUMBER" | "INVALID_DATE" | "STRING_TOO_LONG" | "INVALID_STYLE" | "INVALID_NUMFMT" | "INVALID_HYPERLINK" | "OVERLAPPING_MERGE" | "INVALID_COLUMN" | "TOO_MANY_STYLES" | "ZIP64_REQUIRED" | "INVALID_PROPERTY" | "INVALID_SHEET_PROPERTY" | "INVALID_DEFINED_NAME" | "UNSUPPORTED_FORMAT" | "NOT_XLSX" | "ZIP_INVALID" | "ZIP_UNSUPPORTED_METHOD" | "ZIP_ENCRYPTED" | "ZIP_CRC_MISMATCH" | "XML_MALFORMED" | "XML_DTD_FORBIDDEN" | "LIMIT_EXCEEDED" | "CSV_MALFORMED" | "ENVIRONMENT_UNSUPPORTED";
22
+ type ExcelErrorCode = "NO_SHEETS" | "INVALID_SHEET_NAME" | "DUPLICATE_SHEET_NAME" | "INVALID_ACTIVE_SHEET" | "INVALID_REF" | "OUT_OF_BOUNDS" | "INVALID_CELL" | "INVALID_NUMBER" | "INVALID_DATE" | "STRING_TOO_LONG" | "INVALID_STYLE" | "INVALID_NUMFMT" | "INVALID_HYPERLINK" | "OVERLAPPING_MERGE" | "INVALID_COLUMN" | "TOO_MANY_STYLES" | "ZIP64_REQUIRED" | "INVALID_PROPERTY" | "INVALID_SHEET_PROPERTY" | "INVALID_DEFINED_NAME" | "SHEET_NOT_FOUND" | "VALIDATION_FAILED" | "UNSUPPORTED_FORMAT" | "NOT_XLSX" | "ZIP_INVALID" | "ZIP_UNSUPPORTED_METHOD" | "ZIP_ENCRYPTED" | "ZIP_CRC_MISMATCH" | "XML_MALFORMED" | "XML_DTD_FORBIDDEN" | "LIMIT_EXCEEDED" | "CSV_MALFORMED" | "ENVIRONMENT_UNSUPPORTED";
20
23
  /** Options accepted by every error constructor. */
21
24
  interface ExcelErrorOptions {
22
25
  cause?: unknown;
@@ -50,7 +53,8 @@ interface DateOptions {
50
53
  /**
51
54
  * Converts a Date to an Excel serial number.
52
55
  * Throws `INVALID_DATE` for an invalid Date or one outside the date system's
53
- * range (1900-01-01 or 1904-01-01 to 9999-12-31).
56
+ * range: 1899-12-31 (Excel's day 0, where time-only values live, as serials
57
+ * 0 to <1; serialToDate returns those) or 1904-01-01, to 9999-12-31.
54
58
  */
55
59
  export declare function dateToSerial(d: Date, options?: DateOptions): number;
56
60
  /**
@@ -70,6 +74,18 @@ export declare function serialToDate(serial: number, options?: DateOptions): Dat
70
74
  * The inputs are not modified.
71
75
  */
72
76
  export declare function mergeStyles(...styles: Array<Style | undefined>): Style;
77
+ /** Context for `resolveColor`: the workbook's `theme` and `indexedColors`. */
78
+ interface ColorContext {
79
+ theme?: Theme | undefined;
80
+ indexedColors?: readonly string[] | undefined;
81
+ }
82
+ /**
83
+ * Resolves any `Color` to ARGB ('FFRRGGBB'). Theme colours use the file's
84
+ * theme and apply the tint (ECMA-376 §18.8.19, on HSL luminance); indexed
85
+ * colours use the file's palette. Without them, the defaults are used.
86
+ * Automatic colour and anything unreadable give black.
87
+ */
88
+ export declare function resolveColor(color: Color, ctx?: ColorContext): string;
73
89
  /** Options for `cellText`. */
74
90
  interface CellTextOptions {
75
91
  /** Fields used for dates. Default 'local'. */
@@ -82,6 +98,131 @@ interface CellTextOptions {
82
98
  * Number formats are not applied.
83
99
  */
84
100
  export declare function cellText(cell: CellInput, options?: CellTextOptions): string;
101
+ /** A dataset: column definitions and rows (objects or arrays). */
102
+ interface Dataset<T> {
103
+ /** Falsy entries are skipped (conditional columns). Omitted: inferred from the keys of the first object row. */
104
+ columns?: Array<ColumnDef<T> | null | false | undefined> | undefined;
105
+ /** Objects (picked by key, path or value) or arrays (picked by index). */
106
+ data: readonly T[];
107
+ }
108
+ /** A column definition: a leaf (one sheet column) or a header group. */
109
+ type ColumnDef<T> = LeafColumn<T> | GroupColumn<T>;
110
+ /** A header group: its title spans its leaf columns (a merged header cell). */
111
+ interface GroupColumn<T> {
112
+ title: string | RichText | Cell;
113
+ headerStyle?: Style | undefined;
114
+ children: Array<ColumnDef<T> | null | false | undefined>;
115
+ }
116
+ /** What a totals cell may be: a built-in, a fixed cell, or a function of the column's data. */
117
+ type ColumnTotal = "sum" | "average" | "count" | "min" | "max" | CellInput | ((ctx: {
118
+ range: string;
119
+ values: CellValue[];
120
+ }) => CellInput);
121
+ /** A leaf column: one sheet column. */
122
+ interface LeafColumn<T> {
123
+ /** Header cell. Default: the key or path, or '' for value/index accessors. */
124
+ title?: string | RichText | Cell | undefined;
125
+ /** Own property name, taken literally ('a.b' is a key containing a dot). */
126
+ key?: string | undefined;
127
+ /** Path into nested data: 'a.b', 'items[0].name', "a['x.y']". */
128
+ path?: string | undefined;
129
+ /** Computed value. */
130
+ value?: ((row: T, ctx: {
131
+ rowIndex: number;
132
+ }) => CellInput) | undefined;
133
+ /** Array rows: index into the row. */
134
+ index?: number | undefined;
135
+ /** Coerce data cells. Default 'auto': take values as they are. */
136
+ type?: "auto" | "string" | "number" | "boolean" | "date" | "datetime" | undefined;
137
+ numFmt?: NumFmt | undefined;
138
+ /** Style of this column's data cells. */
139
+ style?: Style | undefined;
140
+ /** Merged over options.headerStyle. */
141
+ headerStyle?: Style | undefined;
142
+ width?: ColumnWidth | undefined;
143
+ hidden?: boolean | undefined;
144
+ /** Totals row entry for this column. */
145
+ total?: ColumnTotal | undefined;
146
+ }
147
+ /** Options for `fromDataset` and `fromDatasets`. */
148
+ interface DatasetOptions<T> {
149
+ /** Sheet name, default 'Sheet1'. An invalid name throws INVALID_SHEET_NAME (§12 Q19). */
150
+ name?: string | undefined;
151
+ /** Top-left cell of the block, default 'A1'. */
152
+ origin?: string | undefined;
153
+ /** Write header rows, default true. */
154
+ header?: boolean | undefined;
155
+ /** Default { font: { bold: true } }. */
156
+ headerStyle?: Style | undefined;
157
+ /** Freeze all header rows. */
158
+ freezeHeader?: boolean | undefined;
159
+ /** Autofilter from the last header row through the last data row (totals excluded). */
160
+ autoFilter?: boolean | undefined;
161
+ /** Estimate column widths from the text. Columns with their own width keep it. */
162
+ autoWidth?: boolean | AutoWidthOptions | undefined;
163
+ rightToLeft?: boolean | undefined;
164
+ /** Totals row label (in the first leaf column, if it has no total) and style. */
165
+ totals?: {
166
+ label?: string | undefined;
167
+ style?: Style | undefined;
168
+ } | undefined;
169
+ rowStyle?: ((row: T, rowIndex: number) => Style | undefined) | undefined;
170
+ /** COERCION_FAILED and NON_FINITE_NUMBER. */
171
+ onWarning?: ((w: ExcelWarning) => void) | undefined;
172
+ }
173
+ /** A block for `fromDatasets`, optionally offset from the previous one. */
174
+ type DatasetBlock<T> = Dataset<T> & {
175
+ offset?: {
176
+ rows?: number | undefined;
177
+ cols?: number | undefined;
178
+ } | undefined;
179
+ };
180
+ /** Builds a sheet from `{ columns, data }`. */
181
+ export declare function fromDataset<T>(dataset: Dataset<T>, options?: DatasetOptions<T>): Sheet;
182
+ /**
183
+ * Stacks several datasets on one sheet (replaces the old xSteps/ySteps).
184
+ * Each block starts `gap` empty rows (default 1) below the previous one, or
185
+ * `offset.rows` rows when given, and `offset.cols` columns right of the
186
+ * origin. Freeze and filter apply to the first block with header rows.
187
+ */
188
+ export declare function fromDatasets(blocks: Array<DatasetBlock<any>>, options?: DatasetOptions<any> & {
189
+ gap?: number | undefined;
190
+ }): Sheet;
191
+ /** Options for `toDataset`. */
192
+ interface ToDatasetOptions {
193
+ /** Zero-based header row, default 0; false = no header, keys are column letters. */
194
+ headerRow?: number | false | undefined;
195
+ /** Range to read, e.g. 'A1:F100'. Default: sheet.dimension, else the used range. */
196
+ range?: string | undefined;
197
+ /** 'value' (default): each field is the cell's value; 'cell': the whole Cell. */
198
+ values?: "value" | "cell" | undefined;
199
+ /**
200
+ * Drop a totals row at the end. 'auto' (default): drop the last row when it
201
+ * has at least one formula and all its formulas are SUBTOTAL(...), as
202
+ * fromDataset writes them (a label such as "Total" may sit next to them).
203
+ * true: always drop the last row. false: keep it.
204
+ */
205
+ skipTotals?: "auto" | boolean | undefined;
206
+ /** Header rows from `headerRow` on, flattened into one title per column (merged cells expanded). Default 1. */
207
+ headerRows?: number | undefined;
208
+ /** Joins the parts of a multi-row title. Default ' / '. */
209
+ join?: string | undefined;
210
+ }
211
+ /** The result of `toDataset`. Rows are null-prototype objects. */
212
+ interface DatasetResult {
213
+ columns: Array<{
214
+ title: string;
215
+ key: string;
216
+ }>;
217
+ data: Array<Record<string, unknown>>;
218
+ }
219
+ /**
220
+ * Reads a sheet back into `{ columns, data }` (import direction). Keys come
221
+ * from the header text, deduplicated with _2, _3...; an empty header gives the
222
+ * column letter. Empty rows are skipped. Rows are null-prototype objects, so
223
+ * a header named __proto__ in an untrusted file is just a key.
224
+ */
225
+ export declare function toDataset(sheet: Sheet<Cell> | Sheet, options?: ToDatasetOptions): DatasetResult;
85
226
  /**
86
227
  * Sheet-name rules (docs/api.md §3.3, §4.6).
87
228
  *
@@ -135,6 +276,6 @@ export declare function decodeCell(ref: string): CellAddress;
135
276
  export declare function encodeRange(r: RangeAddress): string;
136
277
  /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
137
278
  export declare function decodeRange(ref: string): RangeAddress;
138
- /** Package version. Kept in sync with package.json by a unit test. */
139
- export declare const VERSION = "2.0.0-alpha.1";
140
- export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColumnProps, type ColumnWidth, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type Hyperlink, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };
279
+ /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
280
+ export declare const VERSION = "2.0.0-alpha.3";
281
+ export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColorContext, type ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type GroupColumn, type Hyperlink, type LeafColumn, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type ToDatasetOptions, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };