@cj-tech-master/excelts 1.4.5 → 1.5.0-canary.20251213003400.6464c74

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/browser/excelts.iife.js +454 -159
  2. package/dist/browser/excelts.iife.js.map +1 -1
  3. package/dist/browser/excelts.iife.min.js +28 -28
  4. package/dist/cjs/doc/anchor.js +25 -11
  5. package/dist/cjs/doc/cell.js +75 -43
  6. package/dist/cjs/doc/column.js +74 -22
  7. package/dist/cjs/doc/defined-names.js +53 -7
  8. package/dist/cjs/doc/image.js +11 -8
  9. package/dist/cjs/doc/range.js +64 -28
  10. package/dist/cjs/doc/row.js +72 -31
  11. package/dist/cjs/doc/table.js +3 -5
  12. package/dist/cjs/doc/workbook.js +30 -6
  13. package/dist/cjs/doc/worksheet.js +165 -41
  14. package/dist/cjs/utils/sheet-utils.js +3 -1
  15. package/dist/cjs/utils/unzip/extract.js +30 -82
  16. package/dist/cjs/utils/unzip/index.js +18 -2
  17. package/dist/cjs/utils/unzip/zip-parser.js +458 -0
  18. package/dist/esm/doc/anchor.js +25 -11
  19. package/dist/esm/doc/cell.js +75 -43
  20. package/dist/esm/doc/column.js +74 -22
  21. package/dist/esm/doc/defined-names.js +53 -7
  22. package/dist/esm/doc/image.js +11 -8
  23. package/dist/esm/doc/range.js +64 -28
  24. package/dist/esm/doc/row.js +72 -31
  25. package/dist/esm/doc/table.js +3 -5
  26. package/dist/esm/doc/workbook.js +30 -6
  27. package/dist/esm/doc/worksheet.js +165 -41
  28. package/dist/esm/utils/sheet-utils.js +3 -1
  29. package/dist/esm/utils/unzip/extract.js +28 -82
  30. package/dist/esm/utils/unzip/index.js +17 -2
  31. package/dist/esm/utils/unzip/zip-parser.js +451 -0
  32. package/dist/types/doc/anchor.d.ts +14 -7
  33. package/dist/types/doc/cell.d.ts +78 -37
  34. package/dist/types/doc/column.d.ts +72 -36
  35. package/dist/types/doc/defined-names.d.ts +11 -8
  36. package/dist/types/doc/image.d.ts +29 -12
  37. package/dist/types/doc/pivot-table.d.ts +1 -1
  38. package/dist/types/doc/range.d.ts +15 -4
  39. package/dist/types/doc/row.d.ts +78 -40
  40. package/dist/types/doc/table.d.ts +21 -36
  41. package/dist/types/doc/workbook.d.ts +54 -34
  42. package/dist/types/doc/worksheet.d.ts +255 -83
  43. package/dist/types/stream/xlsx/worksheet-reader.d.ts +3 -5
  44. package/dist/types/types.d.ts +86 -26
  45. package/dist/types/utils/col-cache.d.ts +11 -8
  46. package/dist/types/utils/unzip/extract.d.ts +16 -14
  47. package/dist/types/utils/unzip/index.d.ts +15 -1
  48. package/dist/types/utils/unzip/zip-parser.d.ts +92 -0
  49. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @cj-tech-master/excelts v1.4.5
2
+ * @cj-tech-master/excelts v1.5.0-canary.20251213003400.6464c74
3
3
  * TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.
4
4
  * (c) 2025 cjnoname
5
5
  * Released under the MIT License
