@bilig/excel-import 0.14.14

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 (198) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +165 -0
  3. package/dist/index.d.ts +31 -0
  4. package/dist/index.js +748 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/workbook-import-content-types.d.ts +10 -0
  7. package/dist/workbook-import-content-types.js +30 -0
  8. package/dist/workbook-import-content-types.js.map +1 -0
  9. package/dist/workbook-import-helpers.d.ts +21 -0
  10. package/dist/workbook-import-helpers.js +77 -0
  11. package/dist/workbook-import-helpers.js.map +1 -0
  12. package/dist/workbook-import-preview.d.ts +19 -0
  13. package/dist/workbook-import-preview.js +12 -0
  14. package/dist/workbook-import-preview.js.map +1 -0
  15. package/dist/xlsx-array-formulas.d.ts +6 -0
  16. package/dist/xlsx-array-formulas.js +186 -0
  17. package/dist/xlsx-array-formulas.js.map +1 -0
  18. package/dist/xlsx-axis-entries.d.ts +3 -0
  19. package/dist/xlsx-axis-entries.js +90 -0
  20. package/dist/xlsx-axis-entries.js.map +1 -0
  21. package/dist/xlsx-calculation-settings.d.ts +9 -0
  22. package/dist/xlsx-calculation-settings.js +198 -0
  23. package/dist/xlsx-calculation-settings.js.map +1 -0
  24. package/dist/xlsx-cell-insertion.d.ts +11 -0
  25. package/dist/xlsx-cell-insertion.js +164 -0
  26. package/dist/xlsx-cell-insertion.js.map +1 -0
  27. package/dist/xlsx-cell-metadata.d.ts +15 -0
  28. package/dist/xlsx-cell-metadata.js +380 -0
  29. package/dist/xlsx-cell-metadata.js.map +1 -0
  30. package/dist/xlsx-chart-artifacts.d.ts +7 -0
  31. package/dist/xlsx-chart-artifacts.js +327 -0
  32. package/dist/xlsx-chart-artifacts.js.map +1 -0
  33. package/dist/xlsx-charts.d.ts +4 -0
  34. package/dist/xlsx-charts.js +671 -0
  35. package/dist/xlsx-charts.js.map +1 -0
  36. package/dist/xlsx-comment-vml.d.ts +11 -0
  37. package/dist/xlsx-comment-vml.js +292 -0
  38. package/dist/xlsx-comment-vml.js.map +1 -0
  39. package/dist/xlsx-comments.d.ts +7 -0
  40. package/dist/xlsx-comments.js +120 -0
  41. package/dist/xlsx-comments.js.map +1 -0
  42. package/dist/xlsx-conditional-formats.d.ts +5 -0
  43. package/dist/xlsx-conditional-formats.js +513 -0
  44. package/dist/xlsx-conditional-formats.js.map +1 -0
  45. package/dist/xlsx-control-artifacts.d.ts +7 -0
  46. package/dist/xlsx-control-artifacts.js +404 -0
  47. package/dist/xlsx-control-artifacts.js.map +1 -0
  48. package/dist/xlsx-data-model-artifacts.d.ts +4 -0
  49. package/dist/xlsx-data-model-artifacts.js +240 -0
  50. package/dist/xlsx-data-model-artifacts.js.map +1 -0
  51. package/dist/xlsx-data-table-formulas.d.ts +4 -0
  52. package/dist/xlsx-data-table-formulas.js +138 -0
  53. package/dist/xlsx-data-table-formulas.js.map +1 -0
  54. package/dist/xlsx-defined-names.d.ts +7 -0
  55. package/dist/xlsx-defined-names.js +292 -0
  56. package/dist/xlsx-defined-names.js.map +1 -0
  57. package/dist/xlsx-dimensions.d.ts +4 -0
  58. package/dist/xlsx-dimensions.js +495 -0
  59. package/dist/xlsx-dimensions.js.map +1 -0
  60. package/dist/xlsx-drawing-artifacts.d.ts +7 -0
  61. package/dist/xlsx-drawing-artifacts.js +477 -0
  62. package/dist/xlsx-drawing-artifacts.js.map +1 -0
  63. package/dist/xlsx-escaped-text.d.ts +2 -0
  64. package/dist/xlsx-escaped-text.js +22 -0
  65. package/dist/xlsx-escaped-text.js.map +1 -0
  66. package/dist/xlsx-export-xml.d.ts +8 -0
  67. package/dist/xlsx-export-xml.js +99 -0
  68. package/dist/xlsx-export-xml.js.map +1 -0
  69. package/dist/xlsx-export.d.ts +2 -0
  70. package/dist/xlsx-export.js +800 -0
  71. package/dist/xlsx-export.js.map +1 -0
  72. package/dist/xlsx-external-link-artifacts.d.ts +4 -0
  73. package/dist/xlsx-external-link-artifacts.js +317 -0
  74. package/dist/xlsx-external-link-artifacts.js.map +1 -0
  75. package/dist/xlsx-external-references.d.ts +29 -0
  76. package/dist/xlsx-external-references.js +356 -0
  77. package/dist/xlsx-external-references.js.map +1 -0
  78. package/dist/xlsx-filters.d.ts +4 -0
  79. package/dist/xlsx-filters.js +273 -0
  80. package/dist/xlsx-filters.js.map +1 -0
  81. package/dist/xlsx-formula-translation.d.ts +10 -0
  82. package/dist/xlsx-formula-translation.js +391 -0
  83. package/dist/xlsx-formula-translation.js.map +1 -0
  84. package/dist/xlsx-formulas.d.ts +2 -0
  85. package/dist/xlsx-formulas.js +136 -0
  86. package/dist/xlsx-formulas.js.map +1 -0
  87. package/dist/xlsx-freeze-panes.d.ts +4 -0
  88. package/dist/xlsx-freeze-panes.js +206 -0
  89. package/dist/xlsx-freeze-panes.js.map +1 -0
  90. package/dist/xlsx-hyperlinks.d.ts +5 -0
  91. package/dist/xlsx-hyperlinks.js +64 -0
  92. package/dist/xlsx-hyperlinks.js.map +1 -0
  93. package/dist/xlsx-ignored-errors.d.ts +4 -0
  94. package/dist/xlsx-ignored-errors.js +106 -0
  95. package/dist/xlsx-ignored-errors.js.map +1 -0
  96. package/dist/xlsx-import-cell-styles.d.ts +8 -0
  97. package/dist/xlsx-import-cell-styles.js +255 -0
  98. package/dist/xlsx-import-cell-styles.js.map +1 -0
  99. package/dist/xlsx-import-sheet-metadata.d.ts +40 -0
  100. package/dist/xlsx-import-sheet-metadata.js +41 -0
  101. package/dist/xlsx-import-sheet-metadata.js.map +1 -0
  102. package/dist/xlsx-import-warnings.d.ts +8 -0
  103. package/dist/xlsx-import-warnings.js +44 -0
  104. package/dist/xlsx-import-warnings.js.map +1 -0
  105. package/dist/xlsx-import-workbook-metadata.d.ts +28 -0
  106. package/dist/xlsx-import-workbook-metadata.js +29 -0
  107. package/dist/xlsx-import-workbook-metadata.js.map +1 -0
  108. package/dist/xlsx-macros.d.ts +10 -0
  109. package/dist/xlsx-macros.js +63 -0
  110. package/dist/xlsx-macros.js.map +1 -0
  111. package/dist/xlsx-merge-entries.d.ts +3 -0
  112. package/dist/xlsx-merge-entries.js +17 -0
  113. package/dist/xlsx-merge-entries.js.map +1 -0
  114. package/dist/xlsx-number-formats.d.ts +7 -0
  115. package/dist/xlsx-number-formats.js +222 -0
  116. package/dist/xlsx-number-formats.js.map +1 -0
  117. package/dist/xlsx-pivot-artifacts.d.ts +29 -0
  118. package/dist/xlsx-pivot-artifacts.js +292 -0
  119. package/dist/xlsx-pivot-artifacts.js.map +1 -0
  120. package/dist/xlsx-pivots.d.ts +10 -0
  121. package/dist/xlsx-pivots.js +589 -0
  122. package/dist/xlsx-pivots.js.map +1 -0
  123. package/dist/xlsx-print-page-setup.d.ts +6 -0
  124. package/dist/xlsx-print-page-setup.js +224 -0
  125. package/dist/xlsx-print-page-setup.js.map +1 -0
  126. package/dist/xlsx-printer-settings.d.ts +4 -0
  127. package/dist/xlsx-printer-settings.js +279 -0
  128. package/dist/xlsx-printer-settings.js.map +1 -0
  129. package/dist/xlsx-protected-ranges.d.ts +4 -0
  130. package/dist/xlsx-protected-ranges.js +183 -0
  131. package/dist/xlsx-protected-ranges.js.map +1 -0
  132. package/dist/xlsx-rich-text-artifacts.d.ts +4 -0
  133. package/dist/xlsx-rich-text-artifacts.js +303 -0
  134. package/dist/xlsx-rich-text-artifacts.js.map +1 -0
  135. package/dist/xlsx-sheet-properties.d.ts +4 -0
  136. package/dist/xlsx-sheet-properties.js +89 -0
  137. package/dist/xlsx-sheet-properties.js.map +1 -0
  138. package/dist/xlsx-sheet-protection.d.ts +4 -0
  139. package/dist/xlsx-sheet-protection.js +153 -0
  140. package/dist/xlsx-sheet-protection.js.map +1 -0
  141. package/dist/xlsx-sheet-visibility.d.ts +4 -0
  142. package/dist/xlsx-sheet-visibility.js +53 -0
  143. package/dist/xlsx-sheet-visibility.js.map +1 -0
  144. package/dist/xlsx-slicer-connection-artifacts.d.ts +4 -0
  145. package/dist/xlsx-slicer-connection-artifacts.js +426 -0
  146. package/dist/xlsx-slicer-connection-artifacts.js.map +1 -0
  147. package/dist/xlsx-sorts.d.ts +5 -0
  148. package/dist/xlsx-sorts.js +216 -0
  149. package/dist/xlsx-sorts.js.map +1 -0
  150. package/dist/xlsx-sparklines.d.ts +4 -0
  151. package/dist/xlsx-sparklines.js +115 -0
  152. package/dist/xlsx-sparklines.js.map +1 -0
  153. package/dist/xlsx-style-only-blank-cells.d.ts +3 -0
  154. package/dist/xlsx-style-only-blank-cells.js +96 -0
  155. package/dist/xlsx-style-only-blank-cells.js.map +1 -0
  156. package/dist/xlsx-style-runs.d.ts +12 -0
  157. package/dist/xlsx-style-runs.js +35 -0
  158. package/dist/xlsx-style-runs.js.map +1 -0
  159. package/dist/xlsx-styles.d.ts +25 -0
  160. package/dist/xlsx-styles.js +857 -0
  161. package/dist/xlsx-styles.js.map +1 -0
  162. package/dist/xlsx-tab-colors.d.ts +4 -0
  163. package/dist/xlsx-tab-colors.js +166 -0
  164. package/dist/xlsx-tab-colors.js.map +1 -0
  165. package/dist/xlsx-tables.d.ts +4 -0
  166. package/dist/xlsx-tables.js +371 -0
  167. package/dist/xlsx-tables.js.map +1 -0
  168. package/dist/xlsx-theme-artifacts.d.ts +6 -0
  169. package/dist/xlsx-theme-artifacts.js +126 -0
  170. package/dist/xlsx-theme-artifacts.js.map +1 -0
  171. package/dist/xlsx-threaded-comment-artifacts.d.ts +8 -0
  172. package/dist/xlsx-threaded-comment-artifacts.js +329 -0
  173. package/dist/xlsx-threaded-comment-artifacts.js.map +1 -0
  174. package/dist/xlsx-validations.d.ts +4 -0
  175. package/dist/xlsx-validations.js +542 -0
  176. package/dist/xlsx-validations.js.map +1 -0
  177. package/dist/xlsx-view-state.d.ts +8 -0
  178. package/dist/xlsx-view-state.js +144 -0
  179. package/dist/xlsx-view-state.js.map +1 -0
  180. package/dist/xlsx-workbook-properties.d.ts +5 -0
  181. package/dist/xlsx-workbook-properties.js +388 -0
  182. package/dist/xlsx-workbook-properties.js.map +1 -0
  183. package/dist/xlsx-workbook-protection.d.ts +4 -0
  184. package/dist/xlsx-workbook-protection.js +147 -0
  185. package/dist/xlsx-workbook-protection.js.map +1 -0
  186. package/dist/xlsx-workbook-sheet-paths.d.ts +4 -0
  187. package/dist/xlsx-workbook-sheet-paths.js +96 -0
  188. package/dist/xlsx-workbook-sheet-paths.js.map +1 -0
  189. package/dist/xlsx-worksheet-cells.d.ts +16 -0
  190. package/dist/xlsx-worksheet-cells.js +104 -0
  191. package/dist/xlsx-worksheet-cells.js.map +1 -0
  192. package/dist/xlsx-worksheet-text-values.d.ts +2 -0
  193. package/dist/xlsx-worksheet-text-values.js +136 -0
  194. package/dist/xlsx-worksheet-text-values.js.map +1 -0
  195. package/dist/xlsx-zip.d.ts +6 -0
  196. package/dist/xlsx-zip.js +12 -0
  197. package/dist/xlsx-zip.js.map +1 -0
  198. package/package.json +56 -0
