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
@@ -7747,6 +7747,33 @@ function liftCriteria(ctx, pairs, fn) {
7747
7747
  });
7748
7748
  }
7749
7749
 
7750
+ // xlsx/display-text.ts
7751
+ function displayText(workbook, cell) {
7752
+ if (!cell || cell.value === null) return "";
7753
+ const value2 = cell.value;
7754
+ if (isCellError(value2)) return value2.error;
7755
+ if (typeof value2 === "boolean") return value2 ? "TRUE" : "FALSE";
7756
+ if (cell.richText && typeof value2 === "string") return value2;
7757
+ return formatValue(value2, styleAt(workbook, cell.styleId).numFmt, {
7758
+ date1904: workbook.date1904
7759
+ }).text;
7760
+ }
7761
+
7762
+ // xlsx/filter-rows.ts
7763
+ function rowMatchesFilter(workbook, sheet, row2, filter2) {
7764
+ return (filter2.columns ?? []).every((column) => {
7765
+ if (!column.values && !column.blank) return true;
7766
+ const text2 = displayText(workbook, getCell(sheet, row2, filter2.range.start.col + column.offset));
7767
+ return text2 === "" ? !!column.blank : (column.values ?? []).includes(text2);
7768
+ });
7769
+ }
7770
+ function isFilteredRow(workbook, sheet, row2) {
7771
+ const info = sheet.rowInfo.get(row2);
7772
+ if (info?.filteredOut !== void 0) return info.filteredOut;
7773
+ const filter2 = sheet.autoFilter;
7774
+ return !!info?.hidden && !!filter2 && row2 > filter2.range.start.row && row2 <= filter2.range.end.row && !rowMatchesFilter(workbook, sheet, row2, filter2);
7775
+ }
7776
+
7750
7777
  // xlsx/formula/functions/math-sum.ts
7751
7778
  var C18 = "Math & Trig";
7752
7779
  var numbersOf = (values2) => values2.filter((v) => typeof v === "number");
@@ -7784,7 +7811,7 @@ function pairwise(ctx, args, fn) {
7784
7811
  return total2;
7785
7812
  }
7786
7813
  var SUBTOTAL_RE = /\b(?:_xlfn\.)?(?:SUBTOTAL|AGGREGATE)\s*\(/i;
7787
- function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7814
+ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true, skipFiltered = false) {
7788
7815
  const out = [];
7789
7816
  const host = ctx.frame.host;
7790
7817
  for (const arg of args) {
@@ -7797,6 +7824,7 @@ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7797
7824
  for (const area of arg.areas) {
7798
7825
  const sheet = ctx.workbook.sheets[area.sheet];
7799
7826
  host.forEachStored(area.sheet, area.range, (value2, row2, col) => {
7827
+ if (skipFiltered && sheet && isFilteredRow(ctx.workbook, sheet, row2)) return;
7800
7828
  if (skipHidden && sheet?.rowInfo.get(row2)?.hidden) return;
7801
7829
  if (skipNested && SUBTOTAL_RE.test(host.cellFormula(area.sheet, row2, col) ?? "")) return;
7802
7830
  if (skipErrors && isError(value2)) return;
@@ -7962,7 +7990,7 @@ var SUM_FUNCTIONS = [
7962
7990
  const code = int(args[0]);
7963
7991
  const base = code > 100 ? code - 100 : code;
7964
7992
  if (base < 1 || base > 11) fail(ERR.VALUE);
7965
- return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false));
7993
+ return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false, true, true));
7966
7994
  },
7967
7995
  ["value", "any"]
7968
7996
  ),
@@ -13460,6 +13488,31 @@ function renameTableInFormula(formula, oldName, newName) {
13460
13488
  }
13461
13489
  return changed ? joinTokens(tokens) : formula;
13462
13490
  }
