ooxml-core 1.3.0 → 1.4.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 (86) hide show
  1. package/README.md +2 -0
  2. package/dist/automation/index.cjs +5785 -5295
  3. package/dist/automation/index.mjs +5785 -5295
  4. package/dist/teams/index.cjs +72 -23
  5. package/dist/teams/index.mjs +72 -23
  6. package/dist/visio/edit-commands.d.ts +11 -2
  7. package/dist/visio/edit-commands.d.ts.map +1 -1
  8. package/dist/visio/edit-page-size.d.ts +5 -0
  9. package/dist/visio/edit-page-size.d.ts.map +1 -0
  10. package/dist/visio/edit-pages.d.ts.map +1 -1
  11. package/dist/visio/edit-text-range-commands.d.ts +21 -0
  12. package/dist/visio/edit-text-range-commands.d.ts.map +1 -0
  13. package/dist/visio/edit-text-range-plan.d.ts +7 -0
  14. package/dist/visio/edit-text-range-plan.d.ts.map +1 -0
  15. package/dist/visio/edit-text-ranges.d.ts +4 -0
  16. package/dist/visio/edit-text-ranges.d.ts.map +1 -0
  17. package/dist/visio/edit-text-target.d.ts +3 -0
  18. package/dist/visio/edit-text-target.d.ts.map +1 -0
  19. package/dist/visio/edit-text.d.ts.map +1 -1
  20. package/dist/visio/edit.d.ts +1 -1
  21. package/dist/visio/edit.d.ts.map +1 -1
  22. package/dist/visio/index.cjs +395 -27
  23. package/dist/visio/index.d.ts +1 -1
  24. package/dist/visio/index.d.ts.map +1 -1
  25. package/dist/visio/index.mjs +395 -27
  26. package/dist/visio/model.d.ts +3 -0
  27. package/dist/visio/model.d.ts.map +1 -1
  28. package/dist/visio/parser.d.ts.map +1 -1
  29. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  30. package/dist/visio/ui/index.cjs +134 -11
  31. package/dist/visio/ui/index.d.ts +1 -0
  32. package/dist/visio/ui/index.d.ts.map +1 -1
  33. package/dist/visio/ui/index.mjs +130 -12
  34. package/dist/visio/ui/page-size.d.ts +31 -0
  35. package/dist/visio/ui/page-size.d.ts.map +1 -0
  36. package/dist/visio/ui/scene-validation.d.ts.map +1 -1
  37. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  38. package/dist/visio/ui/text-replace-types.d.ts +6 -2
  39. package/dist/visio/ui/text-replace-types.d.ts.map +1 -1
  40. package/dist/visio/ui/text-replace.d.ts +3 -4
  41. package/dist/visio/ui/text-replace.d.ts.map +1 -1
  42. package/dist/visio/xml-validation.d.ts.map +1 -1
  43. package/dist/xlsx/collab/codec.d.ts +2 -0
  44. package/dist/xlsx/collab/codec.d.ts.map +1 -1
  45. package/dist/xlsx/collab/index.cjs +5 -0
  46. package/dist/xlsx/collab/index.mjs +5 -0
  47. package/dist/xlsx/display-text.d.ts +4 -0
  48. package/dist/xlsx/display-text.d.ts.map +1 -0
  49. package/dist/xlsx/edit/cell-values.d.ts +4 -3
  50. package/dist/xlsx/edit/cell-values.d.ts.map +1 -1
  51. package/dist/xlsx/edit/clipboard.d.ts.map +1 -1
  52. package/dist/xlsx/edit/context.d.ts +7 -5
  53. package/dist/xlsx/edit/context.d.ts.map +1 -1
  54. package/dist/xlsx/edit/deps.d.ts +1 -1
  55. package/dist/xlsx/edit/deps.d.ts.map +1 -1
  56. package/dist/xlsx/edit/dimensions.d.ts.map +1 -1
  57. package/dist/xlsx/edit/fill.d.ts.map +1 -1
  58. package/dist/xlsx/edit/filter.d.ts.map +1 -1
  59. package/dist/xlsx/edit/find.d.ts.map +1 -1
  60. package/dist/xlsx/edit/paste-selection.d.ts.map +1 -1
  61. package/dist/xlsx/edit/shift-formulas.d.ts +10 -4
  62. package/dist/xlsx/edit/shift-formulas.d.ts.map +1 -1
  63. package/dist/xlsx/edit/table-header-names.d.ts +3 -0
  64. package/dist/xlsx/edit/table-header-names.d.ts.map +1 -0
  65. package/dist/xlsx/edit/tables.d.ts +1 -2
  66. package/dist/xlsx/edit/tables.d.ts.map +1 -1
  67. package/dist/xlsx/filter-rows.d.ts +8 -0
  68. package/dist/xlsx/filter-rows.d.ts.map +1 -0
  69. package/dist/xlsx/formula/functions/math-sum.d.ts.map +1 -1
  70. package/dist/xlsx/formula/table-refs.d.ts +2 -0
  71. package/dist/xlsx/formula/table-refs.d.ts.map +1 -1
  72. package/dist/xlsx/index.cjs +445 -323
  73. package/dist/xlsx/index.mjs +445 -323
  74. package/dist/xlsx/load/index.cjs +7621 -7585
  75. package/dist/xlsx/load/index.mjs +7621 -7585
  76. package/dist/xlsx/model.d.ts +4 -0
  77. package/dist/xlsx/model.d.ts.map +1 -1
  78. package/dist/xlsx/read/load.d.ts.map +1 -1
  79. package/dist/xlsx/ui/index.cjs +443 -323
  80. package/dist/xlsx/ui/index.mjs +443 -323
  81. package/dist/xlsx/ui/locales/de/shell.d.ts.map +1 -1
  82. package/dist/xlsx/ui/locales/en/shell.d.ts.map +1 -1
  83. package/dist/xlsx/ui/locales/es/shell.d.ts.map +1 -1
  84. package/dist/xlsx/ui/locales/fr/shell.d.ts.map +1 -1
  85. package/dist/xlsx/ui/locales/zh-CN/shell.d.ts.map +1 -1
  86. package/package.json +1 -1
