@shbernal/ts-xlsx 1.0.3 → 1.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.
Files changed (136) hide show
  1. package/README.md +21 -0
  2. package/dist/core/address.js +0 -33
  3. package/dist/core/autofilter.js +0 -9
  4. package/dist/core/cell.d.ts +10 -0
  5. package/dist/core/cell.js +4 -123
  6. package/dist/core/color-resolution.js +0 -60
  7. package/dist/core/column.d.ts +9 -1
  8. package/dist/core/column.js +0 -52
  9. package/dist/core/comment-thread.js +0 -45
  10. package/dist/core/conditional-formatting-overlay.js +0 -11
  11. package/dist/core/conditional-formatting.js +0 -10
  12. package/dist/core/containers.js +0 -15
  13. package/dist/core/data-validation-overlay.js +0 -25
  14. package/dist/core/data-validation.js +0 -7
  15. package/dist/core/date.js +0 -39
  16. package/dist/core/formula.js +0 -117
  17. package/dist/core/grid-edits.js +0 -38
  18. package/dist/core/image.js +0 -25
  19. package/dist/core/internal.js +0 -27
  20. package/dist/core/limits.d.ts +30 -0
  21. package/dist/core/limits.js +2 -0
  22. package/dist/core/merge.d.ts +18 -0
  23. package/dist/core/merge.js +22 -7
  24. package/dist/core/modern-functions.js +0 -17
  25. package/dist/core/page-setup.js +0 -5
  26. package/dist/core/pivot-table.d.ts +1 -1
  27. package/dist/core/pivot-table.js +0 -44
  28. package/dist/core/preserved.js +0 -4
  29. package/dist/core/protection.js +0 -26
  30. package/dist/core/range.js +0 -112
  31. package/dist/core/row-input.d.ts +24 -0
  32. package/dist/core/row-input.js +29 -0
  33. package/dist/core/row.d.ts +9 -1
  34. package/dist/core/row.js +0 -58
  35. package/dist/core/style.js +0 -26
  36. package/dist/core/table-style.js +0 -28
  37. package/dist/core/table.js +0 -97
  38. package/dist/core/text-metrics.d.ts +20 -0
  39. package/dist/core/text-metrics.js +10 -0
  40. package/dist/core/theme.js +0 -85
  41. package/dist/core/value.d.ts +40 -0
  42. package/dist/core/value.js +30 -48
  43. package/dist/core/workbook-protection.js +0 -13
  44. package/dist/core/workbook.d.ts +13 -0
  45. package/dist/core/workbook.js +11 -368
  46. package/dist/core/worksheet-model.js +2 -23
  47. package/dist/core/worksheet.d.ts +22 -0
  48. package/dist/core/worksheet.js +14 -485
  49. package/dist/customui/errors.js +0 -10
  50. package/dist/customui/index.js +0 -5
  51. package/dist/customui/ribbon.js +0 -43
  52. package/dist/entries/core.d.ts +3 -1
  53. package/dist/entries/core.js +3 -7
  54. package/dist/entries/csv.js +0 -4
  55. package/dist/entries/customui.js +0 -2
  56. package/dist/entries/errors.js +0 -13
  57. package/dist/entries/vba.js +0 -5
  58. package/dist/entries/xlsb.js +0 -6
  59. package/dist/entries/xlsx.js +0 -13
  60. package/dist/errors.d.ts +14 -0
  61. package/dist/errors.js +5 -56
  62. package/dist/index.js +0 -12
  63. package/dist/io/csv/read.js +0 -18
  64. package/dist/io/csv/write.js +5 -35
  65. package/dist/io/opc/errors.js +0 -30
  66. package/dist/io/opc/inflate.js +0 -35
  67. package/dist/io/opc/namespaces.js +0 -15
  68. package/dist/io/opc/part-paths.js +0 -11
  69. package/dist/io/opc/read-opc.js +0 -31
  70. package/dist/io/opc/read-options.js +0 -6
  71. package/dist/io/opc/rels.js +0 -13
  72. package/dist/io/opc/sniff-format.js +0 -50
  73. package/dist/io/style/xf-style.js +0 -31
  74. package/dist/io/xlsb/errors.js +0 -10
  75. package/dist/io/xlsb/formula.js +1 -99
  76. package/dist/io/xlsb/primitives.js +1 -83
  77. package/dist/io/xlsb/ptg-functions.js +0 -34
  78. package/dist/io/xlsb/read-shared-strings.js +0 -7
  79. package/dist/io/xlsb/read-styles.js +3 -66
  80. package/dist/io/xlsb/read-worksheet.js +4 -87
  81. package/dist/io/xlsb/read.js +2 -60
  82. package/dist/io/xlsb/record-stream.js +0 -28
  83. package/dist/io/xlsb/record-types.js +0 -19
  84. package/dist/io/xlsx/cell-accumulator.js +0 -32
  85. package/dist/io/xlsx/cell-value.js +0 -29
  86. package/dist/io/xlsx/color-xml.d.ts +6 -0
  87. package/dist/io/xlsx/color-xml.js +42 -0
  88. package/dist/io/xlsx/comments.js +0 -84
  89. package/dist/io/xlsx/conditional-formatting.d.ts +1 -1
  90. package/dist/io/xlsx/conditional-formatting.js +1 -97
  91. package/dist/io/xlsx/data-validation.js +0 -56
  92. package/dist/io/xlsx/edit-vba.js +0 -54
  93. package/dist/io/xlsx/errors.js +0 -12
  94. package/dist/io/xlsx/hyperlinks.js +0 -40
  95. package/dist/io/xlsx/images.js +0 -32
  96. package/dist/io/xlsx/namespaces.js +0 -42
  97. package/dist/io/xlsx/package-plan.js +0 -47
  98. package/dist/io/xlsx/pivot.js +0 -22
  99. package/dist/io/xlsx/{pivot-read.js → read-pivot.js} +0 -30
  100. package/dist/io/xlsx/read-rows.js +1 -83
  101. package/dist/io/xlsx/{shared-strings-read.js → read-shared-strings.js} +0 -11
  102. package/dist/io/xlsx/read-styles.d.ts +25 -1
  103. package/dist/io/xlsx/read-styles.js +61 -108
  104. package/dist/io/xlsx/read-worksheet.js +1 -88
  105. package/dist/io/xlsx/read.js +3 -211
  106. package/dist/io/xlsx/relationships.js +0 -11
  107. package/dist/io/xlsx/rich-runs.js +0 -16
  108. package/dist/io/xlsx/rich-text.js +0 -12
  109. package/dist/io/xlsx/shared-formulas.js +0 -7
  110. package/dist/io/xlsx/shared-strings.js +0 -21
  111. package/dist/io/xlsx/sheet-properties.js +1 -64
  112. package/dist/io/xlsx/styles.d.ts +1 -29
  113. package/dist/io/xlsx/styles.js +2 -366
  114. package/dist/io/xlsx/tables.js +5 -52
  115. package/dist/io/xlsx/threaded-comments.js +0 -103
  116. package/dist/io/xlsx/workbook-xml.js +0 -94
  117. package/dist/io/xlsx/worksheet-xml.js +0 -174
  118. package/dist/io/xlsx/write-stream.js +0 -137
  119. package/dist/io/xlsx/write.js +1 -134
  120. package/dist/io/xlsx/x14-ext.js +0 -8
  121. package/dist/vba/cfb-writer.js +12 -59
  122. package/dist/vba/cfb.js +2 -32
  123. package/dist/vba/codepage.js +1 -23
  124. package/dist/vba/errors.js +0 -15
  125. package/dist/vba/index.js +0 -10
  126. package/dist/vba/ms-ovba.js +3 -46
  127. package/dist/vba/project-editor.js +4 -89
  128. package/dist/vba/project.js +2 -34
  129. package/dist/vba/vba-encoding.js +1 -17
  130. package/dist/xml/errors.js +0 -10
  131. package/dist/xml/xml-read.js +3 -82
  132. package/dist/xml/xml.js +0 -39
  133. package/package.json +9 -10
  134. package/skills/ts-xlsx-upstream/SKILL.md +178 -0
  135. /package/dist/io/xlsx/{pivot-read.d.ts → read-pivot.d.ts} +0 -0
  136. /package/dist/io/xlsx/{shared-strings-read.d.ts → read-shared-strings.d.ts} +0 -0
