@shbernal/ts-xlsx 1.3.1 → 2.1.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 (186) hide show
  1. package/README.md +20 -10
  2. package/dist/bytes.d.ts +24 -0
  3. package/dist/bytes.js +34 -0
  4. package/dist/core/address.d.ts +72 -3
  5. package/dist/core/address.js +50 -10
  6. package/dist/core/autofilter.d.ts +13 -2
  7. package/dist/core/autofilter.js +35 -10
  8. package/dist/core/cell.d.ts +17 -16
  9. package/dist/core/cell.js +3 -7
  10. package/dist/core/color-resolution.d.ts +8 -8
  11. package/dist/core/color-resolution.js +7 -8
  12. package/dist/core/column.d.ts +8 -9
  13. package/dist/core/column.js +2 -4
  14. package/dist/core/comment-thread.d.ts +32 -23
  15. package/dist/core/comment-thread.js +4 -4
  16. package/dist/core/conditional-formatting-overlay.d.ts +6 -1
  17. package/dist/core/conditional-formatting-overlay.js +11 -0
  18. package/dist/core/conditional-formatting.d.ts +48 -8
  19. package/dist/core/conditional-formatting.js +88 -0
  20. package/dist/core/data-validation-overlay.d.ts +12 -1
  21. package/dist/core/data-validation-overlay.js +21 -2
  22. package/dist/core/data-validation.d.ts +12 -5
  23. package/dist/core/data-validation.js +34 -0
  24. package/dist/core/date.d.ts +3 -3
  25. package/dist/core/formula.d.ts +6 -6
  26. package/dist/core/grid-edits.d.ts +16 -0
  27. package/dist/core/grid-edits.js +29 -11
  28. package/dist/core/grid-shift.d.ts +19 -0
  29. package/dist/core/grid-shift.js +8 -0
  30. package/dist/core/image.d.ts +39 -2
  31. package/dist/core/image.js +10 -0
  32. package/dist/core/internal.d.ts +9 -1
  33. package/dist/core/limits.d.ts +4 -4
  34. package/dist/core/merge.d.ts +17 -12
  35. package/dist/core/merge.js +36 -5
  36. package/dist/core/page-setup.d.ts +20 -6
  37. package/dist/core/page-setup.js +8 -1
  38. package/dist/core/pivot-table.d.ts +4 -4
  39. package/dist/core/pivot-table.js +29 -20
  40. package/dist/core/preserved.d.ts +3 -3
  41. package/dist/core/protection.d.ts +7 -4
  42. package/dist/core/protection.js +20 -14
  43. package/dist/core/range.d.ts +16 -14
  44. package/dist/core/range.js +5 -5
  45. package/dist/core/row-input.d.ts +9 -8
  46. package/dist/core/row-input.js +12 -10
  47. package/dist/core/row.d.ts +7 -8
  48. package/dist/core/row.js +2 -4
  49. package/dist/core/style.d.ts +41 -14
  50. package/dist/core/style.js +82 -67
  51. package/dist/core/table-style.d.ts +9 -9
  52. package/dist/core/table-style.js +1 -1
  53. package/dist/core/table.d.ts +53 -51
  54. package/dist/core/table.js +83 -41
  55. package/dist/core/theme.d.ts +16 -44
  56. package/dist/core/theme.js +6 -148
  57. package/dist/core/value.d.ts +7 -7
  58. package/dist/core/workbook-protection.d.ts +2 -2
  59. package/dist/core/workbook-styles.d.ts +26 -0
  60. package/dist/core/workbook-styles.js +48 -0
  61. package/dist/core/workbook-theme.d.ts +25 -0
  62. package/dist/core/workbook-theme.js +49 -0
  63. package/dist/core/workbook-vba.d.ts +17 -0
  64. package/dist/core/workbook-vba.js +79 -0
  65. package/dist/core/workbook.d.ts +133 -87
  66. package/dist/core/workbook.js +74 -133
  67. package/dist/core/worksheet-comments.d.ts +17 -0
  68. package/dist/core/worksheet-comments.js +70 -0
  69. package/dist/core/worksheet-model.d.ts +4 -4
  70. package/dist/core/worksheet-model.js +1 -0
  71. package/dist/core/worksheet-pictures.d.ts +29 -0
  72. package/dist/core/worksheet-pictures.js +42 -0
  73. package/dist/core/worksheet.d.ts +100 -79
  74. package/dist/core/worksheet.js +63 -142
  75. package/dist/customui/errors.d.ts +1 -1
  76. package/dist/customui/ribbon.d.ts +3 -3
  77. package/dist/customui/ribbon.js +24 -23
  78. package/dist/entries/core.d.ts +7 -7
  79. package/dist/entries/core.js +1 -1
  80. package/dist/entries/csv.d.ts +1 -1
  81. package/dist/entries/node-unavailable.d.ts +15 -0
  82. package/dist/entries/node-unavailable.js +20 -0
  83. package/dist/entries/node.d.ts +1 -0
  84. package/dist/entries/node.js +1 -0
  85. package/dist/entries/vba.d.ts +1 -1
  86. package/dist/entries/vba.js +1 -1
  87. package/dist/entries/xlsx.d.ts +1 -1
  88. package/dist/entries/xlsx.js +1 -1
  89. package/dist/errors.d.ts +12 -12
  90. package/dist/io/csv/read.js +2 -3
  91. package/dist/io/csv/write.d.ts +19 -4
  92. package/dist/io/csv/write.js +34 -4
  93. package/dist/io/opc/errors.d.ts +6 -6
  94. package/dist/io/opc/inflate.d.ts +1 -1
  95. package/dist/io/opc/inflate.js +2 -12
  96. package/dist/io/opc/namespaces.d.ts +1 -1
  97. package/dist/io/opc/read-opc.d.ts +19 -3
  98. package/dist/io/opc/read-opc.js +14 -8
  99. package/dist/io/opc/read-options.d.ts +2 -2
  100. package/dist/io/opc/rels.d.ts +11 -0
  101. package/dist/io/opc/rels.js +3 -2
  102. package/dist/io/opc/sniff-format.d.ts +2 -2
  103. package/dist/io/style/xf-style.d.ts +44 -7
  104. package/dist/io/style/xf-style.js +27 -0
  105. package/dist/io/xlsb/errors.d.ts +1 -1
  106. package/dist/io/xlsb/formula.d.ts +4 -4
  107. package/dist/io/xlsb/primitives.d.ts +8 -8
  108. package/dist/io/xlsb/ptg-functions.d.ts +1 -1
  109. package/dist/io/xlsb/read-styles.js +2 -20
  110. package/dist/io/xlsb/read.d.ts +2 -2
  111. package/dist/io/xlsx/cell-accumulator.d.ts +26 -9
  112. package/dist/io/xlsx/cell-accumulator.js +89 -46
  113. package/dist/io/xlsx/cell-value.d.ts +3 -3
  114. package/dist/io/xlsx/cell-value.js +9 -6
  115. package/dist/io/xlsx/color-xml.d.ts +1 -1
  116. package/dist/io/xlsx/color-xml.js +18 -23
  117. package/dist/io/xlsx/comments.d.ts +5 -5
  118. package/dist/io/xlsx/comments.js +17 -8
  119. package/dist/io/xlsx/conditional-formatting.d.ts +4 -4
  120. package/dist/io/xlsx/conditional-formatting.js +64 -58
  121. package/dist/io/xlsx/data-validation.d.ts +3 -3
  122. package/dist/io/xlsx/data-validation.js +35 -33
  123. package/dist/io/xlsx/errors.d.ts +3 -3
  124. package/dist/io/xlsx/hyperlinks.d.ts +4 -2
  125. package/dist/io/xlsx/hyperlinks.js +10 -18
  126. package/dist/io/xlsx/images.d.ts +1 -1
  127. package/dist/io/xlsx/images.js +25 -28
  128. package/dist/io/xlsx/namespaces.d.ts +2 -2
  129. package/dist/io/xlsx/package-plan.js +5 -2
  130. package/dist/io/xlsx/read-pivot.js +4 -13
  131. package/dist/io/xlsx/read-rows.d.ts +13 -13
  132. package/dist/io/xlsx/read-rows.js +19 -55
  133. package/dist/io/xlsx/read-shared-strings.js +7 -44
  134. package/dist/io/xlsx/read-styles.d.ts +3 -3
  135. package/dist/io/xlsx/read-styles.js +42 -66
  136. package/dist/io/xlsx/read-worksheet.js +73 -129
  137. package/dist/io/xlsx/read.d.ts +4 -6
  138. package/dist/io/xlsx/read.js +104 -142
  139. package/dist/io/xlsx/rich-runs.d.ts +41 -7
  140. package/dist/io/xlsx/rich-runs.js +94 -30
  141. package/dist/io/xlsx/rich-text.d.ts +1 -1
  142. package/dist/io/xlsx/shared-strings.d.ts +2 -2
  143. package/dist/io/xlsx/sheet-properties.d.ts +1 -1
  144. package/dist/io/xlsx/sheet-properties.js +14 -10
  145. package/dist/io/xlsx/styles.d.ts +9 -22
  146. package/dist/io/xlsx/styles.js +65 -89
  147. package/dist/io/xlsx/tables.d.ts +2 -2
  148. package/dist/io/xlsx/tables.js +20 -25
  149. package/dist/io/xlsx/theme-xml.d.ts +37 -0
  150. package/dist/io/xlsx/theme-xml.js +145 -0
  151. package/dist/io/xlsx/threaded-comments.d.ts +18 -27
  152. package/dist/io/xlsx/threaded-comments.js +26 -38
  153. package/dist/io/xlsx/workbook-xml.js +14 -8
  154. package/dist/io/xlsx/worksheet-xml.d.ts +2 -2
  155. package/dist/io/xlsx/worksheet-xml.js +40 -48
  156. package/dist/io/xlsx/write-stream.d.ts +23 -16
  157. package/dist/io/xlsx/write-stream.js +13 -14
  158. package/dist/io/xlsx/write.d.ts +8 -7
  159. package/dist/io/xlsx/write.js +6 -3
  160. package/dist/io/xlsx/x14-ext.d.ts +1 -1
  161. package/dist/sha512.d.ts +2 -0
  162. package/dist/sha512.js +146 -0
  163. package/dist/vba/bytes.d.ts +11 -0
  164. package/dist/vba/bytes.js +29 -0
  165. package/dist/vba/cfb-writer.d.ts +1 -1
  166. package/dist/vba/cfb.d.ts +1 -1
  167. package/dist/vba/cfb.js +15 -51
  168. package/dist/vba/codepage.d.ts +2 -2
  169. package/dist/vba/dir-records.d.ts +53 -0
  170. package/dist/vba/dir-records.js +28 -0
  171. package/dist/vba/errors.d.ts +2 -2
  172. package/dist/vba/index.d.ts +2 -2
  173. package/dist/vba/index.js +2 -2
  174. package/dist/vba/ms-ovba.d.ts +1 -1
  175. package/dist/vba/ms-ovba.js +1 -3
  176. package/dist/vba/project-editor.d.ts +9 -9
  177. package/dist/vba/project-editor.js +6 -44
  178. package/dist/vba/project.d.ts +5 -5
  179. package/dist/vba/project.js +3 -28
  180. package/dist/vba/vba-encoding.d.ts +1 -1
  181. package/dist/xml/errors.d.ts +1 -1
  182. package/dist/xml/xml-read.d.ts +98 -9
  183. package/dist/xml/xml-read.js +70 -0
  184. package/dist/xml/xml.d.ts +74 -10
  185. package/dist/xml/xml.js +39 -7
  186. package/package.json +59 -36