13491
+ function renameTableColumnInFormula(formula, tableName, oldName, newName, insideTable = false) {
13492
+ const tokens = safeTokens2(formula);
13493
+ if (!tokens) return formula;
13494
+ const escaped = newName.replace(/['#@[\]]/g, "'$&");
13495
+ let changed = false;
13496
+ for (const [index2, token] of tokens.entries()) {
13497
+ if (token.kind !== "structured" || token.prefix) continue;
13498
+ if (token.value === "" && tokens[index2 - 1]?.prefix) continue;
13499
+ if (token.value === "" ? !insideTable : String(token.value).toLowerCase() !== tableName.toLowerCase())
13500
+ continue;
13501
+ const next = token.text.replace(
13502
+ /\[(@?)((?:[^\[\]']|'[\s\S])*)\]/g,
13503
+ (original, at, name) => {
13504
+ if (name.startsWith("#") || name.replace(/'(.)/g, "$1").toLowerCase() !== oldName.toLowerCase())
13505
+ return original;
13506
+ return `[${at}${escaped}]`;
13507
+ }
13508
+ );
13509
+ if (next !== token.text) {
13510
+ token.text = next;
13511
+ changed = true;
13512
+ }
13513
+ }
13514
+ return changed ? joinTokens(tokens) : formula;
13515
+ }
13463
13516
 
13464
13517
  // xlsx/formula/structured-to-a1.ts
13465
13518
  var abs = (row2, col, rowAbs = true) => `$${columnLabel(col)}${rowAbs ? "$" : ""}${row2 + 1}`;
@@ -14296,16 +14349,6 @@ function forEachPosition(sheet, range2, visit2) {
14296
14349
  for (let row2 = r.start.row; row2 <= r.end.row; row2++)
14297
14350
  for (let col = r.start.col; col <= r.end.col; col++) visit2(row2, col);
14298
14351
  }
14299
- function displayText(workbook, cell) {
14300
- if (!cell) return "";
14301
- const value2 = cell.value;
14302
- if (value2 === null) return "";
14303
- if (isCellError(value2)) return value2.error;
14304
- if (typeof value2 === "boolean") return value2 ? "TRUE" : "FALSE";
14305
- if (cell.richText && typeof value2 === "string") return value2;
14306
- const format = styleAt(workbook, cell.styleId).numFmt;
14307
- return formatValue(value2, format, { date1904: workbook.date1904 }).text;
14308
- }
14309
14352
  function rawText(value2) {
14310
14353
  if (value2 === null) return "";
14311
14354
  if (isCellError(value2)) return value2.error;
@@ -14322,19 +14365,266 @@ function pruneCell(sheet, row2, col) {
14322
14365
  }
14323
14366
  }
14324
14367
 
14368
+ // xlsx/edit/shift-preserved.ts
14369
+ var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
14370
+ function descendants2(root, ns, local) {
14371
+ return Array.from(root.getElementsByTagNameNS(ns, local));
14372
+ }
14373
+ function editEntries(sheet, key, edit, quick) {
14374
+ const list = sheet.preserved.get(key);
14375
+ if (!list) return;
14376
+ const next = [];
14377
+ for (const xml of list) {
14378
+ if (!quick(xml)) {
14379
+ next.push(xml);
14380
+ continue;
14381
+ }
14382
+ let doc;
14383
+ try {
14384
+ doc = parseXml(xml);
14385
+ } catch {
14386
+ next.push(xml);
14387
+ continue;
14388
+ }
14389
+ const outcome = edit(doc.documentElement);
14390
+ if (outcome === "same") next.push(xml);
14391
+ else if (outcome === "changed") next.push(buildXml(doc));
14392
+ }
14393
+ if (next.length) sheet.preserved.set(key, next);
14394
+ else sheet.preserved.delete(key);
14395
+ }
14396
+ function shiftBreaks(root, shift2) {
14397
+ let changed = false;
14398
+ for (const brk of elements(root).filter((e) => e.localName === "brk")) {
14399
+ const id = Number(brk.getAttribute("id") ?? "0");
14400
+ const moved = shiftIndex(id, shift2);
14401
+ if (moved === id) continue;
14402
+ changed = true;
14403
+ if (moved === void 0 || moved === 0) root.removeChild(brk);
14404
+ else brk.setAttribute("id", String(moved));
14405
+ }
14406
+ if (!changed) return "same";
14407
+ const left2 = elements(root).filter((e) => e.localName === "brk");
14408
+ if (!left2.length) return "drop";
14409
+ if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
14410
+ if (root.hasAttribute("manualBreakCount")) {
14411
+ const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
14412
+ root.setAttribute("manualBreakCount", String(manual));
14413
+ }
14414
+ return "changed";
14415
+ }
14416
+ function removeUpwards(node, root) {
14417
+ let current = node;
14418
+ while (current && current !== root) {
14419
+ const parent = current.parentNode;
14420
+ parent?.removeChild(current);
14421
+ if (!parent) break;
14422
+ const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
14423
+ if (!emptied) break;
14424
+ current = parent;
14425
+ }
14426
+ }
14427
+ function shiftSqrefs(root, moveRange) {
14428
+ let changed = false;
14429
+ for (const sqref of descendants2(root, XM3, "sqref")) {
14430
+ const old = sqref.textContent ?? "";
14431
+ const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
14432
+ const text2 = ranges.map(formatRange).join(" ");
14433
+ if (text2 === old.trim()) continue;
14434
+ changed = true;
14435
+ const owner = sqref.parentNode;
14436
+ if (ranges.length) sqref.textContent = text2;
14437
+ else if (owner) removeUpwards(owner, root);
14438
+ }
14439
+ if (!changed) return "same";
14440
+ for (const list of elements(root).flatMap((ext) => elements(ext)))
14441
+ if (list.localName === "dataValidations" && list.hasAttribute("count"))
14442
+ list.setAttribute("count", String(elements(list).length));
14443
+ return elements(root).length > 0 ? "changed" : "drop";
14444
+ }
14445
+ function shiftPreservedXml(sheet, shift2, moveRange, banded) {
14446
+ if (!banded)
14447
+ editEntries(
14448
+ sheet,
14449
+ shift2.axis === "row" ? "rowBreaks" : "colBreaks",
14450
+ (root) => shiftBreaks(root, shift2),
14451
+ (xml) => xml.includes("brk")
14452
+ );
14453
+ editEntries(
14454
+ sheet,
14455
+ "extLst",
14456
+ (root) => shiftSqrefs(root, moveRange),
14457
+ (xml) => xml.includes("sqref")
14458
+ );
14459
+ }
14460
+ function rewritePreservedFormulas(sheet, rewrite) {
14461
+ editEntries(
14462
+ sheet,
14463
+ "extLst",
14464
+ (root) => {
14465
+ let changed = false;
14466
+ for (const f6 of descendants2(root, XM3, "f")) {
14467
+ const text2 = f6.textContent ?? "";
14468
+ let next = text2;
14469
+ try {
14470
+ next = rewrite(text2, sheet.name);
14471
+ } catch {
14472
+ next = text2;
14473
+ }
14474
+ if (next === text2) continue;
14475
+ f6.textContent = next;
14476
+ changed = true;
14477
+ }
14478
+ return changed ? "changed" : "same";
14479
+ },
14480
+ (xml) => xml.includes(":f>")
14481
+ );
14482
+ }
14483
+
14484
+ // xlsx/edit/conditional-formulas.ts
14485
+ function rewriteConditionalRule(rule, rewrite) {
14486
+ const safe2 = (formula) => {
14487
+ try {
14488
+ return rewrite(formula);
14489
+ } catch {
14490
+ return formula;
14491
+ }
14492
+ };
14493
+ if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
14494
+ else if (rule.type === "expression") rule.formula = safe2(rule.formula);
14495
+ if (rule.type === "colorScale" || rule.type === "iconSet") {
14496
+ for (const threshold of rule.thresholds)
14497
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14498
+ }
14499
+ if (rule.type === "dataBar") {
14500
+ for (const threshold of [rule.min, rule.max])
14501
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14502
+ }
14503
+ if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
14504
+ }
14505
+
14506
+ // xlsx/edit/shift-formulas.ts
14507
+ function safe(rewrite, formula, formulaSheet, at) {
14508
+ try {
14509
+ return rewrite(formula, formulaSheet, at);
14510
+ } catch {
14511
+ return formula;
14512
+ }
14513
+ }
14514
+ function rewriteFormulas(workbook, rewrite, formulaCells) {
14515
+ const bySheet = formulaCells && /* @__PURE__ */ new Map();
14516
+ if (bySheet)
14517
+ for (const cell of formulaCells ?? []) {
14518
+ const positions2 = bySheet.get(cell.sheet);
14519
+ if (positions2) positions2.push(cell);
14520
+ else bySheet.set(cell.sheet, [cell]);
14521
+ }
14522
+ workbook.sheets.forEach(
14523
+ (sheet, index2) => rewriteSheetFormulas(sheet, rewrite, bySheet ? bySheet.get(index2) ?? [] : void 0)
14524
+ );
14525
+ for (const definedName of workbook.definedNames) {
14526
+ const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
14527
+ definedName.formula = safe(rewrite, definedName.formula, local?.name ?? "");
14528
+ }
14529
+ }
14530
+ function rewriteSheetFormulas(sheet, rewrite, formulaCells) {
14531
+ rewritePreservedFormulas(sheet, rewrite);
14532
+ {
14533
+ const name = sheet.name;
14534
+ for (const table2 of sheet.tables)
14535
+ for (const [index2, column] of table2.columns.entries())
14536
+ if (column.calculatedColumnFormula !== void 0)
14537
+ column.calculatedColumnFormula = safe(rewrite, column.calculatedColumnFormula, name, {
14538
+ row: table2.range.start.row + (table2.headerRow ? 1 : 0),
14539
+ col: table2.range.start.col + index2
14540
+ });
14541
+ if (formulaCells) {
14542
+ for (const at of formulaCells) {
14543
+ const cell = getCell(sheet, at.row, at.col);
14544
+ if (cell?.formula !== void 0) cell.formula = safe(rewrite, cell.formula, name, at);
14545
+ }
14546
+ } else {
14547
+ sheet.rows.forEach(
14548
+ (cells, row2) => cells.forEach((cell, col) => {
14549
+ if (cell.formula !== void 0)
14550
+ cell.formula = safe(rewrite, cell.formula, name, { row: row2, col });
14551
+ })
14552
+ );
14553
+ }
14554
+ for (const cf of sheet.conditionalFormats)
14555
+ for (const rule of cf.rules)
14556
+ rewriteConditionalRule(rule, (f6) => rewrite(f6, name, cf.ranges[0]?.start));
14557
+ for (const dv of sheet.dataValidations) {
14558
+ if (dv.formula1 !== void 0)
14559
+ dv.formula1 = safe(rewrite, dv.formula1, name, dv.ranges[0]?.start);
14560
+ if (dv.formula2 !== void 0)
14561
+ dv.formula2 = safe(rewrite, dv.formula2, name, dv.ranges[0]?.start);
14562
+ }
14563
+ for (const link of sheet.hyperlinks)
14564
+ if (link.location && /![A-Za-z$]/.test(link.location))
14565
+ link.location = safe(rewrite, link.location, name);
14566
+ for (const drawing of sheet.drawings) {
14567
+ if (drawing.kind !== "chart") continue;
14568
+ for (const series of drawing.series) {
14569
+ if (series.nameRef) series.nameRef = safe(rewrite, series.nameRef, name);
14570
+ if (series.categoriesRef) series.categoriesRef = safe(rewrite, series.categoriesRef, name);
14571
+ if (series.valuesRef) series.valuesRef = safe(rewrite, series.valuesRef, name);
14572
+ }
14573
+ }
14574
+ }
14575
+ }
14576
+
14577
+ // xlsx/edit/table-header-names.ts
14578
+ function uniqueHeaders(texts) {
14579
+ const used = /* @__PURE__ */ new Set();
14580
+ return texts.map((text2, i2) => {
14581
+ let base = text2.trim() || `Column${i2 + 1}`;
14582
+ if (!used.has(base.toLowerCase())) {
14583
+ used.add(base.toLowerCase());
14584
+ return base;
14585
+ }
14586
+ for (let n = 2; ; n++) {
14587
+ const candidate = `${base}${n}`;
14588
+ if (!used.has(candidate.toLowerCase())) {
14589
+ used.add(candidate.toLowerCase());
14590
+ base = candidate;
14591
+ return base;
14592
+ }
14593
+ }
14594
+ });
14595
+ }
14596
+
14325
14597
  // xlsx/edit/cell-values.ts
14326
14598
  function tableHeaderAt(sheet, row2, col) {
14327
14599
  return sheet.tables.find(
14328
14600
  (t) => t.headerRow && t.range.start.row === row2 && col >= t.range.start.col && col <= t.range.end.col
14329
14601
  );
14330
14602
  }
14331
- function syncTableHeader(ctx, sheet, row2, col) {
14603
+ function syncTableHeader(ctx, sheet, row2, col, formulaCells) {
14332
14604
  const table2 = tableHeaderAt(sheet, row2, col);
14333
14605
  if (!table2) return;
14334
14606
  const column = table2.columns[col - table2.range.start.col];
14335
14607
  if (!column) return;
14336
14608
  const text2 = displayText(ctx.workbook, getCell(sheet, row2, col)).trim();
14337
- if (text2) column.name = text2;
14609
+ if (!text2 || column.name === text2) return;
14610
+ const oldName = column.name;
14611
+ const others = table2.columns.filter((entry) => entry !== column).map((entry) => entry.name);
14612
+ const newName = uniqueHeaders([...others, text2]).at(-1);
14613
+ column.name = newName;
14614
+ if (newName !== text2) writeValue(sheet, row2, col, newName);
14615
+ const index2 = ctx.workbook.sheets.indexOf(sheet);
14616
+ const cells = formulaCells && (formulaCells.some((cell) => cell.sheet === index2 && cell.row === row2 && cell.col === col) ? formulaCells : [...formulaCells, { sheet: index2, row: row2, col }]);
14617
+ rewriteFormulas(
14618
+ ctx.workbook,
14619
+ (formula, formulaSheet, at) => renameTableColumnInFormula(
14620
+ formula,
14621
+ table2.name,
14622
+ oldName,
14623
+ newName,
14624
+ formulaSheet === sheet.name && !!at && rangeContains(table2.range, at)
14625
+ ),
14626
+ cells
14627
+ );
14338
14628
  }
14339
14629
  function writeScopes(sheet, index2, range2, parts = []) {
14340
14630
  const r = normalizeRange(range2);
@@ -14344,9 +14634,9 @@ function writeScopes(sheet, index2, range2, parts = []) {
14344
14634
  cellRange(t.range.start.row, t.range.start.col, t.range.start.row, t.range.end.col)
14345
14635
  )
14346
14636
  );
14347
- const all2 = touchesHeader && !parts.includes("tables") ? [...parts, "tables"] : parts;
14637
+ if (touchesHeader) return [{ kind: "refs" }, { kind: "cells", sheet: index2, ranges: [r] }];
14348
14638
  const scopes = [{ kind: "cells", sheet: index2, ranges: [r] }];
14349
- if (all2.length) scopes.push({ kind: "parts", sheet: index2, parts: all2 });
14639
+ if (parts.length) scopes.push({ kind: "parts", sheet: index2, parts });
14350
14640
  return scopes;
14351
14641
  }
14352
14642
  function writeInput(ctx, sheet, row2, col, text2) {
@@ -14397,9 +14687,9 @@ function setCellInput(ctx, s, row2, col, text2) {
14397
14687
  `Typing in ${formatAddress({ row: row2, col })}`,
14398
14688
  "cells",
14399
14689
  writeScopes(sheet, s, range2),
14400
- () => {
14690
+ (formulaCells) => {
14401
14691
  writeInput(ctx, sheet, row2, col, text2);
14402
- syncTableHeader(ctx, sheet, row2, col);
14692
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
14403
14693
  },
14404
14694
  { sheet: s, ranges: [range2] }
14405
14695
  );
@@ -14411,9 +14701,9 @@ function setCellValue(ctx, s, row2, col, value2) {
14411
14701
  `Edit ${formatAddress({ row: row2, col })}`,
14412
14702
  "cells",
14413
14703
  writeScopes(sheet, s, range2),
14414
- () => {
14704
+ (formulaCells) => {
14415
14705
  writeValue(sheet, row2, col, value2);
14416
- syncTableHeader(ctx, sheet, row2, col);
14706
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
14417
14707
  },
14418
14708
  { sheet: s, ranges: [range2] }
14419
14709
  );
@@ -14840,7 +15130,7 @@ function fillRange(ctx, s, source, target2, mode = "auto") {
14840
15130
  ctx.run(
14841
15131
  "Fill",
14842
15132
  "cells",
14843
- [{ kind: "cells", sheet: s, ranges: [all2] }],
15133
+ writeScopes(sheet, s, all2),
14844
15134
  () => {
14845
15135
  const laneCount = vertical2 ? src.end.col - src.start.col + 1 : src.end.row - src.start.row + 1;
14846
15136
  const length = vertical2 ? src.end.row - src.start.row + 1 : src.end.col - src.start.col + 1;
@@ -14863,6 +15153,7 @@ function fillRange(ctx, s, source, target2, mode = "auto") {
14863
15153
  const step = series?.(k);
14864
15154
  const cell = !step || step.kind === "copy" ? copyCell(origin, row2 - srcRow, col - srcCol) : { value: step.value, ...origin.styleId ? { styleId: origin.styleId } : {} };
14865
15155
  putCell(sheet, row2, col, cell);
15156
+ syncTableHeader(ctx, sheet, row2, col);
14866
15157
  }
14867
15158
  }
14868
15159
  },
@@ -14901,28 +15192,6 @@ function removeValidationArea(rules, area) {
14901
15192
  });
14902
15193
  }
14903
15194
 
14904
- // xlsx/edit/conditional-formulas.ts
14905
- function rewriteConditionalRule(rule, rewrite) {
14906
- const safe2 = (formula) => {
14907
- try {
14908
- return rewrite(formula);
14909
- } catch {
14910
- return formula;
14911
- }
14912
- };
14913
- if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
14914
- else if (rule.type === "expression") rule.formula = safe2(rule.formula);
14915
- if (rule.type === "colorScale" || rule.type === "iconSet") {
14916
- for (const threshold of rule.thresholds)
14917
- if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14918
- }
14919
- if (rule.type === "dataBar") {
14920
- for (const threshold of [rule.min, rule.max])
14921
- if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14922
- }
14923
- if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
14924
- }
14925
-
14926
15195
  // xlsx/edit/conditional-formats.ts
14927
15196
  function formatAt(sheet, index2) {
14928
15197
  const format = sheet.conditionalFormats[index2];
@@ -15332,168 +15601,6 @@ function setBorders(ctx, s, range2, preset, edge = { style: "thin" }) {
15332
15601
  );
15333
15602
  }
15334
15603
 
15335
- // xlsx/edit/shift-preserved.ts
15336
- var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
15337
- function descendants2(root, ns, local) {
15338
- return Array.from(root.getElementsByTagNameNS(ns, local));
15339
- }
15340
- function editEntries(sheet, key, edit, quick) {
15341
- const list = sheet.preserved.get(key);
15342
- if (!list) return;
15343
- const next = [];
15344
- for (const xml of list) {
15345
- if (!quick(xml)) {
15346
- next.push(xml);
15347
- continue;
15348
- }
15349
- let doc;
15350
- try {
15351
- doc = parseXml(xml);
15352
- } catch {
15353
- next.push(xml);
15354
- continue;
15355
- }
15356
- const outcome = edit(doc.documentElement);
15357
- if (outcome === "same") next.push(xml);
15358
- else if (outcome === "changed") next.push(buildXml(doc));
15359
- }
15360
- if (next.length) sheet.preserved.set(key, next);
15361
- else sheet.preserved.delete(key);
15362
- }
15363
- function shiftBreaks(root, shift2) {
15364
- let changed = false;
15365
- for (const brk of elements(root).filter((e) => e.localName === "brk")) {
15366
- const id = Number(brk.getAttribute("id") ?? "0");
15367
- const moved = shiftIndex(id, shift2);
15368
- if (moved === id) continue;
15369
- changed = true;
15370
- if (moved === void 0 || moved === 0) root.removeChild(brk);
15371
- else brk.setAttribute("id", String(moved));
15372
- }
15373
- if (!changed) return "same";
15374
- const left2 = elements(root).filter((e) => e.localName === "brk");
15375
- if (!left2.length) return "drop";
15376
- if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
15377
- if (root.hasAttribute("manualBreakCount")) {
15378
- const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
15379
- root.setAttribute("manualBreakCount", String(manual));
15380
- }
15381
- return "changed";
15382
- }
15383
- function removeUpwards(node, root) {
15384
- let current = node;
15385
- while (current && current !== root) {
15386
- const parent = current.parentNode;
15387
- parent?.removeChild(current);
15388
- if (!parent) break;
15389
- const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
15390
- if (!emptied) break;
15391
- current = parent;
15392
- }
15393
- }
15394
- function shiftSqrefs(root, moveRange) {
15395
- let changed = false;
15396
- for (const sqref of descendants2(root, XM3, "sqref")) {
15397
- const old = sqref.textContent ?? "";
15398
- const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
15399
- const text2 = ranges.map(formatRange).join(" ");
15400
- if (text2 === old.trim()) continue;
15401
- changed = true;
15402
- const owner = sqref.parentNode;
15403
- if (ranges.length) sqref.textContent = text2;
15404
- else if (owner) removeUpwards(owner, root);
15405
- }
15406
- if (!changed) return "same";
15407
- for (const list of elements(root).flatMap((ext) => elements(ext)))
15408
- if (list.localName === "dataValidations" && list.hasAttribute("count"))
15409
- list.setAttribute("count", String(elements(list).length));
15410
- return elements(root).length > 0 ? "changed" : "drop";
15411
- }
15412
- function shiftPreservedXml(sheet, shift2, moveRange, banded) {
15413
- if (!banded)
15414
- editEntries(
15415
- sheet,
15416
- shift2.axis === "row" ? "rowBreaks" : "colBreaks",
15417
- (root) => shiftBreaks(root, shift2),
15418
- (xml) => xml.includes("brk")
15419
- );
15420
- editEntries(
15421
- sheet,
15422
- "extLst",
15423
- (root) => shiftSqrefs(root, moveRange),
15424
- (xml) => xml.includes("sqref")
15425
- );
15426
- }
15427
- function rewritePreservedFormulas(sheet, rewrite) {
15428
- editEntries(
15429
- sheet,
15430
- "extLst",
15431
- (root) => {
15432
- let changed = false;
15433
- for (const f6 of descendants2(root, XM3, "f")) {
15434
- const text2 = f6.textContent ?? "";
15435
- let next = text2;
15436
- try {
15437
- next = rewrite(text2, sheet.name);
15438
- } catch {
15439
- next = text2;
15440
- }
15441
- if (next === text2) continue;
15442
- f6.textContent = next;
15443
- changed = true;
15444
- }
15445
- return changed ? "changed" : "same";
15446
- },
15447
- (xml) => xml.includes(":f>")
15448
- );
15449
- }
15450
-
15451
- // xlsx/edit/shift-formulas.ts
15452
- function safe(rewrite, formula, formulaSheet) {
15453
- try {
15454
- return rewrite(formula, formulaSheet);
15455
- } catch {
15456
- return formula;
15457
- }
15458
- }
15459
- function rewriteFormulas(workbook, rewrite) {
15460
- for (const sheet of workbook.sheets) rewriteSheetFormulas(sheet, rewrite);
15461
- for (const definedName of workbook.definedNames) {
15462
- const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
15463
- definedName.formula = safe(rewrite, definedName.formula, local?.name ?? "");
15464
- }
15465
- }
15466
- function rewriteSheetFormulas(sheet, rewrite) {
15467
- rewritePreservedFormulas(sheet, rewrite);
15468
- {
15469
- const name = sheet.name;
15470
- for (const table2 of sheet.tables)
15471
- for (const column of table2.columns)
15472
- if (column.calculatedColumnFormula !== void 0)
15473
- column.calculatedColumnFormula = safe(rewrite, column.calculatedColumnFormula, name);
15474
- for (const cells of sheet.rows.values())
15475
- for (const cell of cells.values())
15476
- if (cell.formula !== void 0) cell.formula = safe(rewrite, cell.formula, name);
15477
- for (const cf of sheet.conditionalFormats)
15478
- for (const rule of cf.rules) rewriteConditionalRule(rule, (f6) => rewrite(f6, name));
15479
- for (const dv of sheet.dataValidations) {
15480
- if (dv.formula1 !== void 0) dv.formula1 = safe(rewrite, dv.formula1, name);
15481
- if (dv.formula2 !== void 0) dv.formula2 = safe(rewrite, dv.formula2, name);
15482
- }
15483
- for (const link of sheet.hyperlinks)
15484
- if (link.location && /![A-Za-z$]/.test(link.location))
15485
- link.location = safe(rewrite, link.location, name);
15486
- for (const drawing of sheet.drawings) {
15487
- if (drawing.kind !== "chart") continue;
15488
- for (const series of drawing.series) {
15489
- if (series.nameRef) series.nameRef = safe(rewrite, series.nameRef, name);
15490
- if (series.categoriesRef) series.categoriesRef = safe(rewrite, series.categoriesRef, name);
15491
- if (series.valuesRef) series.valuesRef = safe(rewrite, series.valuesRef, name);
15492
- }
15493
- }
15494
- }
15495
- }
15496
-
15497
15604
  // xlsx/edit/shift-sheet.ts
15498
15605
  function shiftSheetContent(sheet, shift2, band) {
15499
15606
  const moveRange = (range2) => band ? shiftRangeInBand(range2, shift2, band.lo, band.hi) : shiftRange(range2, shift2);
@@ -16483,14 +16590,13 @@ function pasteAt(ctx, s, at, payload, request) {
16483
16590
  if (cut && operation !== "none")
16484
16591
  throw new RangeError("Paste operations are not available for cut cells.");
16485
16592
  const destCells = { kind: "cells", sheet: s, ranges: [dest] };
16486
- const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : [
16487
- destCells,
16488
- {
16489
- kind: "parts",
16490
- sheet: s,
16491
- parts: ["merges", "comments", "dataValidations", "hyperlinks", "conditionalFormats"]
16492
- }
16493
- ];
16593
+ const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : writeScopes(sheet, s, dest, [
16594
+ "merges",
16595
+ "comments",
16596
+ "dataValidations",
16597
+ "hyperlinks",
16598
+ "conditionalFormats"
16599
+ ]);
16494
16600
  const move = cut && {
16495
16601
  fromSheet: sheetAt(workbook, cut.sheet).name,
16496
16602
  range: cut.range,
@@ -16563,6 +16669,8 @@ function pasteAt(ctx, s, at, payload, request) {
16563
16669
  const origin = cells.source?.range.start;
16564
16670
  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);
16565
16671
  writeClip(workbook, sheet, row2, col, clip, mode, formula, styleOf, operation);
16672
+ if (mode !== "formats" && mode !== "comments" && mode !== "validation")
16673
+ syncTableHeader(ctx, sheet, row2, col);
16566
16674
  }
16567
16675
  if (mode === "all" || mode === "mergeFormats" || mode === "noBorders" || mode === "formats") {
16568
16676
  sheet.merges = sheet.merges.filter((m) => !rangesIntersect(m, dest));
@@ -16606,14 +16714,13 @@ function pasteSelection(ctx, sheet, selection, payload, request) {
16606
16714
  return ctx.run(
16607
16715
  "Paste",
16608
16716
  "cells",
16609
- [
16610
- { kind: "cells", sheet, ranges: [dest] },
16611
- {
16612
- kind: "parts",
16613
- sheet,
16614
- parts: ["merges", "comments", "dataValidations", "hyperlinks", "conditionalFormats"]
16615
- }
16616
- ],
16717
+ writeScopes(sheetAt(ctx.workbook, sheet), sheet, dest, [
16718
+ "merges",
16719
+ "comments",
16720
+ "dataValidations",
16721
+ "hyperlinks",
16722
+ "conditionalFormats"
16723
+ ]),
16617
16724
  () => {
16618
16725
  for (let row2 = dest.start.row; row2 <= dest.end.row; row2 += height)
16619
16726
  for (let col = dest.start.col; col <= dest.end.col; col += width)
@@ -16765,6 +16872,15 @@ function setHidden(ctx, s, axis, indices, hidden) {
16765
16872
  }
16766
16873
  for (const row2 of indices) {
16767
16874
  const info = { ...sheet.rowInfo.get(row2) };
16875
+ if (info.filteredOut) {
16876
+ if (hidden) info.manuallyHidden = true;
16877
+ else delete info.manuallyHidden;
16878
+ sheet.rowInfo.set(row2, info);
16879
+ continue;
16880
+ }
16881
+ const filter2 = sheet.autoFilter;
16882
+ if (filter2?.columns?.length && row2 > filter2.range.start.row && row2 <= filter2.range.end.row)
16883
+ info.filteredOut = false;
16768
16884
  if (hidden) info.hidden = true;
16769
16885
  else {
16770
16886
  delete info.hidden;
@@ -16919,14 +17035,21 @@ function currentRegion(sheet, at) {
16919
17035
  function applyFilter(ctx, sheet, filter2) {
16920
17036
  const { range: range2 } = filter2;
16921
17037
  for (let row2 = range2.start.row + 1; row2 <= range2.end.row; row2++) {
16922
- const visible = (filter2.columns ?? []).every((fc) => {
16923
- if (!fc.values && !fc.blank) return true;
16924
- const text2 = displayText(ctx.workbook, getCell(sheet, row2, range2.start.col + fc.offset));
16925
- return text2 === "" ? !!fc.blank : (fc.values ?? []).includes(text2);
16926
- });
17038
+ const visible = rowMatchesFilter(ctx.workbook, sheet, row2, filter2);
16927
17039
  const info = { ...sheet.rowInfo.get(row2) };
16928
- if (visible) delete info.hidden;
16929
- else info.hidden = true;
17040
+ const manual = info.manuallyHidden || info.hidden && !info.filteredOut;
17041
+ if (visible) {
17042
+ delete info.filteredOut;
17043
+ delete info.manuallyHidden;
17044
+ if (manual) {
17045
+ info.hidden = true;
17046
+ if (filter2.columns?.length) info.filteredOut = false;
17047
+ } else delete info.hidden;
17048
+ } else {
17049
+ info.hidden = true;
17050
+ info.filteredOut = true;
17051
+ if (manual) info.manuallyHidden = true;
17052
+ }
16930
17053
  if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
16931
17054
  else sheet.rowInfo.delete(row2);
16932
17055
  }
@@ -17086,16 +17209,16 @@ var isSpilledAt = (workbook, at) => {
17086
17209
  return !!sheet && isSpilledCell(getCell(sheet, at.row, at.col));
17087
17210
  };
17088
17211
  var replaceQuery = (query) => query.lookIn === "comments" ? query : { ...query, lookIn: "formulas" };
17089
- function replaceScopes(query, sheet, matches2) {
17212
+ function replaceScopes(ctx, query, sheet, matches2) {
17090
17213
  if (query.lookIn === "comments") return [{ kind: "parts", sheet, parts: ["comments"] }];
17091
17214
  const ranges = matches2.map((m) => ({
17092
17215
  start: { row: m.row, col: m.col },
17093
17216
  end: { row: m.row, col: m.col }
17094
17217
  }));
17095
- return [
17096
- { kind: "cells", sheet, ranges },
17097
- { kind: "parts", sheet, parts: ["tables"] }
17098
- ];
17218
+ const header = ranges.some(
17219
+ (range2) => writeScopes(sheetAt(ctx.workbook, sheet), sheet, range2).some((scope) => scope.kind === "refs")
17220
+ );
17221
+ return [...header ? [{ kind: "refs" }] : [], { kind: "cells", sheet, ranges }];
17099
17222
  }
17100
17223
  function applyReplace(ctx, query, replacement, matches2) {
17101
17224
  let changed = 0;
@@ -17125,14 +17248,24 @@ function replaceAll(ctx, query, replacement) {
17125
17248
  const sheets = [...new Set(matches2.map((m) => m.sheet))];
17126
17249
  const scopes = sheets.flatMap(
17127
17250
  (sheet) => replaceScopes(
17251
+ ctx,
17128
17252
  q,
17129
17253
  sheet,
17130
17254
  matches2.filter((m) => m.sheet === sheet)
17131
17255
  )
17132
17256
  );
17133
- return ctx.run("Replace", "cells", scopes, () => applyReplace(ctx, q, replacement, matches2), {
17134
- ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
17135
- });
17257
+ const uniqueScopes = scopes.filter(
17258
+ (scope, index2) => scope.kind !== "refs" || scopes.findIndex((entry) => entry.kind === "refs") === index2
17259
+ );
17260
+ return ctx.run(
17261
+ "Replace",
17262
+ "cells",
17263
+ uniqueScopes,
17264
+ () => applyReplace(ctx, q, replacement, matches2),
17265
+ {
17266
+ ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
17267
+ }
17268
+ );
17136
17269
  }
17137
17270
  function replaceOne(ctx, query, replacement, at) {
17138
17271
  const q = replaceQuery(query);
@@ -17145,7 +17278,7 @@ function replaceOne(ctx, query, replacement, at) {
17145
17278
  ctx.run(
17146
17279
  "Replace",
17147
17280
  "cells",
17148
- replaceScopes(q, at.sheet, [match2]),
17281
+ replaceScopes(ctx, q, at.sheet, [match2]),
17149
17282
  () => applyReplace(ctx, q, replacement, [match2]),
17150
17283
  { sheet: at.sheet }
17151
17284
  );
@@ -17925,90 +18058,6 @@ function applyTotalsRow(sheet, table2) {
17925
18058
  });
17926
18059
  }
17927
18060
 
17928
- // xlsx/edit/tables.ts
17929
- function nextTableName(workbook) {
17930
- const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
17931
- const names = new Set(workbook.definedNames.map((n) => n.name.toLowerCase()));
17932
- for (let n = 1; ; n++) if (!taken.has(`table${n}`) && !names.has(`table${n}`)) return `Table${n}`;
17933
- }
17934
- function uniqueHeaders(texts) {
17935
- const used = /* @__PURE__ */ new Set();
17936
- return texts.map((text2, i2) => {
17937
- let base = text2.trim() || `Column${i2 + 1}`;
17938
- if (!used.has(base.toLowerCase())) {
17939
- used.add(base.toLowerCase());
17940
- return base;
17941
- }
17942
- for (let n = 2; ; n++) {
17943
- const candidate = `${base}${n}`;
17944
- if (!used.has(candidate.toLowerCase())) {
17945
- used.add(candidate.toLowerCase());
17946
- base = candidate;
17947
- return base;
17948
- }
17949
- }
17950
- });
17951
- }
17952
- function createTable(ctx, s, range2, hasHeader, styleName = "TableStyleMedium2") {
17953
- const { workbook } = ctx;
17954
- const sheet = sheetAt(workbook, s);
17955
- let r = normalizeRange(range2);
17956
- if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
17957
- if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
17958
- throw new Error("A table cannot overlap another table.");
17959
- if (sheet.merges.some((m) => rangesIntersect(m, r)))
17960
- throw new Error("A table cannot contain merged cells.");
17961
- return ctx.run(
17962
- "Create table",
17963
- "structure",
17964
- [hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
17965
- () => {
17966
- if (!hasHeader) {
17967
- const shift2 = { axis: "row", at: r.start.row, count: 1 };
17968
- const band = { lo: r.start.col, hi: r.end.col };
17969
- rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
17970
- shiftSheetContent(sheet, shift2, band);
17971
- r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
17972
- }
17973
- const width = r.end.col - r.start.col + 1;
17974
- const texts = Array.from(
17975
- { length: width },
17976
- (_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
17977
- );
17978
- const headers = uniqueHeaders(texts);
17979
- const columns = headers.map((name2, i2) => {
17980
- const cell = getCell(sheet, r.start.row, r.start.col + i2);
17981
- if (cell?.value !== name2) {
17982
- const styleId = cell?.styleId;
17983
- writeValue(sheet, r.start.row, r.start.col + i2, name2);
17984
- const written = getCell(sheet, r.start.row, r.start.col + i2);
17985
- if (written && styleId) written.styleId = styleId;
17986
- }
17987
- return { name: name2 };
17988
- });
17989
- const name = nextTableName(workbook);
17990
- const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
17991
- const table2 = {
17992
- id,
17993
- name,
17994
- displayName: name,
17995
- range: r,
17996
- headerRow: true,
17997
- totalsRow: false,
17998
- columns,
17999
- styleName,
18000
- showRowStripes: true,
18001
- showColumnStripes: false,
18002
- showFirstColumn: false,
18003
- showLastColumn: false
18004
- };
18005
- sheet.tables.push(table2);
18006
- return table2;
18007
- },
18008
- { sheet: s, ranges: [r], structural: !hasHeader }
18009
- );
18010
- }
18011
-
18012
18061
  // xlsx/edit/table-edits.ts
18013
18062
  function tableIndex(sheet, ref) {
18014
18063
  const index2 = typeof ref === "number" ? ref : sheet.tables.findIndex((t) => t.name.toLowerCase() === ref.toLowerCase());
@@ -21225,8 +21274,8 @@ function setSheetState(ctx, index2, state) {
21225
21274
  const { workbook } = ctx;
21226
21275
  const sheet = sheetAt(workbook, index2);
21227
21276
  if (sheet.state === state) return;
21277
+ assertUnlocked(workbook);
21228
21278
  if (state !== "visible") {
21229
- assertUnlocked(workbook);
21230
21279
  if (sheet.state === "visible" && visibleCount(workbook) <= 1)
21231
21280
  throw new Error("A workbook must contain at least one visible sheet.");
21232
21281
  }
@@ -21256,6 +21305,72 @@ function setTabColor(ctx, index2, color) {
21256
21305
  );
21257
21306
  }
21258
21307
 
21308
+ // xlsx/edit/tables.ts
21309
+ function nextTableName(workbook) {
21310
+ const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
21311
+ const names = new Set(workbook.definedNames.map((n) => n.name.toLowerCase()));
21312
+ for (let n = 1; ; n++) if (!taken.has(`table${n}`) && !names.has(`table${n}`)) return `Table${n}`;
21313
+ }
21314
+ function createTable(ctx, s, range2, hasHeader, styleName = "TableStyleMedium2") {
21315
+ const { workbook } = ctx;
21316
+ const sheet = sheetAt(workbook, s);
21317
+ let r = normalizeRange(range2);
21318
+ if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
21319
+ if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
21320
+ throw new Error("A table cannot overlap another table.");
21321
+ if (sheet.merges.some((m) => rangesIntersect(m, r)))
21322
+ throw new Error("A table cannot contain merged cells.");
21323
+ return ctx.run(
21324
+ "Create table",
21325
+ "structure",
21326
+ [hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
21327
+ () => {
21328
+ if (!hasHeader) {
21329
+ const shift2 = { axis: "row", at: r.start.row, count: 1 };
21330
+ const band = { lo: r.start.col, hi: r.end.col };
21331
+ rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
21332
+ shiftSheetContent(sheet, shift2, band);
21333
+ r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
21334
+ }
21335
+ const width = r.end.col - r.start.col + 1;
21336
+ const texts = Array.from(
21337
+ { length: width },
21338
+ (_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
21339
+ );
21340
+ const headers = uniqueHeaders(texts);
21341
+ const columns = headers.map((name2, i2) => {
21342
+ const cell = getCell(sheet, r.start.row, r.start.col + i2);
21343
+ if (cell?.value !== name2) {
21344
+ const styleId = cell?.styleId;
21345
+ writeValue(sheet, r.start.row, r.start.col + i2, name2);
21346
+ const written = getCell(sheet, r.start.row, r.start.col + i2);
21347
+ if (written && styleId) written.styleId = styleId;
21348
+ }
21349
+ return { name: name2 };
21350
+ });
21351
+ const name = nextTableName(workbook);
21352
+ const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
21353
+ const table2 = {
21354
+ id,
21355
+ name,
21356
+ displayName: name,
21357
+ range: r,
21358
+ headerRow: true,
21359
+ totalsRow: false,
21360
+ columns,
21361
+ styleName,
21362
+ showRowStripes: true,
21363
+ showColumnStripes: false,
21364
+ showFirstColumn: false,
21365
+ showLastColumn: false
21366
+ };
21367
+ sheet.tables.push(table2);
21368
+ return table2;
21369
+ },
21370
+ { sheet: s, ranges: [r], structural: !hasHeader }
21371
+ );
21372
+ }
21373
+
21259
21374
  // xlsx/edit/validation-list.ts
21260
21375
  function listSource(workbook, sheet, formula, evaluate, at, depth = 0) {
21261
21376
  const text2 = formula.replace(/^=/, "").trim();
@@ -21543,7 +21658,7 @@ function createEditSession(workbook, options = {}) {
21543
21658
  const befores = scopes.map((scope) => captureScope(workbook, scope));
21544
21659
  let result2;
21545
21660
  try {
21546
- result2 = fn();
21661
+ result2 = fn(befores.find((snapshot) => snapshot.kind === "refs")?.data.formulas);
21547
21662
  } catch (error) {
21548
21663
  for (let i2 = befores.length - 1; i2 >= 0; i2--) {
21549
21664
  const snapshot = befores[i2];
@@ -26989,6 +27104,7 @@ __export(shell_exports, {
26989
27104
  shell: () => shell
26990
27105
  });
26991
27106
  var shell = {
27107
+ "Finish or cancel the current cell edit before saving.": "Beenden oder verwerfen Sie die aktuelle Zellbearbeitung vor dem Speichern.",
26992
27108
  File: "Datei",
26993
27109
  Ribbon: "Men\xFCband",
26994
27110
  "Ribbon tabs": "Men\xFCbandregisterkarten",
@@ -27374,6 +27490,7 @@ __export(shell_exports2, {
27374
27490
  shell: () => shell2
27375
27491
  });
27376
27492
  var shell2 = {
27493
+ "Finish or cancel the current cell edit before saving.": "Finish or cancel the current cell edit before saving.",
27377
27494
  File: "File",
27378
27495
  Ribbon: "Ribbon",
27379
27496
  "Ribbon tabs": "Ribbon tabs",
@@ -27759,6 +27876,7 @@ __export(shell_exports3, {
27759
27876
  shell: () => shell3
27760
27877
  });
27761
27878
  var shell3 = {
27879
+ "Finish or cancel the current cell edit before saving.": "Finalice o cancele la edici\xF3n de la celda actual antes de guardar.",
27762
27880
  File: "Archivo",
27763
27881
  Ribbon: "Cinta de opciones",
27764
27882
  "Ribbon tabs": "Pesta\xF1as de la cinta",
@@ -28144,6 +28262,7 @@ __export(shell_exports4, {
28144
28262
  shell: () => shell4
28145
28263
  });
28146
28264
  var shell4 = {
28265
+ "Finish or cancel the current cell edit before saving.": "Terminez ou annulez la modification de la cellule avant de sauvegarder.",
28147
28266
  File: "Fichier",
28148
28267
  Ribbon: "Ruban",
28149
28268
  "Ribbon tabs": "Onglets du ruban",
@@ -28529,6 +28648,7 @@ __export(shell_exports5, {
28529
28648
  shell: () => shell5
28530
28649
  });
28531
28650
  var shell5 = {
28651
+ "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",
28532
28652
  File: "\u6587\u4EF6",
28533
28653
  Ribbon: "\u529F\u80FD\u533A",
28534
28654
  "Ribbon tabs": "\u529F\u80FD\u533A\u9009\u9879\u5361",