@@ -282,10 +282,16 @@ var ExcelTS = (function(exports) {
282
282
  //#region src/doc/range.ts
283
283
  var Range = class Range {
284
284
  constructor(...args) {
285
+ this.model = {
286
+ top: 0,
287
+ left: 0,
288
+ bottom: 0,
289
+ right: 0
290
+ };
285
291
  this.decode(args);
286
292
  }
287
293
  setTLBR(t, l, b, r, s) {
288
- if (arguments.length < 4) {
294
+ if (typeof t === "string" && typeof l === "string") {
289
295
  const tl = colCache.decodeAddress(t);
290
296
  const br = colCache.decodeAddress(l);
291
297
  this.model = {
@@ -293,10 +299,9 @@ var ExcelTS = (function(exports) {
293
299
  left: Math.min(tl.col, br.col),
294
300
  bottom: Math.max(tl.row, br.row),
295
301
  right: Math.max(tl.col, br.col),
296
- sheetName: b
302
+ sheetName: typeof b === "string" ? b : void 0
297
303
  };
298
- this.setTLBR(tl.row, tl.col, br.row, br.col, s);
299
- } else this.model = {
304
+ } else if (typeof t === "number" && typeof l === "number" && typeof b === "number" && typeof r === "number") this.model = {
300
305
  top: Math.min(t, b),
301
306
  left: Math.min(l, r),
302
307
  bottom: Math.max(t, b),
@@ -307,16 +312,16 @@ var ExcelTS = (function(exports) {
307
312
  decode(argv$1) {
308
313
  switch (argv$1.length) {
309
314
  case 5:
310
- this.setTLBR(argv$1[0], argv$1[1], argv$1[2], argv$1[3], argv$1[4]);
315
+ if (typeof argv$1[0] === "number" && typeof argv$1[1] === "number" && typeof argv$1[2] === "number" && typeof argv$1[3] === "number" && typeof argv$1[4] === "string") this.setTLBR(argv$1[0], argv$1[1], argv$1[2], argv$1[3], argv$1[4]);
311
316
  break;
312
317
  case 4:
313
- this.setTLBR(argv$1[0], argv$1[1], argv$1[2], argv$1[3]);
318
+ if (typeof argv$1[0] === "number" && typeof argv$1[1] === "number" && typeof argv$1[2] === "number" && typeof argv$1[3] === "number") this.setTLBR(argv$1[0], argv$1[1], argv$1[2], argv$1[3]);
314
319
  break;
315
320
  case 3:
316
- this.setTLBR(argv$1[0], argv$1[1], argv$1[2]);
321
+ if (typeof argv$1[0] === "string" && typeof argv$1[1] === "string" && typeof argv$1[2] === "string") this.setTLBR(argv$1[0], argv$1[1], argv$1[2]);
317
322
  break;
318
323
  case 2:
319
- this.setTLBR(argv$1[0], argv$1[1]);
324
+ if (typeof argv$1[0] === "string" && typeof argv$1[1] === "string") this.setTLBR(argv$1[0], argv$1[1]);
320
325
  break;
321
326
  case 1: {
322
327
  const value = argv$1[0];
@@ -327,29 +332,29 @@ var ExcelTS = (function(exports) {
327
332
  right: value.model.right,
328
333
  sheetName: value.sheetName
329
334
  };
330
- else if (value instanceof Array) this.decode(value);
331
- else if (value.top && value.left && value.bottom && value.right) this.model = {
335
+ else if (Array.isArray(value)) this.decode(value);
336
+ else if (typeof value === "object" && "top" in value && "left" in value && "bottom" in value && "right" in value) this.model = {
332
337
  top: value.top,
333
338
  left: value.left,
334
339
  bottom: value.bottom,
335
340
  right: value.right,
336
341
  sheetName: value.sheetName
337
342
  };
338
- else {
339
- const tlbr = colCache.decodeEx(value);
340
- if (tlbr.top) this.model = {
341
- top: tlbr.top,
342
- left: tlbr.left,
343
- bottom: tlbr.bottom,
344
- right: tlbr.right,
345
- sheetName: tlbr.sheetName
343
+ else if (typeof value === "string") {
344
+ const decoded = colCache.decodeEx(value);
345
+ if ("top" in decoded) this.model = {
346
+ top: decoded.top,
347
+ left: decoded.left,
348
+ bottom: decoded.bottom,
349
+ right: decoded.right,
350
+ sheetName: decoded.sheetName
346
351
  };
347
- else this.model = {
348
- top: tlbr.row,
349
- left: tlbr.col,
350
- bottom: tlbr.row,
351
- right: tlbr.col,
352
- sheetName: tlbr.sheetName
352
+ else if ("row" in decoded) this.model = {
353
+ top: decoded.row,
354
+ left: decoded.col,
355
+ bottom: decoded.row,
356
+ right: decoded.col,
357
+ sheetName: decoded.sheetName
353
358
  };
354
359
  }
355
360
  break;
@@ -417,7 +422,7 @@ var ExcelTS = (function(exports) {
417
422
  }
418
423
  expandToAddress(addressStr) {
419
424
  const address = colCache.decodeEx(addressStr);
420
- this.expand(address.row, address.col, address.row, address.col);
425
+ if ("row" in address && "col" in address) this.expand(address.row, address.col, address.row, address.col);
421
426
  }
422
427
  get tl() {
423
428
  return colCache.n2l(this.left) + this.top;
@@ -459,7 +464,8 @@ var ExcelTS = (function(exports) {
459
464
  }
460
465
  contains(addressStr) {
461
466
  const address = colCache.decodeEx(addressStr);
462
- return this.containsEx(address);
467
+ if ("row" in address && "col" in address) return this.containsEx(address);
468
+ return false;
463
469
  }
464
470
  containsEx(address) {
465
471
  if (address.sheetName && this.sheetName && address.sheetName !== this.sheetName) return false;
@@ -857,11 +863,20 @@ var ExcelTS = (function(exports) {
857
863
  this._value = Value.create(Value.getType(v), this, v);
858
864
  }
859
865
  get note() {
860
- return this._comment && this._comment.note;
866
+ if (!this._comment) return;
867
+ return this._comment.note;
861
868
  }
862
869
  set note(note) {
863
870
  this._comment = new Note(note);
864
871
  }
872
+ get comment() {
873
+ return this._comment;
874
+ }
875
+ set comment(comment) {
876
+ if (comment === void 0) this._comment = void 0;
877
+ else if (comment instanceof Note) this._comment = comment;
878
+ else this._comment = new Note(comment);
879
+ }
865
880
  get text() {
866
881
  return this._value.toString();
867
882
  }
@@ -873,7 +888,7 @@ var ExcelTS = (function(exports) {
873
888
  }
874
889
  _upgradeToHyperlink(hyperlink) {
875
890
  if (this.type === Cell.Types.String) this._value = Value.create(Cell.Types.Hyperlink, this, {
876
- text: this._value.value,
891
+ text: String(this._value.value),
877
892
  hyperlink
878
893
  });
879
894
  }
@@ -1129,12 +1144,11 @@ var ExcelTS = (function(exports) {
1129
1144
  if (value && value.tooltip) this.model.tooltip = value.tooltip;
1130
1145
  }
1131
1146
  get value() {
1132
- const v = {
1133
- text: this.model.text,
1134
- hyperlink: this.model.hyperlink
1147
+ return {
1148
+ text: this.model.text || "",
1149
+ hyperlink: this.model.hyperlink || "",
1150
+ tooltip: this.model.tooltip
1135
1151
  };
1136
- if (this.model.tooltip) v.tooltip = this.model.tooltip;
1137
- return v;
1138
1152
  }
1139
1153
  set value(value) {
1140
1154
  this.model.text = value.text;
@@ -1236,22 +1250,22 @@ var ExcelTS = (function(exports) {
1236
1250
  }
1237
1251
  _copyModel(model) {
1238
1252
  const copy = {};
1239
- const cp = (name) => {
1240
- const value = model[name];
1241
- if (value) copy[name] = value;
1242
- };
1243
- cp("formula");
1244
- cp("result");
1245
- cp("ref");
1246
- cp("shareType");
1247
- cp("sharedFormula");
1253
+ if (model.formula) copy.formula = model.formula;
1254
+ if (model.result !== void 0) copy.result = model.result;
1255
+ if (model.ref) copy.ref = model.ref;
1256
+ if (model.shareType) copy.shareType = model.shareType;
1257
+ if (model.sharedFormula) copy.sharedFormula = model.sharedFormula;
1248
1258
  return copy;
1249
1259
  }
1250
1260
  get value() {
1251
1261
  return this._copyModel(this.model);
1252
1262
  }
1253
1263
  set value(value) {
1254
- this.model = this._copyModel(value);
1264
+ if (value.formula) this.model.formula = value.formula;
1265
+ if (value.result !== void 0) this.model.result = value.result;
1266
+ if (value.ref) this.model.ref = value.ref;
1267
+ if (value.shareType) this.model.shareType = value.shareType;
1268
+ if (value.sharedFormula) this.model.sharedFormula = value.sharedFormula;
1255
1269
  }
1256
1270
  validate(value) {
1257
1271
  switch (Value.getType(value)) {
@@ -1296,8 +1310,7 @@ var ExcelTS = (function(exports) {
1296
1310
  if (v instanceof String || typeof v === "string") return Enums.ValueType.String;
1297
1311
  if (typeof v === "number") return Enums.ValueType.Number;
1298
1312
  if (v instanceof Date) return Enums.ValueType.Date;
1299
- if (v.text && v.hyperlink) return Enums.ValueType.Hyperlink;
1300
- if (v.formula) return Enums.ValueType.Formula;
1313
+ if (typeof v === "object" && "error" in v) return Enums.ValueType.Error;
1301
1314
  return Enums.ValueType.Null;
1302
1315
  }
1303
1316
  get address() {
@@ -1467,11 +1480,13 @@ var ExcelTS = (function(exports) {
1467
1480
  if (typeof value === "number") return Cell.Types.Number;
1468
1481
  if (typeof value === "boolean") return Cell.Types.Boolean;
1469
1482
  if (value instanceof Date) return Cell.Types.Date;
1470
- if (value.text && value.hyperlink) return Cell.Types.Hyperlink;
1471
- if (value.formula || value.sharedFormula) return Cell.Types.Formula;
1472
- if (value.richText) return Cell.Types.RichText;
1473
- if (value.sharedString) return Cell.Types.SharedString;
1474
- if (value.error) return Cell.Types.Error;
1483
+ if (typeof value === "object") {
1484
+ if ("text" in value && value.text && "hyperlink" in value && value.hyperlink) return Cell.Types.Hyperlink;
1485
+ if ("formula" in value && value.formula || "sharedFormula" in value && value.sharedFormula) return Cell.Types.Formula;
1486
+ if ("richText" in value && value.richText) return Cell.Types.RichText;
1487
+ if ("sharedString" in value && value.sharedString) return Cell.Types.SharedString;
1488
+ if ("error" in value && value.error) return Cell.Types.Error;
1489
+ }
1475
1490
  return Cell.Types.JSON;
1476
1491
  },
1477
1492
  types: [
@@ -1544,15 +1559,29 @@ var ExcelTS = (function(exports) {
1544
1559
  this.style = {};
1545
1560
  this.outlineLevel = 0;
1546
1561
  }
1562
+ /**
1563
+ * The row number
1564
+ */
1547
1565
  get number() {
1548
1566
  return this._number;
1549
1567
  }
1568
+ /**
1569
+ * The worksheet that contains this row
1570
+ */
1550
1571
  get worksheet() {
1551
1572
  return this._worksheet;
1552
1573
  }
1574
+ /**
1575
+ * Commit a completed row to stream.
1576
+ * Inform Streaming Writer that this row (and all rows before it) are complete
1577
+ * and ready to write. Has no effect on Worksheet document.
1578
+ */
1553
1579
  commit() {
1554
1580
  this._worksheet._commitRow(this);
1555
1581
  }
1582
+ /**
1583
+ * Helps GC by breaking cyclic references
1584
+ */
1556
1585
  destroy() {
1557
1586
  delete this._worksheet;
1558
1587
  delete this._cells;
@@ -1570,6 +1599,9 @@ var ExcelTS = (function(exports) {
1570
1599
  }
1571
1600
  return cell;
1572
1601
  }
1602
+ /**
1603
+ * Get cell by number, column letter or column key
1604
+ */
1573
1605
  getCell(col) {
1574
1606
  let colNum;
1575
1607
  if (typeof col === "string") {
@@ -1583,6 +1615,11 @@ var ExcelTS = (function(exports) {
1583
1615
  col: colNum
1584
1616
  });
1585
1617
  }
1618
+ /**
1619
+ * Cut one or more cells (cells to the right are shifted left)
1620
+ *
1621
+ * Note: this operation will not affect other rows
1622
+ */
1586
1623
  splice(start, count, ...inserts) {
1587
1624
  const nKeep = start + count;
1588
1625
  const nExpand = inserts.length - count;
@@ -1597,11 +1634,11 @@ var ExcelTS = (function(exports) {
1597
1634
  cDst = this.getCell(i$1);
1598
1635
  cDst.value = cSrc.value;
1599
1636
  cDst.style = cSrc.style;
1600
- cDst._comment = cSrc._comment;
1637
+ cDst.comment = cSrc.comment;
1601
1638
  } else if (cDst) {
1602
1639
  cDst.value = null;
1603
1640
  cDst.style = {};
1604
- cDst._comment = void 0;
1641
+ cDst.comment = void 0;
1605
1642
  }
1606
1643
  }
1607
1644
  else if (nExpand > 0) for (i$1 = nEnd; i$1 >= nKeep; i$1--) {
@@ -1610,29 +1647,29 @@ var ExcelTS = (function(exports) {
1610
1647
  cDst = this.getCell(i$1 + nExpand);
1611
1648
  cDst.value = cSrc.value;
1612
1649
  cDst.style = cSrc.style;
1613
- cDst._comment = cSrc._comment;
1650
+ cDst.comment = cSrc.comment;
1614
1651
  } else this._cells[i$1 + nExpand - 1] = void 0;
1615
1652
  }
1616
1653
  for (i$1 = 0; i$1 < inserts.length; i$1++) {
1617
1654
  cDst = this.getCell(start + i$1);
1618
1655
  cDst.value = inserts[i$1];
1619
1656
  cDst.style = {};
1620
- cDst._comment = void 0;
1657
+ cDst.comment = void 0;
1621
1658
  }
1622
1659
  }
1623
- eachCell(optionsOrIteratee, maybeIteratee) {
1660
+ eachCell(optOrCallback, maybeCallback) {
1624
1661
  let options = null;
1625
- let iteratee;
1626
- if (typeof optionsOrIteratee === "function") iteratee = optionsOrIteratee;
1662
+ let callback;
1663
+ if (typeof optOrCallback === "function") callback = optOrCallback;
1627
1664
  else {
1628
- options = optionsOrIteratee;
1629
- iteratee = maybeIteratee;
1665
+ options = optOrCallback;
1666
+ callback = maybeCallback;
1630
1667
  }
1631
1668
  if (options && options.includeEmpty) {
1632
1669
  const n = this._cells.length;
1633
- for (let i$1 = 1; i$1 <= n; i$1++) iteratee(this.getCell(i$1), i$1);
1670
+ for (let i$1 = 1; i$1 <= n; i$1++) callback(this.getCell(i$1), i$1);
1634
1671
  } else this._cells.forEach((cell, index) => {
1635
- if (cell && cell.type !== Enums.ValueType.Null) iteratee(cell, index + 1);
1672
+ if (cell && cell.type !== Enums.ValueType.Null) callback(cell, index + 1);
1636
1673
  });
1637
1674
  }
1638
1675
  addPageBreak(lft, rght) {
@@ -1647,6 +1684,9 @@ var ExcelTS = (function(exports) {
1647
1684
  if (left) pb.min = left;
1648
1685
  ws.rowBreaks.push(pb);
1649
1686
  }
1687
+ /**
1688
+ * Get a row as a sparse array
1689
+ */
1650
1690
  get values() {
1651
1691
  const values = [];
1652
1692
  this._cells.forEach((cell) => {
@@ -1654,6 +1694,9 @@ var ExcelTS = (function(exports) {
1654
1694
  });
1655
1695
  return values;
1656
1696
  }
1697
+ /**
1698
+ * Set the values by contiguous or sparse array, or by key'd object literal
1699
+ */
1657
1700
  set values(value) {
1658
1701
  this._cells = [];
1659
1702
  if (!value) {} else if (value instanceof Array) {
@@ -1674,12 +1717,21 @@ var ExcelTS = (function(exports) {
1674
1717
  }).value = value[key];
1675
1718
  });
1676
1719
  }
1720
+ /**
1721
+ * Returns true if the row includes at least one cell with a value
1722
+ */
1677
1723
  get hasValues() {
1678
1724
  return this._cells.some((cell) => cell && cell.type !== Enums.ValueType.Null);
1679
1725
  }
1726
+ /**
1727
+ * Number of cells including empty ones
1728
+ */
1680
1729
  get cellCount() {
1681
1730
  return this._cells.length;
1682
1731
  }
1732
+ /**
1733
+ * Number of non-empty cells
1734
+ */
1683
1735
  get actualCellCount() {
1684
1736
  let count = 0;
1685
1737
  this.eachCell(() => {
@@ -1687,6 +1739,9 @@ var ExcelTS = (function(exports) {
1687
1739
  });
1688
1740
  return count;
1689
1741
  }
1742
+ /**
1743
+ * Get the min and max column number for the non-null cells in this row or null
1744
+ */
1690
1745
  get dimensions() {
1691
1746
  let min = 0;
1692
1747
  let max$1 = 0;
@@ -1704,45 +1759,44 @@ var ExcelTS = (function(exports) {
1704
1759
  _applyStyle(name, value) {
1705
1760
  this.style[name] = value;
1706
1761
  this._cells.forEach((cell) => {
1707
- if (cell) cell[name] = value;
1762
+ if (cell) cell.style[name] = value;
1708
1763
  });
1709
- return value;
1710
1764
  }
1711
1765
  get numFmt() {
1712
1766
  return this.style.numFmt;
1713
1767
  }
1714
1768
  set numFmt(value) {
1715
- this._applyStyle("numFmt", value);
1769
+ if (value !== void 0) this._applyStyle("numFmt", value);
1716
1770
  }
1717
1771
  get font() {
1718
1772
  return this.style.font;
1719
1773
  }
1720
1774
  set font(value) {
1721
- this._applyStyle("font", value);
1775
+ if (value !== void 0) this._applyStyle("font", value);
1722
1776
  }
1723
1777
  get alignment() {
1724
1778
  return this.style.alignment;
1725
1779
  }
1726
1780
  set alignment(value) {
1727
- this._applyStyle("alignment", value);
1781
+ if (value !== void 0) this._applyStyle("alignment", value);
1728
1782
  }
1729
1783
  get protection() {
1730
1784
  return this.style.protection;
1731
1785
  }
1732
1786
  set protection(value) {
1733
- this._applyStyle("protection", value);
1787
+ if (value !== void 0) this._applyStyle("protection", value);
1734
1788
  }
1735
1789
  get border() {
1736
1790
  return this.style.border;
1737
1791
  }
1738
1792
  set border(value) {
1739
- this._applyStyle("border", value);
1793
+ if (value !== void 0) this._applyStyle("border", value);
1740
1794
  }
1741
1795
  get fill() {
1742
1796
  return this.style.fill;
1743
1797
  }
1744
1798
  set fill(value) {
1745
- this._applyStyle("fill", value);
1799
+ if (value !== void 0) this._applyStyle("fill", value);
1746
1800
  }
1747
1801
  get hidden() {
1748
1802
  return !!this._hidden;
@@ -1823,6 +1877,11 @@ var ExcelTS = (function(exports) {
1823
1877
  //#endregion
1824
1878
  //#region src/doc/column.ts
1825
1879
  const DEFAULT_COLUMN_WIDTH = 9;
1880
+ /**
1881
+ * Column defines the column properties for 1 column.
1882
+ * This includes header rows, widths, key, (style), etc.
1883
+ * Worksheet will condense the columns as appropriate during serialization
1884
+ */
1826
1885
  var Column = class Column {
1827
1886
  constructor(worksheet, number, defn) {
1828
1887
  this._worksheet = worksheet;
@@ -1835,6 +1894,9 @@ var ExcelTS = (function(exports) {
1835
1894
  get worksheet() {
1836
1895
  return this._worksheet;
1837
1896
  }
1897
+ /**
1898
+ * Column letter key
1899
+ */
1838
1900
  get letter() {
1839
1901
  return colCache.n2l(this._number);
1840
1902
  }
@@ -1869,8 +1931,13 @@ var ExcelTS = (function(exports) {
1869
1931
  }
1870
1932
  }
1871
1933
  get headers() {
1872
- return this._header && this._header instanceof Array ? this._header : [this._header];
1934
+ if (Array.isArray(this._header)) return this._header;
1935
+ if (this._header !== void 0) return [this._header];
1936
+ return [];
1873
1937
  }
1938
+ /**
1939
+ * Can be a string to set one row high header or an array to set multi-row high header
1940
+ */
1874
1941
  get header() {
1875
1942
  return this._header;
1876
1943
  }
@@ -1882,6 +1949,9 @@ var ExcelTS = (function(exports) {
1882
1949
  });
1883
1950
  } else this._header = void 0;
1884
1951
  }
1952
+ /**
1953
+ * The name of the properties associated with this column in each row
1954
+ */
1885
1955
  get key() {
1886
1956
  return this._key;
1887
1957
  }
@@ -1890,18 +1960,27 @@ var ExcelTS = (function(exports) {
1890
1960
  this._key = value;
1891
1961
  if (value) this._worksheet.setColumnKey(this._key, this);
1892
1962
  }
1963
+ /**
1964
+ * Hides the column
1965
+ */
1893
1966
  get hidden() {
1894
1967
  return !!this._hidden;
1895
1968
  }
1896
1969
  set hidden(value) {
1897
1970
  this._hidden = value;
1898
1971
  }
1972
+ /**
1973
+ * Set an outline level for columns
1974
+ */
1899
1975
  get outlineLevel() {
1900
1976
  return this._outlineLevel || 0;
1901
1977
  }
1902
1978
  set outlineLevel(value) {
1903
1979
  this._outlineLevel = value;
1904
1980
  }
1981
+ /**
1982
+ * Indicate the collapsed state based on outlineLevel
1983
+ */
1905
1984
  get collapsed() {
1906
1985
  return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelCol);
1907
1986
  }
@@ -1915,6 +1994,9 @@ var ExcelTS = (function(exports) {
1915
1994
  equivalentTo(other) {
1916
1995
  return this.width === other.width && this.hidden === other.hidden && this.outlineLevel === other.outlineLevel && isEqual(this.style, other.style);
1917
1996
  }
1997
+ equivalentToModel(model) {
1998
+ return this.width === model.width && this.hidden === model.hidden && this.outlineLevel === model.outlineLevel && isEqual(this.style, model.style);
1999
+ }
1918
2000
  get isDefault() {
1919
2001
  if (this.isCustomWidth) return false;
1920
2002
  if (this.hidden) return false;
@@ -1926,16 +2008,24 @@ var ExcelTS = (function(exports) {
1926
2008
  get headerCount() {
1927
2009
  return this.headers.length;
1928
2010
  }
1929
- eachCell(options, iteratee) {
2011
+ eachCell(optionsOrCallback, maybeCallback) {
1930
2012
  const colNumber = this.number;
1931
- if (!iteratee) {
1932
- iteratee = options;
2013
+ let options;
2014
+ let callback;
2015
+ if (typeof optionsOrCallback === "function") {
1933
2016
  options = {};
2017
+ callback = optionsOrCallback;
2018
+ } else {
2019
+ options = optionsOrCallback;
2020
+ callback = maybeCallback;
1934
2021
  }
1935
2022
  this._worksheet.eachRow(options, (row, rowNumber) => {
1936
- iteratee(row.getCell(colNumber), rowNumber);
2023
+ callback(row.getCell(colNumber), rowNumber);
1937
2024
  });
1938
2025
  }
2026
+ /**
2027
+ * The cell values in the column
2028
+ */
1939
2029
  get values() {
1940
2030
  const v = [];
1941
2031
  this.eachCell((cell, rowNumber) => {
@@ -1952,48 +2042,59 @@ var ExcelTS = (function(exports) {
1952
2042
  this._worksheet.getCell(index + offset, colNumber).value = value;
1953
2043
  });
1954
2044
  }
1955
- _applyStyle(name, value) {
1956
- this.style[name] = value;
1957
- this.eachCell((cell) => {
1958
- cell[name] = value;
1959
- });
1960
- return value;
1961
- }
1962
2045
  get numFmt() {
1963
2046
  return this.style.numFmt;
1964
2047
  }
1965
2048
  set numFmt(value) {
1966
- this._applyStyle("numFmt", value);
2049
+ this.style.numFmt = value;
2050
+ this.eachCell((cell) => {
2051
+ cell.numFmt = value;
2052
+ });
1967
2053
  }
1968
2054
  get font() {
1969
2055
  return this.style.font;
1970
2056
  }
1971
2057
  set font(value) {
1972
- this._applyStyle("font", value);
2058
+ this.style.font = value;
2059
+ this.eachCell((cell) => {
2060
+ cell.font = value;
2061
+ });
1973
2062
  }
1974
2063
  get alignment() {
1975
2064
  return this.style.alignment;
1976
2065
  }
1977
2066
  set alignment(value) {
1978
- this._applyStyle("alignment", value);
2067
+ this.style.alignment = value;
2068
+ this.eachCell((cell) => {
2069
+ cell.alignment = value;
2070
+ });
1979
2071
  }
1980
2072
  get protection() {
1981
2073
  return this.style.protection;
1982
2074
  }
1983
2075
  set protection(value) {
1984
- this._applyStyle("protection", value);
2076
+ this.style.protection = value;
2077
+ this.eachCell((cell) => {
2078
+ cell.protection = value;
2079
+ });
1985
2080
  }
1986
2081
  get border() {
1987
2082
  return this.style.border;
1988
2083
  }
1989
2084
  set border(value) {
1990
- this._applyStyle("border", value);
2085
+ this.style.border = value;
2086
+ this.eachCell((cell) => {
2087
+ cell.border = value;
2088
+ });
1991
2089
  }
1992
2090
  get fill() {
1993
2091
  return this.style.fill;
1994
2092
  }
1995
2093
  set fill(value) {
1996
- this._applyStyle("fill", value);
2094
+ this.style.fill = value;
2095
+ this.eachCell((cell) => {
2096
+ cell.fill = value;
2097
+ });
1997
2098
  }
1998
2099
  static toModel(columns) {
1999
2100
  const cols = [];
@@ -2001,7 +2102,7 @@ var ExcelTS = (function(exports) {
2001
2102
  if (columns) columns.forEach((column, index) => {
2002
2103
  if (column.isDefault) {
2003
2104
  if (col) col = null;
2004
- } else if (!col || !column.equivalentTo(col)) {
2105
+ } else if (!col || !column.equivalentToModel(col)) {
2005
2106
  col = {
2006
2107
  min: index + 1,
2007
2108
  max: index + 1,
@@ -2040,6 +2141,12 @@ var ExcelTS = (function(exports) {
2040
2141
 
2041
2142
  //#endregion
2042
2143
  //#region src/doc/anchor.ts
2144
+ function isAnchorModel(value) {
2145
+ return typeof value === "object" && "nativeCol" in value && "nativeRow" in value && "nativeColOff" in value && "nativeRowOff" in value;
2146
+ }
2147
+ function isSimpleAddress(value) {
2148
+ return typeof value === "object" && "col" in value && "row" in value;
2149
+ }
2043
2150
  var Anchor = class Anchor {
2044
2151
  constructor(worksheet, address, offset = 0) {
2045
2152
  this.worksheet = worksheet;
@@ -2054,16 +2161,14 @@ var ExcelTS = (function(exports) {
2054
2161
  this.nativeColOff = 0;
2055
2162
  this.nativeRow = decoded.row + offset;
2056
2163
  this.nativeRowOff = 0;
2057
- } else if (address.nativeCol !== void 0) {
2058
- const anchor = address;
2059
- this.nativeCol = anchor.nativeCol || 0;
2060
- this.nativeColOff = anchor.nativeColOff || 0;
2061
- this.nativeRow = anchor.nativeRow || 0;
2062
- this.nativeRowOff = anchor.nativeRowOff || 0;
2063
- } else if (address.col !== void 0) {
2064
- const simple = address;
2065
- this.col = simple.col + offset;
2066
- this.row = simple.row + offset;
2164
+ } else if (isAnchorModel(address)) {
2165
+ this.nativeCol = address.nativeCol || 0;
2166
+ this.nativeColOff = address.nativeColOff || 0;
2167
+ this.nativeRow = address.nativeRow || 0;
2168
+ this.nativeRowOff = address.nativeRowOff || 0;
2169
+ } else if (isSimpleAddress(address)) {
2170
+ this.col = address.col + offset;
2171
+ this.row = address.row + offset;
2067
2172
  } else {
2068
2173
  this.nativeCol = 0;
2069
2174
  this.nativeColOff = 0;
@@ -2072,7 +2177,9 @@ var ExcelTS = (function(exports) {
2072
2177
  }
2073
2178
  }
2074
2179
  static asInstance(model) {
2075
- return model instanceof Anchor || model == null ? model : new Anchor(void 0, model);
2180
+ if (model == null) return null;
2181
+ if (model instanceof Anchor) return model;
2182
+ return new Anchor(void 0, model);
2076
2183
  }
2077
2184
  get col() {
2078
2185
  return this.nativeCol + Math.min(this.colWidth - 1, this.nativeColOff) / this.colWidth;
@@ -2140,26 +2247,28 @@ var ExcelTS = (function(exports) {
2140
2247
  set model({ type, imageId, range: range$1, hyperlinks }) {
2141
2248
  this.type = type;
2142
2249
  this.imageId = imageId;
2143
- if (type === "image") if (typeof range$1 === "string") {
2144
- const decoded = colCache.decode(range$1);
2145
- this.range = {
2146
- tl: new Anchor(this.worksheet, {
2147
- col: decoded.left,
2148
- row: decoded.top
2149
- }, -1),
2150
- br: new Anchor(this.worksheet, {
2151
- col: decoded.right,
2152
- row: decoded.bottom
2153
- }, 0),
2154
- editAs: "oneCell"
2250
+ if (type === "image") {
2251
+ if (typeof range$1 === "string") {
2252
+ const decoded = colCache.decode(range$1);
2253
+ if ("top" in decoded) this.range = {
2254
+ tl: new Anchor(this.worksheet, {
2255
+ col: decoded.left,
2256
+ row: decoded.top
2257
+ }, -1),
2258
+ br: new Anchor(this.worksheet, {
2259
+ col: decoded.right,
2260
+ row: decoded.bottom
2261
+ }, 0),
2262
+ editAs: "oneCell"
2263
+ };
2264
+ } else if (range$1) this.range = {
2265
+ tl: new Anchor(this.worksheet, range$1.tl, 0),
2266
+ br: range$1.br ? new Anchor(this.worksheet, range$1.br, 0) : void 0,
2267
+ ext: range$1.ext,
2268
+ editAs: range$1.editAs,
2269
+ hyperlinks: hyperlinks || ("hyperlinks" in range$1 ? range$1.hyperlinks : void 0)
2155
2270
  };
2156
- } else this.range = {
2157
- tl: new Anchor(this.worksheet, range$1.tl, 0),
2158
- br: range$1.br && new Anchor(this.worksheet, range$1.br, 0),
2159
- ext: range$1.ext,
2160
- editAs: range$1.editAs,
2161
- hyperlinks: hyperlinks || range$1.hyperlinks
2162
- };
2271
+ }
2163
2272
  }
2164
2273
  };
2165
2274
 
@@ -2291,9 +2400,7 @@ var ExcelTS = (function(exports) {
2291
2400
  }
2292
2401
  store() {
2293
2402
  const assignStyle = (cell, style) => {
2294
- if (style) Object.keys(style).forEach((key) => {
2295
- cell.style[key] = style[key];
2296
- });
2403
+ if (style) Object.assign(cell.style, style);
2297
2404
  };
2298
2405
  const { worksheet, table } = this;
2299
2406
  const { row, col } = table.tl;
@@ -2470,10 +2577,10 @@ var ExcelTS = (function(exports) {
2470
2577
  this._assign(this.table, "totalsRow", value);
2471
2578
  }
2472
2579
  get theme() {
2473
- return this.table.style.name;
2580
+ return this.table.style.theme;
2474
2581
  }
2475
2582
  set theme(value) {
2476
- this.table.style.name = value;
2583
+ this.table.style.theme = value;
2477
2584
  }
2478
2585
  get showFirstColumn() {
2479
2586
  return this.table.style.showFirstColumn;
@@ -26537,15 +26644,24 @@ var ExcelTS = (function(exports) {
26537
26644
  console.warn(`Worksheet name ${name} exceeds 31 chars. This will be truncated`);
26538
26645
  name = name.substring(0, 31);
26539
26646
  }
26540
- if (this._workbook._worksheets.find((ws) => ws && ws.name.toLowerCase() === name.toLowerCase())) throw new Error(`Worksheet name already exists: ${name}`);
26647
+ if (this._workbook.worksheets.find((ws) => ws && ws.name.toLowerCase() === name.toLowerCase())) throw new Error(`Worksheet name already exists: ${name}`);
26541
26648
  this._name = name;
26542
26649
  }
26650
+ /**
26651
+ * The workbook that contains this worksheet
26652
+ */
26543
26653
  get workbook() {
26544
26654
  return this._workbook;
26545
26655
  }
26656
+ /**
26657
+ * When you're done with this worksheet, call this to remove from workbook
26658
+ */
26546
26659
  destroy() {
26547
26660
  this._workbook.removeWorksheetEx(this);
26548
26661
  }
26662
+ /**
26663
+ * Get the bounding range of the cells in this worksheet
26664
+ */
26549
26665
  get dimensions() {
26550
26666
  const dimensions = new Range();
26551
26667
  this._rows.forEach((row) => {
@@ -26556,12 +26672,21 @@ var ExcelTS = (function(exports) {
26556
26672
  });
26557
26673
  return dimensions;
26558
26674
  }
26675
+ /**
26676
+ * Get the current columns array
26677
+ */
26559
26678
  get columns() {
26560
26679
  return this._columns;
26561
26680
  }
26681
+ /**
26682
+ * Add column headers and define column keys and widths.
26683
+ *
26684
+ * Note: these column structures are a workbook-building convenience only,
26685
+ * apart from the column width, they will not be fully persisted.
26686
+ */
26562
26687
  set columns(value) {
26563
26688
  this._headerRowCount = value.reduce((pv, cv) => {
26564
- const headerCount = cv.header && 1 || cv.headers && cv.headers.length || 0;
26689
+ const headerCount = Array.isArray(cv.header) ? cv.header.length : cv.header ? 1 : 0;
26565
26690
  return Math.max(pv, headerCount);
26566
26691
  }, 0);
26567
26692
  let count = 1;
@@ -26584,6 +26709,9 @@ var ExcelTS = (function(exports) {
26584
26709
  eachColumnKey(f) {
26585
26710
  Object.keys(this._keys).forEach((key) => f(this._keys[key], key));
26586
26711
  }
26712
+ /**
26713
+ * Access an individual column by key, letter and 1-based column number
26714
+ */
26587
26715
  getColumn(c) {
26588
26716
  let colNum;
26589
26717
  if (typeof c === "string") {
@@ -26598,14 +26726,22 @@ var ExcelTS = (function(exports) {
26598
26726
  }
26599
26727
  return this._columns[colNum - 1];
26600
26728
  }
26729
+ /**
26730
+ * Cut one or more columns (columns to the right are shifted left)
26731
+ * and optionally insert more
26732
+ *
26733
+ * If column properties have been defined, they will be cut or moved accordingly
26734
+ *
26735
+ * Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
26736
+ *
26737
+ * Also: If the worksheet has more rows than values in the column inserts,
26738
+ * the rows will still be shifted as if the values existed
26739
+ */
26601
26740
  spliceColumns(start, count, ...inserts) {
26602
26741
  const nRows = this._rows.length;
26603
26742
  if (inserts.length > 0) for (let i$1 = 0; i$1 < nRows; i$1++) {
26604
- const rowArguments = [start, count];
26605
- inserts.forEach((insert) => {
26606
- rowArguments.push(insert[i$1] || null);
26607
- });
26608
- this.getRow(i$1 + 1).splice(...rowArguments);
26743
+ const insertValues = inserts.map((insert) => insert[i$1] || null);
26744
+ this.getRow(i$1 + 1).splice(start, count, ...insertValues);
26609
26745
  }
26610
26746
  else this._rows.forEach((r) => {
26611
26747
  if (r) r.splice(start, count);
@@ -26615,12 +26751,18 @@ var ExcelTS = (function(exports) {
26615
26751
  const nEnd = this._columns ? this._columns.length : 0;
26616
26752
  if (nExpand < 0) for (let i$1 = start + inserts.length; i$1 <= nEnd; i$1++) this.getColumn(i$1).defn = this.getColumn(i$1 - nExpand).defn;
26617
26753
  else if (nExpand > 0) for (let i$1 = nEnd; i$1 >= nKeep; i$1--) this.getColumn(i$1 + nExpand).defn = this.getColumn(i$1).defn;
26618
- for (let i$1 = start; i$1 < start + inserts.length; i$1++) this.getColumn(i$1).defn = null;
26754
+ for (let i$1 = start; i$1 < start + inserts.length; i$1++) this.getColumn(i$1).defn = void 0;
26619
26755
  this.workbook.definedNames.spliceColumns(this.name, start, count, inserts.length);
26620
26756
  }
26757
+ /**
26758
+ * Get the last column in a worksheet
26759
+ */
26621
26760
  get lastColumn() {
26622
26761
  return this.getColumn(this.columnCount);
26623
26762
  }
26763
+ /**
26764
+ * The total column size of the document. Equal to the maximum cell count from all of the rows
26765
+ */
26624
26766
  get columnCount() {
26625
26767
  let maxCount = 0;
26626
26768
  this.eachRow((row) => {
@@ -26628,6 +26770,9 @@ var ExcelTS = (function(exports) {
26628
26770
  });
26629
26771
  return maxCount;
26630
26772
  }
26773
+ /**
26774
+ * A count of the number of columns that have values
26775
+ */
26631
26776
  get actualColumnCount() {
26632
26777
  const counts = [];
26633
26778
  let count = 0;
@@ -26651,18 +26796,38 @@ var ExcelTS = (function(exports) {
26651
26796
  get _nextRow() {
26652
26797
  return this._lastRowNumber + 1;
26653
26798
  }
26799
+ /**
26800
+ * Get the last editable row in a worksheet (or undefined if there are none)
26801
+ */
26654
26802
  get lastRow() {
26655
26803
  if (this._rows.length) return this._rows[this._rows.length - 1];
26656
26804
  }
26805
+ /**
26806
+ * Tries to find and return row for row number, else undefined
26807
+ *
26808
+ * @param r - The 1-indexed row number
26809
+ */
26657
26810
  findRow(r) {
26658
26811
  return this._rows[r - 1];
26659
26812
  }
26813
+ /**
26814
+ * Tries to find and return rows for row number start and length, else undefined
26815
+ *
26816
+ * @param start - The 1-indexed starting row number
26817
+ * @param length - The length of the expected array
26818
+ */
26660
26819
  findRows(start, length) {
26661
26820
  return this._rows.slice(start - 1, start - 1 + length);
26662
26821
  }
26822
+ /**
26823
+ * The total row size of the document. Equal to the row number of the last row that has values.
26824
+ */
26663
26825
  get rowCount() {
26664
26826
  return this._lastRowNumber;
26665
26827
  }
26828
+ /**
26829
+ * A count of the number of rows that have values. If a mid-document row is empty, it will not be included in the count.
26830
+ */
26666
26831
  get actualRowCount() {
26667
26832
  let count = 0;
26668
26833
  this.eachRow(() => {
@@ -26670,17 +26835,27 @@ var ExcelTS = (function(exports) {
26670
26835
  });
26671
26836
  return count;
26672
26837
  }
26838
+ /**
26839
+ * Get or create row by 1-based index
26840
+ */
26673
26841
  getRow(r) {
26674
26842
  let row = this._rows[r - 1];
26675
26843
  if (!row) row = this._rows[r - 1] = new Row(this, r);
26676
26844
  return row;
26677
26845
  }
26846
+ /**
26847
+ * Get or create rows by 1-based index
26848
+ */
26678
26849
  getRows(start, length) {
26679
26850
  if (length < 1) return;
26680
26851
  const rows = [];
26681
26852
  for (let i$1 = start; i$1 < start + length; i$1++) rows.push(this.getRow(i$1));
26682
26853
  return rows;
26683
26854
  }
26855
+ /**
26856
+ * Add a couple of Rows by key-value, after the last current row, using the column keys,
26857
+ * or add a row by contiguous Array (assign to columns A, B & C)
26858
+ */
26684
26859
  addRow(value, style = "n") {
26685
26860
  const rowNo = this._nextRow;
26686
26861
  const row = this.getRow(rowNo);
@@ -26688,6 +26863,9 @@ var ExcelTS = (function(exports) {
26688
26863
  this._setStyleOption(rowNo, style[0] === "i" ? style : "n");
26689
26864
  return row;
26690
26865
  }
26866
+ /**
26867
+ * Add multiple rows by providing an array of arrays or key-value pairs
26868
+ */
26691
26869
  addRows(value, style = "n") {
26692
26870
  const rows = [];
26693
26871
  value.forEach((row) => {
@@ -26695,11 +26873,19 @@ var ExcelTS = (function(exports) {
26695
26873
  });
26696
26874
  return rows;
26697
26875
  }
26876
+ /**
26877
+ * Insert a Row by key-value, at the position (shifting down all rows from position),
26878
+ * using the column keys, or add a row by contiguous Array (assign to columns A, B & C)
26879
+ */
26698
26880
  insertRow(pos, value, style = "n") {
26699
26881
  this.spliceRows(pos, 0, value);
26700
26882
  this._setStyleOption(pos, style);
26701
26883
  return this.getRow(pos);
26702
26884
  }
26885
+ /**
26886
+ * Insert multiple rows at position (shifting down all rows from position)
26887
+ * by providing an array of arrays or key-value pairs
26888
+ */
26703
26889
  insertRows(pos, values, style = "n") {
26704
26890
  this.spliceRows(pos, 0, ...values);
26705
26891
  if (style !== "n") {
@@ -26721,6 +26907,9 @@ var ExcelTS = (function(exports) {
26721
26907
  });
26722
26908
  rDst.height = rSrc.height;
26723
26909
  }
26910
+ /**
26911
+ * Duplicate rows and insert new rows
26912
+ */
26724
26913
  duplicateRow(rowNum, count, insert = false) {
26725
26914
  const rSrc = this._rows[rowNum - 1];
26726
26915
  const inserts = Array.from({ length: count }).fill(rSrc.values);
@@ -26734,6 +26923,12 @@ var ExcelTS = (function(exports) {
26734
26923
  });
26735
26924
  }
26736
26925
  }
26926
+ /**
26927
+ * Cut one or more rows (rows below are shifted up)
26928
+ * and optionally insert more
26929
+ *
26930
+ * Known Issue: If a splice causes any merged cells to move, the results may be unpredictable
26931
+ */
26737
26932
  spliceRows(start, count, ...inserts) {
26738
26933
  const nKeep = start + count;
26739
26934
  const nInserts = inserts.length;
@@ -26765,10 +26960,10 @@ var ExcelTS = (function(exports) {
26765
26960
  rDst.height = rSrc.height;
26766
26961
  rSrc.eachCell({ includeEmpty: true }, (cell, colNumber) => {
26767
26962
  rDst.getCell(colNumber).style = cell.style;
26768
- if (cell._value.constructor.name === "MergeValue") {
26769
- const cellToBeMerged = this.getRow(cell._row._number + nInserts).getCell(colNumber);
26770
- const prevMaster = cell._value._master;
26771
- const newMaster = this.getRow(prevMaster._row._number + nInserts).getCell(prevMaster._column._number);
26963
+ if (cell.type === Enums.ValueType.Merge) {
26964
+ const cellToBeMerged = this.getRow(cell.row + nInserts).getCell(colNumber);
26965
+ const prevMaster = cell.master;
26966
+ const newMaster = this.getRow(prevMaster.row + nInserts).getCell(prevMaster.col);
26772
26967
  cellToBeMerged.merge(newMaster);
26773
26968
  }
26774
26969
  });
@@ -26781,21 +26976,24 @@ var ExcelTS = (function(exports) {
26781
26976
  }
26782
26977
  this.workbook.definedNames.spliceRows(this.name, start, count, nInserts);
26783
26978
  }
26784
- eachRow(optionsOrIteratee, maybeIteratee) {
26979
+ eachRow(optOrCallback, maybeCallback) {
26785
26980
  let options;
26786
- let iteratee;
26787
- if (typeof optionsOrIteratee === "function") iteratee = optionsOrIteratee;
26981
+ let callback;
26982
+ if (typeof optOrCallback === "function") callback = optOrCallback;
26788
26983
  else {
26789
- options = optionsOrIteratee;
26790
- iteratee = maybeIteratee;
26984
+ options = optOrCallback;
26985
+ callback = maybeCallback;
26791
26986
  }
26792
26987
  if (options && options.includeEmpty) {
26793
26988
  const n = this._rows.length;
26794
- for (let i$1 = 1; i$1 <= n; i$1++) iteratee(this.getRow(i$1), i$1);
26989
+ for (let i$1 = 1; i$1 <= n; i$1++) callback(this.getRow(i$1), i$1);
26795
26990
  } else this._rows.forEach((row) => {
26796
- if (row && row.hasValues) iteratee(row, row.number);
26991
+ if (row && row.hasValues) callback(row, row.number);
26797
26992
  });
26798
26993
  }
26994
+ /**
26995
+ * Return all rows as sparse array
26996
+ */
26799
26997
  getSheetValues() {
26800
26998
  const rows = [];
26801
26999
  this._rows.forEach((row) => {
@@ -26803,15 +27001,30 @@ var ExcelTS = (function(exports) {
26803
27001
  });
26804
27002
  return rows;
26805
27003
  }
27004
+ /**
27005
+ * Returns the cell at [r,c] or address given by r. If not found, return undefined
27006
+ */
26806
27007
  findCell(r, c) {
26807
27008
  const address = colCache.getAddress(r, c);
26808
27009
  const row = this._rows[address.row - 1];
26809
27010
  return row ? row.findCell(address.col) : void 0;
26810
27011
  }
27012
+ /**
27013
+ * Get or create cell at [r,c] or address given by r
27014
+ */
26811
27015
  getCell(r, c) {
26812
27016
  const address = colCache.getAddress(r, c);
26813
27017
  return this.getRow(address.row).getCellEx(address);
26814
27018
  }
27019
+ /**
27020
+ * Merge cells, either:
27021
+ *
27022
+ * tlbr string, e.g. `'A4:B5'`
27023
+ *
27024
+ * tl string, br string, e.g. `'G10', 'H11'`
27025
+ *
27026
+ * t, l, b, r numbers, e.g. `10,11,12,13`
27027
+ */
26815
27028
  mergeCells(...cells) {
26816
27029
  const dimensions = new Range(cells);
26817
27030
  this._mergeCellsInternal(dimensions);
@@ -26838,6 +27051,11 @@ var ExcelTS = (function(exports) {
26838
27051
  get hasMerges() {
26839
27052
  return Object.values(this._merges).some(Boolean);
26840
27053
  }
27054
+ /**
27055
+ * Scan the range and if any cell is part of a merge, un-merge the group.
27056
+ * Note this function can affect multiple merges and merge-blocks are
27057
+ * atomic - either they're all merged or all un-merged.
27058
+ */
26841
27059
  unMergeCells(...cells) {
26842
27060
  const dimensions = new Range(cells);
26843
27061
  for (let i$1 = dimensions.top; i$1 <= dimensions.bottom; i$1++) for (let j = dimensions.left; j <= dimensions.right; j++) {
@@ -26860,7 +27078,8 @@ var ExcelTS = (function(exports) {
26860
27078
  else getResult = () => void 0;
26861
27079
  let first = true;
26862
27080
  for (let r = top; r <= bottom; r++) for (let c = left; c <= right; c++) if (first) {
26863
- this.getCell(r, c).value = {
27081
+ const cell = this.getCell(r, c);
27082
+ cell.value = {
26864
27083
  shareType,
26865
27084
  formula,
26866
27085
  ref: range$1,
@@ -26872,6 +27091,10 @@ var ExcelTS = (function(exports) {
26872
27091
  result: getResult(r, c)
26873
27092
  } : getResult(r, c);
26874
27093
  }
27094
+ /**
27095
+ * Using the image id from `Workbook.addImage`,
27096
+ * embed an image within the worksheet to cover a range
27097
+ */
26875
27098
  addImage(imageId, range$1) {
26876
27099
  const model = {
26877
27100
  type: "image",
@@ -26883,6 +27106,9 @@ var ExcelTS = (function(exports) {
26883
27106
  getImages() {
26884
27107
  return this._media.filter((m) => m.type === "image");
26885
27108
  }
27109
+ /**
27110
+ * Using the image id from `Workbook.addImage`, set the background to the worksheet
27111
+ */
26886
27112
  addBackgroundImage(imageId) {
26887
27113
  const model = {
26888
27114
  type: "background",
@@ -26894,6 +27120,9 @@ var ExcelTS = (function(exports) {
26894
27120
  const image = this._media.find((m) => m.type === "background");
26895
27121
  return image && image.imageId;
26896
27122
  }
27123
+ /**
27124
+ * Protect the worksheet with optional password and options
27125
+ */
26897
27126
  protect(password, options) {
26898
27127
  return new Promise((resolve) => {
26899
27128
  this.sheetProtection = { sheet: true };
@@ -26914,17 +27143,29 @@ var ExcelTS = (function(exports) {
26914
27143
  unprotect() {
26915
27144
  this.sheetProtection = null;
26916
27145
  }
27146
+ /**
27147
+ * Add a new table and return a reference to it
27148
+ */
26917
27149
  addTable(model) {
26918
27150
  const table = new Table(this, model);
26919
27151
  this.tables[model.name] = table;
26920
27152
  return table;
26921
27153
  }
27154
+ /**
27155
+ * Fetch table by name
27156
+ */
26922
27157
  getTable(name) {
26923
27158
  return this.tables[name];
26924
27159
  }
27160
+ /**
27161
+ * Delete table by name
27162
+ */
26925
27163
  removeTable(name) {
26926
27164
  delete this.tables[name];
26927
27165
  }
27166
+ /**
27167
+ * Fetch all tables in the worksheet
27168
+ */
26928
27169
  getTables() {
26929
27170
  return Object.values(this.tables);
26930
27171
  }
@@ -26936,9 +27177,15 @@ Please leave feedback at https://github.com/excelts/excelts/discussions/2575`);
26936
27177
  this.workbook.pivotTables.push(pivotTable);
26937
27178
  return pivotTable;
26938
27179
  }
27180
+ /**
27181
+ * Add conditional formatting rules
27182
+ */
26939
27183
  addConditionalFormatting(cf) {
26940
27184
  this.conditionalFormattings.push(cf);
26941
27185
  }
27186
+ /**
27187
+ * Delete conditional formatting rules
27188
+ */
26942
27189
  removeConditionalFormatting(filter) {
26943
27190
  if (typeof filter === "number") this.conditionalFormattings.splice(filter, 1);
26944
27191
  else if (filter instanceof Function) this.conditionalFormattings = this.conditionalFormattings.filter(filter);
@@ -26962,7 +27209,7 @@ Please leave feedback at https://github.com/excelts/excelts/discussions/2575`);
26962
27209
  pivotTables: this.pivotTables,
26963
27210
  conditionalFormattings: this.conditionalFormattings
26964
27211
  };
26965
- model.cols = Column.toModel(this.columns);
27212
+ model.cols = Column.toModel(this.columns || []);
26966
27213
  const rows = model.rows = [];
26967
27214
  const dimensions = model.dimensions = new Range();
26968
27215
  this._rows.forEach((row) => {
@@ -27150,11 +27397,12 @@ Please leave feedback at https://github.com/excelts/excelts/discussions/2575`);
27150
27397
  }
27151
27398
  add(locStr, name) {
27152
27399
  const location = colCache.decodeEx(locStr);
27400
+ if ("error" in location) return;
27153
27401
  this.addEx(location, name);
27154
27402
  }
27155
27403
  addEx(location, name) {
27156
27404
  const matrix = this.getMatrix(name);
27157
- if (location.top) for (let col = location.left; col <= location.right; col++) for (let row = location.top; row <= location.bottom; row++) {
27405
+ if ("top" in location) for (let col = location.left; col <= location.right; col++) for (let row = location.top; row <= location.bottom; row++) {
27158
27406
  const address = {
27159
27407
  sheetName: location.sheetName,
27160
27408
  address: colCache.n2l(col) + row,
@@ -27167,14 +27415,28 @@ Please leave feedback at https://github.com/excelts/excelts/discussions/2575`);
27167
27415
  }
27168
27416
  remove(locStr, name) {
27169
27417
  const location = colCache.decodeEx(locStr);
27418
+ if ("error" in location) return;
27170
27419
  this.removeEx(location, name);
27171
27420
  }
27172
27421
  removeEx(location, name) {
27173
- this.getMatrix(name).removeCellEx(location);
27422
+ const matrix = this.getMatrix(name);
27423
+ if ("top" in location) for (let col = location.left; col <= location.right; col++) for (let row = location.top; row <= location.bottom; row++) matrix.removeCellEx({
27424
+ sheetName: location.sheetName,
27425
+ address: colCache.n2l(col) + row,
27426
+ row,
27427
+ col
27428
+ });
27429
+ else matrix.removeCellEx(location);
27174
27430
  }
27175
27431
  removeAllNames(location) {
27176
27432
  Object.values(this.matrixMap).forEach((matrix) => {
27177
- matrix.removeCellEx(location);
27433
+ if ("top" in location) for (let col = location.left; col <= location.right; col++) for (let row = location.top; row <= location.bottom; row++) matrix.removeCellEx({
27434
+ sheetName: location.sheetName,
27435
+ address: colCache.n2l(col) + row,
27436
+ row,
27437
+ col
27438
+ });
27439
+ else matrix.removeCellEx(location);
27178
27440
  });
27179
27441
  }
27180
27442
  forEach(callback) {
@@ -27185,10 +27447,12 @@ Please leave feedback at https://github.com/excelts/excelts/discussions/2575`);
27185
27447
  });
27186
27448
  }
27187
27449
  getNames(addressStr) {
27188
- return this.getNamesEx(colCache.decodeEx(addressStr));
27450
+ const location = colCache.decodeEx(addressStr);
27451
+ if ("error" in location || "top" in location) return [];
27452
+ return this.getNamesEx(location);
27189
27453
  }
27190
27454
  getNamesEx(address) {
27191
- return Object.entries(this.matrixMap).map(([name, matrix]) => matrix.findCellEx(address, false) && name).filter(Boolean);
27455
+ return Object.entries(this.matrixMap).map(([name, matrix]) => matrix.findCellEx(address, false) && name).filter((name) => Boolean(name));
27192
27456
  }
27193
27457
  _explore(matrix, cell) {
27194
27458
  cell.mark = false;
@@ -27196,8 +27460,11 @@ Please leave feedback at https://github.com/excelts/excelts/discussions/2575`);
27196
27460
  const range$1 = new Range(cell.row, cell.col, cell.row, cell.col, sheetName);
27197
27461
  let x$1;
27198
27462
  let y;
27463
+ const getCell = (row, col) => {
27464
+ return matrix.findCellAt(sheetName, row, col);
27465
+ };
27199
27466
  function vGrow(yy, edge) {
27200
- const c = matrix.findCellAt(sheetName, yy, cell.col);
27467
+ const c = getCell(yy, cell.col);
27201
27468
  if (!c || !c.mark) return false;
27202
27469
  range$1[edge] = yy;
27203
27470
  c.mark = false;
@@ -27208,7 +27475,7 @@ Please leave feedback at https://github.com/excelts/excelts/discussions/2575`);
27208
27475
  function hGrow(xx, edge) {
27209
27476
  const cells = [];
27210
27477
  for (y = range$1.top; y <= range$1.bottom; y++) {
27211
- const c = matrix.findCellAt(sheetName, y, xx);
27478
+ const c = getCell(y, xx);
27212
27479
  if (c && c.mark) cells.push(c);
27213
27480
  else return false;
27214
27481
  }
@@ -50258,10 +50525,16 @@ ${XMLNS_NAMESPACE}.`);
50258
50525
  this.pivotTables = [];
50259
50526
  this._definedNames = new DefinedNames();
50260
50527
  }
50528
+ /**
50529
+ * xlsx file format operations
50530
+ */
50261
50531
  get xlsx() {
50262
50532
  if (!this._xlsx) this._xlsx = new XLSX(this);
50263
50533
  return this._xlsx;
50264
50534
  }
50535
+ /**
50536
+ * csv file format operations
50537
+ */
50265
50538
  get csv() {
50266
50539
  if (!this._csv) this._csv = new CSV(this);
50267
50540
  return this._csv;
@@ -50270,15 +50543,19 @@ ${XMLNS_NAMESPACE}.`);
50270
50543
  for (let i$1 = 1; i$1 < this._worksheets.length; i$1++) if (!this._worksheets[i$1]) return i$1;
50271
50544
  return this._worksheets.length || 1;
50272
50545
  }
50546
+ /**
50547
+ * Add a new worksheet and return a reference to it
50548
+ */
50273
50549
  addWorksheet(name, options) {
50274
50550
  const id = this.nextId;
50275
50551
  const lastOrderNo = this._worksheets.reduce((acc, ws) => (ws && ws.orderNo) > acc ? ws.orderNo : acc, 0);
50276
- const worksheet = new Worksheet(Object.assign({}, options, {
50552
+ const worksheet = new Worksheet({
50553
+ ...options,
50277
50554
  id,
50278
50555
  name,
50279
50556
  orderNo: lastOrderNo + 1,
50280
50557
  workbook: this
50281
- }));
50558
+ });
50282
50559
  this._worksheets[id] = worksheet;
50283
50560
  return worksheet;
50284
50561
  }
@@ -50289,17 +50566,28 @@ ${XMLNS_NAMESPACE}.`);
50289
50566
  const worksheet = this.getWorksheet(id);
50290
50567
  if (worksheet) worksheet.destroy();
50291
50568
  }
50569
+ /**
50570
+ * Fetch sheet by name or id
50571
+ */
50292
50572
  getWorksheet(id) {
50293
50573
  if (id === void 0) return this._worksheets.find(Boolean);
50294
50574
  if (typeof id === "number") return this._worksheets[id];
50295
50575
  if (typeof id === "string") return this._worksheets.find((worksheet) => worksheet && worksheet.name === id);
50296
50576
  }
50577
+ /**
50578
+ * Return a clone of worksheets in order
50579
+ */
50297
50580
  get worksheets() {
50298
50581
  return this._worksheets.slice(1).sort((a, b) => a.orderNo - b.orderNo).filter(Boolean);
50299
50582
  }
50300
- eachSheet(iteratee) {
50583
+ /**
50584
+ * Iterate over all sheets.
50585
+ *
50586
+ * Note: `workbook.worksheets.forEach` will still work but this is better.
50587
+ */
50588
+ eachSheet(callback) {
50301
50589
  this.worksheets.forEach((sheet) => {
50302
- iteratee(sheet, sheet.id);
50590
+ callback(sheet, sheet.id);
50303
50591
  });
50304
50592
  }
50305
50593
  get definedNames() {
@@ -50308,13 +50596,19 @@ ${XMLNS_NAMESPACE}.`);
50308
50596
  clearThemes() {
50309
50597
  this._themes = void 0;
50310
50598
  }
50599
+ /**
50600
+ * Add Image to Workbook and return the id
50601
+ */
50311
50602
  addImage(image) {
50312
50603
  const id = this.media.length;
50313
- this.media.push(Object.assign({}, image, { type: "image" }));
50604
+ this.media.push({
50605
+ ...image,
50606
+ type: "image"
50607
+ });
50314
50608
  return id;
50315
50609
  }
50316
50610
  getImage(id) {
50317
- return this.media[id];
50611
+ return this.media[Number(id)];
50318
50612
  }
50319
50613
  get model() {
50320
50614
  return {
@@ -50963,7 +51257,8 @@ ${XMLNS_NAMESPACE}.`);
50963
51257
  */
50964
51258
  function getCellDisplayText(cell, dateFormat) {
50965
51259
  const value = cell.value;
50966
- const fmt = cell.numFmt || "General";
51260
+ const numFmt = cell.numFmt;
51261
+ const fmt = typeof numFmt === "string" ? numFmt : numFmt?.formatCode ?? "General";
50967
51262
  if (value == null) return "";
50968
51263
  if (value instanceof Date || typeof value === "number" || typeof value === "boolean" || typeof value === "string") return formatValue(value, fmt, dateFormat);
50969
51264
  if (typeof value === "object" && "formula" in value) {