ooxml-core 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +2 -0
  2. package/dist/automation/index.cjs +6089 -5381
  3. package/dist/automation/index.mjs +6089 -5381
  4. package/dist/teams/index.cjs +73 -23
  5. package/dist/teams/index.mjs +73 -23
  6. package/dist/visio/basic-shapes.d.ts +18 -0
  7. package/dist/visio/basic-shapes.d.ts.map +1 -0
  8. package/dist/visio/edit-commands.d.ts +13 -2
  9. package/dist/visio/edit-commands.d.ts.map +1 -1
  10. package/dist/visio/edit-page-size.d.ts +5 -0
  11. package/dist/visio/edit-page-size.d.ts.map +1 -0
  12. package/dist/visio/edit-pages.d.ts.map +1 -1
  13. package/dist/visio/edit-shape-create.d.ts.map +1 -1
  14. package/dist/visio/edit-text-range-commands.d.ts +21 -0
  15. package/dist/visio/edit-text-range-commands.d.ts.map +1 -0
  16. package/dist/visio/edit-text-range-plan.d.ts +7 -0
  17. package/dist/visio/edit-text-range-plan.d.ts.map +1 -0
  18. package/dist/visio/edit-text-ranges.d.ts +4 -0
  19. package/dist/visio/edit-text-ranges.d.ts.map +1 -0
  20. package/dist/visio/edit-text-target.d.ts +3 -0
  21. package/dist/visio/edit-text-target.d.ts.map +1 -0
  22. package/dist/visio/edit-text.d.ts.map +1 -1
  23. package/dist/visio/edit.d.ts +1 -1
  24. package/dist/visio/edit.d.ts.map +1 -1
  25. package/dist/visio/index.cjs +623 -49
  26. package/dist/visio/index.d.ts +2 -1
  27. package/dist/visio/index.d.ts.map +1 -1
  28. package/dist/visio/index.mjs +621 -50
  29. package/dist/visio/model.d.ts +3 -0
  30. package/dist/visio/model.d.ts.map +1 -1
  31. package/dist/visio/parser.d.ts.map +1 -1
  32. package/dist/visio/ui/draw-plan.d.ts +4 -1
  33. package/dist/visio/ui/draw-plan.d.ts.map +1 -1
  34. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  35. package/dist/visio/ui/index.cjs +139 -14
  36. package/dist/visio/ui/index.d.ts +1 -0
  37. package/dist/visio/ui/index.d.ts.map +1 -1
  38. package/dist/visio/ui/index.mjs +135 -15
  39. package/dist/visio/ui/page-size.d.ts +31 -0
  40. package/dist/visio/ui/page-size.d.ts.map +1 -0
  41. package/dist/visio/ui/scene-validation.d.ts.map +1 -1
  42. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  43. package/dist/visio/ui/text-replace-types.d.ts +6 -2
  44. package/dist/visio/ui/text-replace-types.d.ts.map +1 -1
  45. package/dist/visio/ui/text-replace.d.ts +3 -4
  46. package/dist/visio/ui/text-replace.d.ts.map +1 -1
  47. package/dist/visio/xml-validation.d.ts.map +1 -1
  48. package/dist/xlsx/collab/codec.d.ts +2 -0
  49. package/dist/xlsx/collab/codec.d.ts.map +1 -1
  50. package/dist/xlsx/collab/index.cjs +5 -0
  51. package/dist/xlsx/collab/index.mjs +5 -0
  52. package/dist/xlsx/display-text.d.ts +4 -0
  53. package/dist/xlsx/display-text.d.ts.map +1 -0
  54. package/dist/xlsx/edit/cell-values.d.ts +4 -3
  55. package/dist/xlsx/edit/cell-values.d.ts.map +1 -1
  56. package/dist/xlsx/edit/clipboard.d.ts.map +1 -1
  57. package/dist/xlsx/edit/context.d.ts +7 -5
  58. package/dist/xlsx/edit/context.d.ts.map +1 -1
  59. package/dist/xlsx/edit/deps.d.ts +1 -1
  60. package/dist/xlsx/edit/deps.d.ts.map +1 -1
  61. package/dist/xlsx/edit/dimensions.d.ts.map +1 -1
  62. package/dist/xlsx/edit/fill.d.ts.map +1 -1
  63. package/dist/xlsx/edit/filter.d.ts.map +1 -1
  64. package/dist/xlsx/edit/find.d.ts.map +1 -1
  65. package/dist/xlsx/edit/paste-selection.d.ts.map +1 -1
  66. package/dist/xlsx/edit/shift-formulas.d.ts +10 -4
  67. package/dist/xlsx/edit/shift-formulas.d.ts.map +1 -1
  68. package/dist/xlsx/edit/shift-sheet.d.ts.map +1 -1
  69. package/dist/xlsx/edit/structure.d.ts +1 -1
  70. package/dist/xlsx/edit/structure.d.ts.map +1 -1
  71. package/dist/xlsx/edit/table-header-names.d.ts +3 -0
  72. package/dist/xlsx/edit/table-header-names.d.ts.map +1 -0
  73. package/dist/xlsx/edit/tables.d.ts +1 -2
  74. package/dist/xlsx/edit/tables.d.ts.map +1 -1
  75. package/dist/xlsx/filter-rows.d.ts +12 -0
  76. package/dist/xlsx/filter-rows.d.ts.map +1 -0
  77. package/dist/xlsx/formula/functions/math-sum.d.ts.map +1 -1
  78. package/dist/xlsx/formula/table-refs.d.ts +2 -0
  79. package/dist/xlsx/formula/table-refs.d.ts.map +1 -1
  80. package/dist/xlsx/index.cjs +466 -329
  81. package/dist/xlsx/index.mjs +466 -329
  82. package/dist/xlsx/load/index.cjs +7622 -7585
  83. package/dist/xlsx/load/index.mjs +7622 -7585
  84. package/dist/xlsx/model.d.ts +4 -0
  85. package/dist/xlsx/model.d.ts.map +1 -1
  86. package/dist/xlsx/read/load.d.ts.map +1 -1
  87. package/dist/xlsx/ui/index.cjs +464 -329
  88. package/dist/xlsx/ui/index.mjs +464 -329
  89. package/dist/xlsx/ui/locales/de/shell.d.ts.map +1 -1
  90. package/dist/xlsx/ui/locales/en/shell.d.ts.map +1 -1
  91. package/dist/xlsx/ui/locales/es/shell.d.ts.map +1 -1
  92. package/dist/xlsx/ui/locales/fr/shell.d.ts.map +1 -1
  93. package/dist/xlsx/ui/locales/zh-CN/shell.d.ts.map +1 -1
  94. package/package.json +1 -1
@@ -7749,6 +7749,57 @@ function liftCriteria(ctx, pairs, fn) {
7749
7749
  });
7750
7750
  }
7751
7751
 