@@ -1,21 +1,7 @@
1
- // The worksheet's non-cell property blocks: `<sheetPr>`, `<sheetViews>`, `<sheetProtection>`,
2
- // `<autoFilter>`, and the print settings (`<printOptions>`, `<pageMargins>`, `<pageSetup>`,
3
- // `<headerFooter>`, `<rowBreaks>`/`<colBreaks>`). Each renders one CT_Worksheet child (or child
4
- // group) independently of the row/cell body `worksheet-xml.ts` orchestrates them alongside.
5
1
  import { encodeAddress } from '../../core/address.js';
6
2
  import { SHEET_PROTECTION_FLAGS } from '../../core/protection.js';
7
3
  import { attr, boolAttr, escapeAttr, escapeText, numberText } from '../../xml/xml.js';
8
- import { colorAttrs } from './styles.js';
9
- // `<sheetViews>` holds the sheet's single view. A frozen view adds a `<pane>` recording the split
10
- // and a `<selection>` naming the pane the split activates, exactly as Excel writes it — a normal
11
- // view carries neither, so unfreezing leaves no leftover `<pane>` that would trip a repair prompt.
12
- // The active pane is whichever scrolling region the freeze creates: bottom-right when both axes are
13
- // frozen, else top-right (columns only) or bottom-left (rows only).
14
- //
15
- // `active` marks this sheet as the one selected on open (`tabSelected`). Exactly one sheet in a
16
- // workbook carries it — with none, the consumer opens with no sheet view initialised; with several,
17
- // the sheets form a *group selection*, where an edit to one is applied to all of them. The caller
18
- // (`worksheetXml`, fed from `Workbook.activeTabIndex`) is what guarantees the "exactly one".
4
+ import { colorAttrs } from './color-xml.js';
19
5
  export function sheetViewsXml(view, active) {
20
6
  const selected = active ? ' tabSelected="1"' : '';
21
7
  const xSplit = view.xSplit ?? 0;
@@ -32,39 +18,19 @@ export function sheetViewsXml(view, active) {
32
18
  const selection = `<selection pane="${activePane}" activeCell="${escapeAttr(topLeftCell)}" sqref="${escapeAttr(topLeftCell)}"/>`;
33
19
  return `<sheetViews><sheetView${selected} workbookViewId="0">${pane}${selection}</sheetView></sheetViews>`;
34
20
  }
35
- // `<sheetPr>` carries the sheet's appearance properties: the tab colour, the outline
36
- // summary-position flags, and the fit-to-page flag. It is the first child of `<worksheet>` in
37
- // CT_Worksheet order; its own children follow CT_SheetPr order — `<tabColor>`, `<outlinePr>`, then
38
- // `<pageSetUpPr>`. Omitted entirely when the sheet carries none, so an unadorned sheet stays
39
- // byte-clean.
40
21
  export function sheetPrXml(sheet) {
41
22
  const children = (sheet.tabColor !== undefined ? `<tabColor ${colorAttrs(sheet.tabColor)}/>` : '') +
42
23
  outlinePrXml(sheet.outline) +
43
24
  pageSetUpPrXml(sheet.pageSetup);
44
25
  return children === '' ? '' : `<sheetPr>${children}</sheetPr>`;
45
26
  }
46
- // `<pageSetUpPr>` holds the fit-to-page toggle, which lives on the sheet properties rather than on
47
- // `<pageSetup>` — Excel reads it from here to decide whether the `fitToWidth`/`fitToHeight` counts
48
- // or the fixed `scale` govern printing. Emitted only when the author set the flag.
49
27
  function pageSetUpPrXml(pageSetup) {
50
28
  return pageSetup.fitToPage ? '<pageSetUpPr fitToPage="1"/>' : '';
51
29
  }
52
- // `<outlinePr>` carries only the summary-position flags today. Each is emitted solely when the
53
- // caller set it, so an inverted placement (`summaryBelow="0"`) is honoured while an untouched sheet
54
- // keeps the element out of the file entirely.
55
30
  function outlinePrXml(outline) {
56
31
  const attrs = boolAttr('summaryBelow', outline.summaryBelow) + boolAttr('summaryRight', outline.summaryRight);
57
32
  return attrs === '' ? '' : `<outlinePr${attrs}/>`;
58
33
  }
59
- // Each sheet-protection flag maps to a `<sheetProtection>` attribute whose value is INVERTED
60
- // from the author-facing allow-flag: the attribute records that an operation is *forbidden*
61
- // ("1"), so `allow: true` serialises as "0". Only a value that differs from OOXML's per-
62
- // attribute default (see SHEET_PROTECTION_FLAGS) is written — most editing operations default
63
- // to forbidden under protection, while selecting cells defaults to permitted.
64
- //
65
- // <sheetProtection> is what makes the per-cell locked/hidden flags bite. `sheet="1"` marks the
66
- // sheet protected; the password credential (when present) guards lifting it; the flag attributes
67
- // carve out the operations that stay available. base64 salt/hash use only XML-safe characters.
68
34
  export function sheetProtectionXml(protection) {
69
35
  if (protection === undefined)
70
36
  return '';
@@ -89,10 +55,6 @@ export function sheetProtectionXml(protection) {
89
55
  }
90
56
  return `<sheetProtection${attrs}/>`;
91
57
  }
92
- // The sheet's autofilter: `<autoFilter ref="A1:C10"/>` when it only draws dropdowns, or with nested
93
- // `<filterColumn>` children when columns carry criteria. Its companion `_FilterDatabase` defined name
94
- // (the range Excel derives filtering from) is written in the workbook part, so a sheet with no filter
95
- // emits nothing here and nothing there.
96
58
  export function autoFilterXml(filter) {
97
59
  if (filter === undefined)
98
60
  return '';
@@ -104,9 +66,6 @@ export function autoFilterXml(filter) {
104
66
  function filterColumnXml(column) {
105
67
  return `<filterColumn colId="${column.colId}">${filterCriteriaXml(column.criteria)}</filterColumn>`;
106
68
  }
107
- // A values filter is `<filters>` with a `<filter val>` per allowed value (and `blank="1"` to admit
108
- // empty cells); a custom filter is `<customFilters>` with one or two `<customFilter operator val>`
109
- // predicates, `and="1"` when they are AND-combined rather than OR.
110
69
  function filterCriteriaXml(criteria) {
111
70
  if (criteria.kind === 'values') {
112
71
  const blankAttr = criteria.blank ? ' blank="1"' : '';
@@ -119,9 +78,6 @@ function filterCriteriaXml(criteria) {
119
78
  .join('');
120
79
  return `<customFilters${andAttr}>${predicates}</customFilters>`;
121
80
  }
122
- // CT_HeaderFooter child order, paired with the flag their presence gates: the even- and
123
- // first-page variants are silently ignored by Excel unless differentOddEven / differentFirst
124
- // are set, so the writer derives each flag from whether any variant in its class was provided.
125
81
  const HF_CHILDREN = [
126
82
  { tag: 'oddHeader', key: 'oddHeader' },
127
83
  { tag: 'oddFooter', key: 'oddFooter' },
@@ -146,7 +102,6 @@ export function headerFooterXml(hf) {
146
102
  .join('');
147
103
  return `<headerFooter${attrs}>${body}</headerFooter>`;
148
104
  }
149
- // Excel's "Normal" margins, in inches — the defaults Excel writes for an untouched sheet.
150
105
  const DEFAULT_MARGINS = {
151
106
  left: 0.7,
152
107
  right: 0.7,
@@ -156,10 +111,6 @@ const DEFAULT_MARGINS = {
156
111
  footer: 0.3,
157
112
  };
158
113
  const MARGIN_SIDES = ['left', 'right', 'top', 'bottom', 'header', 'footer'];
159
- // `<printOptions>` carries the print-toggle flags and sits just before `<pageMargins>` in
160
- // CT_Worksheet order. Each attribute is emitted only when the model carries it — as an explicit
161
- // `="1"`/`="0"` so a caller can force a flag off against Excel's default — and an untouched sheet
162
- // keeps the element out of the file entirely.
163
114
  export function printOptionsXml(printOptions) {
164
115
  const attrs = boolAttr('horizontalCentered', printOptions.horizontalCentered) +
165
116
  boolAttr('verticalCentered', printOptions.verticalCentered) +
@@ -168,21 +119,12 @@ export function printOptionsXml(printOptions) {
168
119
  boolAttr('gridLinesSet', printOptions.gridLinesSet);
169
120
  return attrs === '' ? '' : `<printOptions${attrs}/>`;
170
121
  }
171
- // OOXML's <pageMargins> is all-or-nothing: setting any one margin requires all six, or Excel
172
- // repairs the file. So the element is emitted only when the caller set at least one, and the
173
- // untouched sides fall back to the Normal-preset defaults.
174
122
  export function pageMarginsXml(margins) {
175
123
  if (MARGIN_SIDES.every((side) => margins[side] === undefined))
176
124
  return '';
177
125
  const attrs = MARGIN_SIDES.map((side) => `${side}="${numberText(margins[side] ?? DEFAULT_MARGINS[side])}"`).join(' ');
178
126
  return `<pageMargins ${attrs}/>`;
179
127
  }
180
- // `<pageSetup>` carries the print-scaling attributes (all but `fitToPage`, which is a `<sheetPr>`
181
- // flag). It sits between `<pageMargins>` and `<headerFooter>` in CT_Worksheet order. Each attribute
182
- // is emitted only when the author set it, so an untouched sheet keeps the element out of the file
183
- // and a partially-set one never fabricates the counts Excel would otherwise default. A non-null
184
- // `printerSettingsRelId` links the sheet's opaque printer-settings blob and forces the element out
185
- // even when no scaling attribute is set — the reference is the only thing the model has to carry.
186
128
  export function pageSetupXml(pageSetup, printerSettingsRelId) {
187
129
  const attrs = attr('paperSize', pageSetup.paperSize) +
188
130
  attr('scale', pageSetup.scale) +
@@ -193,11 +135,6 @@ export function pageSetupXml(pageSetup, printerSettingsRelId) {
193
135
  (printerSettingsRelId !== null ? ` r:id="${printerSettingsRelId}"` : '');
194
136
  return attrs === '' ? '' : `<pageSetup${attrs}/>`;
195
137
  }
196
- // Manual page breaks (`<rowBreaks>`/`<colBreaks>`): one `<brk>` per row/column the layout splits
197
- // before. Excel records both the running total (`count`) and the manual subset (`manualBreakCount`);
198
- // every break the model carries is a manual, author-set one, so the two counts coincide. `max` bounds
199
- // the break across the other axis (Excel writes the last row/column index); a break without one is
200
- // emitted bare. Row and column breaks share this shape, differing only in the wrapping element.
201
138
  export function pageBreaksXml(breaks, element) {
202
139
  if (breaks.length === 0)
203
140
  return '';
@@ -1,4 +1,4 @@
1
- import { type Alignment, type Border, type Color, type DifferentialStyle, type Fill, type Font, type NamedCellStyle, type Protection, type TableStyleTable } from '../../core/style.ts';
1
+ import { type Alignment, type Border, type DifferentialStyle, type Fill, type Font, type NamedCellStyle, type Protection, type TableStyleTable } from '../../core/style.ts';
2
2
  import { type TableStyle } from '../../core/table-style.ts';
3
3
  /** A cell's style facets as the writer composes them: cell overrides atop row/column defaults. */
4
4
  export interface CellStyle {
@@ -106,33 +106,5 @@ export declare class StyleRegistry {
106
106
  /** Serialise the accumulated table into a complete, valid styles.xml part. */
107
107
  toXml(): string;
108
108
  }
109
- /**
110
- * Extract the custom indexed-color palette (`<colors><indexedColors>`) from styles.xml as verbatim
111
- * `<rgbColor rgb="…"/>` fragments, or an empty list when the file rides the default palette. Kept raw
112
- * — rather than parsed into RGB and re-serialised — so the exact entries (count, order, casing) a
113
- * source file declared survive a round-trip and every `indexed="…"` reference keeps its RGB.
114
- */
115
- export declare function parseIndexedColors(stylesXml: string): string[];
116
- /**
117
- * Extract the most-recently-used colour swatches (`<colors><mruColors>`) from styles.xml as verbatim
118
- * `<color .../>` fragments, or an empty list when the file declares none. Kept raw for the same reason
119
- * the indexed palette is: the list is the author's own working set of colours and the model has no
120
- * use for its contents, only for not losing them.
121
- */
122
- export declare function parseMruColors(stylesXml: string): string[];
123
- /**
124
- * Extract the `<tableStyles>` block from styles.xml: each `<tableStyle>` definition verbatim, plus the
125
- * container's nominated `defaultTableStyle`/`defaultPivotStyle`. See {@link TableStyleTable} for why
126
- * the definitions stay raw while the two names are decoded.
127
- *
128
- * A file with no such block — or with the self-closing `count="0"` container Excel writes when it has
129
- * only defaults to state — yields an empty {@link TableStyleTable.styles} and whichever names it did
130
- * carry.
131
- */
132
- export declare function parseTableStyles(stylesXml: string): TableStyleTable;
133
109
  export declare function fontXml(font: Font, nameTag?: 'name' | 'rFont'): string;
134
110
  export declare function dxfXml(style: DifferentialStyle): string;
135
- export declare function colorAttrs(color: Color): string;
136
- export declare function parseColor(attrs: {
137
- readonly [k: string]: string;
138
- }): Color;