@@ -7749,6 +7749,33 @@ 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 isFilteredRow(workbook, sheet, row2) {
7773
+ const info = sheet.rowInfo.get(row2);
7774
+ if (info?.filteredOut !== void 0) return info.filteredOut;
7775
+ const filter2 = sheet.autoFilter;
7776
+ return !!info?.hidden && !!filter2 && row2 > filter2.range.start.row && row2 <= filter2.range.end.row && !rowMatchesFilter(workbook, sheet, row2, filter2);
7777
+ }
7778
+
7752
7779
  // xlsx/formula/functions/math-sum.ts
7753
7780
  var C18 = "Math & Trig";
7754
7781
  var numbersOf = (values2) => values2.filter((v) => typeof v === "number");
@@ -7786,7 +7813,7 @@ function pairwise(ctx, args, fn) {
7786
7813
  return total2;
7787
7814
  }
7788
7815
  var SUBTOTAL_RE = /\b(?:_xlfn\.)?(?:SUBTOTAL|AGGREGATE)\s*\(/i;
7789
- function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7816
+ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true, skipFiltered = false) {
7790
7817
  const out = [];
7791
7818
  const host = ctx.frame.host;
7792
7819
  for (const arg of args) {
@@ -7799,6 +7826,7 @@ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7799
7826
  for (const area of arg.areas) {
7800
7827
  const sheet = ctx.workbook.sheets[area.sheet];
7801
7828
  host.forEachStored(area.sheet, area.range, (value2, row2, col) => {
7829
+ if (skipFiltered && sheet && isFilteredRow(ctx.workbook, sheet, row2)) return;
7802
7830
  if (skipHidden && sheet?.rowInfo.get(row2)?.hidden) return;
7803
7831
  if (skipNested && SUBTOTAL_RE.test(host.cellFormula(area.sheet, row2, col) ?? "")) return;
7804
7832
  if (skipErrors && isError(value2)) return;
@@ -7964,7 +7992,7 @@ var SUM_FUNCTIONS = [
7964
7992
  const code = int(args[0]);
7965
7993
  const base = code > 100 ? code - 100 : code;
7966
7994
  if (base < 1 || base > 11) fail(ERR.VALUE);
7967
- return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false));
7995
+ return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false, true, true));
7968
7996
  },
7969
7997
  ["value", "any"]
7970
7998
  ),
@@ -13462,6 +13490,31 @@ function renameTableInFormula(formula, oldName, newName) {
13462
13490
  }
13463
13491
  return changed ? joinTokens(tokens) : formula;
13464
13492
  }