7752
+ // xlsx/display-text.ts
7753
+ function displayText(workbook, cell) {
7754
+ if (!cell || cell.value === null) return "";
7755
+ const value2 = cell.value;
7756
+ if (isCellError(value2)) return value2.error;
7757
+ if (typeof value2 === "boolean") return value2 ? "TRUE" : "FALSE";
7758
+ if (cell.richText && typeof value2 === "string") return value2;
7759
+ return formatValue(value2, styleAt(workbook, cell.styleId).numFmt, {
7760
+ date1904: workbook.date1904
7761
+ }).text;
7762
+ }
7763
+
7764
+ // xlsx/filter-rows.ts
7765
+ function rowMatchesFilter(workbook, sheet, row2, filter2) {
7766
+ return (filter2.columns ?? []).every((column) => {
7767
+ if (!column.values && !column.blank) return true;
7768
+ const text2 = displayText(workbook, getCell(sheet, row2, filter2.range.start.col + column.offset));
7769
+ return text2 === "" ? !!column.blank : (column.values ?? []).includes(text2);
7770
+ });
7771
+ }
7772
+ function setRowFiltered(sheet, row2, filteredOut, hasCriteria = false) {
7773
+ const info = { ...sheet.rowInfo.get(row2) };
7774
+ const manual = info.manuallyHidden || info.hidden && !info.filteredOut;
7775
+ if (filteredOut) {
7776
+ info.hidden = true;
7777
+ info.filteredOut = true;
7778
+ if (manual) info.manuallyHidden = true;
7779
+ } else {
7780
+ delete info.filteredOut;
7781
+ delete info.manuallyHidden;
7782
+ if (manual) {
7783
+ info.hidden = true;
7784
+ if (hasCriteria) info.filteredOut = false;
7785
+ } else delete info.hidden;
7786
+ }
7787
+ if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
7788
+ else sheet.rowInfo.delete(row2);
7789
+ }
7790
+ function clearFilteredRows(sheet) {
7791
+ for (const [row2, info] of sheet.rowInfo)
7792
+ if (info.filteredOut !== void 0 || info.manuallyHidden !== void 0)
7793
+ setRowFiltered(sheet, row2, false);
7794
+ }
7795
+ function isFilteredRow(workbook, sheet, row2) {
7796
+ const filter2 = sheet.autoFilter;
7797
+ if (!filter2) return false;
7798
+ const info = sheet.rowInfo.get(row2);
7799
+ if (info?.filteredOut !== void 0) return info.filteredOut;
7800
+ return !!info?.hidden && row2 > filter2.range.start.row && row2 <= filter2.range.end.row && !rowMatchesFilter(workbook, sheet, row2, filter2);
7801
+ }
7802
+
7752
7803
  // xlsx/formula/functions/math-sum.ts
7753
7804
  var C18 = "Math & Trig";
7754
7805
  var numbersOf = (values2) => values2.filter((v) => typeof v === "number");
@@ -7786,7 +7837,7 @@ function pairwise(ctx, args, fn) {
7786
7837
  return total2;
7787
7838
  }
7788
7839
  var SUBTOTAL_RE = /\b(?:_xlfn\.)?(?:SUBTOTAL|AGGREGATE)\s*\(/i;
7789
- function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7840
+ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true, skipFiltered = false) {
7790
7841
  const out = [];
7791
7842
  const host = ctx.frame.host;
7792
7843
  for (const arg of args) {
@@ -7799,6 +7850,7 @@ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7799
7850
  for (const area of arg.areas) {
7800
7851
  const sheet = ctx.workbook.sheets[area.sheet];
7801
7852
  host.forEachStored(area.sheet, area.range, (value2, row2, col) => {
7853
+ if (skipFiltered && sheet && isFilteredRow(ctx.workbook, sheet, row2)) return;
7802
7854
  if (skipHidden && sheet?.rowInfo.get(row2)?.hidden) return;
7803
7855
  if (skipNested && SUBTOTAL_RE.test(host.cellFormula(area.sheet, row2, col) ?? "")) return;
7804
7856
  if (skipErrors && isError(value2)) return;
@@ -7964,7 +8016,7 @@ var SUM_FUNCTIONS = [
7964
8016
  const code = int(args[0]);
7965
8017
  const base = code > 100 ? code - 100 : code;
7966
8018
  if (base < 1 || base > 11) fail(ERR.VALUE);
7967
- return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false));
8019
+ return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false, true, true));
7968
8020
  },
7969
8021
  ["value", "any"]
7970
8022
  ),
@@ -13462,6 +13514,31 @@ function renameTableInFormula(formula, oldName, newName) {
13462
13514
  }
13463
13515
  return changed ? joinTokens(tokens) : formula;
13464
13516
  }
