@js-ak/excel-toolbox 1.8.2 → 1.9.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 (210) hide show
  1. package/build/cjs/lib/template/template-fs.js +2 -1
  2. package/build/cjs/lib/template/template-memory.js +2 -1
  3. package/build/cjs/lib/template/utils/column-letter-to-index.js +15 -0
  4. package/build/cjs/lib/template/utils/index.js +1 -1
  5. package/build/cjs/lib/template/utils/prepare-row-to-cells.js +2 -2
  6. package/build/cjs/lib/template/utils/validate-worksheet-xml.js +19 -9
  7. package/build/cjs/lib/utils/index.js +2 -0
  8. package/build/cjs/lib/utils/trim-and-join-multiline.js +32 -0
  9. package/build/cjs/lib/workbook-builder/default/border.js +18 -0
  10. package/build/cjs/lib/workbook-builder/default/cell-xf.js +15 -0
  11. package/build/cjs/lib/workbook-builder/default/fill.js +18 -0
  12. package/build/cjs/lib/workbook-builder/default/font.js +19 -0
  13. package/build/cjs/lib/workbook-builder/default/index.js +21 -0
  14. package/build/cjs/lib/workbook-builder/default/sheet-name.js +10 -0
  15. package/build/cjs/lib/workbook-builder/index.js +18 -0
  16. package/build/cjs/lib/workbook-builder/merge-cells/add.js +72 -0
  17. package/build/cjs/lib/workbook-builder/merge-cells/helpers/index.js +18 -0
  18. package/build/cjs/lib/workbook-builder/merge-cells/helpers/ranges-equal.js +17 -0
  19. package/build/cjs/lib/workbook-builder/merge-cells/helpers/ranges-intersect.js +17 -0
  20. package/build/cjs/lib/workbook-builder/merge-cells/index.js +18 -0
  21. package/build/cjs/lib/workbook-builder/merge-cells/remove.js +60 -0
  22. package/build/cjs/lib/workbook-builder/shared-string-ref/add.js +24 -0
  23. package/build/cjs/lib/workbook-builder/shared-string-ref/index.js +19 -0
  24. package/build/cjs/lib/workbook-builder/shared-string-ref/remove-all-from-sheet.js +66 -0
  25. package/build/cjs/lib/workbook-builder/shared-string-ref/remove.js +66 -0
  26. package/build/cjs/lib/workbook-builder/style-ref/add-or-get.js +94 -0
  27. package/build/cjs/lib/workbook-builder/style-ref/helpers/add-num-fmt.js +25 -0
  28. package/build/cjs/lib/workbook-builder/style-ref/helpers/border-to-xml.js +49 -0
  29. package/build/cjs/lib/workbook-builder/style-ref/helpers/fill-to-xml.js +51 -0
  30. package/build/cjs/lib/workbook-builder/style-ref/helpers/font-to-xml.js +112 -0
  31. package/build/cjs/lib/workbook-builder/style-ref/helpers/index.js +21 -0
  32. package/build/cjs/lib/workbook-builder/style-ref/helpers/reindex-style-map-after-removal.js +30 -0
  33. package/build/cjs/lib/workbook-builder/style-ref/index.js +19 -0
  34. package/build/cjs/lib/workbook-builder/style-ref/remove-all-from-sheet.js +26 -0
  35. package/build/cjs/lib/workbook-builder/style-ref/remove.js +52 -0
  36. package/build/cjs/lib/workbook-builder/types/app-xml-options.js +2 -0
  37. package/build/cjs/lib/workbook-builder/types/border-style.js +2 -0
  38. package/build/cjs/lib/workbook-builder/types/cell-data.js +2 -0
  39. package/build/cjs/lib/workbook-builder/types/cell-style.js +2 -0
  40. package/build/cjs/lib/workbook-builder/types/cell-type.js +2 -0
  41. package/build/cjs/lib/workbook-builder/types/cell-value.js +2 -0
  42. package/build/cjs/lib/workbook-builder/types/cell-xf.js +2 -0
  43. package/build/cjs/lib/workbook-builder/types/index.js +27 -0
  44. package/build/cjs/lib/workbook-builder/types/merge-cell.js +2 -0
  45. package/build/cjs/lib/workbook-builder/types/row-data.js +2 -0
  46. package/build/cjs/lib/workbook-builder/types/sheet-data.js +2 -0
  47. package/build/cjs/lib/workbook-builder/types/xml-node.js +2 -0
  48. package/build/cjs/lib/workbook-builder/utils/build-app-xml.js +51 -0
  49. package/build/cjs/lib/workbook-builder/utils/build-cell-children.js +59 -0
  50. package/build/cjs/lib/workbook-builder/utils/build-content-types-xml.js +42 -0
  51. package/build/cjs/lib/workbook-builder/utils/build-core-xml.js +27 -0
  52. package/build/cjs/lib/workbook-builder/utils/build-rels-xml.js +19 -0
  53. package/build/cjs/lib/workbook-builder/utils/build-shared-strings-xml.js +39 -0
  54. package/build/cjs/lib/workbook-builder/utils/build-styles-xml.js +178 -0
  55. package/build/cjs/lib/workbook-builder/utils/build-theme-xml.js +609 -0
  56. package/build/cjs/lib/workbook-builder/utils/build-workbook-rels-xml.js +58 -0
  57. package/build/cjs/lib/workbook-builder/utils/build-workbook-xml.js +26 -0
  58. package/build/cjs/lib/workbook-builder/utils/build-worksheet-xml.js +66 -0
  59. package/build/cjs/lib/workbook-builder/utils/build-xml.js +72 -0
  60. package/build/cjs/lib/workbook-builder/utils/constants.js +55 -0
  61. package/build/cjs/lib/workbook-builder/utils/date-to-excel-serial.js +16 -0
  62. package/build/cjs/lib/workbook-builder/utils/index.js +34 -0
  63. package/build/cjs/lib/workbook-builder/utils/initialize-files.js +40 -0
  64. package/build/cjs/lib/workbook-builder/utils/sheet.js +144 -0
  65. package/build/cjs/lib/workbook-builder/utils/write-shared-strings-xml.js +49 -0
  66. package/build/cjs/lib/workbook-builder/utils/write-styles-xml.js +196 -0
  67. package/build/cjs/lib/workbook-builder/utils/write-worksheet-xml.js +209 -0
  68. package/build/cjs/lib/workbook-builder/utils/write-xml.js +37 -0
  69. package/build/cjs/lib/workbook-builder/workbook-builder.js +414 -0
  70. package/build/cjs/lib/zip/utils/to-bytes.js +19 -11
  71. package/build/esm/lib/template/template-fs.js +2 -1
  72. package/build/esm/lib/template/template-memory.js +2 -1
  73. package/build/esm/lib/template/utils/column-letter-to-index.js +12 -0
  74. package/build/esm/lib/template/utils/index.js +1 -1
  75. package/build/esm/lib/template/utils/prepare-row-to-cells.js +1 -1
  76. package/build/esm/lib/template/utils/validate-worksheet-xml.js +19 -9
  77. package/build/esm/lib/utils/index.js +2 -0
  78. package/build/esm/lib/utils/trim-and-join-multiline.js +29 -0
  79. package/build/esm/lib/workbook-builder/default/border.js +14 -0
  80. package/build/esm/lib/workbook-builder/default/cell-xf.js +11 -0
  81. package/build/esm/lib/workbook-builder/default/fill.js +14 -0
  82. package/build/esm/lib/workbook-builder/default/font.js +15 -0
  83. package/build/esm/lib/workbook-builder/default/index.js +5 -0
  84. package/build/esm/lib/workbook-builder/default/sheet-name.js +6 -0
  85. package/build/esm/lib/workbook-builder/index.js +2 -0
  86. package/build/esm/lib/workbook-builder/merge-cells/add.js +36 -0
  87. package/build/esm/lib/workbook-builder/merge-cells/helpers/index.js +2 -0
  88. package/build/esm/lib/workbook-builder/merge-cells/helpers/ranges-equal.js +14 -0
  89. package/build/esm/lib/workbook-builder/merge-cells/helpers/ranges-intersect.js +14 -0
  90. package/build/esm/lib/workbook-builder/merge-cells/index.js +2 -0
  91. package/build/esm/lib/workbook-builder/merge-cells/remove.js +24 -0
  92. package/build/esm/lib/workbook-builder/shared-string-ref/add.js +21 -0
  93. package/build/esm/lib/workbook-builder/shared-string-ref/index.js +3 -0
  94. package/build/esm/lib/workbook-builder/shared-string-ref/remove-all-from-sheet.js +63 -0
  95. package/build/esm/lib/workbook-builder/shared-string-ref/remove.js +63 -0
  96. package/build/esm/lib/workbook-builder/style-ref/add-or-get.js +58 -0
  97. package/build/esm/lib/workbook-builder/style-ref/helpers/add-num-fmt.js +21 -0
  98. package/build/esm/lib/workbook-builder/style-ref/helpers/border-to-xml.js +45 -0
  99. package/build/esm/lib/workbook-builder/style-ref/helpers/fill-to-xml.js +47 -0
  100. package/build/esm/lib/workbook-builder/style-ref/helpers/font-to-xml.js +75 -0
  101. package/build/esm/lib/workbook-builder/style-ref/helpers/index.js +5 -0
  102. package/build/esm/lib/workbook-builder/style-ref/helpers/reindex-style-map-after-removal.js +26 -0
  103. package/build/esm/lib/workbook-builder/style-ref/index.js +3 -0
  104. package/build/esm/lib/workbook-builder/style-ref/remove-all-from-sheet.js +23 -0
  105. package/build/esm/lib/workbook-builder/style-ref/remove.js +49 -0
  106. package/build/esm/lib/workbook-builder/types/app-xml-options.js +1 -0
  107. package/build/esm/lib/workbook-builder/types/border-style.js +1 -0
  108. package/build/esm/lib/workbook-builder/types/cell-data.js +1 -0
  109. package/build/esm/lib/workbook-builder/types/cell-style.js +1 -0
  110. package/build/esm/lib/workbook-builder/types/cell-type.js +1 -0
  111. package/build/esm/lib/workbook-builder/types/cell-value.js +1 -0
  112. package/build/esm/lib/workbook-builder/types/cell-xf.js +1 -0
  113. package/build/esm/lib/workbook-builder/types/index.js +11 -0
  114. package/build/esm/lib/workbook-builder/types/merge-cell.js +1 -0
  115. package/build/esm/lib/workbook-builder/types/row-data.js +1 -0
  116. package/build/esm/lib/workbook-builder/types/sheet-data.js +1 -0
  117. package/build/esm/lib/workbook-builder/types/xml-node.js +1 -0
  118. package/build/esm/lib/workbook-builder/utils/build-app-xml.js +48 -0
  119. package/build/esm/lib/workbook-builder/utils/build-cell-children.js +56 -0
  120. package/build/esm/lib/workbook-builder/utils/build-content-types-xml.js +39 -0
  121. package/build/esm/lib/workbook-builder/utils/build-core-xml.js +24 -0
  122. package/build/esm/lib/workbook-builder/utils/build-rels-xml.js +16 -0
  123. package/build/esm/lib/workbook-builder/utils/build-shared-strings-xml.js +36 -0
  124. package/build/esm/lib/workbook-builder/utils/build-styles-xml.js +142 -0
  125. package/build/esm/lib/workbook-builder/utils/build-theme-xml.js +606 -0
  126. package/build/esm/lib/workbook-builder/utils/build-workbook-rels-xml.js +55 -0
  127. package/build/esm/lib/workbook-builder/utils/build-workbook-xml.js +23 -0
  128. package/build/esm/lib/workbook-builder/utils/build-worksheet-xml.js +63 -0
  129. package/build/esm/lib/workbook-builder/utils/build-xml.js +69 -0
  130. package/build/esm/lib/workbook-builder/utils/constants.js +52 -0
  131. package/build/esm/lib/workbook-builder/utils/date-to-excel-serial.js +13 -0
  132. package/build/esm/lib/workbook-builder/utils/index.js +18 -0
  133. package/build/esm/lib/workbook-builder/utils/initialize-files.js +36 -0
  134. package/build/esm/lib/workbook-builder/utils/sheet.js +141 -0
  135. package/build/esm/lib/workbook-builder/utils/write-shared-strings-xml.js +43 -0
  136. package/build/esm/lib/workbook-builder/utils/write-styles-xml.js +157 -0
  137. package/build/esm/lib/workbook-builder/utils/write-worksheet-xml.js +203 -0
  138. package/build/esm/lib/workbook-builder/utils/write-xml.js +34 -0
  139. package/build/esm/lib/workbook-builder/workbook-builder.js +374 -0
  140. package/build/esm/lib/zip/utils/to-bytes.js +19 -11
  141. package/build/types/lib/template/utils/column-letter-to-index.d.ts +1 -0
  142. package/build/types/lib/template/utils/index.d.ts +1 -1
  143. package/build/types/lib/utils/index.d.ts +2 -0
  144. package/build/types/lib/utils/trim-and-join-multiline.d.ts +23 -0
  145. package/build/types/lib/workbook-builder/default/border.d.ts +7 -0
  146. package/build/types/lib/workbook-builder/default/cell-xf.d.ts +7 -0
  147. package/build/types/lib/workbook-builder/default/fill.d.ts +7 -0
  148. package/build/types/lib/workbook-builder/default/font.d.ts +21 -0
  149. package/build/types/lib/workbook-builder/default/index.d.ts +5 -0
  150. package/build/types/lib/workbook-builder/default/sheet-name.d.ts +6 -0
  151. package/build/types/lib/workbook-builder/index.d.ts +2 -0
  152. package/build/types/lib/workbook-builder/merge-cells/add.d.ts +15 -0
  153. package/build/types/lib/workbook-builder/merge-cells/helpers/index.d.ts +2 -0
  154. package/build/types/lib/workbook-builder/merge-cells/helpers/ranges-equal.d.ts +10 -0
  155. package/build/types/lib/workbook-builder/merge-cells/helpers/ranges-intersect.d.ts +10 -0
  156. package/build/types/lib/workbook-builder/merge-cells/index.d.ts +2 -0
  157. package/build/types/lib/workbook-builder/merge-cells/remove.d.ts +15 -0
  158. package/build/types/lib/workbook-builder/shared-string-ref/add.d.ts +13 -0
  159. package/build/types/lib/workbook-builder/shared-string-ref/index.d.ts +3 -0
  160. package/build/types/lib/workbook-builder/shared-string-ref/remove-all-from-sheet.d.ts +10 -0
  161. package/build/types/lib/workbook-builder/shared-string-ref/remove.d.ts +13 -0
  162. package/build/types/lib/workbook-builder/style-ref/add-or-get.d.ts +16 -0
  163. package/build/types/lib/workbook-builder/style-ref/helpers/add-num-fmt.d.ts +17 -0
  164. package/build/types/lib/workbook-builder/style-ref/helpers/border-to-xml.d.ts +16 -0
  165. package/build/types/lib/workbook-builder/style-ref/helpers/fill-to-xml.d.ts +17 -0
  166. package/build/types/lib/workbook-builder/style-ref/helpers/font-to-xml.d.ts +18 -0
  167. package/build/types/lib/workbook-builder/style-ref/helpers/index.d.ts +5 -0
  168. package/build/types/lib/workbook-builder/style-ref/helpers/reindex-style-map-after-removal.d.ts +15 -0
  169. package/build/types/lib/workbook-builder/style-ref/index.d.ts +3 -0
  170. package/build/types/lib/workbook-builder/style-ref/remove-all-from-sheet.d.ts +4 -0
  171. package/build/types/lib/workbook-builder/style-ref/remove.d.ts +18 -0
  172. package/build/types/lib/workbook-builder/types/app-xml-options.d.ts +9 -0
  173. package/build/types/lib/workbook-builder/types/border-style.d.ts +5 -0
  174. package/build/types/lib/workbook-builder/types/cell-data.d.ts +10 -0
  175. package/build/types/lib/workbook-builder/types/cell-style.d.ts +32 -0
  176. package/build/types/lib/workbook-builder/types/cell-type.d.ts +11 -0
  177. package/build/types/lib/workbook-builder/types/cell-value.d.ts +2 -0
  178. package/build/types/lib/workbook-builder/types/cell-xf.d.ts +13 -0
  179. package/build/types/lib/workbook-builder/types/index.d.ts +11 -0
  180. package/build/types/lib/workbook-builder/types/merge-cell.d.ts +6 -0
  181. package/build/types/lib/workbook-builder/types/row-data.d.ts +5 -0
  182. package/build/types/lib/workbook-builder/types/sheet-data.d.ts +13 -0
  183. package/build/types/lib/workbook-builder/types/xml-node.d.ts +11 -0
  184. package/build/types/lib/workbook-builder/utils/build-app-xml.d.ts +2 -0
  185. package/build/types/lib/workbook-builder/utils/build-cell-children.d.ts +9 -0
  186. package/build/types/lib/workbook-builder/utils/build-content-types-xml.d.ts +1 -0
  187. package/build/types/lib/workbook-builder/utils/build-core-xml.d.ts +1 -0
  188. package/build/types/lib/workbook-builder/utils/build-rels-xml.d.ts +1 -0
  189. package/build/types/lib/workbook-builder/utils/build-shared-strings-xml.d.ts +10 -0
  190. package/build/types/lib/workbook-builder/utils/build-styles-xml.d.ts +23 -0
  191. package/build/types/lib/workbook-builder/utils/build-theme-xml.d.ts +1 -0
  192. package/build/types/lib/workbook-builder/utils/build-workbook-rels-xml.d.ts +9 -0
  193. package/build/types/lib/workbook-builder/utils/build-workbook-xml.d.ts +3 -0
  194. package/build/types/lib/workbook-builder/utils/build-worksheet-xml.d.ts +2 -0
  195. package/build/types/lib/workbook-builder/utils/build-xml.d.ts +50 -0
  196. package/build/types/lib/workbook-builder/utils/constants.d.ts +47 -0
  197. package/build/types/lib/workbook-builder/utils/date-to-excel-serial.d.ts +9 -0
  198. package/build/types/lib/workbook-builder/utils/index.d.ts +18 -0
  199. package/build/types/lib/workbook-builder/utils/initialize-files.d.ts +13 -0
  200. package/build/types/lib/workbook-builder/utils/sheet.d.ts +21 -0
  201. package/build/types/lib/workbook-builder/utils/write-shared-strings-xml.d.ts +11 -0
  202. package/build/types/lib/workbook-builder/utils/write-styles-xml.d.ts +24 -0
  203. package/build/types/lib/workbook-builder/utils/write-worksheet-xml.d.ts +14 -0
  204. package/build/types/lib/workbook-builder/utils/write-xml.d.ts +3 -0
  205. package/build/types/lib/workbook-builder/workbook-builder.d.ts +110 -0
  206. package/build/types/lib/zip/utils/to-bytes.d.ts +2 -2
  207. package/package.json +4 -2
  208. /package/build/cjs/lib/{template/utils → utils}/escape-xml.js +0 -0
  209. /package/build/esm/lib/{template/utils → utils}/escape-xml.js +0 -0
  210. /package/build/types/lib/{template/utils → utils}/escape-xml.d.ts +0 -0
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildAppXml = buildAppXml;
4
+ const constants_js_1 = require("./constants.js");
5
+ const build_xml_js_1 = require("./build-xml.js");
6
+ function buildAppXml({ appVersion = "16.0300", application = "Microsoft Excel", company = "", hyperlinksChanged = false, linksUpToDate = false, sharedDoc = false, sheetNames = ["Sheet1"], } = {}) {
7
+ const app = {
8
+ attrs: {
9
+ xmlns: constants_js_1.XML_NAMESPACES.EXTENDED_PROPERTIES,
10
+ "xmlns:vt": constants_js_1.XML_NAMESPACES.DOC_PROPS_VTYPES,
11
+ },
12
+ children: [
13
+ { children: [application], tag: "Application" },
14
+ { children: ["0"], tag: "DocSecurity" },
15
+ { children: ["false"], tag: "ScaleCrop" },
16
+ {
17
+ children: [
18
+ {
19
+ attrs: { baseType: "variant", size: "2" },
20
+ children: [
21
+ { children: [{ children: ["Worksheets"], tag: "vt:lpstr" }], tag: "vt:variant" },
22
+ { children: [{ children: [String(sheetNames.length)], tag: "vt:i4" }], tag: "vt:variant" },
23
+ ],
24
+ tag: "vt:vector",
25
+ },
26
+ ],
27
+ tag: "HeadingPairs",
28
+ },
29
+ {
30
+ children: [
31
+ {
32
+ attrs: { baseType: "lpstr", size: String(sheetNames.length) },
33
+ children: sheetNames.map((name) => ({ children: [name], tag: "vt:lpstr" })),
34
+ tag: "vt:vector",
35
+ },
36
+ ],
37
+ tag: "TitlesOfParts",
38
+ },
39
+ { children: [company], tag: "Company" },
40
+ { children: [String(linksUpToDate)], tag: "LinksUpToDate" },
41
+ { children: [String(sharedDoc)], tag: "SharedDoc" },
42
+ { children: [String(hyperlinksChanged)], tag: "HyperlinksChanged" },
43
+ { children: [appVersion], tag: "AppVersion" },
44
+ ],
45
+ tag: "Properties",
46
+ };
47
+ return [
48
+ constants_js_1.XML_DECLARATION,
49
+ (0, build_xml_js_1.buildXml)(app),
50
+ ].join("\n");
51
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCellChildren = buildCellChildren;
4
+ /**
5
+ * Builds XML children nodes for a cell based on its type and value.
6
+ *
7
+ * @param cell - The cell data containing value and type information
8
+ *
9
+ * @returns Array of XML nodes representing the cell's content structure
10
+ */
11
+ function buildCellChildren(cell) {
12
+ if (cell.value === undefined) {
13
+ return [];
14
+ }
15
+ if (cell.isFormula) {
16
+ return [
17
+ {
18
+ children: [String(cell.value)],
19
+ tag: "f",
20
+ },
21
+ ];
22
+ }
23
+ switch (cell.type) {
24
+ case "b": {
25
+ return [
26
+ {
27
+ children: [cell.value ? "1" : "0"],
28
+ tag: "v",
29
+ },
30
+ ];
31
+ }
32
+ case "inlineStr": {
33
+ // For inlineStr, wrap value in <is><t>value</t></is>
34
+ return [
35
+ {
36
+ children: [
37
+ {
38
+ children: [String(cell.value)],
39
+ tag: "t",
40
+ },
41
+ ],
42
+ tag: "is",
43
+ },
44
+ ];
45
+ }
46
+ case "s":
47
+ case "n":
48
+ case "str":
49
+ case "e":
50
+ default: {
51
+ return [
52
+ {
53
+ children: [String(cell.value)],
54
+ tag: "v",
55
+ },
56
+ ];
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildContentTypesXml = buildContentTypesXml;
4
+ const constants_js_1 = require("./constants.js");
5
+ const build_xml_js_1 = require("./build-xml.js");
6
+ function buildContentTypesXml(sheetsCount) {
7
+ const defaults = [
8
+ { ContentType: constants_js_1.CONTENT_TYPES.RELATIONSHIPS, Extension: "rels" },
9
+ { ContentType: constants_js_1.CONTENT_TYPES.XML, Extension: "xml" },
10
+ ].map(({ ContentType, Extension }) => ({
11
+ attrs: { ContentType, Extension },
12
+ tag: "Default",
13
+ }));
14
+ const overrides = [
15
+ { ContentType: constants_js_1.CONTENT_TYPES.THEME, PartName: "/xl/theme/theme1.xml" },
16
+ { ContentType: constants_js_1.CONTENT_TYPES.WORKBOOK, PartName: "/xl/workbook.xml" },
17
+ { ContentType: constants_js_1.CONTENT_TYPES.STYLES, PartName: "/xl/styles.xml" },
18
+ { ContentType: constants_js_1.CONTENT_TYPES.CORE, PartName: "/docProps/core.xml" },
19
+ { ContentType: constants_js_1.CONTENT_TYPES.APP, PartName: "/docProps/app.xml" },
20
+ { ContentType: constants_js_1.CONTENT_TYPES.SHARED_STRINGS, PartName: "/xl/sharedStrings.xml" },
21
+ ].map(({ ContentType, PartName }) => ({
22
+ attrs: { ContentType, PartName },
23
+ tag: "Override",
24
+ }));
25
+ for (let i = 1; i <= sheetsCount; i++) {
26
+ overrides.push({
27
+ attrs: {
28
+ ContentType: constants_js_1.CONTENT_TYPES.WORKSHEET,
29
+ PartName: `/xl/worksheets/sheet${i}.xml`,
30
+ },
31
+ tag: "Override",
32
+ });
33
+ }
34
+ return [
35
+ constants_js_1.XML_DECLARATION,
36
+ (0, build_xml_js_1.buildXml)({
37
+ attrs: { xmlns: constants_js_1.XML_NAMESPACES.CONTENT_TYPES },
38
+ children: [...defaults, ...overrides],
39
+ tag: "Types",
40
+ }),
41
+ ].join("\n");
42
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCoreXml = buildCoreXml;
4
+ const constants_js_1 = require("./constants.js");
5
+ const build_xml_js_1 = require("./build-xml.js");
6
+ function buildCoreXml(creator = "Excel Generator", lastModifiedBy = "Excel Generator", created = "2025-01-01T00:00:00Z", modified = "2025-01-01T00:00:00Z") {
7
+ const coreProps = {
8
+ attrs: {
9
+ "xmlns:cp": constants_js_1.XML_NAMESPACES.CORE_PROPERTIES,
10
+ "xmlns:dc": constants_js_1.XML_NAMESPACES.DC,
11
+ "xmlns:dcmitype": constants_js_1.XML_NAMESPACES.DCMITYPE,
12
+ "xmlns:dcterms": constants_js_1.XML_NAMESPACES.DCTERMS,
13
+ "xmlns:xsi": constants_js_1.XML_NAMESPACES.XSI,
14
+ },
15
+ children: [
16
+ { children: [creator], tag: "dc:creator" },
17
+ { children: [lastModifiedBy], tag: "cp:lastModifiedBy" },
18
+ { attrs: { "xsi:type": "dcterms:W3CDTF" }, children: [created], tag: "dcterms:created" },
19
+ { attrs: { "xsi:type": "dcterms:W3CDTF" }, children: [modified], tag: "dcterms:modified" },
20
+ ],
21
+ tag: "cp:coreProperties",
22
+ };
23
+ return [
24
+ constants_js_1.XML_DECLARATION,
25
+ (0, build_xml_js_1.buildXml)(coreProps),
26
+ ].join("\n");
27
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRelsXml = buildRelsXml;
4
+ const constants_js_1 = require("./constants.js");
5
+ const build_xml_js_1 = require("./build-xml.js");
6
+ function buildRelsXml() {
7
+ return [
8
+ constants_js_1.XML_DECLARATION,
9
+ (0, build_xml_js_1.buildXml)({
10
+ attrs: { xmlns: constants_js_1.XML_NAMESPACES.PACKAGE_RELATIONSHIPS },
11
+ children: [
12
+ { attrs: { Id: "rId1", Target: "xl/workbook.xml", Type: constants_js_1.RELATIONSHIP_TYPES.OFFICE_DOCUMENT }, tag: "Relationship" },
13
+ { attrs: { Id: "rId2", Target: "docProps/core.xml", Type: constants_js_1.RELATIONSHIP_TYPES.CORE }, tag: "Relationship" },
14
+ { attrs: { Id: "rId3", Target: "docProps/app.xml", Type: constants_js_1.RELATIONSHIP_TYPES.APP }, tag: "Relationship" },
15
+ ],
16
+ tag: "Relationships",
17
+ }),
18
+ ].join("\n");
19
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSharedStringsXml = buildSharedStringsXml;
4
+ const index_js_1 = require("../../utils/index.js");
5
+ const constants_js_1 = require("./constants.js");
6
+ const build_xml_js_1 = require("./build-xml.js");
7
+ /**
8
+ * Builds the `sharedStrings.xml` content from the provided strings.
9
+ *
10
+ * Note: According to the Excel specification, leading/trailing spaces in text
11
+ * nodes must set the attribute `xml:space="preserve"` on the corresponding <t>.
12
+ *
13
+ * @param strings - Array of unique strings used in the workbook
14
+ * @returns XML string for the shared strings part
15
+ */
16
+ function buildSharedStringsXml(strings = []) {
17
+ return [
18
+ constants_js_1.XML_DECLARATION,
19
+ (0, build_xml_js_1.buildXml)({
20
+ attrs: {
21
+ count: String(strings.length),
22
+ uniqueCount: String(strings.length),
23
+ xmlns: constants_js_1.XML_NAMESPACES.SPREADSHEET_ML,
24
+ },
25
+ children: strings.map((s) => ({
26
+ children: [
27
+ {
28
+ // Excel spec: leading/trailing spaces require xml:space="preserve"
29
+ attrs: /^\s|\s$/.test(s) ? { "xml:space": "preserve" } : undefined,
30
+ children: [(0, index_js_1.escapeXml)(s)],
31
+ tag: "t",
32
+ },
33
+ ],
34
+ tag: "si",
35
+ })),
36
+ tag: "sst",
37
+ }),
38
+ ].join("\n");
39
+ }
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.buildStylesXml = buildStylesXml;
37
+ const Default = __importStar(require("../default/index.js"));
38
+ const constants_js_1 = require("./constants.js");
39
+ const build_xml_js_1 = require("./build-xml.js");
40
+ /**
41
+ * Builds the `styles.xml` part for the workbook based on provided style collections.
42
+ * Falls back to default font/fill/border collections when none are provided.
43
+ *
44
+ * @param data - Style collections used to construct the stylesheet
45
+ * @param data.borders - Array of border XmlNodes
46
+ * @param data.cellXfs - Array of cell format records
47
+ * @param data.fills - Array of fill XmlNodes
48
+ * @param data.fonts - Array of font XmlNodes
49
+ * @param data.numFmts - Array of custom number formats (formatCode and id)
50
+ * @returns XML string for the styles part
51
+ */
52
+ function buildStylesXml(data) {
53
+ const { borders = [], cellXfs = [], fills = [], fonts = [], numFmts = [], } = data || {};
54
+ const children = [];
55
+ if (numFmts.length) {
56
+ children.push({
57
+ attrs: { count: String(numFmts.length) },
58
+ children: numFmts.map(nf => ({
59
+ attrs: {
60
+ formatCode: nf.formatCode,
61
+ numFmtId: String(nf.id),
62
+ },
63
+ tag: "numFmt",
64
+ })),
65
+ tag: "numFmts",
66
+ });
67
+ }
68
+ if (fonts.length) {
69
+ children.push({
70
+ attrs: { count: String(fonts.length) },
71
+ children: fonts,
72
+ tag: "fonts",
73
+ });
74
+ }
75
+ else {
76
+ children.push({
77
+ attrs: { count: "1" },
78
+ children: [Default.font()],
79
+ tag: "fonts",
80
+ });
81
+ }
82
+ if (fills.length) {
83
+ children.push({
84
+ attrs: { count: String(fills.length) },
85
+ children: fills,
86
+ tag: "fills",
87
+ });
88
+ }
89
+ else {
90
+ children.push({
91
+ attrs: { count: "1" },
92
+ children: [Default.fill()],
93
+ tag: "fills",
94
+ });
95
+ }
96
+ if (borders.length) {
97
+ children.push({
98
+ attrs: { count: String(borders.length) },
99
+ children: borders,
100
+ tag: "borders",
101
+ });
102
+ }
103
+ else {
104
+ children.push({
105
+ attrs: { count: "1" },
106
+ children: [Default.border()],
107
+ tag: "borders",
108
+ });
109
+ }
110
+ children.push({
111
+ attrs: { count: "1" },
112
+ children: [{
113
+ attrs: { borderId: "0", fillId: "0", fontId: "0", numFmtId: "0" },
114
+ tag: "xf",
115
+ }],
116
+ tag: "cellStyleXfs",
117
+ });
118
+ if (cellXfs.length) {
119
+ children.push({
120
+ attrs: { count: String(cellXfs.length) },
121
+ children: cellXfs.map((xf, i) => {
122
+ const isBaseXf = i === 0;
123
+ const hasAlignment = !!xf.alignment;
124
+ const xfChildren = [];
125
+ if (hasAlignment) {
126
+ xfChildren.push({
127
+ attrs: {
128
+ ...(xf.alignment?.horizontal ? { horizontal: xf.alignment.horizontal } : {}),
129
+ ...(xf.alignment?.vertical ? { vertical: xf.alignment.vertical } : {}),
130
+ ...(xf.alignment?.wrapText ? { wrapText: "1" } : {}),
131
+ ...(xf.alignment?.indent !== undefined ? { indent: String(xf.alignment.indent) } : {}),
132
+ },
133
+ tag: "alignment",
134
+ });
135
+ }
136
+ return {
137
+ attrs: {
138
+ ...(isBaseXf
139
+ ? {}
140
+ : {
141
+ applyBorder: "1",
142
+ applyFill: "1",
143
+ applyFont: "1",
144
+ applyNumberFormat: xf.numFmtId ? "1" : "0",
145
+ }),
146
+ ...(hasAlignment ? { applyAlignment: "1" } : {}),
147
+ borderId: String(xf.borderId),
148
+ fillId: String(xf.fillId),
149
+ fontId: String(xf.fontId),
150
+ numFmtId: String(xf.numFmtId ?? 0),
151
+ xfId: "0",
152
+ },
153
+ children: xfChildren,
154
+ tag: "xf",
155
+ };
156
+ }),
157
+ tag: "cellXfs",
158
+ });
159
+ }
160
+ else {
161
+ // Base style without fill
162
+ children.push({
163
+ attrs: { count: "1" },
164
+ children: [
165
+ { attrs: { borderId: "0", fillId: "0", fontId: "0", numFmtId: "0", xfId: "0" }, tag: "xf" },
166
+ ],
167
+ tag: "cellXfs",
168
+ });
169
+ }
170
+ return [
171
+ constants_js_1.XML_DECLARATION,
172
+ (0, build_xml_js_1.buildXml)({
173
+ attrs: { xmlns: constants_js_1.XML_NAMESPACES.SPREADSHEET_ML },
174
+ children,
175
+ tag: "styleSheet",
176
+ }),
177
+ ].join("\n");
178
+ }