@rowsncolumns/toolkit 24.5.18 → 24.5.20

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 (49) hide show
  1. package/dist/cjs/excel-parser/defined-names.d.ts +18 -0
  2. package/dist/cjs/excel-parser/defined-names.d.ts.map +1 -0
  3. package/dist/cjs/excel-parser/defined-names.js +59 -0
  4. package/dist/cjs/excel-parser/interface.d.ts +7 -1
  5. package/dist/cjs/excel-parser/interface.d.ts.map +1 -1
  6. package/dist/cjs/excel-parser/plugins/xlsb/function-table.d.ts +17 -0
  7. package/dist/cjs/excel-parser/plugins/xlsb/function-table.d.ts.map +1 -0
  8. package/dist/cjs/excel-parser/plugins/xlsb/function-table.js +988 -0
  9. package/dist/cjs/excel-parser/plugins/xlsb/index.d.ts +45 -3
  10. package/dist/cjs/excel-parser/plugins/xlsb/index.d.ts.map +1 -1
  11. package/dist/cjs/excel-parser/plugins/xlsb/index.js +406 -374
  12. package/dist/cjs/excel-parser/plugins/xlsb/rgce-parser.d.ts +43 -9
  13. package/dist/cjs/excel-parser/plugins/xlsb/rgce-parser.d.ts.map +1 -1
  14. package/dist/cjs/excel-parser/plugins/xlsb/rgce-parser.js +422 -478
  15. package/dist/cjs/excel-parser/plugins/xlsx/index.d.ts.map +1 -1
  16. package/dist/cjs/excel-parser/plugins/xlsx/index.js +147 -191
  17. package/dist/cjs/excel-parser/types.d.ts +17 -0
  18. package/dist/cjs/excel-parser/types.d.ts.map +1 -1
  19. package/dist/cjs/excel-parser/workbook.d.ts +1 -0
  20. package/dist/cjs/excel-parser/workbook.d.ts.map +1 -1
  21. package/dist/cjs/excel-parser/workbook.js +4 -0
  22. package/dist/cjs/exporter/xlsx/xlsx-export.d.ts.map +1 -1
  23. package/dist/cjs/exporter/xlsx/xlsx-export.js +46 -23
  24. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  25. package/dist/esm/excel-parser/defined-names.d.ts +18 -0
  26. package/dist/esm/excel-parser/defined-names.d.ts.map +1 -0
  27. package/dist/esm/excel-parser/defined-names.js +67 -0
  28. package/dist/esm/excel-parser/interface.d.ts +7 -1
  29. package/dist/esm/excel-parser/interface.d.ts.map +1 -1
  30. package/dist/esm/excel-parser/plugins/xlsb/function-table.d.ts +17 -0
  31. package/dist/esm/excel-parser/plugins/xlsb/function-table.d.ts.map +1 -0
  32. package/dist/esm/excel-parser/plugins/xlsb/function-table.js +988 -0
  33. package/dist/esm/excel-parser/plugins/xlsb/index.d.ts +45 -3
  34. package/dist/esm/excel-parser/plugins/xlsb/index.d.ts.map +1 -1
  35. package/dist/esm/excel-parser/plugins/xlsb/index.js +266 -205
  36. package/dist/esm/excel-parser/plugins/xlsb/rgce-parser.d.ts +43 -9
  37. package/dist/esm/excel-parser/plugins/xlsb/rgce-parser.d.ts.map +1 -1
  38. package/dist/esm/excel-parser/plugins/xlsb/rgce-parser.js +405 -472
  39. package/dist/esm/excel-parser/plugins/xlsx/index.d.ts.map +1 -1
  40. package/dist/esm/excel-parser/plugins/xlsx/index.js +9 -58
  41. package/dist/esm/excel-parser/types.d.ts +17 -0
  42. package/dist/esm/excel-parser/types.d.ts.map +1 -1
  43. package/dist/esm/excel-parser/workbook.d.ts +1 -0
  44. package/dist/esm/excel-parser/workbook.d.ts.map +1 -1
  45. package/dist/esm/excel-parser/workbook.js +3 -0
  46. package/dist/esm/exporter/xlsx/xlsx-export.d.ts.map +1 -1
  47. package/dist/esm/exporter/xlsx/xlsx-export.js +26 -5
  48. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  49. package/package.json +1 -1
@@ -3,7 +3,9 @@ import { getCellXfsKey, ssfFormat, uuid } from "@rowsncolumns/utils";
3
3
  import { IndexedColors } from "@rowsncolumns/utils";
4
4
  import { XMLParser } from "fast-xml-parser";
5
5
  import { get } from "lodash-es";
6
- import { parseRgce } from "./rgce-parser";
6
+ import { namedRangesForDefinedName } from "../../defined-names";
7
+ import { isBuiltinPrintName } from "../../../print-settings";
8
+ import { decodeRgce, parseRgce, quoteSheetName, RgceUnsupportedError, } from "./rgce-parser";
7
9
  import { StreamingZipParser } from "../../zip-parser-streaming";
8
10
  import { createFilterSpecsFromAutoFilter, createSortSpecsFromSortState, excelColumnWidthToPixels, getRangeFromAddressRef, hiddenFilterButtonColumns, parseTableColumnTotals, } from "../../helpers";
9
11
  import { defaultSpreadsheetTheme } from "../../theme-default";
@@ -58,6 +60,7 @@ var RT = {
58
60
  BrtSupBookSrc: 0x0163,
59
61
  BrtSupSelf: 0x0165,
60
62
  BrtSupSame: 0x0166,
63
+ BrtSupAddin: 0x029b,
61
64
  BrtExternSheet: 0x016a,
62
65
  BrtDrawing: 0x0226,
63
66
  BrtBeginAFilter: 0x00a1,
@@ -75,7 +78,10 @@ var RT = {
75
78
  BrtEndDVal: 0x0104,
76
79
  BrtWbProp: 0x0099,
77
80
  BrtCalcProp: 0x009d,
78
- BrtShrFmla: 0x0018,
81
+ // [MS-XLSB] 2.3.2: BrtArrFmla 426, BrtShrFmla 427. A shared formula's
82
+ // cells each hold a PtgExp naming its first row.
83
+ BrtArrFmla: 0x01aa,
84
+ BrtShrFmla: 0x01ab,
79
85
  BrtCFRule: 0x01df,
80
86
  BrtDVal: 0x0103,
81
87
  };
@@ -253,49 +259,33 @@ var parseBrtExternSheet = function (payload) {
253
259
  }
254
260
  return [];
255
261
  };
262
+ var emptyFormulaDecodeStats = function () { return ({
263
+ decoded: 0,
264
+ unsupported: 0,
265
+ reasons: {},
266
+ definedNames: { decoded: 0, unsupported: 0 },
267
+ }); };
268
+ var PTG_EXP = 0x01;
269
+ /** A PtgExp: the token and the shared formula's first row (4 bytes). */
270
+ var PTG_EXP_LENGTH = 5;
271
+ var readUInt32 = function (bytes, at) {
272
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(at, true);
273
+ };
256
274
  var parseBrtShrFmla = function (payload) {
257
- var e_2, _a;
275
+ // RfX (rwFirst, rwLast, colFirst, colLast: 4 bytes each), then the formula:
276
+ // cce (4 bytes) and cce bytes of tokens ([MS-XLSB] 2.4.758).
258
277
  if (payload.length < 20)
259
278
  return null;
260
- var reader = new Reader(payload);
261
- var startRowZero = reader.readUInt32LE();
262
- var endRowZero = reader.readUInt32LE();
263
- var startColZero = reader.readUInt32LE();
264
- var endColZero = reader.readUInt32LE();
265
- // cce can be preceded by small metadata in some files; try a few offsets.
266
- var candidateOffsets = [16, 18, 20, 24];
267
- var rgceBytes;
268
- try {
269
- for (var candidateOffsets_1 = __values(candidateOffsets), candidateOffsets_1_1 = candidateOffsets_1.next(); !candidateOffsets_1_1.done; candidateOffsets_1_1 = candidateOffsets_1.next()) {
270
- var offset = candidateOffsets_1_1.value;
271
- if (offset + 4 > payload.length)
272
- continue;
273
- var cce = new DataView(payload.buffer, payload.byteOffset + offset, 4).getUint32(0, true);
274
- if (cce <= 0)
275
- continue;
276
- var start = offset + 4;
277
- var end = start + cce;
278
- if (end <= payload.length) {
279
- rgceBytes = payload.subarray(start, end);
280
- break;
281
- }
282
- }
283
- }
284
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
285
- finally {
286
- try {
287
- if (candidateOffsets_1_1 && !candidateOffsets_1_1.done && (_a = candidateOffsets_1.return)) _a.call(candidateOffsets_1);
288
- }
289
- finally { if (e_2) throw e_2.error; }
290
- }
291
- if (!rgceBytes || rgceBytes.length === 0)
279
+ var view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
280
+ var cce = view.getUint32(16, true);
281
+ if (cce === 0 || 20 + cce > payload.length)
292
282
  return null;
293
283
  return {
294
- startRow: startRowZero + 1,
295
- endRow: endRowZero + 1,
296
- startCol: startColZero + 1,
297
- endCol: endColZero + 1,
298
- rgceBytes: rgceBytes,
284
+ startRow: view.getUint32(0, true) + 1,
285
+ endRow: view.getUint32(4, true) + 1,
286
+ startCol: view.getUint32(8, true) + 1,
287
+ endCol: view.getUint32(12, true) + 1,
288
+ rgceBytes: payload.subarray(20, 20 + cce),
299
289
  };
300
290
  };
301
291
  var parseWsView = function (payload) {
@@ -326,39 +316,40 @@ var parsePane = function (payload) {
326
316
  frozenRowCount: isFrozen && ySplit > 0 ? Math.round(ySplit) : 0,
327
317
  };
328
318
  };
