@shbernal/ts-xlsx 1.2.0 → 2.0.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.
Files changed (161) hide show
  1. package/README.md +5 -0
  2. package/dist/core/address.d.ts +49 -2
  3. package/dist/core/address.js +31 -3
  4. package/dist/core/autofilter.d.ts +2 -2
  5. package/dist/core/cell.d.ts +17 -16
  6. package/dist/core/cell.js +3 -7
  7. package/dist/core/color-resolution.d.ts +7 -7
  8. package/dist/core/column.d.ts +8 -9
  9. package/dist/core/column.js +2 -4
  10. package/dist/core/comment-thread.d.ts +32 -23
  11. package/dist/core/comment-thread.js +4 -4
  12. package/dist/core/conditional-formatting-overlay.d.ts +1 -1
  13. package/dist/core/conditional-formatting.d.ts +3 -3
  14. package/dist/core/data-validation-overlay.d.ts +1 -1
  15. package/dist/core/data-validation.d.ts +3 -3
  16. package/dist/core/date.d.ts +3 -3
  17. package/dist/core/formula.d.ts +6 -6
  18. package/dist/core/grid-edits.js +3 -3
  19. package/dist/core/image.d.ts +37 -2
  20. package/dist/core/image.js +6 -0
  21. package/dist/core/internal.d.ts +9 -1
  22. package/dist/core/limits.d.ts +4 -4
  23. package/dist/core/merge.d.ts +6 -12
  24. package/dist/core/merge.js +0 -3
  25. package/dist/core/page-setup.d.ts +4 -4
  26. package/dist/core/pivot-table.d.ts +2 -4
  27. package/dist/core/pivot-table.js +5 -5
  28. package/dist/core/preserved.d.ts +3 -3
  29. package/dist/core/protection.d.ts +4 -4
  30. package/dist/core/range.d.ts +16 -14
  31. package/dist/core/range.js +5 -5
  32. package/dist/core/row-input.d.ts +2 -8
  33. package/dist/core/row-input.js +2 -2
  34. package/dist/core/row.d.ts +7 -8
  35. package/dist/core/row.js +2 -4
  36. package/dist/core/style.d.ts +14 -14
  37. package/dist/core/table-style.d.ts +9 -9
  38. package/dist/core/table-style.js +1 -1
  39. package/dist/core/table.d.ts +30 -42
  40. package/dist/core/table.js +16 -10
  41. package/dist/core/theme.d.ts +13 -43
  42. package/dist/core/theme.js +2 -148
  43. package/dist/core/value.d.ts +7 -7
  44. package/dist/core/workbook-protection.d.ts +2 -2
  45. package/dist/core/workbook-styles.d.ts +26 -0
  46. package/dist/core/workbook-styles.js +48 -0
  47. package/dist/core/workbook-theme.d.ts +25 -0
  48. package/dist/core/workbook-theme.js +49 -0
  49. package/dist/core/workbook-vba.d.ts +17 -0
  50. package/dist/core/workbook-vba.js +79 -0
  51. package/dist/core/workbook.d.ts +141 -83
  52. package/dist/core/workbook.js +74 -133
  53. package/dist/core/worksheet-comments.d.ts +9 -0
  54. package/dist/core/worksheet-comments.js +52 -0
  55. package/dist/core/worksheet-model.d.ts +4 -4
  56. package/dist/core/worksheet-model.js +1 -0
  57. package/dist/core/worksheet-pictures.d.ts +29 -0
  58. package/dist/core/worksheet-pictures.js +42 -0
  59. package/dist/core/worksheet.d.ts +94 -77
  60. package/dist/core/worksheet.js +36 -95
  61. package/dist/customui/errors.d.ts +1 -1
  62. package/dist/customui/ribbon.d.ts +3 -3
  63. package/dist/entries/core.d.ts +4 -4
  64. package/dist/entries/core.js +1 -1
  65. package/dist/entries/vba.d.ts +1 -1
  66. package/dist/entries/vba.js +1 -1
  67. package/dist/entries/xlsx.d.ts +1 -0
  68. package/dist/entries/xlsx.js +1 -0
  69. package/dist/errors.d.ts +12 -12
  70. package/dist/io/csv/read.js +1 -2
  71. package/dist/io/csv/write.d.ts +8 -3
  72. package/dist/io/csv/write.js +17 -2
  73. package/dist/io/opc/errors.d.ts +6 -6
  74. package/dist/io/opc/inflate.d.ts +1 -1
  75. package/dist/io/opc/namespaces.d.ts +1 -1
  76. package/dist/io/opc/read-opc.d.ts +19 -3
  77. package/dist/io/opc/read-opc.js +14 -8
  78. package/dist/io/opc/read-options.d.ts +2 -2
  79. package/dist/io/opc/sniff-format.d.ts +2 -2
  80. package/dist/io/opc/zip-mtime.d.ts +5 -0
  81. package/dist/io/opc/zip-mtime.js +1 -0
  82. package/dist/io/style/xf-style.d.ts +38 -6
  83. package/dist/io/style/xf-style.js +22 -0
  84. package/dist/io/xlsb/errors.d.ts +1 -1
  85. package/dist/io/xlsb/formula.d.ts +4 -4
  86. package/dist/io/xlsb/primitives.d.ts +8 -8
  87. package/dist/io/xlsb/ptg-functions.d.ts +1 -1
  88. package/dist/io/xlsb/read-styles.js +2 -20
  89. package/dist/io/xlsb/read.d.ts +2 -2
  90. package/dist/io/xlsx/cell-accumulator.d.ts +25 -6
  91. package/dist/io/xlsx/cell-accumulator.js +111 -30
  92. package/dist/io/xlsx/cell-value.d.ts +2 -2
  93. package/dist/io/xlsx/cell-value.js +3 -3
  94. package/dist/io/xlsx/color-xml.js +11 -17
  95. package/dist/io/xlsx/comments.d.ts +5 -5
  96. package/dist/io/xlsx/comments.js +13 -6
  97. package/dist/io/xlsx/conditional-formatting.d.ts +3 -3
  98. package/dist/io/xlsx/conditional-formatting.js +7 -16
  99. package/dist/io/xlsx/data-validation.d.ts +2 -2
  100. package/dist/io/xlsx/data-validation.js +1 -1
  101. package/dist/io/xlsx/edit-vba.js +2 -1
  102. package/dist/io/xlsx/errors.d.ts +3 -3
  103. package/dist/io/xlsx/hyperlinks.d.ts +4 -2
  104. package/dist/io/xlsx/hyperlinks.js +5 -5
  105. package/dist/io/xlsx/images.d.ts +1 -1
  106. package/dist/io/xlsx/images.js +8 -8
  107. package/dist/io/xlsx/namespaces.d.ts +2 -2
  108. package/dist/io/xlsx/package-plan.js +5 -2
  109. package/dist/io/xlsx/read-pivot.js +2 -5
  110. package/dist/io/xlsx/read-rows.d.ts +13 -13
  111. package/dist/io/xlsx/read-rows.js +19 -55
  112. package/dist/io/xlsx/read-shared-strings.js +7 -5
  113. package/dist/io/xlsx/read-styles.d.ts +3 -3
  114. package/dist/io/xlsx/read-styles.js +40 -65
  115. package/dist/io/xlsx/read-worksheet.js +67 -115
  116. package/dist/io/xlsx/read.d.ts +3 -5
  117. package/dist/io/xlsx/read.js +94 -71
  118. package/dist/io/xlsx/rich-runs.d.ts +1 -1
  119. package/dist/io/xlsx/rich-runs.js +1 -1
  120. package/dist/io/xlsx/rich-text.d.ts +1 -1
  121. package/dist/io/xlsx/shared-strings.d.ts +2 -2
  122. package/dist/io/xlsx/sheet-properties.js +5 -4
  123. package/dist/io/xlsx/styles.d.ts +8 -9
  124. package/dist/io/xlsx/styles.js +4 -3
  125. package/dist/io/xlsx/tables.d.ts +2 -2
  126. package/dist/io/xlsx/tables.js +8 -13
  127. package/dist/io/xlsx/theme-xml.d.ts +37 -0
  128. package/dist/io/xlsx/theme-xml.js +142 -0
  129. package/dist/io/xlsx/threaded-comments.d.ts +18 -27
  130. package/dist/io/xlsx/threaded-comments.js +9 -21
  131. package/dist/io/xlsx/workbook-xml.d.ts +1 -1
  132. package/dist/io/xlsx/workbook-xml.js +6 -2
  133. package/dist/io/xlsx/worksheet-xml.d.ts +2 -2
  134. package/dist/io/xlsx/worksheet-xml.js +7 -12
  135. package/dist/io/xlsx/write-stream.d.ts +15 -15
  136. package/dist/io/xlsx/write-stream.js +5 -3
  137. package/dist/io/xlsx/write.d.ts +12 -7
  138. package/dist/io/xlsx/write.js +10 -6
  139. package/dist/io/xlsx/x14-ext.d.ts +1 -1
  140. package/dist/vba/bytes.d.ts +12 -0
  141. package/dist/vba/bytes.js +40 -0
  142. package/dist/vba/cfb-writer.d.ts +1 -1
  143. package/dist/vba/cfb.d.ts +1 -1
  144. package/dist/vba/cfb.js +15 -51
  145. package/dist/vba/codepage.d.ts +2 -2
  146. package/dist/vba/errors.d.ts +2 -2
  147. package/dist/vba/index.d.ts +2 -2
  148. package/dist/vba/index.js +2 -2
  149. package/dist/vba/ms-ovba.d.ts +1 -1
  150. package/dist/vba/ms-ovba.js +1 -3
  151. package/dist/vba/project-editor.d.ts +9 -9
  152. package/dist/vba/project-editor.js +2 -11
  153. package/dist/vba/project.d.ts +5 -5
  154. package/dist/vba/project.js +1 -10
  155. package/dist/vba/vba-encoding.d.ts +1 -1
  156. package/dist/xml/errors.d.ts +1 -1
  157. package/dist/xml/xml-read.d.ts +38 -9
  158. package/dist/xml/xml-read.js +23 -0
  159. package/dist/xml/xml.d.ts +31 -9
  160. package/dist/xml/xml.js +23 -3
  161. package/package.json +41 -35