13517
+ function renameTableColumnInFormula(formula, tableName, oldName, newName, insideTable = false) {
13518
+ const tokens = safeTokens2(formula);
13519
+ if (!tokens) return formula;
13520
+ const escaped = newName.replace(/['#@[\]]/g, "'$&");
13521
+ let changed = false;
13522
+ for (const [index2, token] of tokens.entries()) {
13523
+ if (token.kind !== "structured" || token.prefix) continue;
13524
+ if (token.value === "" && tokens[index2 - 1]?.prefix) continue;
13525
+ if (token.value === "" ? !insideTable : String(token.value).toLowerCase() !== tableName.toLowerCase())
13526
+ continue;
13527
+ const next = token.text.replace(
13528
+ /\[(@?)((?:[^\[\]']|'[\s\S])*)\]/g,
13529
+ (original, at, name) => {
13530
+ if (name.startsWith("#") || name.replace(/'(.)/g, "$1").toLowerCase() !== oldName.toLowerCase())
13531
+ return original;
13532
+ return `[${at}${escaped}]`;
13533
+ }
13534
+ );
13535
+ if (next !== token.text) {
13536
+ token.text = next;
13537
+ changed = true;
13538
+ }
13539
+ }
13540
+ return changed ? joinTokens(tokens) : formula;
13541
+ }
13465
13542
 
13466
13543
  // xlsx/formula/structured-to-a1.ts
13467
13544
  var abs = (row2, col, rowAbs = true) => `$${columnLabel(col)}${rowAbs ? "$" : ""}${row2 + 1}`;
@@ -14298,16 +14375,6 @@ function forEachPosition(sheet, range2, visit2) {
14298
14375
  for (let row2 = r.start.row; row2 <= r.end.row; row2++)
14299
14376
  for (let col = r.start.col; col <= r.end.col; col++) visit2(row2, col);
14300
14377
  }
14301
- function displayText(workbook, cell) {
14302
- if (!cell) return "";
14303
- const value2 = cell.value;
14304
- if (value2 === null) return "";
14305
- if (isCellError(value2)) return value2.error;
14306
- if (typeof value2 === "boolean") return value2 ? "TRUE" : "FALSE";
14307
- if (cell.richText && typeof value2 === "string") return value2;
14308
- const format = styleAt(workbook, cell.styleId).numFmt;
14309
- return formatValue(value2, format, { date1904: workbook.date1904 }).text;
14310
- }
14311
14378
  function rawText(value2) {
14312
14379
  if (value2 === null) return "";
14313
14380
  if (isCellError(value2)) return value2.error;
@@ -14324,19 +14391,266 @@ function pruneCell(sheet, row2, col) {
14324
14391
  }
14325
14392
  }
14326
14393
 
14394
+ // xlsx/edit/shift-preserved.ts
14395
+ var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
14396
+ function descendants2(root, ns, local) {
14397
+ return Array.from(root.getElementsByTagNameNS(ns, local));
14398
+ }
14399
+ function editEntries(sheet, key, edit, quick) {
14400
+ const list = sheet.preserved.get(key);
14401
+ if (!list) return;
14402
+ const next = [];
14403
+ for (const xml of list) {
14404
+ if (!quick(xml)) {
14405
+ next.push(xml);
14406
+ continue;
14407
+ }
14408
+ let doc;
14409
+ try {
14410
+ doc = parseXml(xml);
14411
+ } catch {
14412
+ next.push(xml);
14413
+ continue;
14414
+ }
14415
+ const outcome = edit(doc.documentElement);
14416
+ if (outcome === "same") next.push(xml);
14417
+ else if (outcome === "changed") next.push(buildXml(doc));
14418
+ }
14419
+ if (next.length) sheet.preserved.set(key, next);
14420
+ else sheet.preserved.delete(key);
14421
+ }
14422
+ function shiftBreaks(root, shift2) {
14423
+ let changed = false;
14424
+ for (const brk of elements(root).filter((e) => e.localName === "brk")) {
14425
+ const id = Number(brk.getAttribute("id") ?? "0");
14426
+ const moved = shiftIndex(id, shift2);
14427
+ if (moved === id) continue;
14428
+ changed = true;
14429
+ if (moved === void 0 || moved === 0) root.removeChild(brk);
14430
+ else brk.setAttribute("id", String(moved));
14431
+ }
14432
+ if (!changed) return "same";
14433
+ const left2 = elements(root).filter((e) => e.localName === "brk");
14434
+ if (!left2.length) return "drop";
14435
+ if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
14436
+ if (root.hasAttribute("manualBreakCount")) {
14437
+ const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
14438
+ root.setAttribute("manualBreakCount", String(manual));
14439
+ }
14440
+ return "changed";
14441
+ }
14442
+ function removeUpwards(node, root) {
14443
+ let current = node;
14444
+ while (current && current !== root) {
14445
+ const parent = current.parentNode;
14446
+ parent?.removeChild(current);
14447
+ if (!parent) break;
14448
+ const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
14449
+ if (!emptied) break;
14450
+ current = parent;
14451
+ }
14452
+ }
14453
+ function shiftSqrefs(root, moveRange) {
14454
+ let changed = false;
14455
+ for (const sqref of descendants2(root, XM3, "sqref")) {
14456
+ const old = sqref.textContent ?? "";
14457
+ const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
14458
+ const text2 = ranges.map(formatRange).join(" ");
14459
+ if (text2 === old.trim()) continue;
14460
+ changed = true;
14461
+ const owner = sqref.parentNode;
14462
+ if (ranges.length) sqref.textContent = text2;
14463
+ else if (owner) removeUpwards(owner, root);
14464
+ }
14465
+ if (!changed) return "same";
14466
+ for (const list of elements(root).flatMap((ext) => elements(ext)))
14467
+ if (list.localName === "dataValidations" && list.hasAttribute("count"))
14468
+ list.setAttribute("count", String(elements(list).length));
14469
+ return elements(root).length > 0 ? "changed" : "drop";
14470
+ }
14471
+ function shiftPreservedXml(sheet, shift2, moveRange, banded) {
14472
+ if (!banded)
14473
+ editEntries(
14474
+ sheet,
14475
+ shift2.axis === "row" ? "rowBreaks" : "colBreaks",
14476
+ (root) => shiftBreaks(root, shift2),
14477
+ (xml) => xml.includes("brk")
14478
+ );
14479
+ editEntries(
14480
+ sheet,
14481
+ "extLst",
14482
+ (root) => shiftSqrefs(root, moveRange),
14483
+ (xml) => xml.includes("sqref")
14484
+ );
14485
+ }
14486
+ function rewritePreservedFormulas(sheet, rewrite) {
14487
+ editEntries(
14488
+ sheet,
14489
+ "extLst",
14490
+ (root) => {
14491
+ let changed = false;
14492
+ for (const f6 of descendants2(root, XM3, "f")) {
14493
+ const text2 = f6.textContent ?? "";
14494
+ let next = text2;
14495
+ try {
14496
+ next = rewrite(text2, sheet.name);
14497
+ } catch {
14498
+ next = text2;
14499
+ }
14500
+ if (next === text2) continue;
14501
+ f6.textContent = next;
14502
+ changed = true;
14503
+ }
14504
+ return changed ? "changed" : "same";
14505
+ },
14506
+ (xml) => xml.includes(":f>")
14507
+ );
14508
+ }
14509
+
14510
+ // xlsx/edit/conditional-formulas.ts
14511
+ function rewriteConditionalRule(rule, rewrite) {
14512
+ const safe2 = (formula) => {
14513
+ try {
14514
+ return rewrite(formula);
14515
+ } catch {
14516
+ return formula;
14517
+ }
14518
+ };
14519
+ if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
14520
+ else if (rule.type === "expression") rule.formula = safe2(rule.formula);
14521
+ if (rule.type === "colorScale" || rule.type === "iconSet") {
14522
+ for (const threshold of rule.thresholds)
14523
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14524
+ }
14525
+ if (rule.type === "dataBar") {
14526
+ for (const threshold of [rule.min, rule.max])
14527
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14528
+ }
14529
+ if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
14530
+ }
14531
+
14532
+ // xlsx/edit/shift-formulas.ts
14533
+ function safe(rewrite, formula, formulaSheet, at) {
14534
+ try {
14535
+ return rewrite(formula, formulaSheet, at);
14536
+ } catch {
14537
+ return formula;
14538
+ }
14539
+ }
14540
+ function rewriteFormulas(workbook, rewrite, formulaCells) {
14541
+ const bySheet = formulaCells && /* @__PURE__ */ new Map();
14542
+ if (bySheet)
14543
+ for (const cell of formulaCells ?? []) {
14544
+ const positions2 = bySheet.get(cell.sheet);
14545
+ if (positions2) positions2.push(cell);
14546
+ else bySheet.set(cell.sheet, [cell]);
14547
+ }
14548
+ workbook.sheets.forEach(
14549
+ (sheet, index2) => rewriteSheetFormulas(sheet, rewrite, bySheet ? bySheet.get(index2) ?? [] : void 0)
14550
+ );
14551
+ for (const definedName of workbook.definedNames) {
14552
+ const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
14553
+ definedName.formula = safe(rewrite, definedName.formula, local?.name ?? "");
14554
+ }
14555
+ }
14556
+ function rewriteSheetFormulas(sheet, rewrite, formulaCells) {
14557
+ rewritePreservedFormulas(sheet, rewrite);
14558
+ {
14559
+ const name = sheet.name;
14560
+ for (const table2 of sheet.tables)
14561
+ for (const [index2, column] of table2.columns.entries())
14562
+ if (column.calculatedColumnFormula !== void 0)
14563
+ column.calculatedColumnFormula = safe(rewrite, column.calculatedColumnFormula, name, {
14564
+ row: table2.range.start.row + (table2.headerRow ? 1 : 0),
14565
+ col: table2.range.start.col + index2
14566
+ });
14567
+ if (formulaCells) {
14568
+ for (const at of formulaCells) {
14569
+ const cell = getCell(sheet, at.row, at.col);
14570
+ if (cell?.formula !== void 0) cell.formula = safe(rewrite, cell.formula, name, at);
14571
+ }
14572
+ } else {
14573
+ sheet.rows.forEach(
14574
+ (cells, row2) => cells.forEach((cell, col) => {
14575
+ if (cell.formula !== void 0)
14576
+ cell.formula = safe(rewrite, cell.formula, name, { row: row2, col });
14577
+ })
14578
+ );
14579
+ }
14580
+ for (const cf of sheet.conditionalFormats)
14581
+ for (const rule of cf.rules)
14582
+ rewriteConditionalRule(rule, (f6) => rewrite(f6, name, cf.ranges[0]?.start));
14583
+ for (const dv of sheet.dataValidations) {
14584
+ if (dv.formula1 !== void 0)
14585
+ dv.formula1 = safe(rewrite, dv.formula1, name, dv.ranges[0]?.start);
14586
+ if (dv.formula2 !== void 0)
14587
+ dv.formula2 = safe(rewrite, dv.formula2, name, dv.ranges[0]?.start);
14588
+ }
14589
+ for (const link of sheet.hyperlinks)
14590
+ if (link.location && /![A-Za-z$]/.test(link.location))
14591
+ link.location = safe(rewrite, link.location, name);
14592
+ for (const drawing of sheet.drawings) {
14593
+ if (drawing.kind !== "chart") continue;
14594
+ for (const series of drawing.series) {
14595
+ if (series.nameRef) series.nameRef = safe(rewrite, series.nameRef, name);
14596
+ if (series.categoriesRef) series.categoriesRef = safe(rewrite, series.categoriesRef, name);
14597
+ if (series.valuesRef) series.valuesRef = safe(rewrite, series.valuesRef, name);
14598
+ }
14599
+ }
14600
+ }
14601
+ }
14602
+
14603
+ // xlsx/edit/table-header-names.ts
14604
+ function uniqueHeaders(texts) {
14605
+ const used = /* @__PURE__ */ new Set();
14606
+ return texts.map((text2, i2) => {
14607
+ let base = text2.trim() || `Column${i2 + 1}`;
14608
+ if (!used.has(base.toLowerCase())) {
14609
+ used.add(base.toLowerCase());
14610
+ return base;
14611
+ }
14612
+ for (let n = 2; ; n++) {
14613
+ const candidate = `${base}${n}`;
14614
+ if (!used.has(candidate.toLowerCase())) {
14615
+ used.add(candidate.toLowerCase());
14616
+ base = candidate;
14617
+ return base;
14618
+ }
14619
+ }
14620
+ });
14621
+ }
14622
+
14327
14623
  // xlsx/edit/cell-values.ts
14328
14624
  function tableHeaderAt(sheet, row2, col) {
14329
14625
  return sheet.tables.find(
14330
14626
  (t) => t.headerRow && t.range.start.row === row2 && col >= t.range.start.col && col <= t.range.end.col
14331
14627
  );
14332
14628
  }
14333
- function syncTableHeader(ctx, sheet, row2, col) {
14629
+ function syncTableHeader(ctx, sheet, row2, col, formulaCells) {
14334
14630
  const table2 = tableHeaderAt(sheet, row2, col);
14335
14631
  if (!table2) return;
14336
14632
  const column = table2.columns[col - table2.range.start.col];
14337
14633
  if (!column) return;
14338
14634
  const text2 = displayText(ctx.workbook, getCell(sheet, row2, col)).trim();
14339
- if (text2) column.name = text2;
14635
+ if (!text2 || column.name === text2) return;
14636
+ const oldName = column.name;
14637
+ const others = table2.columns.filter((entry) => entry !== column).map((entry) => entry.name);
14638
+ const newName = uniqueHeaders([...others, text2]).at(-1);
14639
+ column.name = newName;
14640
+ if (newName !== text2) writeValue(sheet, row2, col, newName);
14641
+ const index2 = ctx.workbook.sheets.indexOf(sheet);
14642
+ const cells = formulaCells && (formulaCells.some((cell) => cell.sheet === index2 && cell.row === row2 && cell.col === col) ? formulaCells : [...formulaCells, { sheet: index2, row: row2, col }]);
14643
+ rewriteFormulas(
14644
+ ctx.workbook,
14645
+ (formula, formulaSheet, at) => renameTableColumnInFormula(
14646
+ formula,
14647
+ table2.name,
14648
+ oldName,
14649
+ newName,
14650
+ formulaSheet === sheet.name && !!at && rangeContains(table2.range, at)
14651
+ ),
14652
+ cells
14653
+ );
14340
14654
  }
14341
14655
  function writeScopes(sheet, index2, range2, parts = []) {
14342
14656
  const r = normalizeRange(range2);
@@ -14346,9 +14660,9 @@ function writeScopes(sheet, index2, range2, parts = []) {
14346
14660
  cellRange(t.range.start.row, t.range.start.col, t.range.start.row, t.range.end.col)
14347
14661
  )
14348
14662
  );
14349
- const all2 = touchesHeader && !parts.includes("tables") ? [...parts, "tables"] : parts;
14663
+ if (touchesHeader) return [{ kind: "refs" }, { kind: "cells", sheet: index2, ranges: [r] }];
14350
14664
  const scopes = [{ kind: "cells", sheet: index2, ranges: [r] }];
14351
- if (all2.length) scopes.push({ kind: "parts", sheet: index2, parts: all2 });
14665
+ if (parts.length) scopes.push({ kind: "parts", sheet: index2, parts });
14352
14666
  return scopes;
14353
14667
  }
14354
14668
  function writeInput(ctx, sheet, row2, col, text2) {
@@ -14399,9 +14713,9 @@ function setCellInput(ctx, s, row2, col, text2) {
14399
14713
  `Typing in ${formatAddress({ row: row2, col })}`,
14400
14714
  "cells",
14401
14715
  writeScopes(sheet, s, range2),
14402
- () => {
14716
+ (formulaCells) => {
14403
14717
  writeInput(ctx, sheet, row2, col, text2);
14404
- syncTableHeader(ctx, sheet, row2, col);
14718
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
14405
14719
  },
14406
14720
  { sheet: s, ranges: [range2] }
14407
14721
  );
@@ -14413,9 +14727,9 @@ function setCellValue(ctx, s, row2, col, value2) {
14413
14727
  `Edit ${formatAddress({ row: row2, col })}`,
14414
14728
  "cells",
14415
14729
  writeScopes(sheet, s, range2),
14416
- () => {
14730
+ (formulaCells) => {
14417
14731
  writeValue(sheet, row2, col, value2);
14418
- syncTableHeader(ctx, sheet, row2, col);
14732
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
14419
14733
  },
14420
14734
  { sheet: s, ranges: [range2] }
14421
14735
  );
@@ -14842,7 +15156,7 @@ function fillRange(ctx, s, source, target2, mode = "auto") {
14842
15156
  ctx.run(
14843
15157
  "Fill",
14844
15158
  "cells",
14845
- [{ kind: "cells", sheet: s, ranges: [all2] }],
15159
+ writeScopes(sheet, s, all2),
14846
15160
  () => {
14847
15161
  const laneCount = vertical2 ? src.end.col - src.start.col + 1 : src.end.row - src.start.row + 1;
14848
15162
  const length = vertical2 ? src.end.row - src.start.row + 1 : src.end.col - src.start.col + 1;
@@ -14865,6 +15179,7 @@ function fillRange(ctx, s, source, target2, mode = "auto") {
14865
15179
  const step = series?.(k);
14866
15180
  const cell = !step || step.kind === "copy" ? copyCell(origin, row2 - srcRow, col - srcCol) : { value: step.value, ...origin.styleId ? { styleId: origin.styleId } : {} };
14867
15181
  putCell(sheet, row2, col, cell);
15182
+ syncTableHeader(ctx, sheet, row2, col);
14868
15183
  }
14869
15184
  }
14870
15185
  },
@@ -14903,28 +15218,6 @@ function removeValidationArea(rules, area) {
14903
15218
  });
14904
15219
  }
14905
15220
 
14906
- // xlsx/edit/conditional-formulas.ts
14907
- function rewriteConditionalRule(rule, rewrite) {
14908
- const safe2 = (formula) => {
14909
- try {
14910
- return rewrite(formula);
14911
- } catch {
14912
- return formula;
14913
- }
14914
- };
14915
- if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
14916
- else if (rule.type === "expression") rule.formula = safe2(rule.formula);
14917
- if (rule.type === "colorScale" || rule.type === "iconSet") {
14918
- for (const threshold of rule.thresholds)
14919
- if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14920
- }
14921
- if (rule.type === "dataBar") {
14922
- for (const threshold of [rule.min, rule.max])
14923
- if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14924
- }
14925
- if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
14926
- }
14927
-
14928
15221
  // xlsx/edit/conditional-formats.ts
14929
15222
  function formatAt(sheet, index2) {
14930
15223
  const format = sheet.conditionalFormats[index2];
@@ -15334,168 +15627,6 @@ function setBorders(ctx, s, range2, preset, edge = { style: "thin" }) {
15334
15627
  );
15335
15628
  }
15336
15629
 
15337
- // xlsx/edit/shift-preserved.ts
15338
- var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
15339
- function descendants2(root, ns, local) {
15340
- return Array.from(root.getElementsByTagNameNS(ns, local));
15341
- }
15342
- function editEntries(sheet, key, edit, quick) {
15343
- const list = sheet.preserved.get(key);
15344
- if (!list) return;
15345
- const next = [];
15346
- for (const xml of list) {
15347
- if (!quick(xml)) {
15348
- next.push(xml);
15349
- continue;
15350
- }
15351
- let doc;
15352
- try {
15353
- doc = parseXml(xml);
15354
- } catch {
15355
- next.push(xml);
15356
- continue;
15357
- }
15358
- const outcome = edit(doc.documentElement);
15359
- if (outcome === "same") next.push(xml);
15360
- else if (outcome === "changed") next.push(buildXml(doc));
15361
- }
15362
- if (next.length) sheet.preserved.set(key, next);
15363
- else sheet.preserved.delete(key);
15364
- }
15365
- function shiftBreaks(root, shift2) {
15366
- let changed = false;
15367
- for (const brk of elements(root).filter((e) => e.localName === "brk")) {
15368
- const id = Number(brk.getAttribute("id") ?? "0");
15369
- const moved = shiftIndex(id, shift2);
15370
- if (moved === id) continue;
15371
- changed = true;
15372
- if (moved === void 0 || moved === 0) root.removeChild(brk);
15373
- else brk.setAttribute("id", String(moved));
15374
- }
15375
- if (!changed) return "same";
15376
- const left2 = elements(root).filter((e) => e.localName === "brk");
15377
- if (!left2.length) return "drop";
15378
- if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
15379
- if (root.hasAttribute("manualBreakCount")) {
15380
- const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
15381
- root.setAttribute("manualBreakCount", String(manual));
15382
- }
15383
- return "changed";
15384
- }
15385
- function removeUpwards(node, root) {
15386
- let current = node;
15387
- while (current && current !== root) {
15388
- const parent = current.parentNode;
15389
- parent?.removeChild(current);
15390
- if (!parent) break;
15391
- const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
15392
- if (!emptied) break;
15393
- current = parent;
15394
- }
15395
- }
15396
- function shiftSqrefs(root, moveRange) {
15397
- let changed = false;
15398
- for (const sqref of descendants2(root, XM3, "sqref")) {
15399
- const old = sqref.textContent ?? "";
15400
- const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
15401
- const text2 = ranges.map(formatRange).join(" ");
15402
- if (text2 === old.trim()) continue;
15403
- changed = true;
15404
- const owner = sqref.parentNode;
15405
- if (ranges.length) sqref.textContent = text2;
15406
- else if (owner) removeUpwards(owner, root);
15407
- }
15408
- if (!changed) return "same";
15409
- for (const list of elements(root).flatMap((ext) => elements(ext)))
15410
- if (list.localName === "dataValidations" && list.hasAttribute("count"))
15411
- list.setAttribute("count", String(elements(list).length));
15412
- return elements(root).length > 0 ? "changed" : "drop";
15413
- }
15414
- function shiftPreservedXml(sheet, shift2, moveRange, banded) {
15415
- if (!banded)
15416
- editEntries(
15417
- sheet,
15418
- shift2.axis === "row" ? "rowBreaks" : "colBreaks",
15419
- (root) => shiftBreaks(root, shift2),
15420
- (xml) => xml.includes("brk")
15421
- );
15422
- editEntries(
15423
- sheet,
15424
- "extLst",
15425
- (root) => shiftSqrefs(root, moveRange),
15426
- (xml) => xml.includes("sqref")
15427
- );
15428
- }
15429
- function rewritePreservedFormulas(sheet, rewrite) {
15430
- editEntries(
15431
- sheet,
15432
- "extLst",
15433
- (root) => {
15434
- let changed = false;
15435
- for (const f6 of descendants2(root, XM3, "f")) {
15436
- const text2 = f6.textContent ?? "";
15437
- let next = text2;
15438
- try {
15439
- next = rewrite(text2, sheet.name);
15440
- } catch {
15441
- next = text2;
15442
- }
15443
- if (next === text2) continue;
15444
- f6.textContent = next;
15445
- changed = true;
15446
- }
15447
- return changed ? "changed" : "same";
15448
- },
15449
- (xml) => xml.includes(":f>")
15450
- );
15451
- }
15452
-
15453
- // xlsx/edit/shift-formulas.ts
15454
- function safe(rewrite, formula, formulaSheet) {
15455
- try {
15456
- return rewrite(formula, formulaSheet);
15457
- } catch {
15458
- return formula;
15459
- }
15460
- }
15461
- function rewriteFormulas(workbook, rewrite) {
15462
- for (const sheet of workbook.sheets) rewriteSheetFormulas(sheet, rewrite);
15463
- for (const definedName of workbook.definedNames) {
15464
- const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
15465
- definedName.formula = safe(rewrite, definedName.formula, local?.name ?? "");
15466
- }
15467
- }
15468
- function rewriteSheetFormulas(sheet, rewrite) {
15469
- rewritePreservedFormulas(sheet, rewrite);
15470
- {
15471
- const name = sheet.name;
15472
- for (const table2 of sheet.tables)
15473
- for (const column of table2.columns)
15474
- if (column.calculatedColumnFormula !== void 0)
15475
- column.calculatedColumnFormula = safe(rewrite, column.calculatedColumnFormula, name);
15476
- for (const cells of sheet.rows.values())
15477
- for (const cell of cells.values())
15478
- if (cell.formula !== void 0) cell.formula = safe(rewrite, cell.formula, name);
15479
- for (const cf of sheet.conditionalFormats)
15480
- for (const rule of cf.rules) rewriteConditionalRule(rule, (f6) => rewrite(f6, name));
15481
- for (const dv of sheet.dataValidations) {
15482
- if (dv.formula1 !== void 0) dv.formula1 = safe(rewrite, dv.formula1, name);
15483
- if (dv.formula2 !== void 0) dv.formula2 = safe(rewrite, dv.formula2, name);
15484
- }
15485
- for (const link of sheet.hyperlinks)
15486
- if (link.location && /![A-Za-z$]/.test(link.location))
15487
- link.location = safe(rewrite, link.location, name);
15488
- for (const drawing of sheet.drawings) {
15489
- if (drawing.kind !== "chart") continue;
15490
- for (const series of drawing.series) {
15491
- if (series.nameRef) series.nameRef = safe(rewrite, series.nameRef, name);
15492
- if (series.categoriesRef) series.categoriesRef = safe(rewrite, series.categoriesRef, name);
15493
- if (series.valuesRef) series.valuesRef = safe(rewrite, series.valuesRef, name);
15494
- }
15495
- }
15496
- }
15497
- }
15498
-
15499
15630
  // xlsx/edit/shift-sheet.ts
15500
15631
  function shiftSheetContent(sheet, shift2, band) {
15501
15632
  const moveRange = (range2) => band ? shiftRangeInBand(range2, shift2, band.lo, band.hi) : shiftRange(range2, shift2);
@@ -15517,8 +15648,10 @@ function shiftSheetContent(sheet, shift2, band) {
15517
15648
  if (sheet.autoFilter) {
15518
15649
  const old = sheet.autoFilter.range;
15519
15650
  const range2 = moveRange(old);
15520
- if (!range2) delete sheet.autoFilter;
15521
- else {
15651
+ if (!range2) {
15652
+ delete sheet.autoFilter;
15653
+ clearFilteredRows(sheet);
15654
+ } else {
15522
15655
  const filter2 = { ...sheet.autoFilter, range: range2 };
15523
15656
  if (shift2.axis === "col" && filter2.columns)
15524
15657
  filter2.columns = filter2.columns.flatMap((fc) => {
@@ -15669,6 +15802,9 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
15669
15802
  const sheet = sheetAt(ctx.workbook, s);
15670
15803
  const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
15671
15804
  const shift2 = { axis, at, count: insert ? count2 : -count2 };
15805
+ const info = { sheet: s, structural: true };
15806
+ if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
15807
+ info.calc = { kind: "shift", sheet: s, shift: shift2 };
15672
15808
  ctx.run(
15673
15809
  `${insert ? "Insert" : "Delete"} ${noun}`,
15674
15810
  "structure",
@@ -15677,7 +15813,7 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
15677
15813
  applyAxisShift(ctx, sheet, shift2);
15678
15814
  if (insert) inheritFormats(sheet, axis, at, count2);
15679
15815
  },
15680
- { sheet: s, structural: true, calc: { kind: "shift", sheet: s, shift: shift2 } }
15816
+ info
15681
15817
  );
15682
15818
  }
15683
15819
  var insertRows = (ctx, s, at, count2) => shiftAxis(ctx, s, "row", at, count2, true);
@@ -16485,14 +16621,13 @@ function pasteAt(ctx, s, at, payload, request) {
16485
16621
  if (cut && operation !== "none")
16486
16622
  throw new RangeError("Paste operations are not available for cut cells.");
16487
16623
  const destCells = { kind: "cells", sheet: s, ranges: [dest] };
16488
- const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : [
16489
- destCells,
16490
- {
16491
- kind: "parts",
16492
- sheet: s,
16493
- parts: ["merges", "comments", "dataValidations", "hyperlinks", "conditionalFormats"]
16494
- }
16495
- ];
16624
+ const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : writeScopes(sheet, s, dest, [
16625
+ "merges",
16626
+ "comments",
16627
+ "dataValidations",
16628
+ "hyperlinks",
16629
+ "conditionalFormats"
16630
+ ]);
16496
16631
  const move = cut && {
16497
16632
  fromSheet: sheetAt(workbook, cut.sheet).name,
16498
16633
  range: cut.range,
@@ -16565,6 +16700,8 @@ function pasteAt(ctx, s, at, payload, request) {
16565
16700
  const origin = cells.source?.range.start;
16566
16701
  const formula = clip?.formula === void 0 ? void 0 : move ? moveReferencesInFormula(clip.formula, move.fromSheet, move, move.toSheet) : !origin ? clip.formula : moveFormula(clip.formula, at.row - origin.row, at.col - origin.col);
16567
16702
  writeClip(workbook, sheet, row2, col, clip, mode, formula, styleOf, operation);
16703
+ if (mode !== "formats" && mode !== "comments" && mode !== "validation")
16704
+ syncTableHeader(ctx, sheet, row2, col);
16568
16705
  }
16569
16706
  if (mode === "all" || mode === "mergeFormats" || mode === "noBorders" || mode === "formats") {
16570
16707
  sheet.merges = sheet.merges.filter((m) => !rangesIntersect(m, dest));
@@ -16608,14 +16745,13 @@ function pasteSelection(ctx, sheet, selection, payload, request) {
16608
16745
  return ctx.run(
16609
16746
  "Paste",
16610
16747
  "cells",
16611
- [
16612
- { kind: "cells", sheet, ranges: [dest] },
16613
- {
16614
- kind: "parts",
16615
- sheet,
16616
- parts: ["merges", "comments", "dataValidations", "hyperlinks", "conditionalFormats"]
16617
- }
16618
- ],
16748
+ writeScopes(sheetAt(ctx.workbook, sheet), sheet, dest, [
16749
+ "merges",
16750
+ "comments",
16751
+ "dataValidations",
16752
+ "hyperlinks",
16753
+ "conditionalFormats"
16754
+ ]),
16619
16755
  () => {
16620
16756
  for (let row2 = dest.start.row; row2 <= dest.end.row; row2 += height)
16621
16757
  for (let col = dest.start.col; col <= dest.end.col; col += width)
@@ -16767,9 +16903,19 @@ function setHidden(ctx, s, axis, indices, hidden) {
16767
16903
  }
16768
16904
  for (const row2 of indices) {
16769
16905
  const info = { ...sheet.rowInfo.get(row2) };
16906
+ if (info.filteredOut) {
16907
+ if (hidden) info.manuallyHidden = true;
16908
+ else delete info.manuallyHidden;
16909
+ sheet.rowInfo.set(row2, info);
16910
+ continue;
16911
+ }
16912
+ const filter2 = sheet.autoFilter;
16913
+ if (hidden && filter2?.columns?.length && row2 > filter2.range.start.row && row2 <= filter2.range.end.row)
16914
+ info.filteredOut = false;
16770
16915
  if (hidden) info.hidden = true;
16771
16916
  else {
16772
16917
  delete info.hidden;
16918
+ delete info.filteredOut;
16773
16919
  if (info.height === 0) delete info.height;
16774
16920
  }
16775
16921
  if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
@@ -16921,16 +17067,8 @@ function currentRegion(sheet, at) {
16921
17067
  function applyFilter(ctx, sheet, filter2) {
16922
17068
  const { range: range2 } = filter2;
16923
17069
  for (let row2 = range2.start.row + 1; row2 <= range2.end.row; row2++) {
16924
- const visible = (filter2.columns ?? []).every((fc) => {
16925
- if (!fc.values && !fc.blank) return true;
16926
- const text2 = displayText(ctx.workbook, getCell(sheet, row2, range2.start.col + fc.offset));
16927
- return text2 === "" ? !!fc.blank : (fc.values ?? []).includes(text2);
16928
- });
16929
- const info = { ...sheet.rowInfo.get(row2) };
16930
- if (visible) delete info.hidden;
16931
- else info.hidden = true;
16932
- if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
16933
- else sheet.rowInfo.delete(row2);
17070
+ const visible = rowMatchesFilter(ctx.workbook, sheet, row2, filter2);
17071
+ setRowFiltered(sheet, row2, !visible, !!filter2.columns?.length);
16934
17072
  }
16935
17073
  }
16936
17074
  function setAutoFilter(ctx, s, range2) {
@@ -17088,16 +17226,16 @@ var isSpilledAt = (workbook, at) => {
17088
17226
  return !!sheet && isSpilledCell(getCell(sheet, at.row, at.col));
17089
17227
  };
17090
17228
  var replaceQuery = (query) => query.lookIn === "comments" ? query : { ...query, lookIn: "formulas" };
17091
- function replaceScopes(query, sheet, matches2) {
17229
+ function replaceScopes(ctx, query, sheet, matches2) {
17092
17230
  if (query.lookIn === "comments") return [{ kind: "parts", sheet, parts: ["comments"] }];
17093
17231
  const ranges = matches2.map((m) => ({
17094
17232
  start: { row: m.row, col: m.col },
17095
17233
  end: { row: m.row, col: m.col }
17096
17234
  }));
17097
- return [
17098
- { kind: "cells", sheet, ranges },
17099
- { kind: "parts", sheet, parts: ["tables"] }
17100
- ];
17235
+ const header = ranges.some(
17236
+ (range2) => writeScopes(sheetAt(ctx.workbook, sheet), sheet, range2).some((scope) => scope.kind === "refs")
17237
+ );
17238
+ return [...header ? [{ kind: "refs" }] : [], { kind: "cells", sheet, ranges }];
17101
17239
  }
17102
17240
  function applyReplace(ctx, query, replacement, matches2) {
17103
17241
  let changed = 0;
@@ -17127,14 +17265,24 @@ function replaceAll(ctx, query, replacement) {
17127
17265
  const sheets = [...new Set(matches2.map((m) => m.sheet))];
17128
17266
  const scopes = sheets.flatMap(
17129
17267
  (sheet) => replaceScopes(
17268
+ ctx,
17130
17269
  q,
17131
17270
  sheet,
17132
17271
  matches2.filter((m) => m.sheet === sheet)
17133
17272
  )
17134
17273
  );
17135
- return ctx.run("Replace", "cells", scopes, () => applyReplace(ctx, q, replacement, matches2), {
17136
- ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
17137
- });
17274
+ const uniqueScopes = scopes.filter(
17275
+ (scope, index2) => scope.kind !== "refs" || scopes.findIndex((entry) => entry.kind === "refs") === index2
17276
+ );
17277
+ return ctx.run(
17278
+ "Replace",
17279
+ "cells",
17280
+ uniqueScopes,
17281
+ () => applyReplace(ctx, q, replacement, matches2),
17282
+ {
17283
+ ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
17284
+ }
17285
+ );
17138
17286
  }
17139
17287
  function replaceOne(ctx, query, replacement, at) {
17140
17288
  const q = replaceQuery(query);
@@ -17147,7 +17295,7 @@ function replaceOne(ctx, query, replacement, at) {
17147
17295
  ctx.run(
17148
17296
  "Replace",
17149
17297
  "cells",
17150
- replaceScopes(q, at.sheet, [match2]),
17298
+ replaceScopes(ctx, q, at.sheet, [match2]),
17151
17299
  () => applyReplace(ctx, q, replacement, [match2]),
17152
17300
  { sheet: at.sheet }
17153
17301
  );
@@ -17927,90 +18075,6 @@ function applyTotalsRow(sheet, table2) {
17927
18075
  });
17928
18076
  }
17929
18077
 
17930
- // xlsx/edit/tables.ts
17931
- function nextTableName(workbook) {
17932
- const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
17933
- const names = new Set(workbook.definedNames.map((n) => n.name.toLowerCase()));
17934
- for (let n = 1; ; n++) if (!taken.has(`table${n}`) && !names.has(`table${n}`)) return `Table${n}`;
17935
- }
17936
- function uniqueHeaders(texts) {
17937
- const used = /* @__PURE__ */ new Set();
17938
- return texts.map((text2, i2) => {
17939
- let base = text2.trim() || `Column${i2 + 1}`;
17940
- if (!used.has(base.toLowerCase())) {
17941
- used.add(base.toLowerCase());
17942
- return base;
17943
- }
17944
- for (let n = 2; ; n++) {
17945
- const candidate = `${base}${n}`;
17946
- if (!used.has(candidate.toLowerCase())) {
17947
- used.add(candidate.toLowerCase());
17948
- base = candidate;
17949
- return base;
17950
- }
17951
- }
17952
- });
17953
- }
17954
- function createTable(ctx, s, range2, hasHeader, styleName = "TableStyleMedium2") {
17955
- const { workbook } = ctx;
17956
- const sheet = sheetAt(workbook, s);
17957
- let r = normalizeRange(range2);
17958
- if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
17959
- if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
17960
- throw new Error("A table cannot overlap another table.");
17961
- if (sheet.merges.some((m) => rangesIntersect(m, r)))
17962
- throw new Error("A table cannot contain merged cells.");
17963
- return ctx.run(
17964
- "Create table",
17965
- "structure",
17966
- [hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
17967
- () => {
17968
- if (!hasHeader) {
17969
- const shift2 = { axis: "row", at: r.start.row, count: 1 };
17970
- const band = { lo: r.start.col, hi: r.end.col };
17971
- rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
17972
- shiftSheetContent(sheet, shift2, band);
17973
- r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
17974
- }
17975
- const width = r.end.col - r.start.col + 1;
17976
- const texts = Array.from(
17977
- { length: width },
17978
- (_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
17979
- );
17980
- const headers = uniqueHeaders(texts);
17981
- const columns = headers.map((name2, i2) => {
17982
- const cell = getCell(sheet, r.start.row, r.start.col + i2);
17983
- if (cell?.value !== name2) {
17984
- const styleId = cell?.styleId;
17985
- writeValue(sheet, r.start.row, r.start.col + i2, name2);
17986
- const written = getCell(sheet, r.start.row, r.start.col + i2);
17987
- if (written && styleId) written.styleId = styleId;
17988
- }
17989
- return { name: name2 };
17990
- });
17991
- const name = nextTableName(workbook);
17992
- const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
17993
- const table2 = {
17994
- id,
17995
- name,
17996
- displayName: name,
17997
- range: r,
17998
- headerRow: true,
17999
- totalsRow: false,
18000
- columns,
18001
- styleName,
18002
- showRowStripes: true,
18003
- showColumnStripes: false,
18004
- showFirstColumn: false,
18005
- showLastColumn: false
18006
- };
18007
- sheet.tables.push(table2);
18008
- return table2;
18009
- },
18010
- { sheet: s, ranges: [r], structural: !hasHeader }
18011
- );
18012
- }
18013
-
18014
18078
  // xlsx/edit/table-edits.ts
18015
18079
  function tableIndex(sheet, ref) {
18016
18080
  const index2 = typeof ref === "number" ? ref : sheet.tables.findIndex((t) => t.name.toLowerCase() === ref.toLowerCase());
@@ -21227,8 +21291,8 @@ function setSheetState(ctx, index2, state) {
21227
21291
  const { workbook } = ctx;
21228
21292
  const sheet = sheetAt(workbook, index2);
21229
21293
  if (sheet.state === state) return;
21294
+ assertUnlocked(workbook);
21230
21295
  if (state !== "visible") {
21231
- assertUnlocked(workbook);
21232
21296
  if (sheet.state === "visible" && visibleCount(workbook) <= 1)
21233
21297
  throw new Error("A workbook must contain at least one visible sheet.");
21234
21298
  }
@@ -21258,6 +21322,72 @@ function setTabColor(ctx, index2, color) {
21258
21322
  );
21259
21323
  }
21260
21324
 
21325
+ // xlsx/edit/tables.ts
21326
+ function nextTableName(workbook) {
21327
+ const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
21328
+ const names = new Set(workbook.definedNames.map((n) => n.name.toLowerCase()));
21329
+ for (let n = 1; ; n++) if (!taken.has(`table${n}`) && !names.has(`table${n}`)) return `Table${n}`;
21330
+ }
21331
+ function createTable(ctx, s, range2, hasHeader, styleName = "TableStyleMedium2") {
21332
+ const { workbook } = ctx;
21333
+ const sheet = sheetAt(workbook, s);
21334
+ let r = normalizeRange(range2);
21335
+ if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
21336
+ if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
21337
+ throw new Error("A table cannot overlap another table.");
21338
+ if (sheet.merges.some((m) => rangesIntersect(m, r)))
21339
+ throw new Error("A table cannot contain merged cells.");
21340
+ return ctx.run(
21341
+ "Create table",
21342
+ "structure",
21343
+ [hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
21344
+ () => {
21345
+ if (!hasHeader) {
21346
+ const shift2 = { axis: "row", at: r.start.row, count: 1 };
21347
+ const band = { lo: r.start.col, hi: r.end.col };
21348
+ rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
21349
+ shiftSheetContent(sheet, shift2, band);
21350
+ r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
21351
+ }
21352
+ const width = r.end.col - r.start.col + 1;
21353
+ const texts = Array.from(
21354
+ { length: width },
21355
+ (_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
21356
+ );
21357
+ const headers = uniqueHeaders(texts);
21358
+ const columns = headers.map((name2, i2) => {
21359
+ const cell = getCell(sheet, r.start.row, r.start.col + i2);
21360
+ if (cell?.value !== name2) {
21361
+ const styleId = cell?.styleId;
21362
+ writeValue(sheet, r.start.row, r.start.col + i2, name2);
21363
+ const written = getCell(sheet, r.start.row, r.start.col + i2);
21364
+ if (written && styleId) written.styleId = styleId;
21365
+ }
21366
+ return { name: name2 };
21367
+ });
21368
+ const name = nextTableName(workbook);
21369
+ const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
21370
+ const table2 = {
21371
+ id,
21372
+ name,
21373
+ displayName: name,
21374
+ range: r,
21375
+ headerRow: true,
21376
+ totalsRow: false,
21377
+ columns,
21378
+ styleName,
21379
+ showRowStripes: true,
21380
+ showColumnStripes: false,
21381
+ showFirstColumn: false,
21382
+ showLastColumn: false
21383
+ };
21384
+ sheet.tables.push(table2);
21385
+ return table2;
21386
+ },
21387
+ { sheet: s, ranges: [r], structural: !hasHeader }
21388
+ );
21389
+ }
21390
+
21261
21391
  // xlsx/edit/validation-list.ts
21262
21392
  function listSource(workbook, sheet, formula, evaluate, at, depth = 0) {
21263
21393
  const text2 = formula.replace(/^=/, "").trim();
@@ -21545,7 +21675,7 @@ function createEditSession(workbook, options = {}) {
21545
21675
  const befores = scopes.map((scope) => captureScope(workbook, scope));
21546
21676
  let result2;
21547
21677
  try {
21548
- result2 = fn();
21678
+ result2 = fn(befores.find((snapshot) => snapshot.kind === "refs")?.data.formulas);
21549
21679
  } catch (error) {
21550
21680
  for (let i2 = befores.length - 1; i2 >= 0; i2--) {
21551
21681
  const snapshot = befores[i2];
@@ -26991,6 +27121,7 @@ __export(shell_exports, {
26991
27121
  shell: () => shell
26992
27122
  });
26993
27123
  var shell = {
27124
+ "Finish or cancel the current cell edit before saving.": "Beenden oder verwerfen Sie die aktuelle Zellbearbeitung vor dem Speichern.",
26994
27125
  File: "Datei",
26995
27126
  Ribbon: "Men\xFCband",
26996
27127
  "Ribbon tabs": "Men\xFCbandregisterkarten",
@@ -27376,6 +27507,7 @@ __export(shell_exports2, {
27376
27507
  shell: () => shell2
27377
27508
  });
27378
27509
  var shell2 = {
27510
+ "Finish or cancel the current cell edit before saving.": "Finish or cancel the current cell edit before saving.",
27379
27511
  File: "File",
27380
27512
  Ribbon: "Ribbon",
27381
27513
  "Ribbon tabs": "Ribbon tabs",
@@ -27761,6 +27893,7 @@ __export(shell_exports3, {
27761
27893
  shell: () => shell3
27762
27894
  });
27763
27895
  var shell3 = {
27896
+ "Finish or cancel the current cell edit before saving.": "Finalice o cancele la edici\xF3n de la celda actual antes de guardar.",
27764
27897
  File: "Archivo",
27765
27898
  Ribbon: "Cinta de opciones",
27766
27899
  "Ribbon tabs": "Pesta\xF1as de la cinta",
@@ -28146,6 +28279,7 @@ __export(shell_exports4, {
28146
28279
  shell: () => shell4
28147
28280
  });
28148
28281
  var shell4 = {
28282
+ "Finish or cancel the current cell edit before saving.": "Terminez ou annulez la modification de la cellule avant de sauvegarder.",
28149
28283
  File: "Fichier",
28150
28284
  Ribbon: "Ruban",
28151
28285
  "Ribbon tabs": "Onglets du ruban",
@@ -28531,6 +28665,7 @@ __export(shell_exports5, {
28531
28665
  shell: () => shell5
28532
28666
  });
28533
28667
  var shell5 = {
28668
+ "Finish or cancel the current cell edit before saving.": "\u8BF7\u5148\u5B8C\u6210\u6216\u53D6\u6D88\u5F53\u524D\u5355\u5143\u683C\u7684\u7F16\u8F91\uFF0C\u518D\u4FDD\u5B58\u3002",
28534
28669
  File: "\u6587\u4EF6",
28535
28670
  Ribbon: "\u529F\u80FD\u533A",
28536
28671
  "Ribbon tabs": "\u529F\u80FD\u533A\u9009\u9879\u5361",