@@ -1,9 +1,10 @@
1
- import { decodeRange } from '../../core/address.js';
1
+ import { MAX_COLUMN, MAX_ROW, tryDecodeRange } from '../../core/address.js';
2
2
  import { isCustomFilterOperator, } from '../../core/autofilter.js';
3
3
  import { INTERNAL } from '../../core/internal.js';
4
+ import { isPageOrder, isPageOrientation, } from '../../core/page-setup.js';
4
5
  import { SHEET_PROTECTION_FLAGS, } from '../../core/protection.js';
5
6
  import { assignStyleFacets } from '../../core/style.js';
6
- import { boolPresent, boolStrict, boolTristate, localName, parseXml, } from '../../xml/xml-read.js';
7
+ import { boolPresent, boolStrict, boolTristate, decodeSpreadsheetText, enumToken, localName, numFinite, numInteger, parseXml, } from '../../xml/xml-read.js';
7
8
  import { CellAccumulator } from './cell-accumulator.js';
8
9
  import { parseColor } from './color-xml.js';
9
10
  const MARGIN_SIDES = ['left', 'right', 'top', 'bottom', 'header', 'footer'];
@@ -27,20 +28,18 @@ function parseSheetProtection(attrs) {
27
28
  flags[key] = !boolStrict(raw);
28
29
  }