329
- export var parseBrtNamePayload = function (payload, resolveSheetNameByXti) {
319
+ export var readBrtName = function (payload) {
330
320
  try {
331
321
  var reader = new Reader(payload);
332
322
  var flags = reader.readUInt32LE();
333
- var fHidden = (flags & 0x00000001) !== 0;
334
323
  reader.readUInt8(); // chKey
335
- var itab = reader.readUInt32LE(); // sheet index (0xFFFFFFFF for workbook scope)
336
- // Read the name string
337
- if (reader.offset + 4 > payload.length) {
338
- return null; // Not enough data
339
- }
324
+ var itab = reader.readUInt32LE(); // 0xFFFFFFFF: workbook scope
325
+ if (reader.offset + 4 > payload.length)
326
+ return null;
340
327
  var name_1 = reader.readXLWideString();
341
- // NameParsedFormula: cce (UInt32) followed by cce bytes of Rgce
342
- var formula = "";
328
+ // NameParsedFormula: cce (4 bytes) and cce bytes of tokens.
329
+ var rgce = void 0;
343
330
  if (reader.offset + 4 <= payload.length) {
344
331
  var cce = reader.readUInt32LE();
345
332
  if (cce > 0 && reader.offset + cce <= payload.length) {
346
- var rgceBytes = payload.subarray(reader.offset, reader.offset + cce);
347
- formula = parseRgce(rgceBytes, resolveSheetNameByXti);
333
+ rgce = payload.subarray(reader.offset, reader.offset + cce);
348
334
  }
349
335
  }
350
- return {
351
- name: name_1,
352
- formula: formula,
353
- hidden: fHidden,
354
- sheetIndex: itab === 0xffffffff ? undefined : itab,
355
- };
336
+ return __assign(__assign({ name: name_1, hidden: (flags & 0x00000001) !== 0, builtin: (flags & 0x00000020) !== 0 }, (itab === 0xffffffff ? {} : { itab: itab })), (rgce ? { rgce: rgce } : {}));
356
337
  }
357
- catch (err) {
358
- // If parsing fails, return null to skip this named range
338
+ catch (_a) {
359
339
  return null;
360
340
  }
361
341
  };
342
+ export var parseBrtNamePayload = function (payload, resolveSheetNameByXti) {
343
+ var record = readBrtName(payload);
344
+ if (!record)
345
+ return null;
346
+ return {
347
+ name: record.name,
348
+ formula: record.rgce ? parseRgce(record.rgce, resolveSheetNameByXti) : "",
349
+ hidden: record.hidden,
350
+ sheetIndex: record.itab,
351
+ };
352
+ };
362
353
  /**
363
354
  * Parse the `BrtWbProp` workbook-properties record (MS-XLSB 2.4.312).
364
355
  * The payload starts with a 32-bit flags field; `fDate1904` is bit 0 of the
@@ -532,8 +523,12 @@ var getNumberFormatType = function (pattern) {
532
523
  return "NUMBER";
533
524
  return "GENERAL";
534
525
  };
535
- var parseCellFromRecord = function (type, payload, row, prevCol, resolveSheetNameByXti, resolveSharedFormula, parseFormula) {
536
- if (parseFormula === void 0) { parseFormula = true; }
526
+ var parseCellFromRecord = function (type, payload, row, prevCol,
527
+ /**
528
+ * The formula text for a cell's tokens, or `undefined` to keep only its
529
+ * cached value. Omitted: formulas are not read.
530
+ */
531
+ decodeFormula) {
537
532
  if (row <= 0)
538
533
  return null;
539
534
  var reader = new Reader(payload);
@@ -575,89 +570,26 @@ var parseCellFromRecord = function (type, payload, row, prevCol, resolveSheetNam
575
570
  value: "",
576
571
  };
577
572
  }
573
+ // CellParsedFormula ([MS-XLSB] 2.5.97.1): cce (4 bytes) and the tokens,
574
+ // then cb (4 bytes) and the tokens' extra data (a PtgExp's column).
578
575
  var readFormula = function () {
579
- var e_3, _a, e_4, _b;
580
- if (!parseFormula)
576
+ if (!decodeFormula)
581
577
  return undefined;
582
- var candidateStarts = [
583
- reader.offset - 2,
584
- reader.offset,
585
- reader.offset + 2,
586
- reader.offset + 4,
587
- reader.offset + 6,
588
- reader.offset + 8,
589
- reader.offset + 10,
590
- reader.offset + 12,
591
- ].filter(function (start, idx, arr) { return start >= 0 && arr.indexOf(start) === idx; });
592
- var decodeAt = function (start, cceSize) {
593
- if (cceSize === 4) {
594
- if (start + 4 > payload.length)
595
- return undefined;
596
- var cce_1 = new DataView(payload.buffer, payload.byteOffset + start, 4).getUint32(0, true);
597
- if (cce_1 <= 0)
598
- return undefined;
599
- var rgceStart_1 = start + 4;
600
- var rgceEnd_1 = rgceStart_1 + cce_1;
601
- if (rgceEnd_1 > payload.length)
602
- return undefined;
603
- return payload.subarray(rgceStart_1, rgceEnd_1);
604
- }
605
- if (start + 2 > payload.length)
606
- return undefined;
607
- var cce = new DataView(payload.buffer, payload.byteOffset + start, 2).getUint16(0, true);
608
- if (cce <= 0)
609
- return undefined;
610
- var rgceStart = start + 2;
611
- var rgceEnd = rgceStart + cce;
612
- if (rgceEnd > payload.length)
613
- return undefined;
614
- return payload.subarray(rgceStart, rgceEnd);
615
- };
616
- var tryResolve = function (parsed) {
617
- var expMatch = parsed.match(/^__PTGEXP__:(\d+):(\d+)$/);
618
- if (!expMatch)
619
- return parsed;
620
- if (!resolveSharedFormula)
621
- return undefined;
622
- var sourceRow = Number(expMatch[1]);
623
- var sourceCol = Number(expMatch[2]);
624
- return resolveSharedFormula(sourceRow, sourceCol, row, colZero + 1);
625
- };
626
- try {
627
- for (var candidateStarts_1 = __values(candidateStarts), candidateStarts_1_1 = candidateStarts_1.next(); !candidateStarts_1_1.done; candidateStarts_1_1 = candidateStarts_1.next()) {
628
- var start = candidateStarts_1_1.value;
629
- try {
630
- for (var _c = (e_4 = void 0, __values([4, 2])), _d = _c.next(); !_d.done; _d = _c.next()) {
631
- var cceSize = _d.value;
632
- var rgceBytes = decodeAt(start, cceSize);
633
- if (!rgceBytes || rgceBytes.length === 0)
634
- continue;
635
- var parsed = parseRgce(rgceBytes, resolveSheetNameByXti, { row: row, col: colZero + 1 }, true);
636
- if (!parsed)
637
- continue;
638
- var resolved = tryResolve(parsed);
639
- if (resolved && resolved.length > 0) {
640
- return resolved;
641
- }
642
- }
643
- }
644
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
645
- finally {
646
- try {
647
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
648
- }
649
- finally { if (e_4) throw e_4.error; }
650
- }
651
- }
652
- }
653
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
654
- finally {
655
- try {
656
- if (candidateStarts_1_1 && !candidateStarts_1_1.done && (_a = candidateStarts_1.return)) _a.call(candidateStarts_1);
578
+ if (reader.offset + 4 > payload.length)
579
+ return undefined;
580
+ var cce = reader.readUInt32LE();
581
+ if (cce === 0 || reader.offset + cce > payload.length)
582
+ return undefined;
583
+ var rgce = payload.subarray(reader.offset, reader.offset + cce);
584
+ reader.offset += cce;
585
+ var rgcb = new Uint8Array(0);
586
+ if (reader.offset + 4 <= payload.length) {
587
+ var cb = reader.readUInt32LE();
588
+ if (reader.offset + cb <= payload.length) {
589
+ rgcb = payload.subarray(reader.offset, reader.offset + cb);
657
590
  }
658
- finally { if (e_3) throw e_3.error; }
659
591
  }
660
- return undefined;
592
+ return decodeFormula(rgce, { row: row, col: colZero + 1 }, rgcb);
661
593
  };
662
594
  if (type === RT.BrtFmlaNum) {
663
595
  var value = reader.readFloat64LE();
@@ -687,8 +619,7 @@ var parseCellFromRecord = function (type, payload, row, prevCol, resolveSheetNam
687
619
  }
688
620
  if (type === RT.BrtFmlaBool) {
689
621
  var value = reader.readUInt8() !== 0;
690
- reader.readUInt8(); // padding
691
- reader.readUInt16LE(); // flags
622
+ reader.readUInt16LE(); // grbitFlags
692
623
  var formula = readFormula();
693
624
  return {
694
625
  row: row,
@@ -701,8 +632,7 @@ var parseCellFromRecord = function (type, payload, row, prevCol, resolveSheetNam
701
632
  }
702
633
  if (type === RT.BrtFmlaError) {
703
634
  var value = reader.readUInt8();
704
- reader.readUInt8(); // padding
705
- reader.readUInt16LE(); // flags
635
+ reader.readUInt16LE(); // grbitFlags
706
636
  var formula = readFormula();
707
637
  return {
708
638
  row: row,
@@ -1180,13 +1110,22 @@ var XlsbPlugin = /** @class */ (function (_super) {
1180
1110
  _this.calcProp = {};
1181
1111
  _this.supportingLinks = [];
1182
1112
  _this.externSheetRefs = [];
1113
+ /** Every sheet in workbook order, very hidden ones included; `sheetId` only for imported ones. */
1114
+ _this.workbookSheets = [];
1115
+ /** Every `BrtName` in record order (`null`: unreadable): a `PtgName` is a 1-based index into it. */
1116
+ _this.definedNames = [];
1117
+ /** A name's expression by its 1-based index; `null` when it does not decode. */
1118
+ _this.definedNameExpressions = new Map();
1119
+ /** `${itab}:${lower-cased name}` of every sheet-local name. */
1120
+ _this.sheetLocalNames = new Set();
1121
+ _this.formulaDecodeStats = emptyFormulaDecodeStats();
1183
1122
  _this.use1904 = false;
1184
1123
  return _this;
1185
1124
  }
1186
1125
  XlsbPlugin.prototype.load = function (buffer, password) {
1187
1126
  return __awaiter(this, void 0, void 0, function () {
1188
- var workbookBinary, records, workbookRels, sheets, namedRanges, supportingLinks, externSheetRefs, records_1, records_1_1, record, payload, parsed, relTarget, path, parsed, namedRange, parsed, _a, _b, _c, _d, _e, sheet, stats, e_5_1;
1189
- var e_6, _f, e_5, _g;
1127
+ var workbookBinary, records, workbookRels, sheets, workbookSheets, definedNames, supportingLinks, externSheetRefs, records_1, records_1_1, record, payload, parsed, relTarget, path, sheetId, title, parsed, parsed, _a, _b, _c, _d, _e, sheet, stats, e_2_1;
1128
+ var e_3, _f, e_2, _g;
1190
1129
  return __generator(this, function (_h) {
1191
1130
  switch (_h.label) {
1192
1131
  case 0: return [4 /*yield*/, this.zipParser.load(buffer, password)];
@@ -1208,7 +1147,8 @@ var XlsbPlugin = /** @class */ (function (_super) {
1208
1147
  case 3:
1209
1148
  workbookRels = _h.sent();
1210
1149
  sheets = [];
1211
- namedRanges = [];
1150
+ workbookSheets = [];
1151
+ definedNames = [];
1212
1152
  supportingLinks = [];
1213
1153
  externSheetRefs = [];
1214
1154
  try {
@@ -1219,15 +1159,19 @@ var XlsbPlugin = /** @class */ (function (_super) {
1219
1159
  parsed = parseBundleSheet(payload);
1220
1160
  // Skip veryHidden sheets (hidden === 2) - these are internal sheets not meant for users
1221
1161
  if (parsed.hidden === 2) {
1162
+ workbookSheets.push({ title: parsed.title });
1222
1163
  continue;
1223
1164
  }
1224
1165
  relTarget = workbookRels.get(parsed.rid);
1225
1166
  path = relTarget
1226
1167
  ? resolveRelativePath("xl/workbook.bin", relTarget)
1227
1168
  : undefined;
1169
+ sheetId = parsed.tabId || sheets.length + 1;
1170
+ title = parsed.title || "Sheet".concat(sheets.length + 1);
1228
1171
  sheets.push({
1229
- sheetId: parsed.tabId || sheets.length + 1,
1230
- title: parsed.title || "Sheet".concat(sheets.length + 1),
1172
+ sheetId: sheetId,
1173
+ title: title,
1174
+ workbookIndex: workbookSheets.length,
1231
1175
  hidden: parsed.hidden === 1,
1232
1176
  rid: parsed.rid,
1233
1177
  path: path,
@@ -1238,6 +1182,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
1238
1182
  rowMetadata: [],
1239
1183
  columnMetadata: [],
1240
1184
  });
1185
+ workbookSheets.push({ title: title, sheetId: sheetId });
1241
1186
  }
1242
1187
  else if (record.type === RT.BrtSupSelf) {
1243
1188
  supportingLinks.push("self");
@@ -1248,6 +1193,10 @@ var XlsbPlugin = /** @class */ (function (_super) {
1248
1193
  else if (record.type === RT.BrtSupBookSrc) {
1249
1194
  supportingLinks.push("external");
1250
1195
  }
1196
+ else if (record.type === RT.BrtSupAddin) {
1197
+ // Counted so the XTIs after it index the right supporting link.
1198
+ supportingLinks.push("addin");
1199
+ }
1251
1200
  else if (record.type === RT.BrtExternSheet) {
1252
1201
  parsed = parseBrtExternSheet(payload);
1253
1202
  if (parsed.length > 0) {
@@ -1255,10 +1204,9 @@ var XlsbPlugin = /** @class */ (function (_super) {
1255
1204
  }
1256
1205
  }
1257
1206
  else if (record.type === RT.BrtName) {
1258
- namedRange = this.parseBrtName(payload, sheets);
1259
- if (namedRange) {
1260
- namedRanges.push(namedRange);
1261
- }
1207
+ // Decoded once every sheet and name is known: a name may refer to
1208
+ // sheets and names that come after it.
1209
+ definedNames.push(readBrtName(payload));
1262
1210
  }
1263
1211
  else if (record.type === RT.BrtCalcProp) {
1264
1212
  this.parseBrtCalcProp(payload);
@@ -1271,17 +1219,26 @@ var XlsbPlugin = /** @class */ (function (_super) {
1271
1219
  }
1272
1220
  }
1273
1221
  }
1274
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1222
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1275
1223
  finally {
1276
1224
  try {
1277
1225
  if (records_1_1 && !records_1_1.done && (_f = records_1.return)) _f.call(records_1);
1278
1226
  }
1279
- finally { if (e_6) throw e_6.error; }
1227
+ finally { if (e_3) throw e_3.error; }
1280
1228
  }
1281
- this.namedRanges = namedRanges;
1282
1229
  this.supportingLinks = supportingLinks;
1283
1230
  this.externSheetRefs = externSheetRefs;
1231
+ this.workbookSheets = workbookSheets;
1232
+ this.definedNames = definedNames;
1233
+ this.definedNameExpressions.clear();
1234
+ this.sheetLocalNames = new Set(definedNames.flatMap(function (record) {
1235
+ return (record === null || record === void 0 ? void 0 : record.itab) === undefined
1236
+ ? []
1237
+ : ["".concat(record.itab, ":").concat(record.name.toLowerCase())];
1238
+ }));
1239
+ this.formulaDecodeStats = emptyFormulaDecodeStats();
1284
1240
  this.sheets = sheets;
1241
+ this.namedRanges = this.buildNamedRanges();
1285
1242
  _a = this;
1286
1243
  return [4 /*yield*/, this.loadSharedStrings()];
1287
1244
  case 4:
@@ -1324,14 +1281,14 @@ var XlsbPlugin = /** @class */ (function (_super) {
1324
1281
  return [3 /*break*/, 8];
1325
1282
  case 11: return [3 /*break*/, 14];
1326
1283
  case 12:
1327
- e_5_1 = _h.sent();
1328
- e_5 = { error: e_5_1 };
1284
+ e_2_1 = _h.sent();
1285
+ e_2 = { error: e_2_1 };
1329
1286
  return [3 /*break*/, 14];
1330
1287
  case 13:
1331
1288
  try {
1332
1289
  if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
1333
1290
  }
1334
- finally { if (e_5) throw e_5.error; }
1291
+ finally { if (e_2) throw e_2.error; }
1335
1292
  return [7 /*endfinally*/];
1336
1293
  case 14: return [2 /*return*/];
1337
1294
  }
@@ -1344,7 +1301,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
1344
1301
  XlsbPlugin.prototype.loadWorkbookRelationships = function () {
1345
1302
  return __awaiter(this, void 0, void 0, function () {
1346
1303
  var relsPath, relMap, relText, rels, relations, list, list_1, list_1_1, rel, id, target;
1347
- var e_7, _a;
1304
+ var e_4, _a;
1348
1305
  var _b, _c, _d, _e, _f;
1349
1306
  return __generator(this, function (_g) {
1350
1307
  switch (_g.label) {
@@ -1370,12 +1327,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
1370
1327
  }
1371
1328
  }
1372
1329
  }
1373
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1330
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1374
1331
  finally {
1375
1332
  try {
1376
1333
  if (list_1_1 && !list_1_1.done && (_a = list_1.return)) _a.call(list_1);
1377
1334
  }
1378
- finally { if (e_7) throw e_7.error; }
1335
+ finally { if (e_4) throw e_4.error; }
1379
1336
  }
1380
1337
  return [2 /*return*/, relMap];
1381
1338
  }
@@ -1385,7 +1342,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
1385
1342
  XlsbPlugin.prototype.loadSharedStrings = function () {
1386
1343
  return __awaiter(this, void 0, void 0, function () {
1387
1344
  var path, binary, records, result, records_2, records_2_1, record, payload, reader;
1388
- var e_8, _a;
1345
+ var e_5, _a;
1389
1346
  return __generator(this, function (_b) {
1390
1347
  switch (_b.label) {
1391
1348
  case 0:
@@ -1408,12 +1365,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
1408
1365
  result.push(reader.readXLWideString());
1409
1366
  }
1410
1367
  }
1411
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
1368
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1412
1369
  finally {
1413
1370
  try {
1414
1371
  if (records_2_1 && !records_2_1.done && (_a = records_2.return)) _a.call(records_2);
1415
1372
  }
1416
- finally { if (e_8) throw e_8.error; }
1373
+ finally { if (e_5) throw e_5.error; }
1417
1374
  }
1418
1375
  return [2 /*return*/, result];
1419
1376
  }
@@ -1423,7 +1380,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
1423
1380
  XlsbPlugin.prototype.loadStyles = function () {
1424
1381
  return __awaiter(this, void 0, void 0, function () {
1425
1382
  var path, styles, binary, records, inCellXfs, inStyleXfs, inFonts, inFills, inBorders, inFmts, records_3, records_3_1, record, payload, _a, id, formatCode;
1426
- var e_9, _b;
1383
+ var e_6, _b;
1427
1384
  return __generator(this, function (_c) {
1428
1385
  switch (_c.label) {
1429
1386
  case 0:
@@ -1526,12 +1483,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
1526
1483
  }
1527
1484
  }
1528
1485
  }
1529
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1486
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1530
1487
  finally {
1531
1488
  try {
1532
1489
  if (records_3_1 && !records_3_1.done && (_b = records_3.return)) _b.call(records_3);
1533
1490
  }
1534
- finally { if (e_9) throw e_9.error; }
1491
+ finally { if (e_6) throw e_6.error; }
1535
1492
  }
1536
1493
  return [2 /*return*/, styles];
1537
1494
  }
@@ -1583,7 +1540,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
1583
1540
  XlsbPlugin.prototype.loadRelationshipsForPart = function (basePath) {
1584
1541
  return __awaiter(this, void 0, void 0, function () {
1585
1542
  var base, name, dir, relsPath, relText, rels, relations, list, out, list_2, list_2_1, rel, id, target;
1586
- var e_10, _a;
1543
+ var e_7, _a;
1587
1544
  var _b, _c, _d, _e, _f;
1588
1545
  return __generator(this, function (_g) {
1589
1546
  switch (_g.label) {
@@ -1613,12 +1570,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
1613
1570
  }
1614
1571
  }
1615
1572
  }
1616
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
1573
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1617
1574
  finally {
1618
1575
  try {
1619
1576
  if (list_2_1 && !list_2_1.done && (_a = list_2.return)) _a.call(list_2);
1620
1577
  }
1621
- finally { if (e_10) throw e_10.error; }
1578
+ finally { if (e_7) throw e_7.error; }
1622
1579
  }
1623
1580
  return [2 /*return*/, out];
1624
1581
  }
@@ -1628,7 +1585,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
1628
1585
  XlsbPlugin.prototype.getDrawingPathsForSheet = function (sheet) {
1629
1586
  return __awaiter(this, void 0, void 0, function () {
1630
1587
  var binary, records, relIds, records_4, records_4_1, record, payload, relId, relMap, paths, relIds_1, relIds_1_1, relId, target;
1631
- var e_11, _a, e_12, _b;
1588
+ var e_8, _a, e_9, _b;
1632
1589
  return __generator(this, function (_c) {
1633
1590
  switch (_c.label) {
1634
1591
  case 0:
@@ -1650,12 +1607,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
1650
1607
  relIds.push(relId);
1651
1608
  }
1652
1609
  }
1653
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
1610
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
1654
1611
  finally {
1655
1612
  try {
1656
1613
  if (records_4_1 && !records_4_1.done && (_a = records_4.return)) _a.call(records_4);
1657
1614
  }
1658
- finally { if (e_11) throw e_11.error; }
1615
+ finally { if (e_8) throw e_8.error; }
1659
1616
  }
1660
1617
  if (relIds.length === 0)
1661
1618
  return [2 /*return*/, []];
@@ -1672,12 +1629,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
1672
1629
  paths.push(resolveRelativePath(sheet.path, target));
1673
1630
  }
1674
1631
  }
1675
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
1632
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1676
1633
  finally {
1677
1634
  try {
1678
1635
  if (relIds_1_1 && !relIds_1_1.done && (_b = relIds_1.return)) _b.call(relIds_1);
1679
1636
  }
1680
- finally { if (e_12) throw e_12.error; }
1637
+ finally { if (e_9) throw e_9.error; }
1681
1638
  }
1682
1639
  return [2 /*return*/, Array.from(new Set(paths))];
1683
1640
  }
@@ -1686,8 +1643,8 @@ var XlsbPlugin = /** @class */ (function (_super) {
1686
1643
  };
1687
1644
  XlsbPlugin.prototype.getTablesFromSheet = function (sheet) {
1688
1645
  return __awaiter(this, void 0, void 0, function () {
1689
- var relMap, tables, _a, _b, tableRelId, target, tablePath, tableContent, tableData, tableDefinition, attrs, range, columnDefinitions, columnDefsArray, columns, autoFilter, filterSpecs, _c, _d, colId, sortSpecs, headerRow, tableStyle, tableStyleAttrs, tableView, e_13_1;
1690
- var e_13, _e, e_14, _f;
1646
+ var relMap, tables, _a, _b, tableRelId, target, tablePath, tableContent, tableData, tableDefinition, attrs, range, columnDefinitions, columnDefsArray, columns, autoFilter, filterSpecs, _c, _d, colId, sortSpecs, headerRow, tableStyle, tableStyleAttrs, tableView, e_10_1;
1647
+ var e_10, _e, e_11, _f;
1691
1648
  var _g, _h;
1692
1649
  return __generator(this, function (_j) {
1693
1650
  switch (_j.label) {
@@ -1757,18 +1714,18 @@ var XlsbPlugin = /** @class */ (function (_super) {
1757
1714
  autoFilter = (_g = tableDefinition.autoFilter) !== null && _g !== void 0 ? _g : tableDefinition["x:autoFilter"];
1758
1715
  filterSpecs = createFilterSpecsFromAutoFilter(autoFilter);
1759
1716
  try {
1760
- for (_c = (e_14 = void 0, __values(hiddenFilterButtonColumns(autoFilter))), _d = _c.next(); !_d.done; _d = _c.next()) {
1717
+ for (_c = (e_11 = void 0, __values(hiddenFilterButtonColumns(autoFilter))), _d = _c.next(); !_d.done; _d = _c.next()) {
1761
1718
  colId = _d.value;
1762
1719
  if (columns[colId])
1763
1720
  columns[colId].filterButton = false;
1764
1721
  }
1765
1722
  }
1766
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
1723
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1767
1724
  finally {
1768
1725
  try {
1769
1726
  if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
1770
1727
  }
1771
- finally { if (e_14) throw e_14.error; }
1728
+ finally { if (e_11) throw e_11.error; }
1772
1729
  }
1773
1730
  sortSpecs = createSortSpecsFromSortState((_h = tableDefinition.sortState) !== null && _h !== void 0 ? _h : tableDefinition["x:sortState"], range);
1774
1731
  headerRow = attrs.headerRowCount !== "0";
@@ -1789,14 +1746,14 @@ var XlsbPlugin = /** @class */ (function (_super) {
1789
1746
  return [3 /*break*/, 3];
1790
1747
  case 6: return [3 /*break*/, 9];
1791
1748
  case 7:
1792
- e_13_1 = _j.sent();
1793
- e_13 = { error: e_13_1 };
1749
+ e_10_1 = _j.sent();
1750
+ e_10 = { error: e_10_1 };
1794
1751
  return [3 /*break*/, 9];
1795
1752
  case 8:
1796
1753
  try {
1797
1754
  if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
1798
1755
  }
1799
- finally { if (e_13) throw e_13.error; }
1756
+ finally { if (e_10) throw e_10.error; }
1800
1757
  return [7 /*endfinally*/];
1801
1758
  case 9: return [2 /*return*/, tables];
1802
1759
  }
@@ -1806,8 +1763,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
1806
1763
  XlsbPlugin.prototype.scanSheetStats = function (path) {
1807
1764
  return __awaiter(this, void 0, void 0, function () {
1808
1765
  var binary, records, currentRow, maxRow, maxCol, prevCol, merges, rowMetadata, columnMetadata, showGridLines, rightToLeft, frozenRowCount, frozenColumnCount, basicFilterRange, tablePartRelIds, records_5, records_5_1, record, payload, view, pane, relId, parsedRow, parsedCol, col, dimensionProps, merge, parsed;
1809
- var e_15, _a;
1810
- var _this = this;
1766
+ var e_12, _a;
1811
1767
  return __generator(this, function (_b) {
1812
1768
  switch (_b.label) {
1813
1769
  case 0: return [4 /*yield*/, this.zipParser.getBinary(path)];
@@ -1896,7 +1852,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
1896
1852
  }
1897
1853
  if (!isCellRecord(record.type))
1898
1854
  continue;
1899
- parsed = parseCellFromRecord(record.type, payload, currentRow, prevCol, function (ixti) { return _this.resolveSheetNameByXti(ixti); }, undefined, false);
1855
+ parsed = parseCellFromRecord(record.type, payload, currentRow, prevCol);
1900
1856
  if (!parsed)
1901
1857
  continue;
1902
1858
  prevCol = parsed.col - 1;
@@ -1906,12 +1862,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
1906
1862
  maxCol = parsed.col;
1907
1863
  }
1908
1864
  }
1909
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
1865
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
1910
1866
  finally {
1911
1867
  try {
1912
1868
  if (records_5_1 && !records_5_1.done && (_a = records_5.return)) _a.call(records_5);
1913
1869
  }
1914
- finally { if (e_15) throw e_15.error; }
1870
+ finally { if (e_12) throw e_12.error; }
1915
1871
  }
1916
1872
  return [2 /*return*/, {
1917
1873
  rowCount: maxRow,
@@ -1936,31 +1892,148 @@ var XlsbPlugin = /** @class */ (function (_super) {
1936
1892
  XlsbPlugin.prototype.getSheetNames = function () {
1937
1893
  return this.sheets.map(function (s) { return s.title; });
1938
1894
  };
1939
- XlsbPlugin.prototype.resolveSheetNameByXti = function (ixti) {
1940
- var _a;
1941
- var sheetNames = this.getSheetNames();
1942
- var fallback = (_a = sheetNames[ixti]) !== null && _a !== void 0 ? _a : sheetNames[ixti - 1];
1895
+ /**
1896
+ * The imported sheet an XTI names, or `undefined` when a formula cannot
1897
+ * name it exactly: another workbook, a span of sheets, a deleted or very
1898
+ * hidden sheet.
1899
+ */
1900
+ XlsbPlugin.prototype.sheetNameByXti = function (ixti) {
1943
1901
  var xti = this.externSheetRefs[ixti];
1944
1902
  if (!xti)
1945
- return fallback;
1903
+ return undefined;
1946
1904
  var linkType = this.supportingLinks[xti.iSupBook];
1947
- if (linkType !== "self" && linkType !== "same") {
1948
- return fallback;
1905
+ if (linkType !== "self" && linkType !== "same")
1906
+ return undefined;
1907
+ if (xti.itabFirst !== xti.itabLast)
1908
+ return undefined;
1909
+ var sheet = this.workbookSheets[xti.itabFirst];
1910
+ return (sheet === null || sheet === void 0 ? void 0 : sheet.sheetId) === undefined ? undefined : sheet.title;
1911
+ };
1912
+ /**
1913
+ * A defined name's expression (OOXML's spelling, no leading `=`), or
1914
+ * `undefined` when it does not decode exactly — then no formula may refer
1915
+ * to it either. `visiting` breaks names that refer to themselves.
1916
+ */
1917
+ XlsbPlugin.prototype.definedNameExpression = function (index, visiting) {
1918
+ var _this = this;
1919
+ var _a;
1920
+ if (visiting === void 0) { visiting = new Set(); }
1921
+ var known = this.definedNameExpressions.get(index);
1922
+ if (known !== undefined)
1923
+ return known !== null && known !== void 0 ? known : undefined;
1924
+ var record = this.definedNames[index - 1];
1925
+ if (!(record === null || record === void 0 ? void 0 : record.rgce) || visiting.has(index))
1926
+ return undefined;
1927
+ if (record.itab !== undefined &&
1928
+ ((_a = this.workbookSheets[record.itab]) === null || _a === void 0 ? void 0 : _a.sheetId) === undefined) {
1929
+ this.definedNameExpressions.set(index, null);
1930
+ return undefined;
1949
1931
  }
1950
- var first = xti.itabFirst;
1951
- var last = xti.itabLast;
1952
- if (first < 0 || first >= sheetNames.length)
1953
- return fallback;
1954
- if (last < 0 || last >= sheetNames.length)
1955
- return sheetNames[first];
1956
- if (first === last)
1957
- return sheetNames[first];
1958
- return "".concat(sheetNames[first], ":").concat(sheetNames[last]);
1932
+ visiting.add(index);
1933
+ var expression = null;
1934
+ try {
1935
+ expression = decodeRgce(record.rgce, {
1936
+ sheetName: function (ixti) { return _this.sheetNameByXti(ixti); },
1937
+ definedName: function (target) {
1938
+ return _this.definedNameIn(target, record.itab, visiting);
1939
+ },
1940
+ });
1941
+ }
1942
+ catch (error) {
1943
+ if (!(error instanceof RgceUnsupportedError))
1944
+ throw error;
1945
+ }
1946
+ finally {
1947
+ visiting.delete(index);
1948
+ }
1949
+ this.definedNameExpressions.set(index, expression);
1950
+ return expression !== null && expression !== void 0 ? expression : undefined;
1951
+ };
1952
+ /**
1953
+ * How a formula on the sheet at `formulaItab` (a name's own formula: the
1954
+ * sheet it is local to) writes the name a `PtgName` points at: bare on its
1955
+ * own sheet or for a workbook name, `Sheet!Name` elsewhere. `undefined`
1956
+ * when the name does not survive the import, or when a local name of the
1957
+ * same spelling would capture a bare workbook name.
1958
+ */
1959
+ XlsbPlugin.prototype.definedNameIn = function (index, formulaItab, visiting) {
1960
+ var record = this.definedNames[index - 1];
1961
+ if (!record || record.builtin)
1962
+ return undefined;
1963
+ if (this.definedNameExpression(index, visiting) === undefined) {
1964
+ return undefined;
1965
+ }
1966
+ if (record.itab === undefined) {
1967
+ var shadowed = formulaItab !== undefined &&
1968
+ this.sheetLocalNames.has("".concat(formulaItab, ":").concat(record.name.toLowerCase()));
1969
+ return shadowed ? undefined : record.name;
1970
+ }
1971
+ if (record.itab === formulaItab)
1972
+ return record.name;
1973
+ var sheet = this.workbookSheets[record.itab];
1974
+ return (sheet === null || sheet === void 0 ? void 0 : sheet.sheetId) === undefined
1975
+ ? undefined
1976
+ : "".concat(quoteSheetName(sheet.title), "!").concat(record.name);
1977
+ };
1978
+ /** Every name that decodes, the way the XLSX plugin reads `<definedName>`. */
1979
+ XlsbPlugin.prototype.buildNamedRanges = function () {
1980
+ var e_13, _a;
1981
+ var _this = this;
1982
+ var sheetIdBySheetName = {};
1983
+ try {
1984
+ for (var _b = __values(this.sheets), _c = _b.next(); !_c.done; _c = _b.next()) {
1985
+ var sheet = _c.value;
1986
+ sheetIdBySheetName[sheet.title] = sheet.sheetId;
1987
+ }
1988
+ }
1989
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
1990
+ finally {
1991
+ try {
1992
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1993
+ }
1994
+ finally { if (e_13) throw e_13.error; }
1995
+ }
1996
+ var namedRanges = [];
1997
+ var counts = this.formulaDecodeStats.definedNames;
1998
+ this.definedNames.forEach(function (record, at) {
1999
+ var _a;
2000
+ // Print areas and titles are sheet print facets, not user names.
2001
+ var expression = record && !isBuiltinPrintName(record.name)
2002
+ ? _this.definedNameExpression(at + 1)
2003
+ : undefined;
2004
+ if (!record || expression === undefined) {
2005
+ counts.unsupported += 1;
2006
+ return;
2007
+ }
2008
+ counts.decoded += 1;
2009
+ namedRanges.push.apply(namedRanges, __spreadArray([], __read(namedRangesForDefinedName({
2010
+ name: record.name,
2011
+ expression: expression,
2012
+ hidden: record.hidden,
2013
+ scopeSheetId: record.itab === undefined
2014
+ ? undefined
2015
+ : (_a = _this.workbookSheets[record.itab]) === null || _a === void 0 ? void 0 : _a.sheetId,
2016
+ sheetIdBySheetName: sheetIdBySheetName,
2017
+ })), false));
2018
+ });
2019
+ return namedRanges;
2020
+ };
2021
+ XlsbPlugin.prototype.getFormulaDecodeStats = function () {
2022
+ return __assign(__assign({}, this.formulaDecodeStats), { reasons: __assign({}, this.formulaDecodeStats.reasons), definedNames: __assign({}, this.formulaDecodeStats.definedNames) });
2023
+ };
2024
+ XlsbPlugin.prototype.countUnsupportedFormula = function (reason) {
2025
+ var _a;
2026
+ var stats = this.formulaDecodeStats;
2027
+ stats.unsupported += 1;
2028
+ var key = reason in stats.reasons || Object.keys(stats.reasons).length < 32
2029
+ ? reason
2030
+ : "other";
2031
+ stats.reasons[key] = ((_a = stats.reasons[key]) !== null && _a !== void 0 ? _a : 0) + 1;
1959
2032
  };
1960
2033
  XlsbPlugin.prototype.getSheets = function () {
1961
2034
  return __awaiter(this, arguments, void 0, function (minRowCount, minColumnCount) {
1962
- var tables, sheets, _loop_1, this_1, _a, _b, sheet, e_16_1;
1963
- var e_16, _c;
2035
+ var tables, sheets, _loop_1, this_1, _a, _b, sheet, e_14_1;
2036
+ var e_14, _c;
1964
2037
  var _d;
1965
2038
  if (minRowCount === void 0) { minRowCount = 0; }
1966
2039
  if (minColumnCount === void 0) { minColumnCount = 0; }
@@ -2022,14 +2095,14 @@ var XlsbPlugin = /** @class */ (function (_super) {
2022
2095
  return [3 /*break*/, 2];
2023
2096
  case 5: return [3 /*break*/, 8];
2024
2097
  case 6:
2025
- e_16_1 = _e.sent();
2026
- e_16 = { error: e_16_1 };
2098
+ e_14_1 = _e.sent();
2099
+ e_14 = { error: e_14_1 };
2027
2100
  return [3 /*break*/, 8];
2028
2101
  case 7:
2029
2102
  try {
2030
2103
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2031
2104
  }
2032
- finally { if (e_16) throw e_16.error; }
2105
+ finally { if (e_14) throw e_14.error; }
2033
2106
  return [7 /*endfinally*/];
2034
2107
  case 8: return [2 /*return*/, [sheets, tables]];
2035
2108
  }
@@ -2043,7 +2116,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
2043
2116
  return this.styles;
2044
2117
  };
2045
2118
  XlsbPlugin.prototype.getFonts = function () {
2046
- var e_17, _a;
2119
+ var e_15, _a;
2047
2120
  var out = new Set();
2048
2121
  try {
2049
2122
  for (var _b = __values(this.styles.fonts), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -2052,12 +2125,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
2052
2125
  out.add(font.name);
2053
2126
  }
2054
2127
  }
2055
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
2128
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
2056
2129
  finally {
2057
2130
  try {
2058
2131
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2059
2132
  }
2060
- finally { if (e_17) throw e_17.error; }
2133
+ finally { if (e_15) throw e_15.error; }
2061
2134
  }
2062
2135
  return __spreadArray([], __read(out), false);
2063
2136
  };
@@ -2084,8 +2157,8 @@ var XlsbPlugin = /** @class */ (function (_super) {
2084
2157
  case 0:
2085
2158
  totalSheets = this.sheets.length;
2086
2159
  _loop_2 = function (index) {
2087
- var sheet, binary, records, sharedFormulaBytes, sharedFormulaRanges, records_6, records_6_1, record, payload, parsedShared, currentRow, prevCol, rows, _loop_3, records_7, records_7_1, record, _c, _d, merge, topLeftRow, topLeftCell, sourceFormat, r, c, row, format, _e, borders, formatWithoutBorders, existingCell, _f, ef, uf, cellContent, sortedRows, chunkRows, chunkRowIndices, chunkIndex, startRowIndex, endRowIndex, sortedRows_1, sortedRows_1_1, _g, rowIndex, rowData, e_18_1;
2088
- var e_19, _h, e_20, _j, e_21, _k, e_18, _l;
2160
+ var sheet, binary, records, sharedFormulas, records_6, records_6_1, record, parsedShared, decodeFormula, currentRow, prevCol, rows, records_7, records_7_1, record, payload, parsedRow, parsed, row, _c, _d, merge, topLeftRow, topLeftCell, sourceFormat, r, c, row, format, _e, borders, formatWithoutBorders, existingCell, _f, ef, uf, cellContent, sortedRows, chunkRows, chunkRowIndices, chunkIndex, startRowIndex, endRowIndex, sortedRows_1, sortedRows_1_1, _g, rowIndex, rowData, e_16_1;
2161
+ var e_17, _h, e_18, _j, e_19, _k, e_16, _l;
2089
2162
  return __generator(this, function (_m) {
2090
2163
  switch (_m.label) {
2091
2164
  case 0:
@@ -2096,109 +2169,102 @@ var XlsbPlugin = /** @class */ (function (_super) {
2096
2169
  case 1:
2097
2170
  binary = _m.sent();
2098
2171
  records = readAllRecordHeaders(binary);
2099
- sharedFormulaBytes = new Map();
2100
- sharedFormulaRanges = [];
2172
+ sharedFormulas = new Map();
2101
2173
  try {
2102
- // Pre-scan shared formulas so PtgExp can resolve even when BrtShrFmla
2103
- // appears later in the record stream.
2104
- for (records_6 = (e_19 = void 0, __values(records)), records_6_1 = records_6.next(); !records_6_1.done; records_6_1 = records_6.next()) {
2174
+ for (records_6 = (e_17 = void 0, __values(records)), records_6_1 = records_6.next(); !records_6_1.done; records_6_1 = records_6.next()) {
2105
2175
  record = records_6_1.value;
2106
2176
  if (record.type !== RT.BrtShrFmla)
2107
2177
  continue;
2108
- payload = binary.subarray(record.dataOffset, record.nextOffset);
2109
- parsedShared = parseBrtShrFmla(payload);
2178
+ parsedShared = parseBrtShrFmla(binary.subarray(record.dataOffset, record.nextOffset));
2110
2179
  if (!parsedShared)
2111
2180
  continue;
2112
- sharedFormulaBytes.set("".concat(parsedShared.startRow, ":").concat(parsedShared.startCol), parsedShared.rgceBytes);
2113
- sharedFormulaRanges.push(parsedShared);
2181
+ sharedFormulas.set("".concat(parsedShared.startRow, ":").concat(parsedShared.startCol), parsedShared);
2114
2182
  }
2115
2183
  }
2116
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
2184
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
2117
2185
  finally {
2118
2186
  try {
2119
2187
  if (records_6_1 && !records_6_1.done && (_h = records_6.return)) _h.call(records_6);
2120
2188
  }
2121
- finally { if (e_19) throw e_19.error; }
2189
+ finally { if (e_17) throw e_17.error; }
2122
2190
  }
2123
- currentRow = 0;
2124
- prevCol = -1;
2125
- rows = new Map();
2126
- _loop_3 = function (record) {
2127
- var payload = binary.subarray(record.dataOffset, record.nextOffset);
2128
- if (record.type === RT.BrtShrFmla) {
2129
- return "continue";
2130
- }
2131
- if (record.type === RT.BrtRowHdr) {
2132
- var parsedRow = parseRowHeader(payload);
2133
- currentRow = parsedRow.row;
2134
- prevCol = -1;
2135
- if (!rows.has(currentRow)) {
2136
- rows.set(currentRow, { values: [] });
2191
+ decodeFormula = function (rgce, cell, rgcb) {
2192
+ var tokens = rgce;
2193
+ if (rgce.length === PTG_EXP_LENGTH && rgce[0] === PTG_EXP) {
2194
+ // PtgExp: the shared formula's first row, its column in the extra data.
2195
+ var shared = rgcb.length >= 4
2196
+ ? sharedFormulas.get("".concat(readUInt32(rgce, 1) + 1, ":").concat(readUInt32(rgcb, 0) + 1))
2197
+ : undefined;
2198
+ if (!shared ||
2199
+ cell.row < shared.startRow ||
2200
+ cell.row > shared.endRow ||
2201
+ cell.col < shared.startCol ||
2202
+ cell.col > shared.endCol) {
2203
+ _this.countUnsupportedFormula("array formula");
2204
+ return undefined;
2137
2205
  }
2138
- return "continue";
2206
+ tokens = shared.rgceBytes;
2139
2207
  }
2140
- if (!isCellRecord(record.type))
2141
- return "continue";
2142
- var parsed = parseCellFromRecord(record.type, payload, currentRow, prevCol, function (ixti) { return _this.resolveSheetNameByXti(ixti); }, function (sourceRow, sourceCol, targetRow, targetCol) {
2143
- var rgce = sharedFormulaBytes.get("".concat(sourceRow, ":").concat(sourceCol));
2144
- if (!rgce) {
2145
- var sourceRange = sharedFormulaRanges.find(function (range) {
2146
- return sourceRow >= range.startRow &&
2147
- sourceRow <= range.endRow &&
2148
- sourceCol >= range.startCol &&
2149
- sourceCol <= range.endCol;
2150
- });
2151
- rgce = sourceRange === null || sourceRange === void 0 ? void 0 : sourceRange.rgceBytes;
2152
- }
2153
- if (!rgce)
2154
- return undefined;
2155
- return parseRgce(rgce, function (ixti) { return _this.resolveSheetNameByXti(ixti); }, {
2156
- row: targetRow,
2157
- col: targetCol,
2158
- }, true); // Enable debug logging
2159
- });
2160
- if (!parsed)
2161
- return "continue";
2162
- if (!parsed.formula && sharedFormulaRanges.length > 0) {
2163
- var sharedRange = sharedFormulaRanges.find(function (range) {
2164
- return parsed.row >= range.startRow &&
2165
- parsed.row <= range.endRow &&
2166
- parsed.col >= range.startCol &&
2167
- parsed.col <= range.endCol;
2208
+ try {
2209
+ var formula = decodeRgce(tokens, {
2210
+ sheetName: function (ixti) { return _this.sheetNameByXti(ixti); },
2211
+ definedName: function (index) {
2212
+ return _this.definedNameIn(index, sheet.workbookIndex);
2213
+ },
2214
+ baseCell: cell,
2168
2215
  });
2169
- if (sharedRange) {
2170
- var resolved = parseRgce(sharedRange.rgceBytes, function (ixti) { return _this.resolveSheetNameByXti(ixti); }, { row: parsed.row, col: parsed.col }, true);
2171
- if (resolved) {
2172
- parsed.formula = resolved;
2173
- }
2174
- }
2216
+ _this.formulaDecodeStats.decoded += 1;
2217
+ return formula;
2175
2218
  }
2176
- prevCol = parsed.col - 1;
2177
- var row = rows.get(parsed.row);
2178
- if (!row) {
2179
- row = { values: [] };
2180
- rows.set(parsed.row, row);
2219
+ catch (error) {
2220
+ if (!(error instanceof RgceUnsupportedError))
2221
+ throw error;
2222
+ _this.countUnsupportedFormula(error.message);
2223
+ return undefined;
2181
2224
  }
2182
- row.values[parsed.col] = toCellData(parsed, this_2.styles, this_2.sharedStrings, enableCellXfsRegistry, enableSharedStrings, this_2.cellXfs, this_2.use1904);
2183
2225
  };
2226
+ currentRow = 0;
2227
+ prevCol = -1;
2228
+ rows = new Map();
2184
2229
  try {
2185
- for (records_7 = (e_20 = void 0, __values(records)), records_7_1 = records_7.next(); !records_7_1.done; records_7_1 = records_7.next()) {
2230
+ for (records_7 = (e_18 = void 0, __values(records)), records_7_1 = records_7.next(); !records_7_1.done; records_7_1 = records_7.next()) {
2186
2231
  record = records_7_1.value;
2187
- _loop_3(record);
2232
+ payload = binary.subarray(record.dataOffset, record.nextOffset);
2233
+ if (record.type === RT.BrtRowHdr) {
2234
+ parsedRow = parseRowHeader(payload);
2235
+ currentRow = parsedRow.row;
2236
+ prevCol = -1;
2237
+ if (!rows.has(currentRow)) {
2238
+ rows.set(currentRow, { values: [] });
2239
+ }
2240
+ continue;
2241
+ }
2242
+ if (!isCellRecord(record.type))
2243
+ continue;
2244
+ parsed = parseCellFromRecord(record.type, payload, currentRow, prevCol, decodeFormula);
2245
+ if (!parsed)
2246
+ continue;
2247
+ prevCol = parsed.col - 1;
2248
+ row = rows.get(parsed.row);
2249
+ if (!row) {
2250
+ row = { values: [] };
2251
+ rows.set(parsed.row, row);
2252
+ }
2253
+ row.values[parsed.col] = toCellData(parsed, this_2.styles, this_2.sharedStrings, enableCellXfsRegistry, enableSharedStrings, this_2.cellXfs, this_2.use1904);
2188
2254
  }
2189
2255
  }
2190
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
2256
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
2191
2257
  finally {
2192
2258
  try {
2193
2259
  if (records_7_1 && !records_7_1.done && (_j = records_7.return)) _j.call(records_7);
2194
2260
  }
2195
- finally { if (e_20) throw e_20.error; }
2261
+ finally { if (e_18) throw e_18.error; }
2196
2262
  }
2197
2263
  try {
2198
2264
  // Apply merge cell formatting
2199
2265
  // In Excel, merged cells should have formatting from the top-left (anchor) cell
2200
2266
  // propagated to all cells in the merge range, but borders need special handling
2201
- for (_c = (e_21 = void 0, __values(sheet.merges)), _d = _c.next(); !_d.done; _d = _c.next()) {
2267
+ for (_c = (e_19 = void 0, __values(sheet.merges)), _d = _c.next(); !_d.done; _d = _c.next()) {
2202
2268
  merge = _d.value;
2203
2269
  topLeftRow = rows.get(merge.startRowIndex);
2204
2270
  topLeftCell = (_a = topLeftRow === null || topLeftRow === void 0 ? void 0 : topLeftRow.values) === null || _a === void 0 ? void 0 : _a[merge.startColumnIndex];
@@ -2253,12 +2319,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
2253
2319
  }
2254
2320
  }
2255
2321
  }
2256
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
2322
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
2257
2323
  finally {
2258
2324
  try {
2259
2325
  if (_d && !_d.done && (_k = _c.return)) _k.call(_c);
2260
2326
  }
2261
- finally { if (e_21) throw e_21.error; }
2327
+ finally { if (e_19) throw e_19.error; }
2262
2328
  }
2263
2329
  sortedRows = Array.from(rows.entries()).sort(function (a, b) { return a[0] - b[0]; });
2264
2330
  chunkRows = [];
@@ -2269,7 +2335,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
2269
2335
  _m.label = 2;
2270
2336
  case 2:
2271
2337
  _m.trys.push([2, 8, 9, 10]);
2272
- sortedRows_1 = (e_18 = void 0, __values(sortedRows)), sortedRows_1_1 = sortedRows_1.next();
2338
+ sortedRows_1 = (e_16 = void 0, __values(sortedRows)), sortedRows_1_1 = sortedRows_1.next();
2273
2339
  _m.label = 3;
2274
2340
  case 3:
2275
2341
  if (!!sortedRows_1_1.done) return [3 /*break*/, 7];
@@ -2309,14 +2375,14 @@ var XlsbPlugin = /** @class */ (function (_super) {
2309
2375
  return [3 /*break*/, 3];
2310
2376
  case 7: return [3 /*break*/, 10];
2311
2377
  case 8:
2312
- e_18_1 = _m.sent();
2313
- e_18 = { error: e_18_1 };
2378
+ e_16_1 = _m.sent();
2379
+ e_16 = { error: e_16_1 };
2314
2380
  return [3 /*break*/, 10];
2315
2381
  case 9:
2316
2382
  try {
2317
2383
  if (sortedRows_1_1 && !sortedRows_1_1.done && (_l = sortedRows_1.return)) _l.call(sortedRows_1);
2318
2384
  }
2319
- finally { if (e_18) throw e_18.error; }
2385
+ finally { if (e_16) throw e_16.error; }
2320
2386
  return [7 /*endfinally*/];
2321
2387
  case 10:
2322
2388
  if (!chunkRows.length) return [3 /*break*/, 13];
@@ -2361,8 +2427,8 @@ var XlsbPlugin = /** @class */ (function (_super) {
2361
2427
  };
2362
2428
  XlsbPlugin.prototype.getDrawings = function () {
2363
2429
  return __awaiter(this, void 0, void 0, function () {
2364
- var drawings, _a, _b, sheet, drawingPaths, drawingPaths_1, drawingPaths_1_1, drawingPath, drawingContent, drawingXml, oneCellAnchors, twoCellAnchors, absoluteAnchors, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, e_22_1, e_23_1;
2365
- var e_23, _q, e_22, _r;
2430
+ var drawings, _a, _b, sheet, drawingPaths, drawingPaths_1, drawingPaths_1_1, drawingPath, drawingContent, drawingXml, oneCellAnchors, twoCellAnchors, absoluteAnchors, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, e_20_1, e_21_1;
2431
+ var e_21, _q, e_20, _r;
2366
2432
  return __generator(this, function (_s) {
2367
2433
  switch (_s.label) {
2368
2434
  case 0:
@@ -2381,7 +2447,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
2381
2447
  _s.label = 4;
2382
2448
  case 4:
2383
2449
  _s.trys.push([4, 14, 15, 16]);
2384
- drawingPaths_1 = (e_22 = void 0, __values(drawingPaths)), drawingPaths_1_1 = drawingPaths_1.next();
2450
+ drawingPaths_1 = (e_20 = void 0, __values(drawingPaths)), drawingPaths_1_1 = drawingPaths_1.next();
2385
2451
  _s.label = 5;
2386
2452
  case 5:
2387
2453
  if (!!drawingPaths_1_1.done) return [3 /*break*/, 13];
@@ -2431,28 +2497,28 @@ var XlsbPlugin = /** @class */ (function (_super) {
2431
2497
  return [3 /*break*/, 5];
2432
2498
  case 13: return [3 /*break*/, 16];
2433
2499
  case 14:
2434
- e_22_1 = _s.sent();
2435
- e_22 = { error: e_22_1 };
2500
+ e_20_1 = _s.sent();
2501
+ e_20 = { error: e_20_1 };
2436
2502
  return [3 /*break*/, 16];
2437
2503
  case 15:
2438
2504
  try {
2439
2505
  if (drawingPaths_1_1 && !drawingPaths_1_1.done && (_r = drawingPaths_1.return)) _r.call(drawingPaths_1);
2440
2506
  }
2441
- finally { if (e_22) throw e_22.error; }
2507
+ finally { if (e_20) throw e_20.error; }
2442
2508
  return [7 /*endfinally*/];
2443
2509
  case 16:
2444
2510
  _b = _a.next();
2445
2511
  return [3 /*break*/, 2];
2446
2512
  case 17: return [3 /*break*/, 20];
2447
2513
  case 18:
2448
- e_23_1 = _s.sent();
2449
- e_23 = { error: e_23_1 };
2514
+ e_21_1 = _s.sent();
2515
+ e_21 = { error: e_21_1 };
2450
2516
  return [3 /*break*/, 20];
2451
2517
  case 19:
2452
2518
  try {
2453
2519
  if (_b && !_b.done && (_q = _a.return)) _q.call(_a);
2454
2520
  }
2455
- finally { if (e_23) throw e_23.error; }
2521
+ finally { if (e_21) throw e_21.error; }
2456
2522
  return [7 /*endfinally*/];
2457
2523
  case 20: return [2 /*return*/, drawings];
2458
2524
  }
@@ -2461,8 +2527,8 @@ var XlsbPlugin = /** @class */ (function (_super) {
2461
2527
  };
2462
2528
  XlsbPlugin.prototype.getCharts = function () {
2463
2529
  return __awaiter(this, void 0, void 0, function () {
2464
- var charts, sheetIdByName, _a, _b, sheet, resolveSheetId, _c, _d, sheet, drawingPaths, drawingPaths_2, drawingPaths_2_1, drawingPath, drawingContent, drawingXml, drawingDir, drawingName, drawingRelsPath, drawingRelsContent, drawingRelsXml, drawingRelsList, drawingRelsArray, oneCellAnchors, twoCellAnchors, anchors, _loop_4, this_3, anchors_1, anchors_1_1, anchor, e_24_1, e_25_1, e_26_1;
2465
- var e_27, _e, e_26, _f, e_25, _g, e_24, _h;
2530
+ var charts, sheetIdByName, _a, _b, sheet, resolveSheetId, _c, _d, sheet, drawingPaths, drawingPaths_2, drawingPaths_2_1, drawingPath, drawingContent, drawingXml, drawingDir, drawingName, drawingRelsPath, drawingRelsContent, drawingRelsXml, drawingRelsList, drawingRelsArray, oneCellAnchors, twoCellAnchors, anchors, _loop_3, this_3, anchors_1, anchors_1_1, anchor, e_22_1, e_23_1, e_24_1;
2531
+ var e_25, _e, e_24, _f, e_23, _g, e_22, _h;
2466
2532
  var _j;
2467
2533
  return __generator(this, function (_k) {
2468
2534
  switch (_k.label) {
@@ -2477,12 +2543,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
2477
2543
  }
2478
2544
  }
2479
2545
  }
2480
- catch (e_27_1) { e_27 = { error: e_27_1 }; }
2546
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
2481
2547
  finally {
2482
2548
  try {
2483
2549
  if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
2484
2550
  }
2485
- finally { if (e_27) throw e_27.error; }
2551
+ finally { if (e_25) throw e_25.error; }
2486
2552
  }
2487
2553
  resolveSheetId = function (sheetName) {
2488
2554
  return sheetName ? sheetIdByName[String(sheetName)] : undefined;
@@ -2501,7 +2567,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
2501
2567
  _k.label = 4;
2502
2568
  case 4:
2503
2569
  _k.trys.push([4, 17, 18, 19]);
2504
- drawingPaths_2 = (e_25 = void 0, __values(drawingPaths)), drawingPaths_2_1 = drawingPaths_2.next();
2570
+ drawingPaths_2 = (e_23 = void 0, __values(drawingPaths)), drawingPaths_2_1 = drawingPaths_2.next();
2505
2571
  _k.label = 5;
2506
2572
  case 5:
2507
2573
  if (!!drawingPaths_2_1.done) return [3 /*break*/, 16];
@@ -2542,7 +2608,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
2542
2608
  : twoCellAnchors
2543
2609
  ? [twoCellAnchors]
2544
2610
  : [])), false);
2545
- _loop_4 = function (anchor) {
2611
+ _loop_3 = function (anchor) {
2546
2612
  var chartId, chartRel, chart;
2547
2613
  return __generator(this, function (_l) {
2548
2614
  switch (_l.label) {
@@ -2571,12 +2637,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
2571
2637
  _k.label = 8;
2572
2638
  case 8:
2573
2639
  _k.trys.push([8, 13, 14, 15]);
2574
- anchors_1 = (e_24 = void 0, __values(anchors)), anchors_1_1 = anchors_1.next();
2640
+ anchors_1 = (e_22 = void 0, __values(anchors)), anchors_1_1 = anchors_1.next();
2575
2641
  _k.label = 9;
2576
2642
  case 9:
2577
2643
  if (!!anchors_1_1.done) return [3 /*break*/, 12];
2578
2644
  anchor = anchors_1_1.value;
2579
- return [5 /*yield**/, _loop_4(anchor)];
2645
+ return [5 /*yield**/, _loop_3(anchor)];
2580
2646
  case 10:
2581
2647
  _k.sent();
2582
2648
  _k.label = 11;
@@ -2585,42 +2651,42 @@ var XlsbPlugin = /** @class */ (function (_super) {
2585
2651
  return [3 /*break*/, 9];
2586
2652
  case 12: return [3 /*break*/, 15];
2587
2653
  case 13:
2588
- e_24_1 = _k.sent();
2589
- e_24 = { error: e_24_1 };
2654
+ e_22_1 = _k.sent();
2655
+ e_22 = { error: e_22_1 };
2590
2656
  return [3 /*break*/, 15];
2591
2657
  case 14:
2592
2658
  try {
2593
2659
  if (anchors_1_1 && !anchors_1_1.done && (_h = anchors_1.return)) _h.call(anchors_1);
2594
2660
  }
2595
- finally { if (e_24) throw e_24.error; }
2661
+ finally { if (e_22) throw e_22.error; }
2596
2662
  return [7 /*endfinally*/];
2597
2663
  case 15:
2598
2664
  drawingPaths_2_1 = drawingPaths_2.next();
2599
2665
  return [3 /*break*/, 5];
2600
2666
  case 16: return [3 /*break*/, 19];
2601
2667
  case 17:
2602
- e_25_1 = _k.sent();
2603
- e_25 = { error: e_25_1 };
2668
+ e_23_1 = _k.sent();
2669
+ e_23 = { error: e_23_1 };
2604
2670
  return [3 /*break*/, 19];
2605
2671
  case 18:
2606
2672
  try {
2607
2673
  if (drawingPaths_2_1 && !drawingPaths_2_1.done && (_g = drawingPaths_2.return)) _g.call(drawingPaths_2);
2608
2674
  }
2609
- finally { if (e_25) throw e_25.error; }
2675
+ finally { if (e_23) throw e_23.error; }
2610
2676
  return [7 /*endfinally*/];
2611
2677
  case 19:
2612
2678
  _d = _c.next();
2613
2679
  return [3 /*break*/, 2];
2614
2680
  case 20: return [3 /*break*/, 23];
2615
2681
  case 21:
2616
- e_26_1 = _k.sent();
2617
- e_26 = { error: e_26_1 };
2682
+ e_24_1 = _k.sent();
2683
+ e_24 = { error: e_24_1 };
2618
2684
  return [3 /*break*/, 23];
2619
2685
  case 22:
2620
2686
  try {
2621
2687
  if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
2622
2688
  }
2623
- finally { if (e_26) throw e_26.error; }
2689
+ finally { if (e_24) throw e_24.error; }
2624
2690
  return [7 /*endfinally*/];
2625
2691
  case 23: return [2 /*return*/, charts];
2626
2692
  }
@@ -2629,8 +2695,8 @@ var XlsbPlugin = /** @class */ (function (_super) {
2629
2695
  };
2630
2696
  XlsbPlugin.prototype.getConditionalFormatting = function () {
2631
2697
  return __awaiter(this, void 0, void 0, function () {
2632
- var rules, ruleIdCounter, _a, _b, sheet, binary, records, inCF, currentCFRanges, cfRuleIndex, records_8, records_8_1, record, payload, parsed, cfRule, rangeAddresses, ranges, rangeAddresses_1, rangeAddresses_1_1, address, range, rule, err_1, e_28_1;
2633
- var e_28, _c, e_29, _d, e_30, _e;
2698
+ var rules, ruleIdCounter, _a, _b, sheet, binary, records, inCF, currentCFRanges, cfRuleIndex, records_8, records_8_1, record, payload, parsed, cfRule, rangeAddresses, ranges, rangeAddresses_1, rangeAddresses_1_1, address, range, rule, err_1, e_26_1;
2699
+ var e_26, _c, e_27, _d, e_28, _e;
2634
2700
  return __generator(this, function (_f) {
2635
2701
  switch (_f.label) {
2636
2702
  case 0:
@@ -2657,7 +2723,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
2657
2723
  currentCFRanges = null;
2658
2724
  cfRuleIndex = 0;
2659
2725
  try {
2660
- for (records_8 = (e_29 = void 0, __values(records)), records_8_1 = records_8.next(); !records_8_1.done; records_8_1 = records_8.next()) {
2726
+ for (records_8 = (e_27 = void 0, __values(records)), records_8_1 = records_8.next(); !records_8_1.done; records_8_1 = records_8.next()) {
2661
2727
  record = records_8_1.value;
2662
2728
  payload = binary.subarray(record.dataOffset, record.nextOffset);
2663
2729
  if (record.type === RT.BrtBeginConditionalFormatting) {
@@ -2678,7 +2744,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
2678
2744
  rangeAddresses = currentCFRanges.split(" ");
2679
2745
  ranges = [];
2680
2746
  try {
2681
- for (rangeAddresses_1 = (e_30 = void 0, __values(rangeAddresses)), rangeAddresses_1_1 = rangeAddresses_1.next(); !rangeAddresses_1_1.done; rangeAddresses_1_1 = rangeAddresses_1.next()) {
2747
+ for (rangeAddresses_1 = (e_28 = void 0, __values(rangeAddresses)), rangeAddresses_1_1 = rangeAddresses_1.next(); !rangeAddresses_1_1.done; rangeAddresses_1_1 = rangeAddresses_1.next()) {
2682
2748
  address = rangeAddresses_1_1.value;
2683
2749
  range = getRangeFromAddressRef(address);
2684
2750
  if (range) {
@@ -2686,12 +2752,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
2686
2752
  }
2687
2753
  }
2688
2754
  }
2689
- catch (e_30_1) { e_30 = { error: e_30_1 }; }
2755
+ catch (e_28_1) { e_28 = { error: e_28_1 }; }
2690
2756
  finally {
2691
2757
  try {
2692
2758
  if (rangeAddresses_1_1 && !rangeAddresses_1_1.done && (_e = rangeAddresses_1.return)) _e.call(rangeAddresses_1);
2693
2759
  }
2694
- finally { if (e_30) throw e_30.error; }
2760
+ finally { if (e_28) throw e_28.error; }
2695
2761
  }
2696
2762
  if (ranges.length > 0) {
2697
2763
  rule = {
@@ -2713,12 +2779,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
2713
2779
  }
2714
2780
  }
2715
2781
  }
2716
- catch (e_29_1) { e_29 = { error: e_29_1 }; }
2782
+ catch (e_27_1) { e_27 = { error: e_27_1 }; }
2717
2783
  finally {
2718
2784
  try {
2719
2785
  if (records_8_1 && !records_8_1.done && (_d = records_8.return)) _d.call(records_8);
2720
2786
  }
2721
- finally { if (e_29) throw e_29.error; }
2787
+ finally { if (e_27) throw e_27.error; }
2722
2788
  }
2723
2789
  return [3 /*break*/, 6];
2724
2790
  case 5:
@@ -2731,14 +2797,14 @@ var XlsbPlugin = /** @class */ (function (_super) {
2731
2797
  return [3 /*break*/, 2];
2732
2798
  case 7: return [3 /*break*/, 10];
2733
2799
  case 8:
2734
- e_28_1 = _f.sent();
2735
- e_28 = { error: e_28_1 };
2800
+ e_26_1 = _f.sent();
2801
+ e_26 = { error: e_26_1 };
2736
2802
  return [3 /*break*/, 10];
2737
2803
  case 9:
2738
2804
  try {
2739
2805
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2740
2806
  }
2741
- finally { if (e_28) throw e_28.error; }
2807
+ finally { if (e_26) throw e_26.error; }
2742
2808
  return [7 /*endfinally*/];
2743
2809
  case 10: return [2 /*return*/, rules];
2744
2810
  }
@@ -2747,8 +2813,8 @@ var XlsbPlugin = /** @class */ (function (_super) {
2747
2813
  };
2748
2814
  XlsbPlugin.prototype.getDataValidations = function () {
2749
2815
  return __awaiter(this, void 0, void 0, function () {
2750
- var validations, _a, _b, sheet, binary, records, inDVals, inDVal, currentDVal, currentRanges, records_9, records_9_1, record, payload, reader, maybeRange, rangeAddresses, ranges, rangeAddresses_2, rangeAddresses_2_1, address, range, typeMap, validation, conditionType, alertStyles, err_2, e_31_1;
2751
- var e_31, _c, e_32, _d, e_33, _e;
2816
+ var validations, _a, _b, sheet, binary, records, inDVals, inDVal, currentDVal, currentRanges, records_9, records_9_1, record, payload, reader, maybeRange, rangeAddresses, ranges, rangeAddresses_2, rangeAddresses_2_1, address, range, typeMap, validation, conditionType, alertStyles, err_2, e_29_1;
2817
+ var e_29, _c, e_30, _d, e_31, _e;
2752
2818
  return __generator(this, function (_f) {
2753
2819
  switch (_f.label) {
2754
2820
  case 0:
@@ -2775,7 +2841,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
2775
2841
  currentDVal = null;
2776
2842
  currentRanges = null;
2777
2843
  try {
2778
- for (records_9 = (e_32 = void 0, __values(records)), records_9_1 = records_9.next(); !records_9_1.done; records_9_1 = records_9.next()) {
2844
+ for (records_9 = (e_30 = void 0, __values(records)), records_9_1 = records_9.next(); !records_9_1.done; records_9_1 = records_9.next()) {
2779
2845
  record = records_9_1.value;
2780
2846
  payload = binary.subarray(record.dataOffset, record.nextOffset);
2781
2847
  if (record.type === RT.BrtBeginDVals) {
@@ -2812,7 +2878,7 @@ var XlsbPlugin = /** @class */ (function (_super) {
2812
2878
  rangeAddresses = currentRanges.split(" ");
2813
2879
  ranges = [];
2814
2880
  try {
2815
- for (rangeAddresses_2 = (e_33 = void 0, __values(rangeAddresses)), rangeAddresses_2_1 = rangeAddresses_2.next(); !rangeAddresses_2_1.done; rangeAddresses_2_1 = rangeAddresses_2.next()) {
2881
+ for (rangeAddresses_2 = (e_31 = void 0, __values(rangeAddresses)), rangeAddresses_2_1 = rangeAddresses_2.next(); !rangeAddresses_2_1.done; rangeAddresses_2_1 = rangeAddresses_2.next()) {
2816
2882
  address = rangeAddresses_2_1.value;
2817
2883
  range = getRangeFromAddressRef(address);
2818
2884
  if (range) {
@@ -2820,12 +2886,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
2820
2886
  }
2821
2887
  }
2822
2888
  }
2823
- catch (e_33_1) { e_33 = { error: e_33_1 }; }
2889
+ catch (e_31_1) { e_31 = { error: e_31_1 }; }
2824
2890
  finally {
2825
2891
  try {
2826
2892
  if (rangeAddresses_2_1 && !rangeAddresses_2_1.done && (_e = rangeAddresses_2.return)) _e.call(rangeAddresses_2);
2827
2893
  }
2828
- finally { if (e_33) throw e_33.error; }
2894
+ finally { if (e_31) throw e_31.error; }
2829
2895
  }
2830
2896
  if (ranges.length > 0) {
2831
2897
  typeMap = {
@@ -2886,12 +2952,12 @@ var XlsbPlugin = /** @class */ (function (_super) {
2886
2952
  }
2887
2953
  }
2888
2954
  }
2889
- catch (e_32_1) { e_32 = { error: e_32_1 }; }
2955
+ catch (e_30_1) { e_30 = { error: e_30_1 }; }
2890
2956
  finally {
2891
2957
  try {
2892
2958
  if (records_9_1 && !records_9_1.done && (_d = records_9.return)) _d.call(records_9);
2893
2959
  }
2894
- finally { if (e_32) throw e_32.error; }
2960
+ finally { if (e_30) throw e_30.error; }
2895
2961
  }
2896
2962
  return [3 /*break*/, 6];
2897
2963
  case 5:
@@ -2904,54 +2970,20 @@ var XlsbPlugin = /** @class */ (function (_super) {
2904
2970
  return [3 /*break*/, 2];
2905
2971
  case 7: return [3 /*break*/, 10];
2906
2972
  case 8:
2907
- e_31_1 = _f.sent();
2908
- e_31 = { error: e_31_1 };
2973
+ e_29_1 = _f.sent();
2974
+ e_29 = { error: e_29_1 };
2909
2975
  return [3 /*break*/, 10];
2910
2976
  case 9:
2911
2977
  try {
2912
2978
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2913
2979
  }
2914
- finally { if (e_31) throw e_31.error; }
2980
+ finally { if (e_29) throw e_29.error; }
2915
2981
  return [7 /*endfinally*/];
2916
2982
  case 10: return [2 /*return*/, validations];
2917
2983
  }
2918
2984
  });
2919
2985
  });
2920
2986
  };
2921
- XlsbPlugin.prototype.parseBrtName = function (payload, sheets) {
2922
- var _this = this;
2923
- var parsed = parseBrtNamePayload(payload, function (ixti) {
2924
- return _this.resolveSheetNameByXti(ixti);
2925
- });
2926
- // Skip if parsing failed or hidden names
2927
- if (!parsed || parsed.hidden) {
2928
- return undefined;
2929
- }
2930
- // Try to parse the formula as a range reference
2931
- var gridRange = getRangeFromAddressRef(parsed.formula);
2932
- // Determine the sheet ID if this is a sheet-scoped name
2933
- var sheetId;
2934
- if (parsed.sheetIndex !== undefined && parsed.sheetIndex < sheets.length) {
2935
- sheetId = sheets[parsed.sheetIndex].sheetId;
2936
- }
2937
- // Create the NamedRange object
2938
- var namedRange = {
2939
- namedRangeId: uuid(),
2940
- name: parsed.name,
2941
- };
2942
- // Set either range or value depending on what we parsed
2943
- if (gridRange) {
2944
- // Convert GridRange to SheetRange by adding sheetId
2945
- // Use the sheet-scoped sheetId if available, otherwise use the first sheet
2946
- var rangeSheetId = sheetId !== null && sheetId !== void 0 ? sheetId : (sheets.length > 0 ? sheets[0].sheetId : 1);
2947
- namedRange.range = __assign(__assign({}, gridRange), { sheetId: rangeSheetId });
2948
- }
2949
- else if (parsed.formula) {
2950
- // If we can't parse it as a range, store it as a formula value
2951
- namedRange.value = parsed.formula;
2952
- }
2953
- return namedRange;
2954
- };
2955
2987
  XlsbPlugin.prototype.parseBrtCalcProp = function (payload) {
2956
2988
  var parsed = parseBrtCalcPropPayload(payload);
2957
2989
  if (!parsed) {