@shbernal/ts-xlsx 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/core/address.d.ts +49 -2
- package/dist/core/address.js +31 -3
- package/dist/core/autofilter.d.ts +2 -2
- package/dist/core/cell.d.ts +17 -16
- package/dist/core/cell.js +3 -7
- package/dist/core/color-resolution.d.ts +7 -7
- package/dist/core/column.d.ts +8 -9
- package/dist/core/column.js +2 -4
- package/dist/core/comment-thread.d.ts +32 -23
- package/dist/core/comment-thread.js +4 -4
- package/dist/core/conditional-formatting-overlay.d.ts +1 -1
- package/dist/core/conditional-formatting.d.ts +3 -3
- package/dist/core/data-validation-overlay.d.ts +1 -1
- package/dist/core/data-validation.d.ts +3 -3
- package/dist/core/date.d.ts +3 -3
- package/dist/core/formula.d.ts +6 -6
- package/dist/core/grid-edits.js +3 -3
- package/dist/core/image.d.ts +37 -2
- package/dist/core/image.js +6 -0
- package/dist/core/internal.d.ts +9 -1
- package/dist/core/limits.d.ts +4 -4
- package/dist/core/merge.d.ts +6 -12
- package/dist/core/merge.js +0 -3
- package/dist/core/page-setup.d.ts +4 -4
- package/dist/core/pivot-table.d.ts +2 -4
- package/dist/core/pivot-table.js +5 -5
- package/dist/core/preserved.d.ts +3 -3
- package/dist/core/protection.d.ts +4 -4
- package/dist/core/range.d.ts +16 -14
- package/dist/core/range.js +5 -5
- package/dist/core/row-input.d.ts +2 -8
- package/dist/core/row-input.js +2 -2
- package/dist/core/row.d.ts +7 -8
- package/dist/core/row.js +2 -4
- package/dist/core/style.d.ts +14 -14
- package/dist/core/table-style.d.ts +9 -9
- package/dist/core/table-style.js +1 -1
- package/dist/core/table.d.ts +30 -42
- package/dist/core/table.js +16 -10
- package/dist/core/theme.d.ts +13 -43
- package/dist/core/theme.js +2 -148
- package/dist/core/value.d.ts +7 -7
- package/dist/core/workbook-protection.d.ts +2 -2
- package/dist/core/workbook-styles.d.ts +26 -0
- package/dist/core/workbook-styles.js +48 -0
- package/dist/core/workbook-theme.d.ts +25 -0
- package/dist/core/workbook-theme.js +49 -0
- package/dist/core/workbook-vba.d.ts +17 -0
- package/dist/core/workbook-vba.js +79 -0
- package/dist/core/workbook.d.ts +141 -83
- package/dist/core/workbook.js +74 -133
- package/dist/core/worksheet-comments.d.ts +9 -0
- package/dist/core/worksheet-comments.js +52 -0
- package/dist/core/worksheet-model.d.ts +4 -4
- package/dist/core/worksheet-model.js +1 -0
- package/dist/core/worksheet-pictures.d.ts +29 -0
- package/dist/core/worksheet-pictures.js +42 -0
- package/dist/core/worksheet.d.ts +94 -77
- package/dist/core/worksheet.js +36 -95
- package/dist/customui/errors.d.ts +1 -1
- package/dist/customui/ribbon.d.ts +3 -3
- package/dist/entries/core.d.ts +4 -4
- package/dist/entries/core.js +1 -1
- package/dist/entries/vba.d.ts +1 -1
- package/dist/entries/vba.js +1 -1
- package/dist/entries/xlsx.d.ts +1 -0
- package/dist/entries/xlsx.js +1 -0
- package/dist/errors.d.ts +12 -12
- package/dist/io/csv/read.js +1 -2
- package/dist/io/csv/write.d.ts +8 -3
- package/dist/io/csv/write.js +17 -2
- package/dist/io/opc/errors.d.ts +6 -6
- package/dist/io/opc/inflate.d.ts +1 -1
- package/dist/io/opc/namespaces.d.ts +1 -1
- package/dist/io/opc/read-opc.d.ts +19 -3
- package/dist/io/opc/read-opc.js +14 -8
- package/dist/io/opc/read-options.d.ts +2 -2
- package/dist/io/opc/sniff-format.d.ts +2 -2
- package/dist/io/opc/zip-mtime.d.ts +5 -0
- package/dist/io/opc/zip-mtime.js +1 -0
- package/dist/io/style/xf-style.d.ts +38 -6
- package/dist/io/style/xf-style.js +22 -0
- package/dist/io/xlsb/errors.d.ts +1 -1
- package/dist/io/xlsb/formula.d.ts +4 -4
- package/dist/io/xlsb/primitives.d.ts +8 -8
- package/dist/io/xlsb/ptg-functions.d.ts +1 -1
- package/dist/io/xlsb/read-styles.js +2 -20
- package/dist/io/xlsb/read.d.ts +2 -2
- package/dist/io/xlsx/cell-accumulator.d.ts +25 -6
- package/dist/io/xlsx/cell-accumulator.js +111 -30
- package/dist/io/xlsx/cell-value.d.ts +2 -2
- package/dist/io/xlsx/cell-value.js +3 -3
- package/dist/io/xlsx/color-xml.js +11 -17
- package/dist/io/xlsx/comments.d.ts +5 -5
- package/dist/io/xlsx/comments.js +13 -6
- package/dist/io/xlsx/conditional-formatting.d.ts +3 -3
- package/dist/io/xlsx/conditional-formatting.js +7 -16
- package/dist/io/xlsx/data-validation.d.ts +2 -2
- package/dist/io/xlsx/data-validation.js +1 -1
- package/dist/io/xlsx/edit-vba.js +2 -1
- package/dist/io/xlsx/errors.d.ts +3 -3
- package/dist/io/xlsx/hyperlinks.d.ts +4 -2
- package/dist/io/xlsx/hyperlinks.js +5 -5
- package/dist/io/xlsx/images.d.ts +1 -1
- package/dist/io/xlsx/images.js +8 -8
- package/dist/io/xlsx/namespaces.d.ts +2 -2
- package/dist/io/xlsx/package-plan.js +5 -2
- package/dist/io/xlsx/read-pivot.js +2 -5
- package/dist/io/xlsx/read-rows.d.ts +13 -13
- package/dist/io/xlsx/read-rows.js +19 -55
- package/dist/io/xlsx/read-shared-strings.js +7 -5
- package/dist/io/xlsx/read-styles.d.ts +3 -3
- package/dist/io/xlsx/read-styles.js +40 -65
- package/dist/io/xlsx/read-worksheet.js +67 -115
- package/dist/io/xlsx/read.d.ts +3 -5
- package/dist/io/xlsx/read.js +94 -71
- package/dist/io/xlsx/rich-runs.d.ts +1 -1
- package/dist/io/xlsx/rich-runs.js +1 -1
- package/dist/io/xlsx/rich-text.d.ts +1 -1
- package/dist/io/xlsx/shared-strings.d.ts +2 -2
- package/dist/io/xlsx/sheet-properties.js +5 -4
- package/dist/io/xlsx/styles.d.ts +8 -9
- package/dist/io/xlsx/styles.js +4 -3
- package/dist/io/xlsx/tables.d.ts +2 -2
- package/dist/io/xlsx/tables.js +8 -13
- package/dist/io/xlsx/theme-xml.d.ts +37 -0
- package/dist/io/xlsx/theme-xml.js +142 -0
- package/dist/io/xlsx/threaded-comments.d.ts +18 -27
- package/dist/io/xlsx/threaded-comments.js +9 -21
- package/dist/io/xlsx/workbook-xml.d.ts +1 -1
- package/dist/io/xlsx/workbook-xml.js +6 -2
- package/dist/io/xlsx/worksheet-xml.d.ts +2 -2
- package/dist/io/xlsx/worksheet-xml.js +7 -12
- package/dist/io/xlsx/write-stream.d.ts +15 -15
- package/dist/io/xlsx/write-stream.js +5 -3
- package/dist/io/xlsx/write.d.ts +12 -7
- package/dist/io/xlsx/write.js +10 -6
- package/dist/io/xlsx/x14-ext.d.ts +1 -1
- package/dist/vba/bytes.d.ts +12 -0
- package/dist/vba/bytes.js +40 -0
- package/dist/vba/cfb-writer.d.ts +1 -1
- package/dist/vba/cfb.d.ts +1 -1
- package/dist/vba/cfb.js +15 -51
- package/dist/vba/codepage.d.ts +2 -2
- package/dist/vba/errors.d.ts +2 -2
- package/dist/vba/index.d.ts +2 -2
- package/dist/vba/index.js +2 -2
- package/dist/vba/ms-ovba.d.ts +1 -1
- package/dist/vba/ms-ovba.js +1 -3
- package/dist/vba/project-editor.d.ts +9 -9
- package/dist/vba/project-editor.js +2 -11
- package/dist/vba/project.d.ts +5 -5
- package/dist/vba/project.js +1 -10
- package/dist/vba/vba-encoding.d.ts +1 -1
- package/dist/xml/errors.d.ts +1 -1
- package/dist/xml/xml-read.d.ts +38 -9
- package/dist/xml/xml-read.js +23 -0
- package/dist/xml/xml.d.ts +31 -9
- package/dist/xml/xml.js +23 -3
- package/package.json +41 -35
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { boolPresent, boolStrict, closeEmptyElements, localName, openElements, xmlEvents, } from '../../xml/xml-read.js';
|
|
3
|
-
import { numFmtCodeFor } from '../style/xf-style.js';
|
|
1
|
+
import { isBorderStyle, isFillPatternType, isFontScheme, isFontVerticalAlignment, isHorizontalAlignment, isNamedUnderlineStyle, isVerticalAlignment, } from '../../core/style.js';
|
|
2
|
+
import { boolPresent, boolStrict, closeEmptyElements, localName, numFinite, numInteger, openElements, xmlEvents, } from '../../xml/xml-read.js';
|
|
3
|
+
import { numFmtCodeFor, resolveStyleTable, } from '../style/xf-style.js';
|
|
4
4
|
import { parseColor } from './color-xml.js';
|
|
5
5
|
const BORDER_EDGE_NAMES = ['left', 'right', 'top', 'bottom', 'diagonal'];
|
|
6
6
|
const BORDER_EDGES = new Set(BORDER_EDGE_NAMES);
|
|
@@ -53,24 +53,7 @@ export function parseStyleTable(xml) {
|
|
|
53
53
|
}
|
|
54
54
|
next = events.next();
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
if (xf.xfId === undefined)
|
|
58
|
-
return xf;
|
|
59
|
-
const named = namedXfs[xf.xfId];
|
|
60
|
-
return named === undefined ? xf : { ...named, ...xf };
|
|
61
|
-
});
|
|
62
|
-
const namedStyles = namedXfs.map((xf, index) => {
|
|
63
|
-
const label = cellStyleNames.find((entry) => entry.xfId === index);
|
|
64
|
-
const style = {};
|
|
65
|
-
assignStyleFacets(style, xf);
|
|
66
|
-
if (label?.name !== undefined)
|
|
67
|
-
style.name = label.name;
|
|
68
|
-
if (label?.builtinId !== undefined)
|
|
69
|
-
style.builtinId = label.builtinId;
|
|
70
|
-
return style;
|
|
71
|
-
});
|
|
72
|
-
const defaultFont = fonts[0];
|
|
73
|
-
return defaultFont === undefined ? { cellXfs, namedStyles } : { cellXfs, namedStyles, defaultFont };
|
|
56
|
+
return resolveStyleTable({ directXfs: xfStyles, namedXfs, labels: cellStyleNames, fonts });
|
|
74
57
|
}
|
|
75
58
|
function* until(events, container) {
|
|
76
59
|
let next = events.next();
|
|
@@ -86,8 +69,8 @@ function parseNumFmts(events) {
|
|
|
86
69
|
const codes = new Map();
|
|
87
70
|
for (const event of until(events, 'numFmts')) {
|
|
88
71
|
if (event.kind === 'open' && localName(event.name) === 'numFmt') {
|
|
89
|
-
const id =
|
|
90
|
-
if (
|
|
72
|
+
const id = numInteger(event.attrs.numFmtId, 1);
|
|
73
|
+
if (id !== undefined && event.attrs.formatCode !== undefined) {
|
|
91
74
|
codes.set(id, event.attrs.formatCode);
|
|
92
75
|
}
|
|
93
76
|
}
|
|
@@ -151,8 +134,7 @@ function parseFills(events) {
|
|
|
151
134
|
break;
|
|
152
135
|
case 'stop':
|
|
153
136
|
if (gradientDraft !== null) {
|
|
154
|
-
|
|
155
|
-
gradientDraft.stopPosition = Number.isFinite(position) ? position : 0;
|
|
137
|
+
gradientDraft.stopPosition = numFinite(attrs.position) ?? 0;
|
|
156
138
|
gradientDraft.stopColor = undefined;
|
|
157
139
|
}
|
|
158
140
|
break;
|
|
@@ -271,12 +253,12 @@ function parseXfTable(events, container, deps) {
|
|
|
271
253
|
return xfs;
|
|
272
254
|
}
|
|
273
255
|
function resolveXf(attrs, deps, captureXfId) {
|
|
274
|
-
const fillId =
|
|
275
|
-
const fill =
|
|
276
|
-
const fontId =
|
|
277
|
-
const font =
|
|
278
|
-
const borderId =
|
|
279
|
-
const border =
|
|
256
|
+
const fillId = numInteger(attrs.fillId, 0);
|
|
257
|
+
const fill = fillId !== undefined ? deps.fills[fillId] : undefined;
|
|
258
|
+
const fontId = numInteger(attrs.fontId, 0);
|
|
259
|
+
const font = fontId !== undefined ? deps.fonts[fontId] : undefined;
|
|
260
|
+
const borderId = numInteger(attrs.borderId, 1);
|
|
261
|
+
const border = borderId !== undefined ? deps.borders[borderId] : undefined;
|
|
280
262
|
const numFmt = resolveNumFmt(attrs.numFmtId, deps.numFmtCodes);
|
|
281
263
|
const draft = {};
|
|
282
264
|
if (fill)
|
|
@@ -289,9 +271,9 @@ function resolveXf(attrs, deps, captureXfId) {
|
|
|
289
271
|
draft.border = border;
|
|
290
272
|
if (boolStrict(attrs.quotePrefix))
|
|
291
273
|
draft.quotePrefix = true;
|
|
292
|
-
if (captureXfId
|
|
293
|
-
const xfId =
|
|
294
|
-
if (
|
|
274
|
+
if (captureXfId) {
|
|
275
|
+
const xfId = numInteger(attrs.xfId, 1);
|
|
276
|
+
if (xfId !== undefined)
|
|
295
277
|
draft.xfId = xfId;
|
|
296
278
|
}
|
|
297
279
|
return draft;
|
|
@@ -301,16 +283,14 @@ function parseCellStyles(events) {
|
|
|
301
283
|
for (const event of until(events, 'cellStyles')) {
|
|
302
284
|
if (event.kind === 'open' && localName(event.name) === 'cellStyle') {
|
|
303
285
|
const attrs = event.attrs;
|
|
304
|
-
const xfId =
|
|
305
|
-
if (
|
|
286
|
+
const xfId = numInteger(attrs.xfId);
|
|
287
|
+
if (xfId !== undefined) {
|
|
306
288
|
const entry = { xfId };
|
|
307
289
|
if (attrs.name !== undefined)
|
|
308
290
|
entry.name = attrs.name;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
entry.builtinId = builtinId;
|
|
313
|
-
}
|
|
291
|
+
const builtinId = numInteger(attrs.builtinId);
|
|
292
|
+
if (builtinId !== undefined)
|
|
293
|
+
entry.builtinId = builtinId;
|
|
314
294
|
names.push(entry);
|
|
315
295
|
}
|
|
316
296
|
}
|
|
@@ -346,8 +326,8 @@ export function applyFontChild(draft, local, attrs) {
|
|
|
346
326
|
draft.vertAlign = attrs.val;
|
|
347
327
|
break;
|
|
348
328
|
case 'sz': {
|
|
349
|
-
const size =
|
|
350
|
-
if (
|
|
329
|
+
const size = numFinite(attrs.val);
|
|
330
|
+
if (size !== undefined)
|
|
351
331
|
draft.size = size;
|
|
352
332
|
break;
|
|
353
333
|
}
|
|
@@ -360,14 +340,14 @@ export function applyFontChild(draft, local, attrs) {
|
|
|
360
340
|
draft.name = attrs.val;
|
|
361
341
|
break;
|
|
362
342
|
case 'family': {
|
|
363
|
-
const family =
|
|
364
|
-
if (
|
|
343
|
+
const family = numInteger(attrs.val);
|
|
344
|
+
if (family !== undefined)
|
|
365
345
|
draft.family = family;
|
|
366
346
|
break;
|
|
367
347
|
}
|
|
368
348
|
case 'charset': {
|
|
369
|
-
const charset =
|
|
370
|
-
if (
|
|
349
|
+
const charset = numInteger(attrs.val);
|
|
350
|
+
if (charset !== undefined)
|
|
371
351
|
draft.charset = charset;
|
|
372
352
|
break;
|
|
373
353
|
}
|
|
@@ -380,7 +360,8 @@ export function applyFontChild(draft, local, attrs) {
|
|
|
380
360
|
}
|
|
381
361
|
}
|
|
382
362
|
function resolveNumFmt(raw, custom) {
|
|
383
|
-
|
|
363
|
+
const id = numInteger(raw, 1);
|
|
364
|
+
return id === undefined ? undefined : numFmtCodeFor(id, custom);
|
|
384
365
|
}
|
|
385
366
|
function toFill(pattern, fgColor, bgColor) {
|
|
386
367
|
if (!isFillPatternType(pattern) || pattern === 'none')
|
|
@@ -394,8 +375,8 @@ function toFill(pattern, fgColor, bgColor) {
|
|
|
394
375
|
}
|
|
395
376
|
function assignGradientNumbers(fill, attrs) {
|
|
396
377
|
for (const key of ['degree', 'left', 'right', 'top', 'bottom']) {
|
|
397
|
-
const value =
|
|
398
|
-
if (
|
|
378
|
+
const value = numFinite(attrs[key]);
|
|
379
|
+
if (value !== undefined)
|
|
399
380
|
fill[key] = value;
|
|
400
381
|
}
|
|
401
382
|
}
|
|
@@ -414,25 +395,19 @@ function parseAlignment(attrs) {
|
|
|
414
395
|
}
|
|
415
396
|
if (attrs.vertical !== undefined && isVerticalAlignment(attrs.vertical))
|
|
416
397
|
out.vertical = attrs.vertical;
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
out.textRotation = rotation;
|
|
421
|
-
}
|
|
398
|
+
const rotation = numFinite(attrs.textRotation);
|
|
399
|
+
if (rotation !== undefined && rotation !== 0)
|
|
400
|
+
out.textRotation = rotation;
|
|
422
401
|
if (boolStrict(attrs.wrapText))
|
|
423
402
|
out.wrapText = true;
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
out.indent = indent;
|
|
428
|
-
}
|
|
403
|
+
const indent = numInteger(attrs.indent);
|
|
404
|
+
if (indent !== undefined && indent !== 0)
|
|
405
|
+
out.indent = indent;
|
|
429
406
|
if (boolStrict(attrs.shrinkToFit))
|
|
430
407
|
out.shrinkToFit = true;
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
out.readingOrder = order;
|
|
435
|
-
}
|
|
408
|
+
const order = numInteger(attrs.readingOrder);
|
|
409
|
+
if (order !== undefined && order !== 0)
|
|
410
|
+
out.readingOrder = order;
|
|
436
411
|
return Object.keys(out).length > 0 ? out : undefined;
|
|
437
412
|
}
|
|
438
413
|
function parseProtection(attrs) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { decodeRange } from '../../core/address.js';
|
|
1
|
+
import { decodeRange, MAX_COLUMN, MAX_ROW } from '../../core/address.js';
|
|
2
2
|
import { isCustomFilterOperator, } from '../../core/autofilter.js';
|
|
3
3
|
import { INTERNAL } from '../../core/internal.js';
|
|
4
4
|
import { SHEET_PROTECTION_FLAGS, } from '../../core/protection.js';
|
|
5
5
|
import { assignStyleFacets } from '../../core/style.js';
|
|
6
|
-
import { boolPresent, boolStrict, boolTristate, localName, parseXml, } from '../../xml/xml-read.js';
|
|
6
|
+
import { boolPresent, boolStrict, boolTristate, decodeSpreadsheetText, localName, numFinite, numInteger, parseXml, } from '../../xml/xml-read.js';
|
|
7
7
|
import { CellAccumulator } from './cell-accumulator.js';
|
|
8
8
|
import { parseColor } from './color-xml.js';
|
|
9
9
|
const MARGIN_SIDES = ['left', 'right', 'top', 'bottom', 'header', 'footer'];
|
|
@@ -27,20 +27,18 @@ function parseSheetProtection(attrs) {
|
|
|
27
27
|
flags[key] = !boolStrict(raw);
|
|
28
28
|
}
|
|
29
29
|
const { algorithmName, hashValue, saltValue, spinCount } = attrs;
|
|
30
|
+
const spin = numInteger(spinCount, 0);
|
|
30
31
|
if (algorithmName !== undefined &&
|
|
31
32
|
hashValue !== undefined &&
|
|
32
33
|
saltValue !== undefined &&
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
return { flags, credential };
|
|
43
|
-
}
|
|
34
|
+
spin !== undefined) {
|
|
35
|
+
const credential = {
|
|
36
|
+
algorithmName,
|
|
37
|
+
hashValue,
|
|
38
|
+
saltValue,
|
|
39
|
+
spinCount: spin,
|
|
40
|
+
};
|
|
41
|
+
return { flags, credential };
|
|
44
42
|
}
|
|
45
43
|
return { flags };
|
|
46
44
|
}
|
|
@@ -57,7 +55,7 @@ class AutoFilterAccumulator {
|
|
|
57
55
|
this.#columns = [];
|
|
58
56
|
}
|
|
59
57
|
beginColumn(attrs) {
|
|
60
|
-
this.#colId = attrs.colId
|
|
58
|
+
this.#colId = numInteger(attrs.colId, 0) ?? -1;
|
|
61
59
|
this.#values = null;
|
|
62
60
|
this.#blank = false;
|
|
63
61
|
this.#predicates = null;
|
|
@@ -114,12 +112,12 @@ class PageBreakAccumulator {
|
|
|
114
112
|
add(attrs) {
|
|
115
113
|
if (this.#target === null)
|
|
116
114
|
return;
|
|
117
|
-
const id =
|
|
118
|
-
if (
|
|
115
|
+
const id = numInteger(attrs.id, 1);
|
|
116
|
+
if (id === undefined)
|
|
119
117
|
return;
|
|
120
118
|
const brk = { id };
|
|
121
|
-
const max =
|
|
122
|
-
if (
|
|
119
|
+
const max = numInteger(attrs.max, 0);
|
|
120
|
+
if (max !== undefined)
|
|
123
121
|
brk.max = max;
|
|
124
122
|
if (boolStrict(attrs.man))
|
|
125
123
|
brk.man = true;
|
|
@@ -127,10 +125,7 @@ class PageBreakAccumulator {
|
|
|
127
125
|
}
|
|
128
126
|
}
|
|
129
127
|
export function parseWorksheet(xml, sheet, sharedStrings, xfStyles) {
|
|
130
|
-
const cell = new CellAccumulator();
|
|
131
|
-
let inInlineString = false;
|
|
132
|
-
let capture = false;
|
|
133
|
-
let text = '';
|
|
128
|
+
const cell = new CellAccumulator({ richRuns: true });
|
|
134
129
|
let rowStyle = -1;
|
|
135
130
|
let rowCustomFormat = false;
|
|
136
131
|
const autoFilter = new AutoFilterAccumulator();
|
|
@@ -148,46 +143,24 @@ export function parseWorksheet(xml, sheet, sharedStrings, xfStyles) {
|
|
|
148
143
|
parseXml(xml, {
|
|
149
144
|
onOpen(name, attrs, selfClosing) {
|
|
150
145
|
const local = localName(name);
|
|
151
|
-
|
|
152
|
-
|
|
146
|
+
if (cell.openElement(local, attrs, selfClosing))
|
|
147
|
+
return;
|
|
153
148
|
switch (local) {
|
|
154
149
|
case 'col':
|
|
155
150
|
applyColumn(sheet, attrs, xfStyles, columnStyle);
|
|
156
151
|
break;
|
|
157
152
|
case 'row':
|
|
158
153
|
applyRow(sheet, attrs);
|
|
159
|
-
rowStyle = attrs.s
|
|
154
|
+
rowStyle = numInteger(attrs.s, 0) ?? -1;
|
|
160
155
|
rowCustomFormat = boolStrict(attrs.customFormat);
|
|
161
156
|
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
157
|
case 'oddHeader':
|
|
185
158
|
case 'oddFooter':
|
|
186
159
|
case 'evenHeader':
|
|
187
160
|
case 'evenFooter':
|
|
188
161
|
case 'firstHeader':
|
|
189
162
|
case 'firstFooter':
|
|
190
|
-
capture
|
|
163
|
+
cell.capture();
|
|
191
164
|
break;
|
|
192
165
|
case 'mergeCell':
|
|
193
166
|
if (attrs.ref !== undefined && attrs.ref !== '') {
|
|
@@ -200,6 +173,7 @@ export function parseWorksheet(xml, sheet, sharedStrings, xfStyles) {
|
|
|
200
173
|
break;
|
|
201
174
|
case 'tabColor':
|
|
202
175
|
case 'outlinePr':
|
|
176
|
+
case 'sheetView':
|
|
203
177
|
case 'pane':
|
|
204
178
|
case 'pageSetUpPr':
|
|
205
179
|
case 'printOptions':
|
|
@@ -244,41 +218,27 @@ export function parseWorksheet(xml, sheet, sharedStrings, xfStyles) {
|
|
|
244
218
|
cell.runs.applyProperty(local, attrs);
|
|
245
219
|
break;
|
|
246
220
|
}
|
|
247
|
-
if (selfClosing && (local === 'f' || local === 'v'))
|
|
248
|
-
capture = false;
|
|
249
221
|
},
|
|
250
222
|
onText(chunk) {
|
|
251
|
-
|
|
252
|
-
text += chunk;
|
|
223
|
+
cell.appendChunk(chunk);
|
|
253
224
|
},
|
|
254
225
|
onClose(name) {
|
|
255
226
|
const local = localName(name);
|
|
227
|
+
const claimed = cell.closeElement(local);
|
|
228
|
+
if (claimed === 'cell') {
|
|
229
|
+
finalizeCellFromState();
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (claimed === 'claimed')
|
|
233
|
+
return;
|
|
256
234
|
switch (local) {
|
|
257
|
-
case 'f':
|
|
258
|
-
cell.setFormula(text);
|
|
259
|
-
break;
|
|
260
|
-
case 'v':
|
|
261
|
-
cell.setValue(text);
|
|
262
|
-
break;
|
|
263
|
-
case 't':
|
|
264
|
-
cell.appendText(text, inInlineString);
|
|
265
|
-
break;
|
|
266
|
-
case 'r':
|
|
267
|
-
cell.runs.endRun();
|
|
268
|
-
break;
|
|
269
|
-
case 'is':
|
|
270
|
-
inInlineString = false;
|
|
271
|
-
break;
|
|
272
235
|
case 'oddHeader':
|
|
273
236
|
case 'oddFooter':
|
|
274
237
|
case 'evenHeader':
|
|
275
238
|
case 'evenFooter':
|
|
276
239
|
case 'firstHeader':
|
|
277
240
|
case 'firstFooter':
|
|
278
|
-
sheet.headerFooter[local] =
|
|
279
|
-
break;
|
|
280
|
-
case 'c':
|
|
281
|
-
finalizeCellFromState();
|
|
241
|
+
sheet.headerFooter[local] = decodeSpreadsheetText(cell.capturedText);
|
|
282
242
|
break;
|
|
283
243
|
case 'row':
|
|
284
244
|
rowStyle = -1;
|
|
@@ -297,7 +257,6 @@ export function parseWorksheet(xml, sheet, sharedStrings, xfStyles) {
|
|
|
297
257
|
default:
|
|
298
258
|
break;
|
|
299
259
|
}
|
|
300
|
-
capture = false;
|
|
301
260
|
},
|
|
302
261
|
}, { closeEmptyElements: WORKSHEET_EMPTY_CLOSES });
|
|
303
262
|
}
|
|
@@ -312,13 +271,20 @@ function applySheetProperties(local, attrs, sheet) {
|
|
|
312
271
|
if (attrs.summaryRight !== undefined)
|
|
313
272
|
sheet.outline.summaryRight = boolPresent(attrs.summaryRight);
|
|
314
273
|
break;
|
|
274
|
+
case 'sheetView':
|
|
275
|
+
if (attrs.showGridLines !== undefined && !boolPresent(attrs.showGridLines)) {
|
|
276
|
+
sheet.view.showGridLines = false;
|
|
277
|
+
}
|
|
278
|
+
break;
|
|
315
279
|
case 'pane':
|
|
316
280
|
if (attrs.state === 'frozen' || attrs.state === 'frozenSplit') {
|
|
317
281
|
sheet.view.state = 'frozen';
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
sheet.view.
|
|
282
|
+
const xSplit = numInteger(attrs.xSplit, 0);
|
|
283
|
+
const ySplit = numInteger(attrs.ySplit, 0);
|
|
284
|
+
if (xSplit !== undefined)
|
|
285
|
+
sheet.view.xSplit = xSplit;
|
|
286
|
+
if (ySplit !== undefined)
|
|
287
|
+
sheet.view.ySplit = ySplit;
|
|
322
288
|
if (attrs.topLeftCell !== undefined)
|
|
323
289
|
sheet.view.topLeftCell = attrs.topLeftCell;
|
|
324
290
|
}
|
|
@@ -339,25 +305,24 @@ function applySheetProperties(local, attrs, sheet) {
|
|
|
339
305
|
}
|
|
340
306
|
}
|
|
341
307
|
function applyColumn(sheet, attrs, xfStyles, columnStyle) {
|
|
342
|
-
const min =
|
|
343
|
-
const max =
|
|
344
|
-
if (
|
|
308
|
+
const min = numInteger(attrs.min, 1);
|
|
309
|
+
const max = numInteger(attrs.max, 1);
|
|
310
|
+
if (min === undefined || max === undefined || min > MAX_COLUMN)
|
|
345
311
|
return;
|
|
346
|
-
const
|
|
312
|
+
const last = Math.min(max, MAX_COLUMN);
|
|
313
|
+
const width = numFinite(attrs.width);
|
|
347
314
|
const hidden = boolStrict(attrs.hidden);
|
|
348
|
-
const styleIndex = attrs.style
|
|
315
|
+
const styleIndex = numInteger(attrs.style, 0) ?? -1;
|
|
349
316
|
const style = styleIndex >= 0 ? xfStyles[styleIndex] : undefined;
|
|
350
|
-
for (let index = min; index <=
|
|
317
|
+
for (let index = min; index <= last; index++) {
|
|
351
318
|
const column = sheet.getColumn(index);
|
|
352
|
-
if (width !== undefined &&
|
|
319
|
+
if (width !== undefined && boolPresent(attrs.customWidth))
|
|
353
320
|
column.width = width;
|
|
354
321
|
if (hidden)
|
|
355
322
|
column.hidden = true;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
column.outlineLevel = level;
|
|
360
|
-
}
|
|
323
|
+
const outlineLevel = numInteger(attrs.outlineLevel, 1);
|
|
324
|
+
if (outlineLevel !== undefined)
|
|
325
|
+
column.outlineLevel = outlineLevel;
|
|
361
326
|
if (boolStrict(attrs.collapsed))
|
|
362
327
|
column.collapsed = true;
|
|
363
328
|
if (style !== undefined)
|
|
@@ -367,22 +332,18 @@ function applyColumn(sheet, attrs, xfStyles, columnStyle) {
|
|
|
367
332
|
}
|
|
368
333
|
}
|
|
369
334
|
function applyRow(sheet, attrs) {
|
|
370
|
-
const number =
|
|
371
|
-
if (
|
|
335
|
+
const number = numInteger(attrs.r, 1);
|
|
336
|
+
if (number === undefined || number > MAX_ROW)
|
|
372
337
|
return;
|
|
373
338
|
const row = sheet.getRow(number);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
row.height = height;
|
|
378
|
-
}
|
|
339
|
+
const height = numFinite(attrs.ht);
|
|
340
|
+
if (height !== undefined && boolPresent(attrs.customHeight))
|
|
341
|
+
row.height = height;
|
|
379
342
|
if (boolStrict(attrs.hidden))
|
|
380
343
|
row.hidden = true;
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
row.outlineLevel = level;
|
|
385
|
-
}
|
|
344
|
+
const outlineLevel = numInteger(attrs.outlineLevel, 1);
|
|
345
|
+
if (outlineLevel !== undefined)
|
|
346
|
+
row.outlineLevel = outlineLevel;
|
|
386
347
|
if (boolStrict(attrs.collapsed))
|
|
387
348
|
row.collapsed = true;
|
|
388
349
|
}
|
|
@@ -405,31 +366,22 @@ function applyPrintOptions(printOptions, attrs) {
|
|
|
405
366
|
}
|
|
406
367
|
function applyMargins(margins, attrs) {
|
|
407
368
|
for (const side of MARGIN_SIDES) {
|
|
408
|
-
const
|
|
409
|
-
if (
|
|
410
|
-
continue;
|
|
411
|
-
const value = Number(raw);
|
|
412
|
-
if (Number.isFinite(value))
|
|
369
|
+
const value = numFinite(attrs[side]);
|
|
370
|
+
if (value !== undefined)
|
|
413
371
|
margins[side] = value;
|
|
414
372
|
}
|
|
415
373
|
}
|
|
416
374
|
function applyPageSetup(pageSetup, attrs) {
|
|
417
|
-
const
|
|
418
|
-
if (raw === undefined)
|
|
419
|
-
return undefined;
|
|
420
|
-
const value = Number(raw);
|
|
421
|
-
return Number.isFinite(value) ? value : undefined;
|
|
422
|
-
};
|
|
423
|
-
const paperSize = num(attrs.paperSize);
|
|
375
|
+
const paperSize = numInteger(attrs.paperSize, 0);
|
|
424
376
|
if (paperSize !== undefined)
|
|
425
377
|
pageSetup.paperSize = paperSize;
|
|
426
|
-
const scale =
|
|
378
|
+
const scale = numInteger(attrs.scale, 0);
|
|
427
379
|
if (scale !== undefined)
|
|
428
380
|
pageSetup.scale = scale;
|
|
429
|
-
const fitToWidth =
|
|
381
|
+
const fitToWidth = numInteger(attrs.fitToWidth, 0);
|
|
430
382
|
if (fitToWidth !== undefined)
|
|
431
383
|
pageSetup.fitToWidth = fitToWidth;
|
|
432
|
-
const fitToHeight =
|
|
384
|
+
const fitToHeight = numInteger(attrs.fitToHeight, 0);
|
|
433
385
|
if (fitToHeight !== undefined)
|
|
434
386
|
pageSetup.fitToHeight = fitToHeight;
|
|
435
387
|
if (attrs.pageOrder === 'downThenOver' || attrs.pageOrder === 'overThenDown') {
|
package/dist/io/xlsx/read.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Workbook, type WorkbookView } from '../../core/workbook.ts';
|
|
2
|
-
import { type WorkbookProtection } from '../../core/workbook-protection.ts';
|
|
3
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';
|
|
@@ -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
|
|
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
|
|
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
|
|
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;
|