@shbernal/ts-xlsx 1.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 (223) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +230 -0
  3. package/dist/core/address.d.ts +49 -0
  4. package/dist/core/address.js +125 -0
  5. package/dist/core/autofilter.d.ts +55 -0
  6. package/dist/core/autofilter.js +48 -0
  7. package/dist/core/cell.d.ts +132 -0
  8. package/dist/core/cell.js +249 -0
  9. package/dist/core/color-resolution.d.ts +58 -0
  10. package/dist/core/color-resolution.js +170 -0
  11. package/dist/core/column.d.ts +87 -0
  12. package/dist/core/column.js +167 -0
  13. package/dist/core/comment-thread.d.ts +116 -0
  14. package/dist/core/comment-thread.js +62 -0
  15. package/dist/core/conditional-formatting-overlay.d.ts +15 -0
  16. package/dist/core/conditional-formatting-overlay.js +24 -0
  17. package/dist/core/conditional-formatting.d.ts +70 -0
  18. package/dist/core/conditional-formatting.js +35 -0
  19. package/dist/core/containers.d.ts +2 -0
  20. package/dist/core/containers.js +25 -0
  21. package/dist/core/data-validation-overlay.d.ts +28 -0
  22. package/dist/core/data-validation-overlay.js +56 -0
  23. package/dist/core/data-validation.d.ts +38 -0
  24. package/dist/core/data-validation.js +13 -0
  25. package/dist/core/date.d.ts +25 -0
  26. package/dist/core/date.js +58 -0
  27. package/dist/core/formula.d.ts +49 -0
  28. package/dist/core/formula.js +319 -0
  29. package/dist/core/grid-edits.d.ts +22 -0
  30. package/dist/core/grid-edits.js +206 -0
  31. package/dist/core/image.d.ts +76 -0
  32. package/dist/core/image.js +65 -0
  33. package/dist/core/internal.d.ts +11 -0
  34. package/dist/core/internal.js +29 -0
  35. package/dist/core/merge.d.ts +13 -0
  36. package/dist/core/merge.js +26 -0
  37. package/dist/core/modern-functions.d.ts +1 -0
  38. package/dist/core/modern-functions.js +165 -0
  39. package/dist/core/page-setup.d.ts +94 -0
  40. package/dist/core/page-setup.js +6 -0
  41. package/dist/core/pivot-table.d.ts +113 -0
  42. package/dist/core/pivot-table.js +249 -0
  43. package/dist/core/preserved.d.ts +58 -0
  44. package/dist/core/preserved.js +5 -0
  45. package/dist/core/protection.d.ts +67 -0
  46. package/dist/core/protection.js +68 -0
  47. package/dist/core/range.d.ts +112 -0
  48. package/dist/core/range.js +283 -0
  49. package/dist/core/row.d.ts +73 -0
  50. package/dist/core/row.js +135 -0
  51. package/dist/core/style.d.ts +246 -0
  52. package/dist/core/style.js +125 -0
  53. package/dist/core/table-style.d.ts +67 -0
  54. package/dist/core/table-style.js +90 -0
  55. package/dist/core/table.d.ts +194 -0
  56. package/dist/core/table.js +291 -0
  57. package/dist/core/theme.d.ts +90 -0
  58. package/dist/core/theme.js +272 -0
  59. package/dist/core/value.d.ts +115 -0
  60. package/dist/core/value.js +144 -0
  61. package/dist/core/workbook-protection.d.ts +27 -0
  62. package/dist/core/workbook-protection.js +25 -0
  63. package/dist/core/workbook.d.ts +528 -0
  64. package/dist/core/workbook.js +732 -0
  65. package/dist/core/worksheet-model.d.ts +34 -0
  66. package/dist/core/worksheet-model.js +100 -0
  67. package/dist/core/worksheet.d.ts +647 -0
  68. package/dist/core/worksheet.js +1025 -0
  69. package/dist/customui/errors.d.ts +15 -0
  70. package/dist/customui/errors.js +15 -0
  71. package/dist/customui/index.d.ts +2 -0
  72. package/dist/customui/index.js +7 -0
  73. package/dist/customui/ribbon.d.ts +86 -0
  74. package/dist/customui/ribbon.js +180 -0
  75. package/dist/entries/core.d.ts +23 -0
  76. package/dist/entries/core.js +20 -0
  77. package/dist/entries/csv.d.ts +2 -0
  78. package/dist/entries/csv.js +6 -0
  79. package/dist/entries/customui.d.ts +1 -0
  80. package/dist/entries/customui.js +3 -0
  81. package/dist/entries/errors.d.ts +7 -0
  82. package/dist/entries/errors.js +20 -0
  83. package/dist/entries/vba.d.ts +2 -0
  84. package/dist/entries/vba.js +7 -0
  85. package/dist/entries/xlsb.d.ts +1 -0
  86. package/dist/entries/xlsb.js +7 -0
  87. package/dist/entries/xlsx.d.ts +5 -0
  88. package/dist/entries/xlsx.js +18 -0
  89. package/dist/errors.d.ts +65 -0
  90. package/dist/errors.js +66 -0
  91. package/dist/index.d.ts +7 -0
  92. package/dist/index.js +19 -0
  93. package/dist/io/csv/read.d.ts +15 -0
  94. package/dist/io/csv/read.js +113 -0
  95. package/dist/io/csv/write.d.ts +28 -0
  96. package/dist/io/csv/write.js +124 -0
  97. package/dist/io/opc/errors.d.ts +46 -0
  98. package/dist/io/opc/errors.js +49 -0
  99. package/dist/io/opc/inflate.d.ts +15 -0
  100. package/dist/io/opc/inflate.js +91 -0
  101. package/dist/io/opc/namespaces.d.ts +18 -0
  102. package/dist/io/opc/namespaces.js +18 -0
  103. package/dist/io/opc/part-paths.d.ts +4 -0
  104. package/dist/io/opc/part-paths.js +35 -0
  105. package/dist/io/opc/read-opc.d.ts +24 -0
  106. package/dist/io/opc/read-opc.js +153 -0
  107. package/dist/io/opc/read-options.d.ts +10 -0
  108. package/dist/io/opc/read-options.js +7 -0
  109. package/dist/io/opc/rels.d.ts +15 -0
  110. package/dist/io/opc/rels.js +28 -0
  111. package/dist/io/opc/sniff-format.d.ts +27 -0
  112. package/dist/io/opc/sniff-format.js +92 -0
  113. package/dist/io/style/xf-style.d.ts +47 -0
  114. package/dist/io/style/xf-style.js +95 -0
  115. package/dist/io/xlsb/errors.d.ts +15 -0
  116. package/dist/io/xlsb/errors.js +15 -0
  117. package/dist/io/xlsb/formula.d.ts +48 -0
  118. package/dist/io/xlsb/formula.js +398 -0
  119. package/dist/io/xlsb/primitives.d.ts +86 -0
  120. package/dist/io/xlsb/primitives.js +230 -0
  121. package/dist/io/xlsb/ptg-functions.d.ts +16 -0
  122. package/dist/io/xlsb/ptg-functions.js +659 -0
  123. package/dist/io/xlsb/read-shared-strings.d.ts +2 -0
  124. package/dist/io/xlsb/read-shared-strings.js +22 -0
  125. package/dist/io/xlsb/read-styles.d.ts +4 -0
  126. package/dist/io/xlsb/read-styles.js +386 -0
  127. package/dist/io/xlsb/read-worksheet.d.ts +9 -0
  128. package/dist/io/xlsb/read-worksheet.js +301 -0
  129. package/dist/io/xlsb/read.d.ts +20 -0
  130. package/dist/io/xlsb/read.js +199 -0
  131. package/dist/io/xlsb/record-stream.d.ts +14 -0
  132. package/dist/io/xlsb/record-stream.js +56 -0
  133. package/dist/io/xlsb/record-types.d.ts +55 -0
  134. package/dist/io/xlsb/record-types.js +73 -0
  135. package/dist/io/xlsx/cell-accumulator.d.ts +25 -0
  136. package/dist/io/xlsx/cell-accumulator.js +172 -0
  137. package/dist/io/xlsx/cell-value.d.ts +32 -0
  138. package/dist/io/xlsx/cell-value.js +85 -0
  139. package/dist/io/xlsx/comments.d.ts +74 -0
  140. package/dist/io/xlsx/comments.js +243 -0
  141. package/dist/io/xlsx/conditional-formatting.d.ts +32 -0
  142. package/dist/io/xlsx/conditional-formatting.js +464 -0
  143. package/dist/io/xlsx/data-validation.d.ts +20 -0
  144. package/dist/io/xlsx/data-validation.js +258 -0
  145. package/dist/io/xlsx/edit-vba.d.ts +23 -0
  146. package/dist/io/xlsx/edit-vba.js +139 -0
  147. package/dist/io/xlsx/errors.d.ts +17 -0
  148. package/dist/io/xlsx/errors.js +17 -0
  149. package/dist/io/xlsx/hyperlinks.d.ts +42 -0
  150. package/dist/io/xlsx/hyperlinks.js +139 -0
  151. package/dist/io/xlsx/images.d.ts +34 -0
  152. package/dist/io/xlsx/images.js +218 -0
  153. package/dist/io/xlsx/namespaces.d.ts +55 -0
  154. package/dist/io/xlsx/namespaces.js +55 -0
  155. package/dist/io/xlsx/package-plan.d.ts +103 -0
  156. package/dist/io/xlsx/package-plan.js +168 -0
  157. package/dist/io/xlsx/pivot-read.d.ts +5 -0
  158. package/dist/io/xlsx/pivot-read.js +134 -0
  159. package/dist/io/xlsx/pivot.d.ts +12 -0
  160. package/dist/io/xlsx/pivot.js +141 -0
  161. package/dist/io/xlsx/read-rows.d.ts +85 -0
  162. package/dist/io/xlsx/read-rows.js +286 -0
  163. package/dist/io/xlsx/read-styles.d.ts +8 -0
  164. package/dist/io/xlsx/read-styles.js +551 -0
  165. package/dist/io/xlsx/read-worksheet.d.ts +4 -0
  166. package/dist/io/xlsx/read-worksheet.js +528 -0
  167. package/dist/io/xlsx/read.d.ts +32 -0
  168. package/dist/io/xlsx/read.js +680 -0
  169. package/dist/io/xlsx/relationships.d.ts +33 -0
  170. package/dist/io/xlsx/relationships.js +47 -0
  171. package/dist/io/xlsx/rich-runs.d.ts +13 -0
  172. package/dist/io/xlsx/rich-runs.js +59 -0
  173. package/dist/io/xlsx/rich-text.d.ts +7 -0
  174. package/dist/io/xlsx/rich-text.js +23 -0
  175. package/dist/io/xlsx/shared-formulas.d.ts +6 -0
  176. package/dist/io/xlsx/shared-formulas.js +52 -0
  177. package/dist/io/xlsx/shared-strings-read.d.ts +2 -0
  178. package/dist/io/xlsx/shared-strings-read.js +70 -0
  179. package/dist/io/xlsx/shared-strings.d.ts +17 -0
  180. package/dist/io/xlsx/shared-strings.js +50 -0
  181. package/dist/io/xlsx/sheet-properties.d.ts +13 -0
  182. package/dist/io/xlsx/sheet-properties.js +211 -0
  183. package/dist/io/xlsx/styles.d.ts +138 -0
  184. package/dist/io/xlsx/styles.js +821 -0
  185. package/dist/io/xlsx/tables.d.ts +9 -0
  186. package/dist/io/xlsx/tables.js +208 -0
  187. package/dist/io/xlsx/threaded-comments.d.ts +102 -0
  188. package/dist/io/xlsx/threaded-comments.js +308 -0
  189. package/dist/io/xlsx/workbook-xml.d.ts +12 -0
  190. package/dist/io/xlsx/workbook-xml.js +353 -0
  191. package/dist/io/xlsx/worksheet-xml.d.ts +86 -0
  192. package/dist/io/xlsx/worksheet-xml.js +643 -0
  193. package/dist/io/xlsx/write-stream.d.ts +171 -0
  194. package/dist/io/xlsx/write-stream.js +399 -0
  195. package/dist/io/xlsx/write.d.ts +81 -0
  196. package/dist/io/xlsx/write.js +396 -0
  197. package/dist/io/xlsx/x14-ext.d.ts +9 -0
  198. package/dist/io/xlsx/x14-ext.js +12 -0
  199. package/dist/vba/cfb-writer.d.ts +19 -0
  200. package/dist/vba/cfb-writer.js +277 -0
  201. package/dist/vba/cfb.d.ts +16 -0
  202. package/dist/vba/cfb.js +324 -0
  203. package/dist/vba/codepage.d.ts +18 -0
  204. package/dist/vba/codepage.js +87 -0
  205. package/dist/vba/errors.d.ts +24 -0
  206. package/dist/vba/errors.js +24 -0
  207. package/dist/vba/index.d.ts +5 -0
  208. package/dist/vba/index.js +15 -0
  209. package/dist/vba/ms-ovba.d.ts +12 -0
  210. package/dist/vba/ms-ovba.js +176 -0
  211. package/dist/vba/project-editor.d.ts +62 -0
  212. package/dist/vba/project-editor.js +377 -0
  213. package/dist/vba/project.d.ts +45 -0
  214. package/dist/vba/project.js +160 -0
  215. package/dist/vba/vba-encoding.d.ts +14 -0
  216. package/dist/vba/vba-encoding.js +39 -0
  217. package/dist/xml/errors.d.ts +15 -0
  218. package/dist/xml/errors.js +15 -0
  219. package/dist/xml/xml-read.d.ts +107 -0
  220. package/dist/xml/xml-read.js +283 -0
  221. package/dist/xml/xml.d.ts +41 -0
  222. package/dist/xml/xml.js +86 -0
  223. package/package.json +117 -0