@@ -24,7 +24,7 @@ export type FillPatternType = 'none' | 'solid' | 'gray125' | 'darkGray' | 'mediu
24
24
  export declare function isFillPatternType(value: string): value is FillPatternType;
25
25
  /**
26
26
  * A pattern fill. For a `solid` fill the visible colour is the pattern *foreground*
27
- * (`fgColor`) OOXML's counter-intuitive rule while `bgColor` is the automatic
27
+ * (`fgColor`), OOXML's counter-intuitive rule, while `bgColor` is the automatic
28
28
  * indexed placeholder.
29
29
  */
30
30
  export interface PatternFill {
@@ -89,13 +89,13 @@ export interface Border {
89
89
  export type FontVerticalAlignment = 'superscript' | 'subscript';
90
90
  /** Narrow a raw `<vertAlign val>` token to a known {@link FontVerticalAlignment}. */
91
91
  export declare function isFontVerticalAlignment(value: string): value is FontVerticalAlignment;
92
- /** The theme-font role a `<scheme val>` names `"minor"`/`"major"` bind the font to whichever
92
+ /** The theme-font role a `<scheme val>` names: `"minor"`/`"major"` bind the font to whichever
93
93
  * face the workbook theme assigns that role, `"none"` leaves it a literal, unbound face. */
94
94
  export type FontScheme = 'minor' | 'major' | 'none';
95
95
  /** Narrow a raw `<scheme val>` token to a known {@link FontScheme}. */
96
96
  export declare function isFontScheme(value: string): value is FontScheme;
97
97
  /** A font, as it applies to a cell or a single rich-text run. Every facet is optional and
98
- * independent, like {@link Border}/{@link Alignment}/{@link Protection} a font sets only the
98
+ * independent, like {@link Border}/{@link Alignment}/{@link Protection}: a font sets only the
99
99
  * facets it overrides (Excel's own default font backs the rest), so no consumer ever holds every
100
100
  * field populated at once. */
101
101
  export interface Font {
@@ -125,7 +125,7 @@ export type VerticalAlignment = 'top' | 'center' | 'bottom' | 'justify' | 'distr
125
125
  export declare function isVerticalAlignment(value: string): value is VerticalAlignment;
126
126
  /**
127
127
  * A cell's alignment. Every facet is optional and independent; an absent facet means the cell
128
- * takes Excel's default for it. The boolean flags default to off a cell that never enabled
128
+ * takes Excel's default for it. The boolean flags default to off, so a cell that never enabled
129
129
  * `wrapText`/`shrinkToFit` must never read back with them on. `textRotation` is in degrees
130
130
  * (0–180, where 91–180 encodes -1° to -90°); `indent` is a non-negative indent level.
131
131
  */
@@ -139,7 +139,7 @@ export interface Alignment {
139
139
  readonly readingOrder?: number;
140
140
  }
141
141
  /**
142
- * A cell's protection state, enforced only when the worksheet itself is protected the flags
142
+ * A cell's protection state, enforced only when the worksheet itself is protected. The flags
143
143
  * do nothing on an unprotected sheet. `locked` defaults to TRUE in OOXML (every cell is locked
144
144
  * unless told otherwise), so the meaningful, information-carrying state is an explicitly
145
145
  * *unlocked* cell (`locked: false`); marking a cell locked merely restates the default and
@@ -151,14 +151,14 @@ export interface Protection {
151
151
  readonly hidden?: boolean;
152
152
  }
153
153
  /**
154
- * The six direct-format facets a cell can carry its fill, number format, font, border, alignment,
154
+ * The six direct-format facets a cell can carry: its fill, number format, font, border, alignment,
155
155
  * and protection. Every facet is optional and independent: a cell sets only the facets it overrides
156
156
  * and inherits the rest. This one tuple is the unit of style throughout the library, so the
157
- * interfaces that carry a cell's formatting compose it rather than re-listing the fields a column,
157
+ * interfaces that carry a cell's formatting compose it rather than re-listing the fields: a column,
158
158
  * table column, or named style whose facets *default* the cells that leave them unset (see
159
159
  * {@link ColumnProperties}, {@link NamedCellStyle}), and a cell's own resolved format. Because they
160
160
  * share this type, "add a facet" is a single edit here and the compiler enforces that no read/write
161
- * path silently drops one the round-trip symmetry the merge-loss contract depends on.
161
+ * path silently drops one, the round-trip symmetry the merge-loss contract depends on.
162
162
  */
163
163
  export interface CellStyle {
164
164
  fill?: Fill | undefined;
@@ -171,15 +171,15 @@ export interface CellStyle {
171
171
  /** The names of the {@link CellStyle} facets, for helpers that copy the tuple facet-by-facet. */
172
172
  export declare const CELL_STYLE_FACETS: (keyof CellStyle)[];
173
173
  /**
174
- * Copy each present facet of `source` onto `target`, leaving facets `source` omits untouched the
174
+ * Copy each present facet of `source` onto `target`, leaving facets `source` omits untouched: the
175
175
  * plain-record counterpart to a cell's `applyCellStyle`, for the {@link CellStyle}-shaped targets a
176
176
  * `Cell`'s setters don't reach (a column's cell-defaults, a named style being assembled on read).
177
177
  * Driven by {@link CELL_STYLE_FACETS}, so a facet added to the tuple reaches these paths the moment
178
- * it joins the same single-point-of-change the cell path gets.
178
+ * it joins, the same single-point-of-change the cell path gets.
179
179
  */
180
180
  export declare function assignStyleFacets(target: CellStyle, source: Readonly<CellStyle>): void;
181
181
  /**
182
- * A named cell style the OOXML `cellStyleXfs`/`cellStyles` layer. A spreadsheet applies a built-in
182
+ * A named cell style: the OOXML `cellStyleXfs`/`cellStyles` layer. A spreadsheet applies a built-in
183
183
  * or custom style (e.g. "Normal", "Accent1") whose visual facets live in this shared, named layer
184
184
  * rather than on each cell's direct format; a cell links to it and inherits any facet the direct
185
185
  * format leaves unset. The facets are a cell's own (see {@link CellStyle}); `name` is the style's
@@ -192,7 +192,7 @@ export type NamedCellStyle = Readonly<CellStyle> & {
192
192
  /**
193
193
  * A differential style (OOXML CT_Dxf): formatting laid *over* whatever a cell already carries. Only
194
194
  * the facets present override; the rest of the cell's own style shows through. It carries the subset
195
- * of the cell-style facets (see {@link CellStyle}) a `<dxf>` can express font, number format, fill,
195
+ * of the cell-style facets (see {@link CellStyle}) a `<dxf>` can express: font, number format, fill,
196
196
  * and border.
197
197
  *
198
198
  * Differential styles live in one workbook-level table (`<dxfs>`) that several features index into:
@@ -214,7 +214,7 @@ export type DifferentialStyle = Pick<CellStyle, 'font' | 'numFmt' | 'fill' | 'bo
214
214
  * Each entry of {@link styles} is one `<tableStyle>…</tableStyle>` fragment kept verbatim, for the
215
215
  * same reason a `<dxf>` is: a `tableStyleElement`'s `dxfId` indexes the differential-style table,
216
216
  * which the writer re-emits **at its original indices**, so the references stay valid without
217
- * reparsing anything. That index-stability is load-bearing renumbering the dxf table would
217
+ * reparsing anything. That index-stability is load-bearing: renumbering the dxf table would
218
218
  * silently re-point every preserved table style at a different format.
219
219
  *
220
220
  * The two default names are ordinary strings, not fragments: they are re-escaped on write, so they
@@ -230,7 +230,7 @@ export interface TableStyleTable {
230
230
  *
231
231
  * Carrying a fragment verbatim carries its *prefixes* too. Excel stamps a revision id
232
232
  * (`xr9:uid="{…}"`) on every `<tableStyle>` it writes, so a fragment re-emitted under a
233
- * `<styleSheet>` that declares only the default namespace is not namespace-well-formed no
233
+ * `<styleSheet>` that declares only the default namespace is not namespace-well-formed, and no
234
234
  * consumer can parse the part at all, which is a far louder failure than the dropped table style
235
235
  * this preservation exists to prevent. The writer re-declares each prefix on `<styleSheet>` and
236
236
  * re-states the ignorable ones, exactly as the source did.
@@ -4,19 +4,19 @@ import type { DifferentialStyle } from './style.ts';
4
4
  *
5
5
  * The first thirteen apply to a **table**; the rest style a **pivot table**, which has regions a
6
6
  * table does not have (subtotal rows, page-field labels, subheadings). Both live in the same
7
- * enumeration and the same `<tableStyle>` element what decides which regions a consumer honours is
8
- * the style's own `table`/`pivot` flags, not the element names so the type carries all of them
7
+ * enumeration and the same `<tableStyle>` element. What decides which regions a consumer honours is
8
+ * the style's own `table`/`pivot` flags, not the element names, so the type carries all of them
9
9
  * rather than splitting into two enumerations that a caller would have to choose between up front.
10
10
  */
11
11
  export declare const TABLE_STYLE_ELEMENT_TYPES: readonly ['wholeTable', 'headerRow', 'totalRow', 'firstColumn', 'lastColumn', 'firstRowStripe', 'secondRowStripe', 'firstColumnStripe', 'secondColumnStripe', 'firstHeaderCell', 'lastHeaderCell', 'firstTotalCell', 'lastTotalCell', 'firstSubtotalColumn', 'secondSubtotalColumn', 'thirdSubtotalColumn', 'firstSubtotalRow', 'secondSubtotalRow', 'thirdSubtotalRow', 'blankRow', 'firstColumnSubheading', 'secondColumnSubheading', 'thirdColumnSubheading', 'firstRowSubheading', 'secondRowSubheading', 'thirdRowSubheading', 'pageFieldLabels', 'pageFieldValues'];
12
12
  /** One region of a table or pivot that a table style can format. */
13
13
  export type TableStyleElementType = (typeof TABLE_STYLE_ELEMENT_TYPES)[number];
14
- /** The four element types banded across several rows or columns the only ones {@link TableStyleElement.size} means anything on. */
14
+ /** The four element types banded across several rows or columns: the only ones {@link TableStyleElement.size} means anything on. */
15
15
  export declare const STRIPE_ELEMENT_TYPES: ReadonlySet<TableStyleElementType>;
16
16
  export declare function isTableStyleElementType(value: string): value is TableStyleElementType;
17
17
  /**
18
18
  * How one region of a table is formatted: a {@link DifferentialStyle} laid over whatever the cells
19
- * already carry, plus for a stripe how many rows or columns wide one band is.
19
+ * already carry, plus, for a stripe, how many rows or columns wide one band is.
20
20
  *
21
21
  * A `numFmt` here is carried faithfully but has no visible effect: Excel's own table-style element
22
22
  * exposes a font, an interior and borders, and nothing for a number format. See
@@ -24,7 +24,7 @@ export declare function isTableStyleElementType(value: string): value is TableSt
24
24
  */
25
25
  export interface TableStyleElement extends DifferentialStyle {
26
26
  /**
27
- * The band width, in rows or columns, for a striped element `2` makes each band two rows deep.
27
+ * The band width, in rows or columns, for a striped element: `2` makes each band two rows deep.
28
28
  * Defaults to 1.
29
29
  *
30
30
  * Meaningful **only** on the four stripe types ({@link STRIPE_ELEMENT_TYPES}); ECMA-376 says so and
@@ -41,7 +41,7 @@ export interface TableStyleElement extends DifferentialStyle {
41
41
  * Elements are applied in the order ECMA-376 fixes, not the order they are written here: whole table,
42
42
  * then the column stripes, then the row stripes, then last/first column, header row, total row, and
43
43
  * the four corner cells. So a row stripe wins over a column stripe, and both win over the whole-table
44
- * formatting worth knowing when a stripe colour appears not to take.
44
+ * formatting, which is worth knowing when a stripe colour appears not to take.
45
45
  */
46
46
  export interface TableStyle {
47
47
  /** The name a table references, and the name Excel shows in its style gallery. */
@@ -58,10 +58,10 @@ export interface TableStyle {
58
58
  *
59
59
  * Both failures here are of the same kind: Excel accepts the file and quietly does nothing with the
60
60
  * part the caller cared about. An empty name means no table can ever reference the style, and a
61
- * `size` outside a stripe is ignored neither shows up as a repair prompt or a schema error, so the
61
+ * `size` outside a stripe is ignored. Neither shows up as a repair prompt or a schema error, so the
62
62
  * only place to catch them is the call that made them.
63
63
  *
64
- * @throws {AuthoringError} if the name is empty, or a non-stripe element carries a `size`, or a `size` is not
65
- * a positive integer.
64
+ * @throws {AuthoringError} if the name is empty, or a non-stripe element carries a `size`.
65
+ * @throws {RangeError} if a `size` is not a positive integer.
66
66
  */
67
67
  export declare function checkTableStyle(style: TableStyle): void;
@@ -56,7 +56,7 @@ export function checkTableStyle(style) {
56
56
  `${[...STRIPE_ELEMENT_TYPES].join(', ')}`);
57
57
  }
58
58
  if (!Number.isInteger(size) || size < 1) {
59
- throw new AuthoringError(`Invalid table style band size ${size}: expected a positive integer`);
59
+ throw new RangeError(`Invalid table style band size ${size}: expected a positive integer`);
60
60
  }
61
61
  }
62
62
  }
@@ -1,36 +1,37 @@
1
+ import { type GridRect } from './address.ts';
1
2
  import type { CellStyle } from './style.ts';
2
3
  import type { CellValue } from './value.ts';
3
- /** A per-column cell format applied to a table's body cells the facets Excel's table-column style
4
+ /** A per-column cell format applied to a table's body cells: the facets Excel's table-column style
4
5
  * bakes into the cells rather than storing as table metadata. Every facet ({@link CellStyle}) is
5
6
  * optional; only the ones set are applied, leaving the rest of each cell's style untouched. */
6
7
  export type TableColumnStyle = Readonly<CellStyle>;
7
8
  /** Writes a value into the owning worksheet's grid at a 1-based row/column, applying the column's
8
- * style (if any) to the cell the hook a {@link Table} uses to materialise the cells of a row
9
+ * style (if any) to the cell: the hook a {@link Table} uses to materialise the cells of a row
9
10
  * appended through {@link Table.addRow}. A worksheet supplies it when it registers the table; a table
10
11
  * built standalone has none and cannot write cell values. */
11
12
  export type TableCellWriter = (row: number, col: number, value: CellValue, style?: TableColumnStyle) => void;
12
13
  /** Inserts one empty row into the owning worksheet's grid at a 1-based `row`, shifting that row and
13
- * everything below it down by one the hook a {@link Table} with a totals row uses to open a slot
14
+ * everything below it down by one: the hook a {@link Table} with a totals row uses to open a slot
14
15
  * for an appended data row above the totals. Relocating the totals row lives in the grid, so a
15
16
  * standalone table has no inserter and cannot append past a totals row. */
16
17
  export type TableRowInserter = (row: number) => void;
17
18
  /**
18
19
  * A table's visual style (`<tableStyleInfo>`): the named style to apply plus the banding/highlight
19
- * toggles. Every field is a tri-state so a round-trip stays faithful a value present in the source
20
+ * toggles. Every field is a tri-state so a round-trip stays faithful: a value present in the source
20
21
  * re-emits, one the source omitted stays omitted rather than being defaulted to `"0"`. A workbook
21
22
  * whose part carries no `<tableStyleInfo>` at all leaves {@link TableOptions.style} undefined.
22
23
  */
23
24
  export interface TableStyleInfo {
24
25
  /**
25
- * Named table style to apply one of the built-in gallery (`"TableStyleMedium2"`, …) or a custom
26
+ * Named table style to apply: one of the built-in gallery (`"TableStyleMedium2"`, …) or a custom
26
27
  * one the workbook defines with {@link Workbook.addTableStyle}.
27
28
  *
28
- * **Not validated.** A name that matches nothing renders the table unstyled, silently but this
29
- * library must not be the thing that rejects it. A reader has to accept a name from a newer Excel
30
- * than the gallery list it was built with, and a writer that threw would make round-tripping such a
31
- * file impossible; there is also no diagnostics channel to warn through, so the only options were
32
- * "throw" and "accept". Accepting is the one that never makes a readable file unreadable. If a
33
- * warning channel is ever added, this is the first thing that should use it.
29
+ * **Not validated.** A name that matches nothing renders the table unstyled, silently. Even so,
30
+ * this library must not be the thing that rejects it. A reader has to accept a name from a newer
31
+ * Excel than the gallery list it was built with, and a writer that threw would make round-tripping
32
+ * such a file impossible; there is also no diagnostics channel to warn through, so the only
33
+ * options were "throw" and "accept". Accepting is the one that never makes a readable file
34
+ * unreadable. If a warning channel is ever added, this is the first thing that should use it.
34
35
  */
35
36
  readonly name?: string;
36
37
  /** Emphasise the first column. */
@@ -44,17 +45,17 @@ export interface TableStyleInfo {
44
45
  }
45
46
  /**
46
47
  * OOXML's totals-row function names (`ST_TotalsRowFunction`) to the `SUBTOTAL` first-argument code
47
- * Excel writes into a materialised totals cell. The `10x` band ignores manually hidden rows the
48
+ * Excel writes into a materialised totals cell. The `10x` band ignores manually hidden rows, the
48
49
  * behaviour Excel's totals row uses. The one inversion trap: `count` is COUNTA (103, non-empty) while
49
50
  * `countNums` is COUNT (102, numbers only). `none` (no aggregate) has no built-in code, so a column
50
- * carrying it is absent here and its totals cell is left unmaterialised Excel accepts the blank
51
+ * carrying it is absent here and its totals cell is left unmaterialised: Excel accepts the blank
51
52
  * cell. `custom` is likewise absent: its aggregate is not a `SUBTOTAL` but the arbitrary formula
52
53
  * stored in {@link TableColumn.totalsRowFormula}, which the reader/writer round-trip and the
53
54
  * materialiser writes into the cell verbatim.
54
55
  */
55
56
  export declare const TOTALS_ROW_SUBTOTAL_CODE: Readonly<Partial<Record<TotalsRowFunction, number>>>;
56
57
  /**
57
- * The values `ST_TotalsRowFunction` (ECMA-376 §18.18.86) can take a closed OOXML enumeration Excel
58
+ * The values `ST_TotalsRowFunction` (ECMA-376 §18.18.86) can take: a closed OOXML enumeration Excel
58
59
  * does not extend over time (unlike, say, a conditional-formatting rule type), so an author-side typo
59
60
  * such as `"avg"` is a compile error here rather than a silently no-op attribute at write time.
60
61
  */
@@ -63,7 +64,7 @@ export type TotalsRowFunction = 'average' | 'countNums' | 'count' | 'max' | 'min
63
64
  export declare function isTotalsRowFunction(value: string): value is TotalsRowFunction;
64
65
  /** One column of a table: a header name and its optional totals-row behaviour. */
65
66
  export interface TableColumn {
66
- /** The column's header/display name. Must be unique within the table (case-insensitively)
67
+ /** The column's header/display name. Must be unique within the table (case-insensitively):
67
68
  * Excel writes a table with colliding column names as corrupt. A collision supplied at construction
68
69
  * is disambiguated deterministically (the first keeps its name, later clashes gain a numeric
69
70
  * suffix), the same repair the reader applies to a loaded file, rather than being rejected. */
@@ -73,7 +74,7 @@ export interface TableColumn {
73
74
  /** Built-in totals-row aggregate (`"sum"`, `"average"`, `"count"`, …), or `"custom"` when the
74
75
  * column's total is the arbitrary formula in {@link totalsRowFormula} rather than a `SUBTOTAL`. */
75
76
  readonly totalsRowFunction?: TotalsRowFunction;
76
- /** The formula (no leading `=`) backing a `totalsRowFunction: "custom"` column OOXML's
77
+ /** The formula (no leading `=`) backing a `totalsRowFunction: "custom"` column. This is OOXML's
77
78
  * `<totalsRowFormula>` child. Round-tripped verbatim and written into the totals cell as the
78
79
  * cell's formula. Meaningful only alongside `totalsRowFunction: "custom"`; ignored otherwise. */
79
80
  readonly totalsRowFormula?: string;
@@ -83,13 +84,13 @@ export interface TableColumn {
83
84
  readonly style?: TableColumnStyle;
84
85
  }
85
86
  export interface TableOptions {
86
- /** Table name a valid Excel identifier, unique across the workbook. This is the name used in
87
+ /** Table name: a valid Excel identifier, unique across the workbook. This is the name used in
87
88
  * structured formula references (`Table1[Column]`). */
88
89
  name: string;
89
90
  /** Human-facing display name shown in the UI. A free-form label (spaces allowed) that need not
90
91
  * be a valid identifier. Defaults to {@link name} when omitted. */
91
92
  displayName?: string;
92
- /** A1 reference of the table's top-left cell (an anchor, e.g. `"A1"` not the full range). */
93
+ /** A1 reference of the table's top-left cell (an anchor, e.g. `"A1"`, not the full range). */
93
94
  ref: string;
94
95
  /** The table's columns, left to right. At least one is required. */
95
96
  columns: readonly TableColumn[];
@@ -99,36 +100,23 @@ export interface TableOptions {
99
100
  headerRow?: boolean;
100
101
  /** Whether the table has a totals row. Defaults to `false`. */
101
102
  totalsRow?: boolean;
102
- /** The `totalsRowShown` flag on a table *without* a totals row Excel's record of whether a
103
+ /** The `totalsRowShown` flag on a table *without* a totals row: Excel's record of whether a
103
104
  * totals row has ever been toggled on. Tri-state so a round-trip is faithful: `false` re-emits
104
105
  * `totalsRowShown="0"`, `true` re-emits `totalsRowShown="1"`, and `undefined` (the authoring
105
- * default) emits nothing a file read without the attribute must not have one injected. Ignored
106
+ * default) emits nothing: a file read without the attribute must not have one injected. Ignored
106
107
  * when {@link totalsRow} is set, since a present totals row already implies it is shown. */
107
108
  totalsRowShown?: boolean;
108
109
  /** Whether the header row carries an autoFilter. Defaults to {@link headerRow}: a header table
109
110
  * gains an autoFilter, a headerless one never can. Set `false` to keep a header table's rows
110
- * unfiltered a file read without an autoFilter must round-trip without one being injected. */
111
+ * unfiltered: a file read without an autoFilter must round-trip without one being injected. */
111
112
  autoFilter?: boolean;
112
113
  /** The table's visual style. Preserved verbatim across a round-trip; when omitted, a freshly
113
114
  * authored table is written with Excel's default (`TableStyleMedium2`, banded rows). A part read
114
115
  * with no `<tableStyleInfo>` sets this to `undefined`. See {@link TableStyleInfo}. */
115
116
  style?: TableStyleInfo;
116
117
  }
117
- /**
118
- * Return copies of `columns` with every name made unique (case-insensitively): the first occurrence
119
- * keeps its name; a later clash gains the smallest numeric suffix that resolves it (`foo`, `foo2`,
120
- * `foo3`, …). OOXML requires unique column names within a table — Excel treats a collision as
121
- * corruption — so this is applied both when a table is authored and when one is read from a file,
122
- * keeping the two paths identical rather than rejecting a name list the reader would accept.
123
- */
124
- export declare function disambiguateColumnNames(columns: readonly TableColumn[]): TableColumn[];
125
- /** The rectangle a table occupies, in 1-based coordinates. */
126
- export interface TableRegion {
127
- readonly top: number;
128
- readonly left: number;
129
- readonly bottom: number;
130
- readonly right: number;
131
- }
118
+ /** The rectangle a table occupies, as the {@link GridRect} every range-shaped thing in the library is. */
119
+ export type TableRegion = GridRect;
132
120
  export declare class Table {
133
121
  #private;
134
122
  readonly name: string;
@@ -141,7 +129,7 @@ export declare class Table {
141
129
  readonly style: TableStyleInfo | undefined;
142
130
  constructor(options: TableOptions, writeCell?: TableCellWriter, insertRow?: TableRowInserter);
143
131
  get columnCount(): number;
144
- /** The number of data rows (excludes the header and totals rows). Always defined a table loaded
132
+ /** The number of data rows (excludes the header and totals rows). Always defined: a table loaded
145
133
  * from a file derives it from the stored range, so reading the height never throws. */
146
134
  get rowCount(): number;
147
135
  /**
@@ -150,9 +138,9 @@ export declare class Table {
150
138
  * one, so this works identically whether the table was built in memory or read from a file.
151
139
  *
152
140
  * A table carrying a totals row appends above it: the new data row lands where the totals row sat,
153
- * and the totals row (with any sheet content below) shifts down by one exactly what inserting a
141
+ * and the totals row (with any sheet content below) shifts down by one, exactly what inserting a
154
142
  * worksheet row does. That relocation lives in the grid, so a totals-row table not attached to a
155
- * worksheet throws, as does passing `values` on any detached table there is nowhere to put them.
143
+ * worksheet throws, as does passing `values` on any detached table: there is nowhere to put them.
156
144
  */
157
145
  addRow(values?: readonly CellValue[]): void;
158
146
  /**
@@ -171,7 +159,7 @@ export declare class Table {
171
159
  */
172
160
  shiftColumns(start: number, count: number, delta: number): boolean;
173
161
  /**
174
- * The options that reconstruct this table the anchor as a single-cell ref (not the derived
162
+ * The options that reconstruct this table: the anchor as a single-cell ref (not the derived
175
163
  * full range), the columns, and the data-row count with the header/totals flags. Feeding this
176
164
  * back to the constructor yields an equivalent table, so a worksheet model can carry a table
177
165
  * losslessly across an export/import round-trip.
@@ -179,11 +167,11 @@ export declare class Table {
179
167
  get options(): TableOptions;
180
168
  /** The full A1 range the table occupies: header (if any) + data rows + totals (if any). Distinct
181
169
  * from {@link TableOptions.ref} (and {@link options}'s own `ref`), which is only the single-cell
182
- * anchor a table is constructed from this is the anchor plus the columns/rows it has grown to
170
+ * anchor a table is constructed from; this is the anchor plus the columns/rows it has grown to
183
171
  * cover. */
184
172
  get range(): string;
185
173
  /**
186
- * The autoFilter range the header row plus the data rows, never the totals row or
174
+ * The autoFilter range (the header row plus the data rows, never the totals row), or
187
175
  * `undefined` when the table has no autoFilter: either it is headerless (an autoFilter has
188
176
  * nothing to anchor to and Excel treats its presence as corruption) or its {@link autoFilter}
189
177
  * flag is off (a table read without one must not gain one on round-trip).
@@ -1,5 +1,5 @@
1
1
  import { AuthoringError } from '../errors.js';
2
- import { decodeAddress, encodeAddress } from './address.js';
2
+ import { decodeCellRef, encodeAddress } from './address.js';
3
3
  function cloneStyleInfo(style) {
4
4
  const clone = {};
5
5
  if (style.name !== undefined && style.name !== 'None')
@@ -40,7 +40,7 @@ export function isTotalsRowFunction(value) {
40
40
  return TOTALS_ROW_FUNCTIONS.has(value);
41
41
  }
42
42
  const IDENTIFIER = /^[\p{L}\\_][\p{L}\p{N}._]*$/u;
43
- export function disambiguateColumnNames(columns) {
43
+ function disambiguateColumnNames(columns) {
44
44
  const seen = new Set();
45
45
  return columns.map((column) => {
46
46
  let candidate = column.name;
@@ -52,10 +52,10 @@ export function disambiguateColumnNames(columns) {
52
52
  }
53
53
  function validateTableName(name) {
54
54
  if (name.length === 0 || name.length > 255) {
55
- throw new AuthoringError(`table name ${JSON.stringify(name)} must be between 1 and 255 characters`);
55
+ throw new RangeError(`table name ${JSON.stringify(name)} must be between 1 and 255 characters`);
56
56
  }
57
57
  if (!IDENTIFIER.test(name)) {
58
- throw new AuthoringError(`table name ${JSON.stringify(name)} is not a valid Excel identifier it must start with a letter, ` +
58
+ throw new SyntaxError(`table name ${JSON.stringify(name)} is not a valid Excel identifier: it must start with a letter, ` +
59
59
  'underscore, or backslash and contain only letters, digits, periods, and underscores');
60
60
  }
61
61
  }
@@ -81,10 +81,16 @@ export class Table {
81
81
  if (!Number.isInteger(options.rowCount) || options.rowCount < 0) {
82
82
  throw new RangeError(`table "${options.name}" has an invalid data-row count (${options.rowCount})`);
83
83
  }
84
- const { col, row } = decodeAddress(options.ref);
85
- if (col === undefined || row === undefined) {
86
- throw new SyntaxError(`table ref "${options.ref}" must anchor at a single cell (e.g. "A1")`);
84
+ let anchor;
85
+ try {
86
+ anchor = decodeCellRef(options.ref);
87
87
  }
88
+ catch (cause) {
89
+ throw new SyntaxError(`table ref "${options.ref}" must anchor at a single cell (e.g. "A1")`, {
90
+ cause,
91
+ });
92
+ }
93
+ const { col, row } = anchor;
88
94
  this.name = options.name;
89
95
  this.displayName = options.displayName ?? options.name;
90
96
  this.columns = disambiguateColumnNames(options.columns);
@@ -99,7 +105,7 @@ export class Table {
99
105
  this.#writeCell = writeCell;
100
106
  this.#insertRow = insertRow;
101
107
  if (this.#rowSpan < 1) {
102
- throw new AuthoringError(`table "${this.name}" has no rows it needs a header row or at least one data row`);
108
+ throw new AuthoringError(`table "${this.name}" has no rows: it needs a header row or at least one data row`);
103
109
  }
104
110
  }
105
111
  get columnCount() {
@@ -115,7 +121,7 @@ export class Table {
115
121
  const target = this.#anchorRow + (this.headerRow ? 1 : 0) + this.#dataRowCount;
116
122
  if (this.totalsRow) {
117
123
  if (this.#insertRow === undefined) {
118
- throw new AuthoringError(`table "${this.name}" is not attached to a worksheet cannot relocate its totals row to append a data row`);
124
+ throw new AuthoringError(`table "${this.name}" is not attached to a worksheet: cannot relocate its totals row to append a data row`);
119
125
  }
120
126
  this.#insertRow(target);
121
127
  values.forEach((value, index) => {
@@ -125,7 +131,7 @@ export class Table {
125
131
  }
126
132
  if (values.length > 0) {
127
133
  if (this.#writeCell === undefined) {
128
- throw new AuthoringError(`table "${this.name}" is not attached to a worksheet cannot write appended row values`);
134
+ throw new AuthoringError(`table "${this.name}" is not attached to a worksheet: cannot write appended row values`);
129
135
  }
130
136
  values.forEach((value, index) => {
131
137
  this.#writeCell?.(target, this.#anchorCol + index, value, this.columns[index]?.style);
@@ -3,12 +3,12 @@
3
3
  *
4
4
  * This order is not the order the slots appear in the theme part. ISO/IEC 29500 §20.1.6.2 documents
5
5
  * the `<a:clrScheme>` child sequence as `dk1, lt1, dk2, lt2, accent1…6, hlink, folHlink`, and that is
6
- * how the XML is written but SpreadsheetML's `theme="n"` does **not** index that sequence. Excel
6
+ * how the XML is written. But SpreadsheetML's `theme="n"` does **not** index that sequence: Excel
7
7
  * swaps each dark/light pair: index 0 is `lt1`, 1 is `dk1`, 2 is `lt2`, 3 is `dk2`.
8
8
  *
9
9
  * Verified against Excel Desktop rather than inferred, because the two orders differ only in the
10
- * first four entries and reading either one into the other silently inverts text against background
11
- * see `docs/knowledge/specs/theme-color-index-order.md` and the recorded observation in
10
+ * first four entries and reading either one into the other silently inverts text against
11
+ * background. See `docs/knowledge/specs/theme-color-index-order.md` and the recorded observation in
12
12
  * `test/corpus/fixtures/excel-oracle/theme-color-index-order.json`. The stylesheet's own default font
13
13
  * is the everyday witness: it carries `<color theme="1"/>` and renders black, which is `dk1`.
14
14
  */
@@ -23,16 +23,6 @@ export type ThemeColorSlot = (typeof THEME_COLOR_SLOTS)[number];
23
23
  export type ThemeColorScheme = Readonly<Partial<Record<ThemeColorSlot, string>>>;
24
24
  /** The Office default colour scheme, matching the theme part the writer emits for a workbook with none. */
25
25
  export declare const DEFAULT_THEME_COLOR_SCHEME: ThemeColorScheme;
26
- /**
27
- * Extract the colour scheme from a theme part. Returns only the slots the part actually declares in a
28
- * colour model this reader understands; an unrecognised one is dropped rather than guessed at, so a
29
- * caller can tell "the theme says nothing here" from "the theme says black".
30
- *
31
- * Reads the `<a:clrScheme>` block alone. A theme carries a font scheme and a format scheme too, but
32
- * neither participates in resolving a colour, and scanning the whole part would let a `<a:srgbClr>`
33
- * buried in a gradient stop masquerade as a scheme slot.
34
- */
35
- export declare function parseThemeColorScheme(themeXml: string): ThemeColorScheme;
36
26
  /**
37
27
  * The two typefaces a theme nominates: the `major` face headings use and the `minor` face body text
38
28
  * uses. A cell's font reaches them by `scheme="major"`/`scheme="minor"` instead of naming a typeface,
@@ -43,7 +33,7 @@ export interface ThemeFontScheme {
43
33
  readonly minor?: string | undefined;
44
34
  }
45
35
  /**
46
- * The body typeface a workbook falls back to when neither its theme nor its styles part names one
36
+ * The body typeface a workbook falls back to when neither its theme nor its styles part names one:
47
37
  * the face the default theme nominates, and so the face every `scheme="minor"` font resolves to.
48
38
  * Named rather than inlined because it is also the last resort of the default-font chain
49
39
  * ({@link Workbook.defaultFont}), and the two must not drift.
@@ -51,40 +41,20 @@ export interface ThemeFontScheme {
51
41
  export declare const OFFICE_BODY_FACE = "Calibri";
52
42
  /** The Office default typefaces, matching the theme part the writer emits for a workbook with none. */
53
43
  export declare const DEFAULT_THEME_FONTS: ThemeFontScheme;
54
- /** Extract the major/minor latin typefaces from a theme part's `<a:fontScheme>`. */
55
- export declare function parseThemeFontScheme(themeXml: string): ThemeFontScheme;
56
44
  /** What a caller can author on a workbook's theme: any subset of the colour slots and typefaces. */
57
45
  export interface ThemeOverrides {
58
46
  readonly colors?: Readonly<Partial<Record<ThemeColorSlot, string>>> | undefined;
59
47
  readonly fonts?: ThemeFontScheme | undefined;
60
48
  }
61
- /**
62
- * Apply authored colour/font overrides to a theme part, returning the new part text.
63
- *
64
- * Surgical by design: the base part rides through untouched except for the `<a:clrScheme>` and
65
- * `<a:fontScheme>` blocks, and within those, only what the caller actually named. The format scheme —
66
- * the gradients, line styles and effect styles that make a theme look like a theme — is left exactly
67
- * as it was, because nobody hand-authors `fillStyleLst` gradient stops from a spreadsheet API and
68
- * regenerating it would replace a designer's work with the Office default.
49
+ /** Reduce an authored theme colour to the bare 6-hex RGB DrawingML wants.
69
50
  *
70
- * A slot the caller did not override keeps its **verbatim source element**, not a re-serialisation of
71
- * its value. That matters for `dk1`/`lt1`, which Excel writes as `<a:sysClr val="windowText"
72
- * lastClr="000000"/>`: rewriting those as `<a:srgbClr>` would pin them to one machine's resolved
73
- * window colours and break dark-mode following.
74
- */
75
- export declare function applyThemeOverrides(baseXml: string, overrides: ThemeOverrides): string;
76
- /**
77
- * Each colour slot's verbatim inner element from a theme part — `<a:srgbClr val="…"/>` or
78
- * `<a:sysClr val="…" lastClr="…"/>`. The value-level counterpart is {@link parseThemeColorScheme};
79
- * this keeps the *encoding* so an untouched slot can be re-emitted exactly as the source wrote it.
80
- */
81
- export declare function parseThemeColorElements(themeXml: string): Readonly<Partial<Record<ThemeColorSlot, string>>>;
82
- /**
83
- * The theme part a workbook with no theme of its own ships — the standard Office theme.
51
+ * A theme colour is a bare 6-hex RGB: DrawingML has no alpha channel on `<a:srgbClr val>`. The two
52
+ * conveniences the rest of the library accepts (a leading '#', an 8-hex ARGB) are accepted and
53
+ * reduced here; anything else is a caller's bug and is refused rather than written as corrupt XML,
54
+ * which Excel does not report; it renders the slot as flat black.
84
55
  *
85
- * A spreadsheet must carry one even when nobody configured it: the stylesheet's own default font
86
- * references `theme="1"`, which a consumer can only resolve against this part, so the two travel
87
- * together. It is also the base {@link applyThemeOverrides} authors on top of when a workbook was
88
- * built from scratch rather than read from a file.
56
+ * @throws {SyntaxError} if the value is not a recognisable RGB or ARGB hex string. Native rather
57
+ * than the library's own `AuthoringError`: a string that does not parse is what `SyntaxError` is
58
+ * for, and it is the same kind of failure a malformed comment GUID raises.
89
59
  */
90
- export declare const DEFAULT_THEME_XML: string;
60
+ export declare function normalizeThemeColor(value: string): string;