29
30
  const { algorithmName, hashValue, saltValue, spinCount } = attrs;
31
+ const spin = numInteger(spinCount, 0);
30
32
  if (algorithmName !== undefined &&
31
33
  hashValue !== undefined &&
32
34
  saltValue !== undefined &&
33
- spinCount !== undefined) {
34
- const spin = Number(spinCount);
35
- if (Number.isFinite(spin)) {
36
- const credential = {
37
- algorithmName,
38
- hashValue,
39
- saltValue,
40
- spinCount: spin,
41
- };
42
- return { flags, credential };
43
- }
35
+ spin !== undefined) {
36
+ const credential = {
37
+ algorithmName,
38
+ hashValue,
39
+ saltValue,
40
+ spinCount: spin,
41
+ };
42
+ return { flags, credential };
44
43
  }
45
44
  return { flags };
46
45
  }
@@ -57,7 +56,7 @@ class AutoFilterAccumulator {
57
56
  this.#columns = [];
58
57
  }
59
58
  beginColumn(attrs) {
60
- this.#colId = attrs.colId !== undefined ? Number(attrs.colId) : -1;
59
+ this.#colId = numInteger(attrs.colId, 0) ?? -1;
61
60
  this.#values = null;
62
61
  this.#blank = false;
63
62
  this.#predicates = null;
@@ -92,13 +91,13 @@ class AutoFilterAccumulator {
92
91
  commit(sheet) {
93
92
  if (this.#ref === null)
94
93
  return;
95
- try {
96
- const { left, right } = decodeRange(this.#ref);
97
- const width = left !== undefined && right !== undefined ? right - left + 1 : 0;
94
+ const decoded = tryDecodeRange(this.#ref);
95
+ const left = decoded?.left;
96
+ const right = decoded?.right;
97
+ if (left !== undefined && right !== undefined) {
98
+ const width = right - left + 1;
98
99
  sheet.autoFilter = { ref: this.#ref, columns: this.#columns.filter((c) => c.colId < width) };
99
100
  }
100
- catch {
101
- }
102
101
  this.#ref = null;
103
102
  this.#columns = [];
104
103
  }
@@ -114,12 +113,12 @@ class PageBreakAccumulator {
114
113
  add(attrs) {
115
114
  if (this.#target === null)
116
115
  return;
117
- const id = Number(attrs.id);
118
- if (!Number.isInteger(id) || id < 1)
116
+ const id = numInteger(attrs.id, 1);
117
+ if (id === undefined)
119
118
  return;
120
119
  const brk = { id };
121
- const max = Number(attrs.max);
122
- if (Number.isInteger(max) && max >= 0)
120
+ const max = numInteger(attrs.max, 0);
121
+ if (max !== undefined)
123
122
  brk.max = max;
124
123
  if (boolStrict(attrs.man))
125
124
  brk.man = true;
@@ -127,10 +126,7 @@ class PageBreakAccumulator {
127
126
  }
128
127
  }
129
128
  export function parseWorksheet(xml, sheet, sharedStrings, xfStyles) {
130
- const cell = new CellAccumulator();
131
- let inInlineString = false;
132
- let capture = false;
133
- let text = '';
129
+ const cell = new CellAccumulator({ richRuns: true });
134
130
  let rowStyle = -1;
135
131
  let rowCustomFormat = false;
136
132
  const autoFilter = new AutoFilterAccumulator();
@@ -148,46 +144,24 @@ export function parseWorksheet(xml, sheet, sharedStrings, xfStyles) {
148
144
  parseXml(xml, {
149
145
  onOpen(name, attrs, selfClosing) {
150
146
  const local = localName(name);
151
- text = '';
152
- capture = false;
147
+ if (cell.openElement(local, attrs, selfClosing))
148
+ return;
153
149
  switch (local) {
154
150
  case 'col':
155
151
  applyColumn(sheet, attrs, xfStyles, columnStyle);
156
152
  break;
157
153
  case 'row':
158
154
  applyRow(sheet, attrs);
159
- rowStyle = attrs.s !== undefined ? Number(attrs.s) : -1;
155
+ rowStyle = numInteger(attrs.s, 0) ?? -1;
160
156
  rowCustomFormat = boolStrict(attrs.customFormat);
161
157
  break;
162
- case 'c':
163
- cell.beginCell(attrs);
164
- break;
165
- case 'is':
166
- inInlineString = true;
167
- cell.beginInlineString();
168
- break;
169
- case 'r':
170
- if (inInlineString)
171
- cell.runs.beginRun();
172
- break;
173
- case 'rPr':
174
- cell.runs.beginProperties();
175
- break;
176
- case 'f':
177
- capture = true;
178
- cell.beginFormula(attrs, selfClosing);
179
- break;
180
- case 'v':
181
- case 't':
182
- capture = true;
183
- break;
184
158
  case 'oddHeader':
185
159
  case 'oddFooter':
186
160
  case 'evenHeader':
187
161
  case 'evenFooter':
188
162
  case 'firstHeader':
189
163
  case 'firstFooter':
190
- capture = true;
164
+ cell.capture();
191
165
  break;
192
166
  case 'mergeCell':
193
167
  if (attrs.ref !== undefined && attrs.ref !== '') {
@@ -241,45 +215,28 @@ export function parseWorksheet(xml, sheet, sharedStrings, xfStyles) {
241
215
  case 'customFilter':
242
216
  autoFilter.addCustom(attrs);
243
217
  break;
244
- default:
245
- cell.runs.applyProperty(local, attrs);
246
- break;
247
218
  }
248
- if (selfClosing && (local === 'f' || local === 'v'))
249
- capture = false;
250
219
  },
251
220
  onText(chunk) {
252
- if (capture)
253
- text += chunk;
221
+ cell.appendChunk(chunk);
254
222
  },
255
223
  onClose(name) {
256
224
  const local = localName(name);
225
+ const claimed = cell.closeElement(local);
226
+ if (claimed === 'cell') {
227
+ finalizeCellFromState();
228
+ return;
229
+ }
230
+ if (claimed === 'claimed')
231
+ return;
257
232
  switch (local) {
258
- case 'f':
259
- cell.setFormula(text);
260
- break;
261
- case 'v':
262
- cell.setValue(text);
263
- break;
264
- case 't':
265
- cell.appendText(text, inInlineString);
266
- break;
267
- case 'r':
268
- cell.runs.endRun();
269
- break;
270
- case 'is':
271
- inInlineString = false;
272
- break;
273
233
  case 'oddHeader':
274
234
  case 'oddFooter':
275
235
  case 'evenHeader':
276
236
  case 'evenFooter':
277
237
  case 'firstHeader':
278
238
  case 'firstFooter':
279
- sheet.headerFooter[local] = text;
280
- break;
281
- case 'c':
282
- finalizeCellFromState();
239
+ sheet.headerFooter[local] = decodeSpreadsheetText(cell.capturedText);
283
240
  break;
284
241
  case 'row':
285
242
  rowStyle = -1;
@@ -298,7 +255,6 @@ export function parseWorksheet(xml, sheet, sharedStrings, xfStyles) {
298
255
  default:
299
256
  break;
300
257
  }
301
- capture = false;
302
258
  },
303
259
  }, { closeEmptyElements: WORKSHEET_EMPTY_CLOSES });
304
260
  }
@@ -321,10 +277,12 @@ function applySheetProperties(local, attrs, sheet) {
321
277
  case 'pane':
322
278
  if (attrs.state === 'frozen' || attrs.state === 'frozenSplit') {
323
279
  sheet.view.state = 'frozen';
324
- if (attrs.xSplit !== undefined)
325
- sheet.view.xSplit = Number(attrs.xSplit);
326
- if (attrs.ySplit !== undefined)
327
- sheet.view.ySplit = Number(attrs.ySplit);
280
+ const xSplit = numInteger(attrs.xSplit, 0);
281
+ const ySplit = numInteger(attrs.ySplit, 0);
282
+ if (xSplit !== undefined)
283
+ sheet.view.xSplit = xSplit;
284
+ if (ySplit !== undefined)
285
+ sheet.view.ySplit = ySplit;
328
286
  if (attrs.topLeftCell !== undefined)
329
287
  sheet.view.topLeftCell = attrs.topLeftCell;
330
288
  }
@@ -345,25 +303,24 @@ function applySheetProperties(local, attrs, sheet) {
345
303
  }
346
304
  }
347
305
  function applyColumn(sheet, attrs, xfStyles, columnStyle) {
348
- const min = Number(attrs.min);
349
- const max = Number(attrs.max);
350
- if (!Number.isInteger(min) || !Number.isInteger(max) || min < 1)
306
+ const min = numInteger(attrs.min, 1);
307
+ const max = numInteger(attrs.max, 1);
308
+ if (min === undefined || max === undefined || min > MAX_COLUMN)
351
309
  return;
352
- const width = attrs.width !== undefined ? Number(attrs.width) : undefined;
310
+ const last = Math.min(max, MAX_COLUMN);
311
+ const width = numFinite(attrs.width);
353
312
  const hidden = boolStrict(attrs.hidden);
354
- const styleIndex = attrs.style !== undefined ? Number(attrs.style) : -1;
313
+ const styleIndex = numInteger(attrs.style, 0) ?? -1;
355
314
  const style = styleIndex >= 0 ? xfStyles[styleIndex] : undefined;
356
- for (let index = min; index <= max; index++) {
315
+ for (let index = min; index <= last; index++) {
357
316
  const column = sheet.getColumn(index);
358
- if (width !== undefined && Number.isFinite(width) && attrs.customWidth !== '0')
317
+ if (width !== undefined && boolPresent(attrs.customWidth))
359
318
  column.width = width;
360
319
  if (hidden)
361
320
  column.hidden = true;
362
- if (attrs.outlineLevel !== undefined) {
363
- const level = Number(attrs.outlineLevel);
364
- if (Number.isInteger(level) && level > 0)
365
- column.outlineLevel = level;
366
- }
321
+ const outlineLevel = numInteger(attrs.outlineLevel, 1);
322
+ if (outlineLevel !== undefined)
323
+ column.outlineLevel = outlineLevel;
367
324
  if (boolStrict(attrs.collapsed))
368
325
  column.collapsed = true;
369
326
  if (style !== undefined)
@@ -373,22 +330,18 @@ function applyColumn(sheet, attrs, xfStyles, columnStyle) {
373
330
  }
374
331
  }
375
332
  function applyRow(sheet, attrs) {
376
- const number = Number(attrs.r);
377
- if (!Number.isInteger(number) || number < 1)
333
+ const number = numInteger(attrs.r, 1);
334
+ if (number === undefined || number > MAX_ROW)
378
335
  return;
379
336
  const row = sheet.getRow(number);
380
- if (attrs.ht !== undefined && attrs.customHeight !== '0') {
381
- const height = Number(attrs.ht);
382
- if (Number.isFinite(height))
383
- row.height = height;
384
- }
337
+ const height = numFinite(attrs.ht);
338
+ if (height !== undefined && boolPresent(attrs.customHeight))
339
+ row.height = height;
385
340
  if (boolStrict(attrs.hidden))
386
341
  row.hidden = true;
387
- if (attrs.outlineLevel !== undefined) {
388
- const level = Number(attrs.outlineLevel);
389
- if (Number.isInteger(level) && level > 0)
390
- row.outlineLevel = level;
391
- }
342
+ const outlineLevel = numInteger(attrs.outlineLevel, 1);
343
+ if (outlineLevel !== undefined)
344
+ row.outlineLevel = outlineLevel;
392
345
  if (boolStrict(attrs.collapsed))
393
346
  row.collapsed = true;
394
347
  }
@@ -411,37 +364,28 @@ function applyPrintOptions(printOptions, attrs) {
411
364
  }
412
365
  function applyMargins(margins, attrs) {
413
366
  for (const side of MARGIN_SIDES) {
414
- const raw = attrs[side];
415
- if (raw === undefined)
416
- continue;
417
- const value = Number(raw);
418
- if (Number.isFinite(value))
367
+ const value = numFinite(attrs[side]);
368
+ if (value !== undefined)
419
369
  margins[side] = value;
420
370
  }
421
371
  }
422
372
  function applyPageSetup(pageSetup, attrs) {
423
- const num = (raw) => {
424
- if (raw === undefined)
425
- return undefined;
426
- const value = Number(raw);
427
- return Number.isFinite(value) ? value : undefined;
428
- };
429
- const paperSize = num(attrs.paperSize);
373
+ const paperSize = numInteger(attrs.paperSize, 0);
430
374
  if (paperSize !== undefined)
431
375
  pageSetup.paperSize = paperSize;
432
- const scale = num(attrs.scale);
376
+ const scale = numInteger(attrs.scale, 0);
433
377
  if (scale !== undefined)
434
378
  pageSetup.scale = scale;
435
- const fitToWidth = num(attrs.fitToWidth);
379
+ const fitToWidth = numInteger(attrs.fitToWidth, 0);
436
380
  if (fitToWidth !== undefined)
437
381
  pageSetup.fitToWidth = fitToWidth;
438
- const fitToHeight = num(attrs.fitToHeight);
382
+ const fitToHeight = numInteger(attrs.fitToHeight, 0);
439
383
  if (fitToHeight !== undefined)
440
384
  pageSetup.fitToHeight = fitToHeight;
441
- if (attrs.pageOrder === 'downThenOver' || attrs.pageOrder === 'overThenDown') {
442
- pageSetup.pageOrder = attrs.pageOrder;
443
- }
444
- if (attrs.orientation === 'portrait' || attrs.orientation === 'landscape') {
445
- pageSetup.orientation = attrs.orientation;
446
- }
385
+ const pageOrder = enumToken(attrs.pageOrder, isPageOrder);
386
+ if (pageOrder !== undefined)
387
+ pageSetup.pageOrder = pageOrder;
388
+ const orientation = enumToken(attrs.orientation, isPageOrientation);
389
+ if (orientation !== undefined)
390
+ pageSetup.orientation = orientation;
447
391
  }
@@ -1,6 +1,5 @@
1
1
  import { Workbook, type WorkbookView } from '../../core/workbook.ts';
2
- import { type WorkbookProtection } from '../../core/workbook-protection.ts';
3
- import type { WorksheetState } from '../../core/worksheet.ts';
2
+ import { type WorksheetState } from '../../core/worksheet.ts';
4
3
  import { type ReadXlsxOptions } from '../opc/read-options.ts';
5
4
  export { parseRelationships, resolveWorkbookPart } from '../opc/read-opc.ts';
6
5
  export { DEFAULT_MAX_UNCOMPRESSED, type ReadXlsxOptions } from '../opc/read-options.ts';
@@ -11,14 +10,14 @@ export { parseStyleTable } from './read-styles.ts';
11
10
  *
12
11
  * Both OOXML serialisations are accepted: an XML `.xlsx`, and a binary `.xlsb` (BIFF12), which is the
13
12
  * same OPC container with binary office-document parts. The two are auto-detected from the package
14
- * itself rather than from a file extension, so a caller never branches on which form it holds and
13
+ * itself rather than from a file extension, so a caller never branches on which form it holds, and
15
14
  * the model produced is the same either way. See `../xlsb/read.ts` for what the binary path does not
16
15
  * yet decode.
17
16
  *
18
- * @throws {UnsupportedFormatError} if the input is neither a legacy `.xls` (`.format === 'xls'`) or
17
+ * @throws {UnsupportedFormatError} if the input is neither: a legacy `.xls` (`.format === 'xls'`) or
19
18
  * an unrecognised/non-ZIP blob (`'unknown'`).
20
19
  * @throws {XlsbParseError} if a binary `.xlsb` part is malformed.
21
- * @throws {PackageReadError} if the input is a ZIP that cannot be unpacked a corrupt or
20
+ * @throws {PackageReadError} if the input is a ZIP that cannot be unpacked: a corrupt or
22
21
  * truncated archive, or one exceeding the inflate bound (a probable zip bomb).
23
22
  */
24
23
  export declare function readXlsx(data: Uint8Array, options?: ReadXlsxOptions): Workbook;
@@ -28,5 +27,4 @@ export interface SheetEntry {
28
27
  readonly state?: WorksheetState['state'];
29
28
  }
30
29
  export declare function parseWorkbookSheets(xml: string): SheetEntry[];
31
- export declare function parseWorkbookProtection(xml: string): WorkbookProtection | undefined;
32
30
  export declare function applyWorkbookView(view: WorkbookView, xml: string): void;