@@ -0,0 +1,34 @@
1
+ import type { Worksheet, WorksheetModel } from './worksheet.ts';
2
+ /** One field of a {@link WorksheetModel}, with both directions of its round-trip declared together. */
3
+ interface ModelFacet<K extends keyof WorksheetModel = keyof WorksheetModel> {
4
+ readonly key: K;
5
+ /** Produce the field's value, copied deeply enough that mutating it cannot reach back into the sheet. */
6
+ readonly read: (sheet: Worksheet) => WorksheetModel[K];
7
+ /**
8
+ * Apply the field to a sheet whose content has already been reset. Takes the whole model rather
9
+ * than the field so that a loop over the registry needs no correlation between `key` and the
10
+ * field's type — {@link facet} does that projection once, where the key is still a single type.
11
+ *
12
+ * The obvious shape, `write(sheet, value: WorksheetModel[K])` stored as-is, cannot be called from
13
+ * a loop: over a union of `ModelFacet<K>` the parameter is contravariant under
14
+ * `strictFunctionTypes`, which breaks the correlation. Declaring `write` with method syntax makes
15
+ * it compile — by making the position bivariant, which buys the call back by switching the check
16
+ * off. Projecting inside the helper is correlated *and* sound; do not "simplify" it back.
17
+ */
18
+ readonly write: (sheet: Worksheet, model: WorksheetModel) => void;
19
+ }
20
+ /**
21
+ * Every field of a {@link WorksheetModel}, in the order a model assignment applies them. Order is
22
+ * load-bearing: cells are placed at their exact positions before any merge exists, so a covered
23
+ * cell's value lands where the model says instead of being routed to a region master mid-load.
24
+ */
25
+ export declare const WORKSHEET_MODEL_FACETS: (ModelFacet<"state"> | ModelFacet<"tabColor"> | ModelFacet<"properties"> | ModelFacet<"outline"> | ModelFacet<"pageSetup"> | ModelFacet<"printOptions"> | ModelFacet<"pageMargins"> | ModelFacet<"headerFooter"> | ModelFacet<"rowBreaks"> | ModelFacet<"columnBreaks"> | ModelFacet<"columns"> | ModelFacet<"rows"> | ModelFacet<"cells"> | ModelFacet<"merges"> | ModelFacet<"dataValidations"> | ModelFacet<"conditionalFormattings"> | ModelFacet<"tables"> | ModelFacet<"autoFilter"> | ModelFacet<"protection">)[];
26
+ type AssertNever<T extends never> = T;
27
+ /**
28
+ * Compile-time proof that {@link WORKSHEET_MODEL_FACETS} covers every {@link WorksheetModel} field.
29
+ * A field added without a facet resolves this to that field's name, which does not satisfy `never`,
30
+ * so the error names what is missing. This is the guarantee the registry exists to provide: the two
31
+ * directions of the round-trip can no longer drift apart without the build saying so.
32
+ */
33
+ export type EveryWorksheetModelFieldHasAFacet = AssertNever<Exclude<keyof WorksheetModel, (typeof WORKSHEET_MODEL_FACETS)[number]['key']>>;
34
+ export {};
@@ -0,0 +1,100 @@
1
+ // The field table behind `Worksheet.model`'s round-trip.
2
+ //
3
+ // Both directions used to be hand-written statement lists, one in the getter and one in the setter,
4
+ // each enumerating the same nineteen fields. Nothing but a comment asked the next editor to touch
5
+ // both, and a field exported but not imported loses data silently — the merge-loss failure the
6
+ // model contract exists to prevent. Here each field declares both directions in one place, and the
7
+ // registry is proved exhaustive over `keyof WorksheetModel` at compile time, so adding a field
8
+ // without wiring it is an error naming the field rather than a review catch.
9
+ import { cellToModel, copyCellContent } from "./cell.js";
10
+ import { cloneConditionalFormatting } from "./conditional-formatting.js";
11
+ import { overwrite, replaceContents } from "./containers.js";
12
+ import { cloneDataValidation } from "./data-validation.js";
13
+ import { INTERNAL } from "./internal.js";
14
+ function facet(key, read, write) {
15
+ return { key, read, write: (sheet, model) => write(sheet, model[key]) };
16
+ }
17
+ /**
18
+ * Every field of a {@link WorksheetModel}, in the order a model assignment applies them. Order is
19
+ * load-bearing: cells are placed at their exact positions before any merge exists, so a covered
20
+ * cell's value lands where the model says instead of being routed to a region master mid-load.
21
+ */
22
+ export const WORKSHEET_MODEL_FACETS = [
23
+ facet('state', (sheet) => sheet.state, (sheet, value) => {
24
+ sheet.state = value;
25
+ }),
26
+ facet('tabColor', (sheet) => sheet.tabColor, (sheet, value) => {
27
+ sheet.tabColor = value;
28
+ }),
29
+ facet('properties', (sheet) => ({ ...sheet.properties }), (sheet, value) => overwrite(sheet.properties, value)),
30
+ facet('outline', (sheet) => ({ ...sheet.outline }), (sheet, value) => overwrite(sheet.outline, value)),
31
+ facet('pageSetup', (sheet) => ({ ...sheet.pageSetup }), (sheet, value) => overwrite(sheet.pageSetup, value)),
32
+ facet('printOptions', (sheet) => ({ ...sheet.printOptions }), (sheet, value) => overwrite(sheet.printOptions, value)),
33
+ facet('pageMargins', (sheet) => ({ ...sheet.pageMargins }), (sheet, value) => overwrite(sheet.pageMargins, value)),
34
+ facet('headerFooter', (sheet) => ({ ...sheet.headerFooter }), (sheet, value) => overwrite(sheet.headerFooter, value)),
35
+ facet('rowBreaks', (sheet) => sheet.rowBreaks.map((brk) => ({ ...brk })), (sheet, value) => replaceContents(sheet.rowBreaks, value.map((brk) => ({ ...brk })))),
36
+ facet('columnBreaks', (sheet) => sheet.columnBreaks.map((brk) => ({ ...brk })), (sheet, value) => replaceContents(sheet.columnBreaks, value.map((brk) => ({ ...brk })))),
37
+ facet('columns', (sheet) => [...sheet.columns()].map(({ index, properties }) => ({ index, properties: { ...properties } })), (sheet, value) => {
38
+ for (const { index, properties } of value)
39
+ Object.assign(sheet.getColumn(index), properties);
40
+ }),
41
+ facet('rows', (sheet) => {
42
+ const rows = [];
43
+ // A row appears here only for its formatting; the cells it holds are the `cells` field's
44
+ // business, and a row carrying nothing but cells has no properties to round-trip.
45
+ for (const { number, properties } of sheet.rows()) {
46
+ if (properties !== undefined)
47
+ rows.push({ number, properties: { ...properties } });
48
+ }
49
+ return rows;
50
+ }, (sheet, value) => {
51
+ for (const { number, properties } of value)
52
+ Object.assign(sheet.getRow(number), properties);
53
+ }),
54
+ facet('cells', (sheet) => {
55
+ const cells = [];
56
+ for (const row of sheet.rows())
57
+ for (const cell of row.cells)
58
+ cells.push(cellToModel(cell));
59
+ return cells;
60
+ }, (sheet, value) => {
61
+ for (const cell of value)
62
+ copyCellContent(cell, sheet[INTERNAL].cellAt(cell.row, cell.col));
63
+ }),
64
+ facet('merges', (sheet) => [...sheet.merges], (sheet, value) => {
65
+ for (const range of value)
66
+ sheet.mergeCells(range);
67
+ }),
68
+ facet('dataValidations', (sheet) => sheet.dataValidations.map(({ sqref, rule, extended }) => ({
69
+ sqref,
70
+ rule: cloneDataValidation(rule),
71
+ ...(extended ? { extended: true } : {}),
72
+ })), (sheet, value) => {
73
+ for (const { sqref, rule, extended } of value) {
74
+ sheet.addDataValidation(sqref, rule, extended ? { extended: true } : {});
75
+ }
76
+ }),
77
+ facet('conditionalFormattings', (sheet) => sheet.conditionalFormattings.map(cloneConditionalFormatting), (sheet, value) => {
78
+ for (const formatting of value)
79
+ sheet.addConditionalFormatting(formatting);
80
+ }),
81
+ facet('tables', (sheet) => sheet.tables.map((table) => table.options), (sheet, value) => {
82
+ for (const options of value)
83
+ sheet.addTable(options);
84
+ }),
85
+ facet('autoFilter', (sheet) => sheet.autoFilter,
86
+ // Through the public setter, which re-canonicalises the range and — on `undefined` — clears any
87
+ // autofilter the destination held. That clearing is why the field is applied even when absent.
88
+ (sheet, value) => {
89
+ sheet.autoFilter = value;
90
+ }),
91
+ facet('protection', (sheet) => sheet.protection,
92
+ // A loaded credential is already hashed, so it is reinstated verbatim rather than re-derived;
93
+ // `protect` cannot express that, which is why this goes through the internal channel.
94
+ (sheet, value) => {
95
+ if (value === undefined)
96
+ sheet.unprotect();
97
+ else
98
+ sheet[INTERNAL].restoreProtection(value);
99
+ }),
100
+ ];