@@ -0,0 +1,857 @@
1
+ import { XMLParser } from 'fast-xml-parser';
2
+ import * as XLSX from 'xlsx';
3
+ import { readImportedWorkbookThemeArtifact } from './xlsx-theme-artifacts.js';
4
+ import { workbookDirectorySheetPaths, workbookSheetPath, workbookSheetPathsByName } from './xlsx-workbook-sheet-paths.js';
5
+ import { getZipText as getZipEntryText, readXlsxZipEntries } from './xlsx-zip.js';
6
+ const xmlParser = new XMLParser({
7
+ ignoreAttributes: false,
8
+ attributeNamePrefix: '',
9
+ parseAttributeValue: false,
10
+ removeNSPrefix: true,
11
+ });
12
+ // XLSX can encode whole-sheet visual defaults as one <col min="1" max="16384"> range.
13
+ // Preserve bounded column metadata, but do not expand broad defaults into snapshot state.
14
+ const maxExpandedColumnMetadataEntries = 2_048;
15
+ function isRecord(value) {
16
+ return typeof value === 'object' && value !== null;
17
+ }
18
+ function asArray(value) {
19
+ if (value === undefined || value === null) {
20
+ return [];
21
+ }
22
+ return Array.isArray(value) ? value : [value];
23
+ }
24
+ function stringValue(value) {
25
+ return typeof value === 'string' ? value : null;
26
+ }
27
+ function numberValue(value) {
28
+ if (typeof value !== 'string' || value.trim().length === 0) {
29
+ return null;
30
+ }
31
+ const number = Number(value);
32
+ return Number.isFinite(number) ? number : null;
33
+ }
34
+ function recordChild(value, key) {
35
+ if (!isRecord(value)) {
36
+ return null;
37
+ }
38
+ const child = value[key];
39
+ return isRecord(child) ? child : null;
40
+ }
41
+ function normalizeZipPath(path) {
42
+ return path.replace(/^\/+/, '');
43
+ }
44
+ function getFileText(files, path) {
45
+ if (!isRecord(files)) {
46
+ return null;
47
+ }
48
+ const file = files[normalizeZipPath(path)];
49
+ if (!isRecord(file)) {
50
+ return null;
51
+ }
52
+ const content = file['content'];
53
+ if (typeof content === 'string') {
54
+ return content;
55
+ }
56
+ if (content instanceof ArrayBuffer) {
57
+ return new TextDecoder().decode(content);
58
+ }
59
+ if (ArrayBuffer.isView(content)) {
60
+ return new TextDecoder().decode(content);
61
+ }
62
+ return null;
63
+ }
64
+ function getPackageText(files, sourceZip, path) {
65
+ return sourceZip ? getZipEntryText(readXlsxZipEntries(sourceZip), path) : getFileText(files, path);
66
+ }
67
+ function workbookRecord(workbook) {
68
+ const value = workbook;
69
+ return isRecord(value) ? value : null;
70
+ }
71
+ function workbookFiles(workbook) {
72
+ return workbookRecord(workbook)?.['files'];
73
+ }
74
+ function workbookStylePath(workbook) {
75
+ const directory = workbookRecord(workbook)?.['Directory'];
76
+ if (!isRecord(directory)) {
77
+ return null;
78
+ }
79
+ if (typeof directory['style'] === 'string') {
80
+ return directory['style'];
81
+ }
82
+ const firstStylePath = asArray(directory['styles']).find((entry) => typeof entry === 'string');
83
+ return typeof firstStylePath === 'string' ? firstStylePath : null;
84
+ }
85
+ function normalizeRgbColor(value) {
86
+ if (typeof value !== 'string') {
87
+ return null;
88
+ }
89
+ const normalized = value.trim().replace(/^#/, '');
90
+ if (/^[0-9a-fA-F]{6}$/.test(normalized)) {
91
+ return `#${normalized.toLowerCase()}`;
92
+ }
93
+ if (/^[0-9a-fA-F]{8}$/.test(normalized)) {
94
+ return `#${normalized.slice(2).toLowerCase()}`;
95
+ }
96
+ return null;
97
+ }
98
+ function toArgbColor(value) {
99
+ const normalized = normalizeRgbColor(value);
100
+ return normalized ? `FF${normalized.slice(1).toUpperCase()}` : null;
101
+ }
102
+ function readColorRecord(value) {
103
+ return normalizeRgbColor(recordChild(value, 'color')?.['rgb'] ?? recordChild(value, 'fgColor')?.['rgb'] ?? recordChild(value, 'bgColor')?.['rgb']);
104
+ }
105
+ function readFont(font) {
106
+ if (!isRecord(font)) {
107
+ return undefined;
108
+ }
109
+ const output = {};
110
+ const name = stringValue(recordChild(font, 'name')?.['val']);
111
+ const size = numberValue(recordChild(font, 'sz')?.['val']);
112
+ const color = readColorRecord(font);
113
+ if (name && name.length > 0) {
114
+ output.family = name;
115
+ }
116
+ if (size !== null && size > 0) {
117
+ output.size = size;
118
+ }
119
+ if (font['b'] !== undefined) {
120
+ output.bold = true;
121
+ }
122
+ if (font['i'] !== undefined) {
123
+ output.italic = true;
124
+ }
125
+ if (font['u'] !== undefined) {
126
+ output.underline = true;
127
+ }
128
+ if (color) {
129
+ output.color = color;
130
+ }
131
+ return Object.keys(output).length > 0 ? output : undefined;
132
+ }
133
+ function readFill(fill) {
134
+ const patternFill = recordChild(fill, 'patternFill');
135
+ if (!patternFill || patternFill['patternType'] !== 'solid') {
136
+ return undefined;
137
+ }
138
+ const backgroundColor = normalizeRgbColor(recordChild(patternFill, 'fgColor')?.['rgb'] ?? recordChild(patternFill, 'bgColor')?.['rgb']);
139
+ return backgroundColor ? { backgroundColor } : undefined;
140
+ }
141
+ function readBorderKind(value) {
142
+ switch (value) {
143
+ case 'hair':
144
+ case 'thin':
145
+ return { style: 'solid', weight: 'thin' };
146
+ case 'medium':
147
+ return { style: 'solid', weight: 'medium' };
148
+ case 'thick':
149
+ return { style: 'solid', weight: 'thick' };
150
+ case 'dashed':
151
+ return { style: 'dashed', weight: 'thin' };
152
+ case 'mediumDashed':
153
+ return { style: 'dashed', weight: 'medium' };
154
+ case 'dotted':
155
+ return { style: 'dotted', weight: 'thin' };
156
+ default:
157
+ return null;
158
+ }
159
+ }
160
+ function readBorderSide(side) {
161
+ if (!isRecord(side)) {
162
+ return undefined;
163
+ }
164
+ const borderKind = readBorderKind(side['style']);
165
+ if (!borderKind) {
166
+ return undefined;
167
+ }
168
+ return {
169
+ ...borderKind,
170
+ color: normalizeRgbColor(recordChild(side, 'color')?.['rgb']) ?? '#000000',
171
+ };
172
+ }
173
+ function readBorders(border) {
174
+ if (!isRecord(border)) {
175
+ return undefined;
176
+ }
177
+ const top = readBorderSide(border['top']);
178
+ const right = readBorderSide(border['right']);
179
+ const bottom = readBorderSide(border['bottom']);
180
+ const left = readBorderSide(border['left']);
181
+ const borders = {};
182
+ if (top) {
183
+ borders.top = top;
184
+ }
185
+ if (right) {
186
+ borders.right = right;
187
+ }
188
+ if (bottom) {
189
+ borders.bottom = bottom;
190
+ }
191
+ if (left) {
192
+ borders.left = left;
193
+ }
194
+ return Object.keys(borders).length > 0 ? borders : undefined;
195
+ }
196
+ function readHorizontalAlignment(value) {
197
+ switch (value) {
198
+ case 'general':
199
+ case 'left':
200
+ case 'center':
201
+ case 'right':
202
+ case 'fill':
203
+ case 'justify':
204
+ case 'centerContinuous':
205
+ case 'distributed':
206
+ return value;
207
+ default:
208
+ return undefined;
209
+ }
210
+ }
211
+ function readVerticalAlignment(value) {
212
+ switch (value) {
213
+ case 'top':
214
+ return 'top';
215
+ case 'center':
216
+ case 'middle':
217
+ return 'middle';
218
+ case 'bottom':
219
+ return 'bottom';
220
+ case 'justify':
221
+ return 'justify';
222
+ case 'distributed':
223
+ return 'distributed';
224
+ default:
225
+ return undefined;
226
+ }
227
+ }
228
+ function readAlignment(alignment) {
229
+ if (!isRecord(alignment)) {
230
+ return undefined;
231
+ }
232
+ const horizontal = readHorizontalAlignment(alignment['horizontal']);
233
+ const vertical = readVerticalAlignment(alignment['vertical']);
234
+ const indent = numberValue(alignment['indent']);
235
+ const readingOrder = numberValue(alignment['readingOrder']);
236
+ const textRotation = numberValue(alignment['textRotation']);
237
+ const output = {
238
+ ...(horizontal ? { horizontal } : {}),
239
+ ...(vertical ? { vertical } : {}),
240
+ ...(readBooleanAttribute(alignment['wrapText']) === true ? { wrap: true } : {}),
241
+ ...(indent !== null && indent >= 0 ? { indent } : {}),
242
+ ...(readBooleanAttribute(alignment['shrinkToFit']) === true ? { shrinkToFit: true } : {}),
243
+ ...(readingOrder !== null ? { readingOrder } : {}),
244
+ ...(textRotation !== null ? { textRotation } : {}),
245
+ ...(readBooleanAttribute(alignment['justifyLastLine']) === true ? { justifyLastLine: true } : {}),
246
+ };
247
+ return Object.keys(output).length > 0 ? output : undefined;
248
+ }
249
+ function readBooleanAttribute(value) {
250
+ if (value === true || value === '1' || (typeof value === 'string' && value.toLowerCase() === 'true')) {
251
+ return true;
252
+ }
253
+ if (value === false || value === '0' || (typeof value === 'string' && value.toLowerCase() === 'false')) {
254
+ return false;
255
+ }
256
+ return undefined;
257
+ }
258
+ function isStyleComponentApplied(flag, componentId) {
259
+ const explicit = readBooleanAttribute(flag);
260
+ return explicit ?? (componentId !== null && componentId > 0);
261
+ }
262
+ function readProtection(protection) {
263
+ if (!isRecord(protection)) {
264
+ return undefined;
265
+ }
266
+ const locked = readBooleanAttribute(protection['locked']);
267
+ const hidden = readBooleanAttribute(protection['hidden']);
268
+ return {
269
+ ...(locked !== undefined ? { locked } : {}),
270
+ ...(hidden !== undefined ? { hidden } : {}),
271
+ };
272
+ }
273
+ function parseWorkbookStyles(stylesXml) {
274
+ const relevantStylesXml = ['fonts', 'fills', 'borders', 'cellXfs']
275
+ .flatMap((elementName) => {
276
+ const elementXml = extractStyleXmlElement(stylesXml, elementName);
277
+ return elementXml ? [elementXml] : [];
278
+ })
279
+ .join('');
280
+ if (relevantStylesXml.length === 0) {
281
+ return new Map();
282
+ }
283
+ const parsed = xmlParser.parse(`<styleSheet>${relevantStylesXml}</styleSheet>`);
284
+ const styleSheet = recordChild(parsed, 'styleSheet');
285
+ if (!styleSheet) {
286
+ return new Map();
287
+ }
288
+ const fonts = asArray(recordChild(styleSheet, 'fonts')?.['font']).map(readFont);
289
+ const fills = asArray(recordChild(styleSheet, 'fills')?.['fill']).map(readFill);
290
+ const borders = asArray(recordChild(styleSheet, 'borders')?.['border']).map(readBorders);
291
+ const cellXfs = asArray(recordChild(styleSheet, 'cellXfs')?.['xf']);
292
+ const styles = new Map();
293
+ cellXfs.forEach((entry, index) => {
294
+ if (!isRecord(entry)) {
295
+ return;
296
+ }
297
+ const fontId = numberValue(entry['fontId']);
298
+ const fillId = numberValue(entry['fillId']);
299
+ const borderId = numberValue(entry['borderId']);
300
+ const font = fontId !== null ? fonts[fontId] : undefined;
301
+ const fill = fillId !== null ? fills[fillId] : undefined;
302
+ const bordersValue = borderId !== null ? borders[borderId] : undefined;
303
+ const alignment = readAlignment(entry['alignment']);
304
+ const protection = entry['applyProtection'] === '1' ? (readProtection(entry['protection']) ?? {}) : readProtection(entry['protection']);
305
+ const style = {
306
+ ...(isStyleComponentApplied(entry['applyFill'], fillId) && fill ? { fill } : {}),
307
+ ...(isStyleComponentApplied(entry['applyFont'], fontId) && font ? { font } : {}),
308
+ ...(entry['applyAlignment'] === '1' && alignment ? { alignment } : {}),
309
+ ...(isStyleComponentApplied(entry['applyBorder'], borderId) && bordersValue ? { borders: bordersValue } : {}),
310
+ ...(protection !== undefined ? { protection } : {}),
311
+ };
312
+ if (Object.keys(style).length > 0) {
313
+ styles.set(index, style);
314
+ }
315
+ });
316
+ return styles;
317
+ }
318
+ function extractStyleXmlElement(stylesXml, elementName) {
319
+ const qualifiedName = `(?:[A-Za-z_][\\w.-]*:)?${elementName}`;
320
+ const expanded = new RegExp(`<${qualifiedName}\\b[^>]*>[\\s\\S]*?<\\/${qualifiedName}>`, 'u').exec(stylesXml);
321
+ if (expanded) {
322
+ return expanded[0];
323
+ }
324
+ const selfClosing = new RegExp(`<${qualifiedName}\\b[^>]*\\/>`, 'u').exec(stylesXml);
325
+ return selfClosing?.[0] ?? null;
326
+ }
327
+ function readXmlAttribute(tag, name) {
328
+ const doubleQuoted = new RegExp(`\\b${name}="([^"]*)"`, 'u').exec(tag);
329
+ if (doubleQuoted) {
330
+ return doubleQuoted[1] ?? null;
331
+ }
332
+ const singleQuoted = new RegExp(`\\b${name}='([^']*)'`, 'u').exec(tag);
333
+ return singleQuoted?.[1] ?? null;
334
+ }
335
+ function readXmlNumberAttribute(tag, name) {
336
+ const raw = readXmlAttribute(tag, name);
337
+ if (raw === null || raw.trim().length === 0) {
338
+ return null;
339
+ }
340
+ const value = Number(raw);
341
+ return Number.isFinite(value) ? value : null;
342
+ }
343
+ function readXmlPositiveIntegerAttribute(tag, name) {
344
+ const value = readXmlNumberAttribute(tag, name);
345
+ return value !== null && Number.isSafeInteger(value) && value > 0 ? value : null;
346
+ }
347
+ function readXmlNonNegativeIntegerAttribute(tag, name) {
348
+ const value = readXmlNumberAttribute(tag, name);
349
+ return value !== null && Number.isSafeInteger(value) && value >= 0 ? value : null;
350
+ }
351
+ function readXmlOptionalBooleanAttribute(tag, name) {
352
+ const raw = readXmlAttribute(tag, name);
353
+ if (raw === null) {
354
+ return null;
355
+ }
356
+ return raw === '1' || raw.toLowerCase() === 'true';
357
+ }
358
+ function parseSheetStyleIndexes(sheetXml, candidateAddresses) {
359
+ const output = new Map();
360
+ if (candidateAddresses?.size === 0) {
361
+ return output;
362
+ }
363
+ let remainingCandidateCount = candidateAddresses?.size ?? null;
364
+ for (const match of sheetXml.matchAll(/<c\b[^>]*>/gu)) {
365
+ const cellTag = match[0];
366
+ const address = readXmlAttribute(cellTag, 'r');
367
+ if (!address) {
368
+ continue;
369
+ }
370
+ if (candidateAddresses) {
371
+ if (!candidateAddresses.has(address)) {
372
+ continue;
373
+ }
374
+ remainingCandidateCount = remainingCandidateCount === null ? null : remainingCandidateCount - 1;
375
+ }
376
+ const styleIndexValue = readXmlAttribute(cellTag, 's');
377
+ if (styleIndexValue === null || styleIndexValue.trim().length === 0) {
378
+ if (remainingCandidateCount === 0) {
379
+ break;
380
+ }
381
+ continue;
382
+ }
383
+ const styleIndex = Number(styleIndexValue);
384
+ if (Number.isSafeInteger(styleIndex)) {
385
+ output.set(address, styleIndex);
386
+ }
387
+ if (remainingCandidateCount === 0) {
388
+ break;
389
+ }
390
+ }
391
+ return output;
392
+ }
393
+ function parseColumnStyleRanges(sheetXml) {
394
+ return [...sheetXml.matchAll(/<col\b[^>]*\/?>/gu)].flatMap((match) => {
395
+ const columnTag = match[0];
396
+ if (readXmlNonNegativeIntegerAttribute(columnTag, 'style') === null) {
397
+ return [];
398
+ }
399
+ const min = readXmlPositiveIntegerAttribute(columnTag, 'min');
400
+ const max = readXmlPositiveIntegerAttribute(columnTag, 'max') ?? min;
401
+ if (min === null || max === null || max < min) {
402
+ return [];
403
+ }
404
+ return [{ start: min - 1, end: max - 1 }];
405
+ });
406
+ }
407
+ function columnHasStyle(columnStyleRanges, columnIndex) {
408
+ return columnStyleRanges.some((range) => columnIndex >= range.start && columnIndex <= range.end);
409
+ }
410
+ function isBlankCellXml(cellXml, openingTag) {
411
+ if (openingTag.endsWith('/>')) {
412
+ return true;
413
+ }
414
+ return !/<(?:v|f|is)\b/u.test(cellXml.slice(openingTag.length, -'</c>'.length));
415
+ }
416
+ function parseSheetCellStyleIndexArtifacts(sheetXml) {
417
+ const cellStyleIndexes = [];
418
+ const blankCellAddresses = [];
419
+ const columnStyleRanges = parseColumnStyleRanges(sheetXml);
420
+ for (const rowMatch of sheetXml.matchAll(/<row\b[^>]*(?:\/>|>[\s\S]*?<\/row>)/gu)) {
421
+ const rowXml = rowMatch[0];
422
+ const rowTag = /^<row\b[^>]*(?:\/>|>)/u.exec(rowXml)?.[0];
423
+ if (!rowTag) {
424
+ continue;
425
+ }
426
+ const rowHasStyle = readXmlNonNegativeIntegerAttribute(rowTag, 's') !== null;
427
+ for (const cellMatch of rowXml.matchAll(/<c\b[^>]*(?:\/>|>[\s\S]*?<\/c>)/gu)) {
428
+ const cellXml = cellMatch[0];
429
+ const cellTag = /^<c\b[^>]*(?:\/>|>)/u.exec(cellXml)?.[0];
430
+ if (!cellTag) {
431
+ continue;
432
+ }
433
+ const address = readXmlAttribute(cellTag, 'r');
434
+ if (!address) {
435
+ continue;
436
+ }
437
+ const styleIndex = readXmlNonNegativeIntegerAttribute(cellTag, 's');
438
+ if (styleIndex !== null) {
439
+ cellStyleIndexes.push({ address, styleIndex });
440
+ continue;
441
+ }
442
+ if (!isBlankCellXml(cellXml, cellTag)) {
443
+ continue;
444
+ }
445
+ const columnIndex = XLSX.utils.decode_cell(address).c;
446
+ if (rowHasStyle || columnHasStyle(columnStyleRanges, columnIndex)) {
447
+ blankCellAddresses.push(address);
448
+ }
449
+ }
450
+ }
451
+ return cellStyleIndexes.length > 0 || blankCellAddresses.length > 0
452
+ ? {
453
+ cellStyleIndexes,
454
+ ...(blankCellAddresses.length > 0 ? { blankCellAddresses } : {}),
455
+ }
456
+ : undefined;
457
+ }
458
+ function parseSheetFormatPr(sheetXml) {
459
+ const match = /<sheetFormatPr\b[^>]*\/?>/u.exec(sheetXml);
460
+ if (!match) {
461
+ return undefined;
462
+ }
463
+ const tag = match[0];
464
+ const sheetFormatPr = {
465
+ ...(readXmlNumberAttribute(tag, 'baseColWidth') !== null ? { baseColWidth: readXmlNumberAttribute(tag, 'baseColWidth') } : {}),
466
+ ...(readXmlNumberAttribute(tag, 'defaultColWidth') !== null ? { defaultColWidth: readXmlNumberAttribute(tag, 'defaultColWidth') } : {}),
467
+ ...(readXmlNumberAttribute(tag, 'defaultRowHeight') !== null
468
+ ? { defaultRowHeight: readXmlNumberAttribute(tag, 'defaultRowHeight') }
469
+ : {}),
470
+ ...(readXmlOptionalBooleanAttribute(tag, 'customHeight') !== null
471
+ ? { customHeight: readXmlOptionalBooleanAttribute(tag, 'customHeight') }
472
+ : {}),
473
+ ...(readXmlNonNegativeIntegerAttribute(tag, 'outlineLevelRow') !== null
474
+ ? { outlineLevelRow: readXmlNonNegativeIntegerAttribute(tag, 'outlineLevelRow') }
475
+ : {}),
476
+ ...(readXmlNonNegativeIntegerAttribute(tag, 'outlineLevelCol') !== null
477
+ ? { outlineLevelCol: readXmlNonNegativeIntegerAttribute(tag, 'outlineLevelCol') }
478
+ : {}),
479
+ ...(readXmlOptionalBooleanAttribute(tag, 'thickTop') !== null ? { thickTop: readXmlOptionalBooleanAttribute(tag, 'thickTop') } : {}),
480
+ ...(readXmlOptionalBooleanAttribute(tag, 'thickBottom') !== null
481
+ ? { thickBottom: readXmlOptionalBooleanAttribute(tag, 'thickBottom') }
482
+ : {}),
483
+ };
484
+ return Object.keys(sheetFormatPr).length > 0 ? sheetFormatPr : undefined;
485
+ }
486
+ function parseSheetColumnEntries(sheetXml) {
487
+ const entries = [];
488
+ const metadata = [];
489
+ let skipped = false;
490
+ for (const match of sheetXml.matchAll(/<col\b[^>]*\/?>/gu)) {
491
+ const columnTag = match[0];
492
+ const min = readXmlPositiveIntegerAttribute(columnTag, 'min');
493
+ const max = readXmlPositiveIntegerAttribute(columnTag, 'max') ?? min;
494
+ if (min === null || max === null || max < min) {
495
+ continue;
496
+ }
497
+ const width = readXmlNumberAttribute(columnTag, 'width');
498
+ const widthSize = width !== null && width > 0 ? Math.round(width * 6) : null;
499
+ const size = widthSize !== null && widthSize > 0 ? widthSize : null;
500
+ const startColumn = min - 1;
501
+ const endColumn = max - 1;
502
+ const columnCount = endColumn - startColumn + 1;
503
+ if (columnCount <= 0) {
504
+ continue;
505
+ }
506
+ const customWidth = readXmlOptionalBooleanAttribute(columnTag, 'customWidth');
507
+ const styleIndex = readXmlNonNegativeIntegerAttribute(columnTag, 'style');
508
+ const customFormat = readXmlOptionalBooleanAttribute(columnTag, 'customFormat');
509
+ const bestFit = readXmlOptionalBooleanAttribute(columnTag, 'bestFit');
510
+ const hidden = readXmlOptionalBooleanAttribute(columnTag, 'hidden');
511
+ const outlineLevel = readXmlNonNegativeIntegerAttribute(columnTag, 'outlineLevel');
512
+ const collapsed = readXmlOptionalBooleanAttribute(columnTag, 'collapsed');
513
+ if (size === null &&
514
+ customWidth === null &&
515
+ styleIndex === null &&
516
+ customFormat === null &&
517
+ bestFit === null &&
518
+ hidden === null &&
519
+ outlineLevel === null &&
520
+ collapsed === null) {
521
+ continue;
522
+ }
523
+ metadata.push({
524
+ start: startColumn,
525
+ count: columnCount,
526
+ ...(size !== null && size > 0 ? { size } : {}),
527
+ ...(width !== null && width > 0 ? { xlsxWidth: width } : {}),
528
+ ...(styleIndex !== null ? { styleIndex } : {}),
529
+ ...(customFormat !== null ? { customFormat } : {}),
530
+ ...(customWidth !== null ? { customWidth } : {}),
531
+ ...(bestFit !== null ? { bestFit } : {}),
532
+ ...(hidden !== null ? { hidden } : {}),
533
+ ...(outlineLevel !== null ? { outlineLevel } : {}),
534
+ ...(collapsed !== null ? { collapsed } : {}),
535
+ });
536
+ if (size === null && hidden !== true) {
537
+ continue;
538
+ }
539
+ if (entries.length + columnCount > maxExpandedColumnMetadataEntries) {
540
+ skipped = true;
541
+ continue;
542
+ }
543
+ for (let column = startColumn; column <= endColumn; column += 1) {
544
+ entries.push({
545
+ id: `col:${String(column)}`,
546
+ index: column,
547
+ ...(size !== null ? { size } : {}),
548
+ ...(hidden === true ? { hidden: true } : {}),
549
+ });
550
+ }
551
+ }
552
+ return {
553
+ ...(entries.length > 0 ? { entries } : {}),
554
+ ...(metadata.length > 0 ? { metadata } : {}),
555
+ skipped,
556
+ };
557
+ }
558
+ function rowMetadataValuesMatch(left, right) {
559
+ return (left.size === right.size &&
560
+ left.hidden === right.hidden &&
561
+ left.xlsxHeight === right.xlsxHeight &&
562
+ left.styleIndex === right.styleIndex &&
563
+ left.customFormat === right.customFormat &&
564
+ left.customHeight === right.customHeight &&
565
+ left.outlineLevel === right.outlineLevel &&
566
+ left.collapsed === right.collapsed &&
567
+ left.thickTop === right.thickTop &&
568
+ left.thickBottom === right.thickBottom);
569
+ }
570
+ function coalesceRowMetadata(records) {
571
+ const coalesced = [];
572
+ for (const record of records) {
573
+ const previous = coalesced[coalesced.length - 1];
574
+ if (previous && previous.start + previous.count === record.start && rowMetadataValuesMatch(previous, record)) {
575
+ coalesced[coalesced.length - 1] = { ...previous, count: previous.count + record.count };
576
+ continue;
577
+ }
578
+ coalesced.push({ ...record });
579
+ }
580
+ return coalesced;
581
+ }
582
+ function parseSheetRowEntries(sheetXml) {
583
+ const entries = [];
584
+ const metadata = [];
585
+ for (const match of sheetXml.matchAll(/<row\b[^>]*>/gu)) {
586
+ const rowTag = match[0];
587
+ const rowNumber = readXmlPositiveIntegerAttribute(rowTag, 'r');
588
+ const height = readXmlNumberAttribute(rowTag, 'ht');
589
+ const hidden = readXmlOptionalBooleanAttribute(rowTag, 'hidden');
590
+ if (rowNumber === null) {
591
+ continue;
592
+ }
593
+ const index = rowNumber - 1;
594
+ const size = height !== null && height > 0 ? Math.round(height) : null;
595
+ const styleIndex = readXmlNonNegativeIntegerAttribute(rowTag, 's');
596
+ const customFormat = readXmlOptionalBooleanAttribute(rowTag, 'customFormat');
597
+ const customHeight = readXmlOptionalBooleanAttribute(rowTag, 'customHeight');
598
+ const outlineLevel = readXmlNonNegativeIntegerAttribute(rowTag, 'outlineLevel');
599
+ const collapsed = readXmlOptionalBooleanAttribute(rowTag, 'collapsed');
600
+ const thickTop = readXmlOptionalBooleanAttribute(rowTag, 'thickTop');
601
+ const thickBottom = readXmlOptionalBooleanAttribute(rowTag, 'thickBot');
602
+ if ((size === null || size <= 0) &&
603
+ hidden !== true &&
604
+ styleIndex === null &&
605
+ customFormat === null &&
606
+ customHeight === null &&
607
+ outlineLevel === null &&
608
+ collapsed === null &&
609
+ thickTop === null &&
610
+ thickBottom === null) {
611
+ continue;
612
+ }
613
+ if (size !== null || hidden === true) {
614
+ entries.push({
615
+ id: `row:${String(index)}`,
616
+ index,
617
+ ...(size !== null && size > 0 ? { size } : {}),
618
+ ...(hidden === true ? { hidden: true } : {}),
619
+ });
620
+ }
621
+ metadata.push({
622
+ start: index,
623
+ count: 1,
624
+ ...(size !== null && size > 0 ? { size } : {}),
625
+ ...(height !== null && height > 0 ? { xlsxHeight: height } : {}),
626
+ ...(hidden !== null ? { hidden } : {}),
627
+ ...(styleIndex !== null ? { styleIndex } : {}),
628
+ ...(customFormat !== null ? { customFormat } : {}),
629
+ ...(customHeight !== null ? { customHeight } : {}),
630
+ ...(outlineLevel !== null ? { outlineLevel } : {}),
631
+ ...(collapsed !== null ? { collapsed } : {}),
632
+ ...(thickTop !== null ? { thickTop } : {}),
633
+ ...(thickBottom !== null ? { thickBottom } : {}),
634
+ });
635
+ }
636
+ const coalescedMetadata = coalesceRowMetadata(metadata);
637
+ return {
638
+ ...(entries.length > 0 ? { entries } : {}),
639
+ ...(coalescedMetadata.length > 0 ? { metadata: coalescedMetadata } : {}),
640
+ };
641
+ }
642
+ export function readImportedWorkbookSheetDimensions(workbook, sheetNames) {
643
+ const files = workbookFiles(workbook);
644
+ const sheetPathsByName = workbookSheetPathsByName(workbook);
645
+ const fallbackSheetPaths = workbookDirectorySheetPaths(workbook);
646
+ const output = new Map();
647
+ sheetNames.forEach((sheetName, index) => {
648
+ const sheetPath = workbookSheetPath(sheetPathsByName, fallbackSheetPaths, sheetName, index);
649
+ const sheetXml = sheetPath ? getFileText(files, sheetPath) : null;
650
+ if (!sheetXml) {
651
+ return;
652
+ }
653
+ const sheetFormatPr = parseSheetFormatPr(sheetXml);
654
+ const parsedColumns = parseSheetColumnEntries(sheetXml);
655
+ const parsedRows = parseSheetRowEntries(sheetXml);
656
+ const dimensions = {
657
+ ...(parsedColumns.entries ? { columns: parsedColumns.entries } : {}),
658
+ ...(parsedRows.entries ? { rows: parsedRows.entries } : {}),
659
+ ...(parsedColumns.metadata ? { columnMetadata: parsedColumns.metadata } : {}),
660
+ ...(parsedRows.metadata ? { rowMetadata: parsedRows.metadata } : {}),
661
+ ...(sheetFormatPr ? { sheetFormatPr } : {}),
662
+ ...(parsedColumns.skipped ? { skippedColumnMetadata: true } : {}),
663
+ };
664
+ if (dimensions.columns ||
665
+ dimensions.rows ||
666
+ dimensions.columnMetadata ||
667
+ dimensions.rowMetadata ||
668
+ dimensions.sheetFormatPr ||
669
+ dimensions.skippedColumnMetadata) {
670
+ output.set(sheetName, dimensions);
671
+ }
672
+ });
673
+ return output;
674
+ }
675
+ export function readImportedWorkbookFileStyles(workbook, sheetNames, options = {}, source) {
676
+ const files = workbookFiles(workbook);
677
+ const sourceZip = source ? readXlsxZipEntries(source) : null;
678
+ const stylePath = workbookStylePath(workbook);
679
+ const styleXml = stylePath ? getPackageText(files, sourceZip, stylePath) : null;
680
+ if (!styleXml) {
681
+ return new Map();
682
+ }
683
+ const stylesByIndex = parseWorkbookStyles(styleXml);
684
+ if (stylesByIndex.size === 0) {
685
+ return new Map();
686
+ }
687
+ const sheetPathsByName = workbookSheetPathsByName(workbook);
688
+ const fallbackSheetPaths = workbookDirectorySheetPaths(workbook);
689
+ const output = new Map();
690
+ sheetNames.forEach((sheetName, index) => {
691
+ const candidateAddresses = options.styleCandidateAddressesBySheet?.get(sheetName);
692
+ if (candidateAddresses?.size === 0) {
693
+ return;
694
+ }
695
+ const sheetPath = workbookSheetPath(sheetPathsByName, fallbackSheetPaths, sheetName, index);
696
+ const sheetXml = sheetPath ? getPackageText(files, sourceZip, sheetPath) : null;
697
+ if (!sheetXml) {
698
+ return;
699
+ }
700
+ const styleIndexes = parseSheetStyleIndexes(sheetXml, candidateAddresses);
701
+ const cellStyles = new Map();
702
+ for (const [address, styleIndex] of styleIndexes) {
703
+ const style = stylesByIndex.get(styleIndex);
704
+ if (style) {
705
+ cellStyles.set(address, style);
706
+ }
707
+ }
708
+ if (cellStyles.size > 0) {
709
+ output.set(sheetName, cellStyles);
710
+ }
711
+ });
712
+ return output;
713
+ }
714
+ export function readImportedWorkbookStyleArtifacts(workbook, sheetNames, source) {
715
+ const zip = source ? readXlsxZipEntries(source) : null;
716
+ const files = workbookFiles(workbook);
717
+ const stylePath = workbookStylePath(workbook);
718
+ const readPartText = (path) => {
719
+ if (!path) {
720
+ return null;
721
+ }
722
+ return zip ? getZipEntryText(zip, path) : getFileText(files, path);
723
+ };
724
+ const stylesXml = readPartText(stylePath);
725
+ const theme = readImportedWorkbookThemeArtifact(zip ?? undefined);
726
+ const sheetPathsByName = workbookSheetPathsByName(workbook);
727
+ const fallbackSheetPaths = workbookDirectorySheetPaths(workbook);
728
+ const sheetArtifactsByName = new Map();
729
+ sheetNames.forEach((sheetName, index) => {
730
+ const sheetPath = workbookSheetPath(sheetPathsByName, fallbackSheetPaths, sheetName, index);
731
+ const sheetXml = readPartText(sheetPath);
732
+ if (!sheetXml) {
733
+ return;
734
+ }
735
+ const sheetArtifacts = parseSheetCellStyleIndexArtifacts(sheetXml);
736
+ if (sheetArtifacts) {
737
+ sheetArtifactsByName.set(sheetName, sheetArtifacts);
738
+ }
739
+ });
740
+ return {
741
+ ...(stylesXml ? { workbookArtifacts: { stylesXml, ...(theme ? { theme } : {}) } } : {}),
742
+ sheetArtifactsByName,
743
+ };
744
+ }
745
+ function exportColor(value) {
746
+ const rgb = toArgbColor(value);
747
+ return rgb ? { rgb } : undefined;
748
+ }
749
+ function exportAlignment(alignment) {
750
+ return {
751
+ ...(alignment.horizontal ? { horizontal: alignment.horizontal } : {}),
752
+ ...(alignment.vertical ? { vertical: alignment.vertical === 'middle' ? 'center' : alignment.vertical } : {}),
753
+ ...(alignment.wrap === true ? { wrapText: true } : {}),
754
+ ...(alignment.indent !== undefined && alignment.indent >= 0 ? { indent: alignment.indent } : {}),
755
+ ...(alignment.shrinkToFit === true ? { shrinkToFit: true } : {}),
756
+ ...(alignment.readingOrder !== undefined ? { readingOrder: alignment.readingOrder } : {}),
757
+ ...(alignment.textRotation !== undefined ? { textRotation: alignment.textRotation } : {}),
758
+ ...(alignment.justifyLastLine === true ? { justifyLastLine: true } : {}),
759
+ };
760
+ }
761
+ function exportBorderSide(side) {
762
+ const color = exportColor(side.color) ?? { rgb: 'FF000000' };
763
+ switch (side.style) {
764
+ case 'solid':
765
+ return { color, style: side.weight };
766
+ case 'dashed':
767
+ return { color, style: side.weight === 'thin' ? 'dashed' : 'mediumDashed' };
768
+ case 'dotted':
769
+ return { color, style: 'dotted' };
770
+ case 'double':
771
+ return { color, style: 'thick' };
772
+ }
773
+ }
774
+ function exportStyle(style) {
775
+ const output = {};
776
+ const fillColor = style.fill?.backgroundColor ? exportColor(style.fill.backgroundColor) : undefined;
777
+ if (fillColor) {
778
+ output.fill = { patternType: 'solid', fgColor: fillColor };
779
+ }
780
+ if (style.font) {
781
+ const font = {};
782
+ const fontColor = style.font.color ? exportColor(style.font.color) : undefined;
783
+ if (style.font.family) {
784
+ font.name = style.font.family;
785
+ }
786
+ if (style.font.size) {
787
+ font.sz = style.font.size;
788
+ }
789
+ if (style.font.bold === true) {
790
+ font.bold = true;
791
+ }
792
+ if (style.font.italic === true) {
793
+ font.italic = true;
794
+ }
795
+ if (style.font.underline === true) {
796
+ font.underline = true;
797
+ }
798
+ if (fontColor) {
799
+ font.color = fontColor;
800
+ }
801
+ if (Object.keys(font).length > 0) {
802
+ output.font = font;
803
+ }
804
+ }
805
+ if (style.alignment) {
806
+ const alignment = exportAlignment(style.alignment);
807
+ if (Object.keys(alignment).length > 0) {
808
+ output.alignment = alignment;
809
+ }
810
+ }
811
+ if (style.borders) {
812
+ const border = {};
813
+ if (style.borders.top) {
814
+ border.top = exportBorderSide(style.borders.top);
815
+ }
816
+ if (style.borders.right) {
817
+ border.right = exportBorderSide(style.borders.right);
818
+ }
819
+ if (style.borders.bottom) {
820
+ border.bottom = exportBorderSide(style.borders.bottom);
821
+ }
822
+ if (style.borders.left) {
823
+ border.left = exportBorderSide(style.borders.left);
824
+ }
825
+ if (Object.keys(border).length > 0) {
826
+ output.border = border;
827
+ }
828
+ }
829
+ return output;
830
+ }
831
+ function isStyledWorksheetCell(value) {
832
+ return isRecord(value) && typeof value['t'] === 'string';
833
+ }
834
+ export function addExportStylesToWorksheet(worksheet, styleRanges, styles) {
835
+ if (!styleRanges || styleRanges.length === 0 || !styles || styles.length === 0) {
836
+ return;
837
+ }
838
+ const stylesById = new Map(styles.map((style) => [style.id, style]));
839
+ for (const styleRange of styleRanges) {
840
+ const style = stylesById.get(styleRange.styleId);
841
+ if (!style) {
842
+ continue;
843
+ }
844
+ const exportStyleValue = exportStyle(style);
845
+ const range = XLSX.utils.decode_range(`${styleRange.range.startAddress}:${styleRange.range.endAddress}`);
846
+ for (let row = range.s.r; row <= range.e.r; row += 1) {
847
+ for (let column = range.s.c; column <= range.e.c; column += 1) {
848
+ const address = XLSX.utils.encode_cell({ r: row, c: column });
849
+ const existingCell = worksheet[address];
850
+ const cell = isStyledWorksheetCell(existingCell) ? existingCell : { t: 'z' };
851
+ cell.s = exportStyleValue;
852
+ worksheet[address] = cell;
853
+ }
854
+ }
855
+ }
856
+ }
857
+ //# sourceMappingURL=xlsx-styles.js.map