13493
+ function renameTableColumnInFormula(formula, tableName, oldName, newName, insideTable = false) {
13494
+ const tokens = safeTokens2(formula);
13495
+ if (!tokens) return formula;
13496
+ const escaped = newName.replace(/['#@[\]]/g, "'$&");
13497
+ let changed = false;
13498
+ for (const [index2, token] of tokens.entries()) {
13499
+ if (token.kind !== "structured" || token.prefix) continue;
13500
+ if (token.value === "" && tokens[index2 - 1]?.prefix) continue;
13501
+ if (token.value === "" ? !insideTable : String(token.value).toLowerCase() !== tableName.toLowerCase())
13502
+ continue;
13503
+ const next = token.text.replace(
13504
+ /\[(@?)((?:[^\[\]']|'[\s\S])*)\]/g,
13505
+ (original, at, name) => {
13506
+ if (name.startsWith("#") || name.replace(/'(.)/g, "$1").toLowerCase() !== oldName.toLowerCase())
13507
+ return original;
13508
+ return `[${at}${escaped}]`;
13509
+ }
13510
+ );
13511
+ if (next !== token.text) {
13512
+ token.text = next;
13513
+ changed = true;
13514
+ }
13515
+ }
13516
+ return changed ? joinTokens(tokens) : formula;
13517
+ }
13465
13518
 
13466
13519
  // xlsx/formula/structured-to-a1.ts
13467
13520
  var abs = (row2, col, rowAbs = true) => `$${columnLabel(col)}${rowAbs ? "$" : ""}${row2 + 1}`;
@@ -14298,16 +14351,6 @@ function forEachPosition(sheet, range2, visit2) {
14298
14351
  for (let row2 = r.start.row; row2 <= r.end.row; row2++)
14299
14352
  for (let col = r.start.col; col <= r.end.col; col++) visit2(row2, col);
14300
14353
  }
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
14354
  function rawText(value2) {
14312
14355
  if (value2 === null) return "";
14313
14356
  if (isCellError(value2)) return value2.error;
@@ -14324,19 +14367,266 @@ function pruneCell(sheet, row2, col) {
14324
14367
  }
14325
14368
  }
14326
14369
 
14370
+ // xlsx/edit/shift-preserved.ts
14371
+ var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
14372
+ function descendants2(root, ns, local) {
14373
+ return Array.from(root.getElementsByTagNameNS(ns, local));
14374
+ }
14375
+ function editEntries(sheet, key, edit, quick) {
14376
+ const list = sheet.preserved.get(key);
14377
+ if (!list) return;
14378
+ const next = [];
14379
+ for (const xml of list) {
14380
+ if (!quick(xml)) {
14381
+ next.push(xml);
14382
+ continue;
14383
+ }
14384
+ let doc;
14385
+ try {
14386
+ doc = parseXml(xml);
14387
+ } catch {
14388
+ next.push(xml);
14389
+ continue;
14390
+ }
14391
+ const outcome = edit(doc.documentElement);
14392
+ if (outcome === "same") next.push(xml);
14393
+ else if (outcome === "changed") next.push(buildXml(doc));
14394
+ }
14395
+ if (next.length) sheet.preserved.set(key, next);
14396
+ else sheet.preserved.delete(key);
14397
+ }
14398
+ function shiftBreaks(root, shift2) {
14399
+ let changed = false;
14400
+ for (const brk of elements(root).filter((e) => e.localName === "brk")) {
14401
+ const id = Number(brk.getAttribute("id") ?? "0");
14402
+ const moved = shiftIndex(id, shift2);
14403
+ if (moved === id) continue;
14404
+ changed = true;
14405
+ if (moved === void 0 || moved === 0) root.removeChild(brk);
14406
+ else brk.setAttribute("id", String(moved));
14407
+ }
14408
+ if (!changed) return "same";
14409
+ const left2 = elements(root).filter((e) => e.localName === "brk");
14410
+ if (!left2.length) return "drop";
14411
+ if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
14412
+ if (root.hasAttribute("manualBreakCount")) {
14413
+ const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
14414
+ root.setAttribute("manualBreakCount", String(manual));
14415
+ }
14416
+ return "changed";
14417
+ }
14418
+ function removeUpwards(node, root) {
14419
+ let current = node;
14420
+ while (current && current !== root) {
14421
+ const parent = current.parentNode;
14422
+ parent?.removeChild(current);
14423
+ if (!parent) break;
14424
+ const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
14425
+ if (!emptied) break;
14426
+ current = parent;
14427
+ }
14428
+ }
14429
+ function shiftSqrefs(root, moveRange) {
14430
+ let changed = false;
14431
+ for (const sqref of descendants2(root, XM3, "sqref")) {
14432
+ const old = sqref.textContent ?? "";
14433
+ const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
14434
+ const text2 = ranges.map(formatRange).join(" ");
14435
+ if (text2 === old.trim()) continue;
14436
+ changed = true;
14437
+ const owner = sqref.parentNode;
14438
+ if (ranges.length) sqref.textContent = text2;
14439
+ else if (owner) removeUpwards(owner, root);
14440
+ }
14441
+ if (!changed) return "same";
14442
+ for (const list of elements(root).flatMap((ext) => elements(ext)))
14443
+ if (list.localName === "dataValidations" && list.hasAttribute("count"))
14444
+ list.setAttribute("count", String(elements(list).length));
14445
+ return elements(root).length > 0 ? "changed" : "drop";
14446
+ }
14447
+ function shiftPreservedXml(sheet, shift2, moveRange, banded) {
14448
+ if (!banded)
14449
+ editEntries(
14450
+ sheet,
14451
+ shift2.axis === "row" ? "rowBreaks" : "colBreaks",
14452
+ (root) => shiftBreaks(root, shift2),
14453
+ (xml) => xml.includes("brk")
14454
+ );
14455
+ editEntries(
14456
+ sheet,
14457
+ "extLst",
14458
+ (root) => shiftSqrefs(root, moveRange),
14459
+ (xml) => xml.includes("sqref")
14460
+ );
14461
+ }
14462
+ function rewritePreservedFormulas(sheet, rewrite) {
14463
+ editEntries(
14464
+ sheet,
14465
+ "extLst",
14466
+ (root) => {
14467
+ let changed = false;
14468
+ for (const f6 of descendants2(root, XM3, "f")) {
14469
+ const text2 = f6.textContent ?? "";
14470
+ let next = text2;
14471
+ try {
14472
+ next = rewrite(text2, sheet.name);
14473
+ } catch {
14474
+ next = text2;
14475
+ }
14476
+ if (next === text2) continue;
14477
+ f6.textContent = next;
14478
+ changed = true;
14479
+ }
14480
+ return changed ? "changed" : "same";
14481
+ },
14482
+ (xml) => xml.includes(":f>")
14483
+ );
14484
+ }
14485
+
14486
+ // xlsx/edit/conditional-formulas.ts
14487
+ function rewriteConditionalRule(rule, rewrite) {
14488
+ const safe2 = (formula) => {
14489
+ try {
14490
+ return rewrite(formula);
14491
+ } catch {
14492
+ return formula;
14493
+ }
14494
+ };
14495
+ if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
14496
+ else if (rule.type === "expression") rule.formula = safe2(rule.formula);
14497
+ if (rule.type === "colorScale" || rule.type === "iconSet") {
14498
+ for (const threshold of rule.thresholds)
14499
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14500
+ }
14501
+ if (rule.type === "dataBar") {
14502
+ for (const threshold of [rule.min, rule.max])
14503
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14504
+ }
14505
+ if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
14506
+ }
14507
+
14508
+ // xlsx/edit/shift-formulas.ts
14509
+ function safe(rewrite, formula, formulaSheet, at) {
14510
+ try {
14511
+ return rewrite(formula, formulaSheet, at);
14512
+ } catch {
14513
+ return formula;
14514
+ }
14515
+ }
14516
+ function rewriteFormulas(workbook, rewrite, formulaCells) {
14517
+ const bySheet = formulaCells && /* @__PURE__ */ new Map();
14518
+ if (bySheet)
14519
+ for (const cell of formulaCells ?? []) {
14520
+ const positions2 = bySheet.get(cell.sheet);
14521
+ if (positions2) positions2.push(cell);
14522
+ else bySheet.set(cell.sheet, [cell]);
14523
+ }
14524
+ workbook.sheets.forEach(
14525
+ (sheet, index2) => rewriteSheetFormulas(sheet, rewrite, bySheet ? bySheet.get(index2) ?? [] : void 0)
14526
+ );
14527
+ for (const definedName of workbook.definedNames) {
14528
+ const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
14529
+ definedName.formula = safe(rewrite, definedName.formula, local?.name ?? "");
14530
+ }
14531
+ }
14532
+ function rewriteSheetFormulas(sheet, rewrite, formulaCells) {
14533
+ rewritePreservedFormulas(sheet, rewrite);
14534
+ {
14535
+ const name = sheet.name;
14536
+ for (const table2 of sheet.tables)
14537
+ for (const [index2, column] of table2.columns.entries())
14538
+ if (column.calculatedColumnFormula !== void 0)
14539
+ column.calculatedColumnFormula = safe(rewrite, column.calculatedColumnFormula, name, {
14540
+ row: table2.range.start.row + (table2.headerRow ? 1 : 0),
14541
+ col: table2.range.start.col + index2
14542
+ });
14543
+ if (formulaCells) {
14544
+ for (const at of formulaCells) {
14545
+ const cell = getCell(sheet, at.row, at.col);
14546
+ if (cell?.formula !== void 0) cell.formula = safe(rewrite, cell.formula, name, at);
14547
+ }
14548
+ } else {
14549
+ sheet.rows.forEach(
14550
+ (cells, row2) => cells.forEach((cell, col) => {
14551
+ if (cell.formula !== void 0)
14552
+ cell.formula = safe(rewrite, cell.formula, name, { row: row2, col });
14553
+ })
14554
+ );
14555
+ }
14556
+ for (const cf of sheet.conditionalFormats)
14557
+ for (const rule of cf.rules)
14558
+ rewriteConditionalRule(rule, (f6) => rewrite(f6, name, cf.ranges[0]?.start));
14559
+ for (const dv of sheet.dataValidations) {
14560
+ if (dv.formula1 !== void 0)
14561
+ dv.formula1 = safe(rewrite, dv.formula1, name, dv.ranges[0]?.start);
14562
+ if (dv.formula2 !== void 0)
14563
+ dv.formula2 = safe(rewrite, dv.formula2, name, dv.ranges[0]?.start);
14564
+ }
14565
+ for (const link of sheet.hyperlinks)
14566
+ if (link.location && /![A-Za-z$]/.test(link.location))
14567
+ link.location = safe(rewrite, link.location, name);
14568
+ for (const drawing of sheet.drawings) {
14569
+ if (drawing.kind !== "chart") continue;
14570
+ for (const series of drawing.series) {
14571
+ if (series.nameRef) series.nameRef = safe(rewrite, series.nameRef, name);
14572
+ if (series.categoriesRef) series.categoriesRef = safe(rewrite, series.categoriesRef, name);
14573
+ if (series.valuesRef) series.valuesRef = safe(rewrite, series.valuesRef, name);
14574
+ }
14575
+ }
14576
+ }
14577
+ }
14578
+
14579
+ // xlsx/edit/table-header-names.ts
14580
+ function uniqueHeaders(texts) {
14581
+ const used = /* @__PURE__ */ new Set();
14582
+ return texts.map((text2, i2) => {
14583
+ let base = text2.trim() || `Column${i2 + 1}`;
14584
+ if (!used.has(base.toLowerCase())) {
14585
+ used.add(base.toLowerCase());
14586
+ return base;
14587
+ }
14588
+ for (let n = 2; ; n++) {
14589
+ const candidate = `${base}${n}`;
14590
+ if (!used.has(candidate.toLowerCase())) {
14591
+ used.add(candidate.toLowerCase());
14592
+ base = candidate;
14593
+ return base;
14594
+ }
14595
+ }
14596
+ });
14597
+ }
14598
+
14327
14599
  // xlsx/edit/cell-values.ts
14328
14600
  function tableHeaderAt(sheet, row2, col) {
14329
14601
  return sheet.tables.find(
14330
14602
  (t) => t.headerRow && t.range.start.row === row2 && col >= t.range.start.col && col <= t.range.end.col
14331
14603
  );
14332
14604
  }
14333
- function syncTableHeader(ctx, sheet, row2, col) {
14605
+ function syncTableHeader(ctx, sheet, row2, col, formulaCells) {
14334
14606
  const table2 = tableHeaderAt(sheet, row2, col);
14335
14607
  if (!table2) return;
14336
14608
  const column = table2.columns[col - table2.range.start.col];
14337
14609
  if (!column) return;
14338
14610
  const text2 = displayText(ctx.workbook, getCell(sheet, row2, col)).trim();
14339
- if (text2) column.name = text2;
14611
+ if (!text2 || column.name === text2) return;
14612
+ const oldName = column.name;
14613
+ const others = table2.columns.filter((entry) => entry !== column).map((entry) => entry.name);
14614
+ const newName = uniqueHeaders([...others, text2]).at(-1);
14615
+ column.name = newName;
14616
+ if (newName !== text2) writeValue(sheet, row2, col, newName);
14617
+ const index2 = ctx.workbook.sheets.indexOf(sheet);
14618
+ const cells = formulaCells && (formulaCells.some((cell) => cell.sheet === index2 && cell.row === row2 && cell.col === col) ? formulaCells : [...formulaCells, { sheet: index2, row: row2, col }]);
14619
+ rewriteFormulas(
14620
+ ctx.workbook,
14621
+ (formula, formulaSheet, at) => renameTableColumnInFormula(
14622
+ formula,
14623
+ table2.name,
14624
+ oldName,
14625
+ newName,
14626
+ formulaSheet === sheet.name && !!at && rangeContains(table2.range, at)
14627
+ ),
14628
+ cells
14629
+ );
14340
14630
  }
14341
14631
  function writeScopes(sheet, index2, range2, parts = []) {
14342
14632
  const r = normalizeRange(range2);
@@ -14346,9 +14636,9 @@ function writeScopes(sheet, index2, range2, parts = []) {
14346
14636
  cellRange(t.range.start.row, t.range.start.col, t.range.start.row, t.range.end.col)
14347
14637
  )
14348
14638
  );
14349
- const all2 = touchesHeader && !parts.includes("tables") ? [...parts, "tables"] : parts;
14639
+ if (touchesHeader) return [{ kind: "refs" }, { kind: "cells", sheet: index2, ranges: [r] }];
14350
14640
  const scopes = [{ kind: "cells", sheet: index2, ranges: [r] }];
14351
- if (all2.length) scopes.push({ kind: "parts", sheet: index2, parts: all2 });
14641
+ if (parts.length) scopes.push({ kind: "parts", sheet: index2, parts });
14352
14642
  return scopes;
14353
14643
  }
14354
14644
  function writeInput(ctx, sheet, row2, col, text2) {
@@ -14399,9 +14689,9 @@ function setCellInput(ctx, s, row2, col, text2) {
14399
14689
  `Typing in ${formatAddress({ row: row2, col })}`,
14400
14690
  "cells",
14401
14691
  writeScopes(sheet, s, range2),
14402
- () => {
14692
+ (formulaCells) => {
14403
14693
  writeInput(ctx, sheet, row2, col, text2);
14404
- syncTableHeader(ctx, sheet, row2, col);
14694
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
14405
14695
  },
14406
14696
  { sheet: s, ranges: [range2] }
14407
14697
  );
@@ -14413,9 +14703,9 @@ function setCellValue(ctx, s, row2, col, value2) {
14413
14703
  `Edit ${formatAddress({ row: row2, col })}`,
14414
14704
  "cells",
14415
14705
  writeScopes(sheet, s, range2),
14416
- () => {
14706
+ (formulaCells) => {
14417
14707
  writeValue(sheet, row2, col, value2);
14418
- syncTableHeader(ctx, sheet, row2, col);
14708
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
14419
14709
  },
14420
14710
  { sheet: s, ranges: [range2] }
14421
14711
  );
@@ -14842,7 +15132,7 @@ function fillRange(ctx, s, source, target2, mode = "auto") {
14842
15132
  ctx.run(
14843
15133
  "Fill",
14844
15134
  "cells",
14845
- [{ kind: "cells", sheet: s, ranges: [all2] }],
15135
+ writeScopes(sheet, s, all2),
14846
15136
  () => {
14847
15137
  const laneCount = vertical2 ? src.end.col - src.start.col + 1 : src.end.row - src.start.row + 1;
14848
15138
  const length = vertical2 ? src.end.row - src.start.row + 1 : src.end.col - src.start.col + 1;
@@ -14865,6 +15155,7 @@ function fillRange(ctx, s, source, target2, mode = "auto") {
14865
15155
  const step = series?.(k);
14866
15156
  const cell = !step || step.kind === "copy" ? copyCell(origin, row2 - srcRow, col - srcCol) : { value: step.value, ...origin.styleId ? { styleId: origin.styleId } : {} };
14867
15157
  putCell(sheet, row2, col, cell);
15158
+ syncTableHeader(ctx, sheet, row2, col);
14868
15159
  }
14869
15160
  }
14870
15161
  },
@@ -14903,28 +15194,6 @@ function removeValidationArea(rules, area) {
14903
15194
  });
14904
15195
  }
14905
15196
 
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
15197
  // xlsx/edit/conditional-formats.ts
14929
15198
  function formatAt(sheet, index2) {
14930
15199
  const format = sheet.conditionalFormats[index2];
@@ -15334,168 +15603,6 @@ function setBorders(ctx, s, range2, preset, edge = { style: "thin" }) {
15334
15603
  );
15335
15604
  }
15336
15605
 
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
15606
  // xlsx/edit/shift-sheet.ts
15500
15607
  function shiftSheetContent(sheet, shift2, band) {
15501
15608
  const moveRange = (range2) => band ? shiftRangeInBand(range2, shift2, band.lo, band.hi) : shiftRange(range2, shift2);
@@ -16485,14 +16592,13 @@ function pasteAt(ctx, s, at, payload, request) {
16485
16592
  if (cut && operation !== "none")
16486
16593
  throw new RangeError("Paste operations are not available for cut cells.");
16487
16594
  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
- ];
16595
+ const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : writeScopes(sheet, s, dest, [
16596
+ "merges",
16597
+ "comments",
16598
+ "dataValidations",
16599
+ "hyperlinks",
16600
+ "conditionalFormats"
16601
+ ]);
16496
16602
  const move = cut && {
16497
16603
  fromSheet: sheetAt(workbook, cut.sheet).name,
16498
16604
  range: cut.range,
@@ -16565,6 +16671,8 @@ function pasteAt(ctx, s, at, payload, request) {
16565
16671
  const origin = cells.source?.range.start;
16566
16672
  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
16673
  writeClip(workbook, sheet, row2, col, clip, mode, formula, styleOf, operation);
16674
+ if (mode !== "formats" && mode !== "comments" && mode !== "validation")
16675
+ syncTableHeader(ctx, sheet, row2, col);
16568
16676
  }
16569
16677
  if (mode === "all" || mode === "mergeFormats" || mode === "noBorders" || mode === "formats") {
16570
16678
  sheet.merges = sheet.merges.filter((m) => !rangesIntersect(m, dest));
@@ -16608,14 +16716,13 @@ function pasteSelection(ctx, sheet, selection, payload, request) {
16608
16716
  return ctx.run(
16609
16717
  "Paste",
16610
16718
  "cells",
16611
- [
16612
- { kind: "cells", sheet, ranges: [dest] },
16613
- {
16614
- kind: "parts",
16615
- sheet,
16616
- parts: ["merges", "comments", "dataValidations", "hyperlinks", "conditionalFormats"]
16617
- }
16618
- ],
16719
+ writeScopes(sheetAt(ctx.workbook, sheet), sheet, dest, [
16720
+ "merges",
16721
+ "comments",
16722
+ "dataValidations",
16723
+ "hyperlinks",
16724
+ "conditionalFormats"
16725
+ ]),
16619
16726
  () => {
16620
16727
  for (let row2 = dest.start.row; row2 <= dest.end.row; row2 += height)
16621
16728
  for (let col = dest.start.col; col <= dest.end.col; col += width)
@@ -16767,6 +16874,15 @@ function setHidden(ctx, s, axis, indices, hidden) {
16767
16874
  }
16768
16875
  for (const row2 of indices) {
16769
16876
  const info = { ...sheet.rowInfo.get(row2) };
16877
+ if (info.filteredOut) {
16878
+ if (hidden) info.manuallyHidden = true;
16879
+ else delete info.manuallyHidden;
16880
+ sheet.rowInfo.set(row2, info);
16881
+ continue;
16882
+ }
16883
+ const filter2 = sheet.autoFilter;
16884
+ if (filter2?.columns?.length && row2 > filter2.range.start.row && row2 <= filter2.range.end.row)
16885
+ info.filteredOut = false;
16770
16886
  if (hidden) info.hidden = true;
16771
16887
  else {
16772
16888
  delete info.hidden;
@@ -16921,14 +17037,21 @@ function currentRegion(sheet, at) {
16921
17037
  function applyFilter(ctx, sheet, filter2) {
16922
17038
  const { range: range2 } = filter2;
16923
17039
  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
- });
17040
+ const visible = rowMatchesFilter(ctx.workbook, sheet, row2, filter2);
16929
17041
  const info = { ...sheet.rowInfo.get(row2) };
16930
- if (visible) delete info.hidden;
16931
- else info.hidden = true;
17042
+ const manual = info.manuallyHidden || info.hidden && !info.filteredOut;
17043
+ if (visible) {
17044
+ delete info.filteredOut;
17045
+ delete info.manuallyHidden;
17046
+ if (manual) {
17047
+ info.hidden = true;
17048
+ if (filter2.columns?.length) info.filteredOut = false;
17049
+ } else delete info.hidden;
17050
+ } else {
17051
+ info.hidden = true;
17052
+ info.filteredOut = true;
17053
+ if (manual) info.manuallyHidden = true;
17054
+ }
16932
17055
  if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
16933
17056
  else sheet.rowInfo.delete(row2);
16934
17057
  }
@@ -17088,16 +17211,16 @@ var isSpilledAt = (workbook, at) => {
17088
17211
  return !!sheet && isSpilledCell(getCell(sheet, at.row, at.col));
17089
17212
  };
17090
17213
  var replaceQuery = (query) => query.lookIn === "comments" ? query : { ...query, lookIn: "formulas" };
17091
- function replaceScopes(query, sheet, matches2) {
17214
+ function replaceScopes(ctx, query, sheet, matches2) {
17092
17215
  if (query.lookIn === "comments") return [{ kind: "parts", sheet, parts: ["comments"] }];
17093
17216
  const ranges = matches2.map((m) => ({
17094
17217
  start: { row: m.row, col: m.col },
17095
17218
  end: { row: m.row, col: m.col }
17096
17219
  }));
17097
- return [
17098
- { kind: "cells", sheet, ranges },
17099
- { kind: "parts", sheet, parts: ["tables"] }
17100
- ];
17220
+ const header = ranges.some(
17221
+ (range2) => writeScopes(sheetAt(ctx.workbook, sheet), sheet, range2).some((scope) => scope.kind === "refs")
17222
+ );
17223
+ return [...header ? [{ kind: "refs" }] : [], { kind: "cells", sheet, ranges }];
17101
17224
  }
17102
17225
  function applyReplace(ctx, query, replacement, matches2) {
17103
17226
  let changed = 0;
@@ -17127,14 +17250,24 @@ function replaceAll(ctx, query, replacement) {
17127
17250
  const sheets = [...new Set(matches2.map((m) => m.sheet))];
17128
17251
  const scopes = sheets.flatMap(
17129
17252
  (sheet) => replaceScopes(
17253
+ ctx,
17130
17254
  q,
17131
17255
  sheet,
17132
17256
  matches2.filter((m) => m.sheet === sheet)
17133
17257
  )
17134
17258
  );
17135
- return ctx.run("Replace", "cells", scopes, () => applyReplace(ctx, q, replacement, matches2), {
17136
- ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
17137
- });
17259
+ const uniqueScopes = scopes.filter(
17260
+ (scope, index2) => scope.kind !== "refs" || scopes.findIndex((entry) => entry.kind === "refs") === index2
17261
+ );
17262
+ return ctx.run(
17263
+ "Replace",
17264
+ "cells",
17265
+ uniqueScopes,
17266
+ () => applyReplace(ctx, q, replacement, matches2),
17267
+ {
17268
+ ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
17269
+ }
17270
+ );
17138
17271
  }
17139
17272
  function replaceOne(ctx, query, replacement, at) {
17140
17273
  const q = replaceQuery(query);
@@ -17147,7 +17280,7 @@ function replaceOne(ctx, query, replacement, at) {
17147
17280
  ctx.run(
17148
17281
  "Replace",
17149
17282
  "cells",
17150
- replaceScopes(q, at.sheet, [match2]),
17283
+ replaceScopes(ctx, q, at.sheet, [match2]),
17151
17284
  () => applyReplace(ctx, q, replacement, [match2]),
17152
17285
  { sheet: at.sheet }
17153
17286
  );
@@ -17927,90 +18060,6 @@ function applyTotalsRow(sheet, table2) {
17927
18060
  });
17928
18061
  }
17929
18062
 
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
18063
  // xlsx/edit/table-edits.ts
18015
18064
  function tableIndex(sheet, ref) {
18016
18065
  const index2 = typeof ref === "number" ? ref : sheet.tables.findIndex((t) => t.name.toLowerCase() === ref.toLowerCase());
@@ -21227,8 +21276,8 @@ function setSheetState(ctx, index2, state) {
21227
21276
  const { workbook } = ctx;
21228
21277
  const sheet = sheetAt(workbook, index2);
21229
21278
  if (sheet.state === state) return;
21279
+ assertUnlocked(workbook);
21230
21280
  if (state !== "visible") {
21231
- assertUnlocked(workbook);
21232
21281
  if (sheet.state === "visible" && visibleCount(workbook) <= 1)
21233
21282
  throw new Error("A workbook must contain at least one visible sheet.");
21234
21283
  }
@@ -21258,6 +21307,72 @@ function setTabColor(ctx, index2, color) {
21258
21307
  );
21259
21308
  }
21260
21309
 
21310
+ // xlsx/edit/tables.ts
21311
+ function nextTableName(workbook) {
21312
+ const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
21313
+ const names = new Set(workbook.definedNames.map((n) => n.name.toLowerCase()));
21314
+ for (let n = 1; ; n++) if (!taken.has(`table${n}`) && !names.has(`table${n}`)) return `Table${n}`;
21315
+ }
21316
+ function createTable(ctx, s, range2, hasHeader, styleName = "TableStyleMedium2") {
21317
+ const { workbook } = ctx;
21318
+ const sheet = sheetAt(workbook, s);
21319
+ let r = normalizeRange(range2);
21320
+ if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
21321
+ if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
21322
+ throw new Error("A table cannot overlap another table.");
21323
+ if (sheet.merges.some((m) => rangesIntersect(m, r)))
21324
+ throw new Error("A table cannot contain merged cells.");
21325
+ return ctx.run(
21326
+ "Create table",
21327
+ "structure",
21328
+ [hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
21329
+ () => {
21330
+ if (!hasHeader) {
21331
+ const shift2 = { axis: "row", at: r.start.row, count: 1 };
21332
+ const band = { lo: r.start.col, hi: r.end.col };
21333
+ rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
21334
+ shiftSheetContent(sheet, shift2, band);
21335
+ r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
21336
+ }
21337
+ const width = r.end.col - r.start.col + 1;
21338
+ const texts = Array.from(
21339
+ { length: width },
21340
+ (_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
21341
+ );
21342
+ const headers = uniqueHeaders(texts);
21343
+ const columns = headers.map((name2, i2) => {
21344
+ const cell = getCell(sheet, r.start.row, r.start.col + i2);
21345
+ if (cell?.value !== name2) {
21346
+ const styleId = cell?.styleId;
21347
+ writeValue(sheet, r.start.row, r.start.col + i2, name2);
21348
+ const written = getCell(sheet, r.start.row, r.start.col + i2);
21349
+ if (written && styleId) written.styleId = styleId;
21350
+ }
21351
+ return { name: name2 };
21352
+ });
21353
+ const name = nextTableName(workbook);
21354
+ const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
21355
+ const table2 = {
21356
+ id,
21357
+ name,
21358
+ displayName: name,
21359
+ range: r,
21360
+ headerRow: true,
21361
+ totalsRow: false,
21362
+ columns,
21363
+ styleName,
21364
+ showRowStripes: true,
21365
+ showColumnStripes: false,
21366
+ showFirstColumn: false,
21367
+ showLastColumn: false
21368
+ };
21369
+ sheet.tables.push(table2);
21370
+ return table2;
21371
+ },
21372
+ { sheet: s, ranges: [r], structural: !hasHeader }
21373
+ );
21374
+ }
21375
+
21261
21376
  // xlsx/edit/validation-list.ts
21262
21377
  function listSource(workbook, sheet, formula, evaluate, at, depth = 0) {
21263
21378
  const text2 = formula.replace(/^=/, "").trim();
@@ -21545,7 +21660,7 @@ function createEditSession(workbook, options = {}) {
21545
21660
  const befores = scopes.map((scope) => captureScope(workbook, scope));
21546
21661
  let result2;
21547
21662
  try {
21548
- result2 = fn();
21663
+ result2 = fn(befores.find((snapshot) => snapshot.kind === "refs")?.data.formulas);
21549
21664
  } catch (error) {
21550
21665
  for (let i2 = befores.length - 1; i2 >= 0; i2--) {
21551
21666
  const snapshot = befores[i2];
@@ -26991,6 +27106,7 @@ __export(shell_exports, {
26991
27106
  shell: () => shell
26992
27107
  });
26993
27108
  var shell = {
27109
+ "Finish or cancel the current cell edit before saving.": "Beenden oder verwerfen Sie die aktuelle Zellbearbeitung vor dem Speichern.",
26994
27110
  File: "Datei",
26995
27111
  Ribbon: "Men\xFCband",
26996
27112
  "Ribbon tabs": "Men\xFCbandregisterkarten",
@@ -27376,6 +27492,7 @@ __export(shell_exports2, {
27376
27492
  shell: () => shell2
27377
27493
  });
27378
27494
  var shell2 = {
27495
+ "Finish or cancel the current cell edit before saving.": "Finish or cancel the current cell edit before saving.",
27379
27496
  File: "File",
27380
27497
  Ribbon: "Ribbon",
27381
27498
  "Ribbon tabs": "Ribbon tabs",
@@ -27761,6 +27878,7 @@ __export(shell_exports3, {
27761
27878
  shell: () => shell3
27762
27879
  });
27763
27880
  var shell3 = {
27881
+ "Finish or cancel the current cell edit before saving.": "Finalice o cancele la edici\xF3n de la celda actual antes de guardar.",
27764
27882
  File: "Archivo",
27765
27883
  Ribbon: "Cinta de opciones",
27766
27884
  "Ribbon tabs": "Pesta\xF1as de la cinta",
@@ -28146,6 +28264,7 @@ __export(shell_exports4, {
28146
28264
  shell: () => shell4
28147
28265
  });
28148
28266
  var shell4 = {
28267
+ "Finish or cancel the current cell edit before saving.": "Terminez ou annulez la modification de la cellule avant de sauvegarder.",
28149
28268
  File: "Fichier",
28150
28269
  Ribbon: "Ruban",
28151
28270
  "Ribbon tabs": "Onglets du ruban",
@@ -28531,6 +28650,7 @@ __export(shell_exports5, {
28531
28650
  shell: () => shell5
28532
28651
  });
28533
28652
  var shell5 = {
28653
+ "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
28654
  File: "\u6587\u4EF6",
28535
28655
  Ribbon: "\u529F\u80FD\u533A",
28536
28656
  "Ribbon tabs": "\u529F\u80FD\u533A\u9009\u9879\u5361",