ooxml-core 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/automation/index.cjs +6089 -5381
- package/dist/automation/index.mjs +6089 -5381
- package/dist/teams/index.cjs +73 -23
- package/dist/teams/index.mjs +73 -23
- package/dist/visio/basic-shapes.d.ts +18 -0
- package/dist/visio/basic-shapes.d.ts.map +1 -0
- package/dist/visio/edit-commands.d.ts +13 -2
- package/dist/visio/edit-commands.d.ts.map +1 -1
- package/dist/visio/edit-page-size.d.ts +5 -0
- package/dist/visio/edit-page-size.d.ts.map +1 -0
- package/dist/visio/edit-pages.d.ts.map +1 -1
- package/dist/visio/edit-shape-create.d.ts.map +1 -1
- package/dist/visio/edit-text-range-commands.d.ts +21 -0
- package/dist/visio/edit-text-range-commands.d.ts.map +1 -0
- package/dist/visio/edit-text-range-plan.d.ts +7 -0
- package/dist/visio/edit-text-range-plan.d.ts.map +1 -0
- package/dist/visio/edit-text-ranges.d.ts +4 -0
- package/dist/visio/edit-text-ranges.d.ts.map +1 -0
- package/dist/visio/edit-text-target.d.ts +3 -0
- package/dist/visio/edit-text-target.d.ts.map +1 -0
- package/dist/visio/edit-text.d.ts.map +1 -1
- package/dist/visio/edit.d.ts +1 -1
- package/dist/visio/edit.d.ts.map +1 -1
- package/dist/visio/index.cjs +623 -49
- package/dist/visio/index.d.ts +2 -1
- package/dist/visio/index.d.ts.map +1 -1
- package/dist/visio/index.mjs +621 -50
- package/dist/visio/model.d.ts +3 -0
- package/dist/visio/model.d.ts.map +1 -1
- package/dist/visio/parser.d.ts.map +1 -1
- package/dist/visio/ui/draw-plan.d.ts +4 -1
- package/dist/visio/ui/draw-plan.d.ts.map +1 -1
- package/dist/visio/ui/edit-commands.d.ts.map +1 -1
- package/dist/visio/ui/index.cjs +139 -14
- package/dist/visio/ui/index.d.ts +1 -0
- package/dist/visio/ui/index.d.ts.map +1 -1
- package/dist/visio/ui/index.mjs +135 -15
- package/dist/visio/ui/page-size.d.ts +31 -0
- package/dist/visio/ui/page-size.d.ts.map +1 -0
- package/dist/visio/ui/scene-validation.d.ts.map +1 -1
- package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
- package/dist/visio/ui/text-replace-types.d.ts +6 -2
- package/dist/visio/ui/text-replace-types.d.ts.map +1 -1
- package/dist/visio/ui/text-replace.d.ts +3 -4
- package/dist/visio/ui/text-replace.d.ts.map +1 -1
- package/dist/visio/xml-validation.d.ts.map +1 -1
- package/dist/xlsx/collab/codec.d.ts +2 -0
- package/dist/xlsx/collab/codec.d.ts.map +1 -1
- package/dist/xlsx/collab/index.cjs +5 -0
- package/dist/xlsx/collab/index.mjs +5 -0
- package/dist/xlsx/display-text.d.ts +4 -0
- package/dist/xlsx/display-text.d.ts.map +1 -0
- package/dist/xlsx/edit/cell-values.d.ts +4 -3
- package/dist/xlsx/edit/cell-values.d.ts.map +1 -1
- package/dist/xlsx/edit/clipboard.d.ts.map +1 -1
- package/dist/xlsx/edit/context.d.ts +7 -5
- package/dist/xlsx/edit/context.d.ts.map +1 -1
- package/dist/xlsx/edit/deps.d.ts +1 -1
- package/dist/xlsx/edit/deps.d.ts.map +1 -1
- package/dist/xlsx/edit/dimensions.d.ts.map +1 -1
- package/dist/xlsx/edit/fill.d.ts.map +1 -1
- package/dist/xlsx/edit/filter.d.ts.map +1 -1
- package/dist/xlsx/edit/find.d.ts.map +1 -1
- package/dist/xlsx/edit/paste-selection.d.ts.map +1 -1
- package/dist/xlsx/edit/shift-formulas.d.ts +10 -4
- package/dist/xlsx/edit/shift-formulas.d.ts.map +1 -1
- package/dist/xlsx/edit/shift-sheet.d.ts.map +1 -1
- package/dist/xlsx/edit/structure.d.ts +1 -1
- package/dist/xlsx/edit/structure.d.ts.map +1 -1
- package/dist/xlsx/edit/table-header-names.d.ts +3 -0
- package/dist/xlsx/edit/table-header-names.d.ts.map +1 -0
- package/dist/xlsx/edit/tables.d.ts +1 -2
- package/dist/xlsx/edit/tables.d.ts.map +1 -1
- package/dist/xlsx/filter-rows.d.ts +12 -0
- package/dist/xlsx/filter-rows.d.ts.map +1 -0
- package/dist/xlsx/formula/functions/math-sum.d.ts.map +1 -1
- package/dist/xlsx/formula/table-refs.d.ts +2 -0
- package/dist/xlsx/formula/table-refs.d.ts.map +1 -1
- package/dist/xlsx/index.cjs +466 -329
- package/dist/xlsx/index.mjs +466 -329
- package/dist/xlsx/load/index.cjs +7622 -7585
- package/dist/xlsx/load/index.mjs +7622 -7585
- package/dist/xlsx/model.d.ts +4 -0
- package/dist/xlsx/model.d.ts.map +1 -1
- package/dist/xlsx/read/load.d.ts.map +1 -1
- package/dist/xlsx/ui/index.cjs +464 -329
- package/dist/xlsx/ui/index.mjs +464 -329
- package/dist/xlsx/ui/locales/de/shell.d.ts.map +1 -1
- package/dist/xlsx/ui/locales/en/shell.d.ts.map +1 -1
- package/dist/xlsx/ui/locales/es/shell.d.ts.map +1 -1
- package/dist/xlsx/ui/locales/fr/shell.d.ts.map +1 -1
- package/dist/xlsx/ui/locales/zh-CN/shell.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/xlsx/index.mjs
CHANGED
|
@@ -7809,6 +7809,63 @@ function liftCriteria(ctx, pairs, fn) {
|
|
|
7809
7809
|
});
|
|
7810
7810
|
}
|
|
7811
7811
|
|
|
7812
|
+
// xlsx/display-text.ts
|
|
7813
|
+
function displayText(workbook, cell) {
|
|
7814
|
+
if (!cell || cell.value === null) return "";
|
|
7815
|
+
const value = cell.value;
|
|
7816
|
+
if (isCellError(value)) return value.error;
|
|
7817
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
7818
|
+
if (cell.richText && typeof value === "string") return value;
|
|
7819
|
+
return formatValue(value, styleAt(workbook, cell.styleId).numFmt, {
|
|
7820
|
+
date1904: workbook.date1904
|
|
7821
|
+
}).text;
|
|
7822
|
+
}
|
|
7823
|
+
|
|
7824
|
+
// xlsx/filter-rows.ts
|
|
7825
|
+
function rowMatchesFilter(workbook, sheet, row2, filter2) {
|
|
7826
|
+
return (filter2.columns ?? []).every((column) => {
|
|
7827
|
+
if (!column.values && !column.blank) return true;
|
|
7828
|
+
const text3 = displayText(workbook, getCell(sheet, row2, filter2.range.start.col + column.offset));
|
|
7829
|
+
return text3 === "" ? !!column.blank : (column.values ?? []).includes(text3);
|
|
7830
|
+
});
|
|
7831
|
+
}
|
|
7832
|
+
function setRowFiltered(sheet, row2, filteredOut, hasCriteria = false) {
|
|
7833
|
+
const info = { ...sheet.rowInfo.get(row2) };
|
|
7834
|
+
const manual = info.manuallyHidden || info.hidden && !info.filteredOut;
|
|
7835
|
+
if (filteredOut) {
|
|
7836
|
+
info.hidden = true;
|
|
7837
|
+
info.filteredOut = true;
|
|
7838
|
+
if (manual) info.manuallyHidden = true;
|
|
7839
|
+
} else {
|
|
7840
|
+
delete info.filteredOut;
|
|
7841
|
+
delete info.manuallyHidden;
|
|
7842
|
+
if (manual) {
|
|
7843
|
+
info.hidden = true;
|
|
7844
|
+
if (hasCriteria) info.filteredOut = false;
|
|
7845
|
+
} else delete info.hidden;
|
|
7846
|
+
}
|
|
7847
|
+
if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
|
|
7848
|
+
else sheet.rowInfo.delete(row2);
|
|
7849
|
+
}
|
|
7850
|
+
function clearFilteredRows(sheet) {
|
|
7851
|
+
for (const [row2, info] of sheet.rowInfo)
|
|
7852
|
+
if (info.filteredOut !== void 0 || info.manuallyHidden !== void 0)
|
|
7853
|
+
setRowFiltered(sheet, row2, false);
|
|
7854
|
+
}
|
|
7855
|
+
function isFilteredRow(workbook, sheet, row2) {
|
|
7856
|
+
const filter2 = sheet.autoFilter;
|
|
7857
|
+
if (!filter2) return false;
|
|
7858
|
+
const info = sheet.rowInfo.get(row2);
|
|
7859
|
+
if (info?.filteredOut !== void 0) return info.filteredOut;
|
|
7860
|
+
return !!info?.hidden && row2 > filter2.range.start.row && row2 <= filter2.range.end.row && !rowMatchesFilter(workbook, sheet, row2, filter2);
|
|
7861
|
+
}
|
|
7862
|
+
function readFilteredRows(workbook) {
|
|
7863
|
+
for (const sheet of workbook.sheets)
|
|
7864
|
+
for (const [row2, info] of sheet.rowInfo)
|
|
7865
|
+
if (sheet.autoFilter && row2 > sheet.autoFilter.range.start.row && row2 <= sheet.autoFilter.range.end.row && info.hidden)
|
|
7866
|
+
info.filteredOut = isFilteredRow(workbook, sheet, row2);
|
|
7867
|
+
}
|
|
7868
|
+
|
|
7812
7869
|
// xlsx/formula/functions/math-sum.ts
|
|
7813
7870
|
var C18 = "Math & Trig";
|
|
7814
7871
|
var numbersOf = (values2) => values2.filter((v) => typeof v === "number");
|
|
@@ -7846,7 +7903,7 @@ function pairwise(ctx, args, fn) {
|
|
|
7846
7903
|
return total2;
|
|
7847
7904
|
}
|
|
7848
7905
|
var SUBTOTAL_RE = /\b(?:_xlfn\.)?(?:SUBTOTAL|AGGREGATE)\s*\(/i;
|
|
7849
|
-
function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
|
|
7906
|
+
function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true, skipFiltered = false) {
|
|
7850
7907
|
const out = [];
|
|
7851
7908
|
const host = ctx.frame.host;
|
|
7852
7909
|
for (const arg of args) {
|
|
@@ -7859,6 +7916,7 @@ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
|
|
|
7859
7916
|
for (const area of arg.areas) {
|
|
7860
7917
|
const sheet = ctx.workbook.sheets[area.sheet];
|
|
7861
7918
|
host.forEachStored(area.sheet, area.range, (value, row2, col) => {
|
|
7919
|
+
if (skipFiltered && sheet && isFilteredRow(ctx.workbook, sheet, row2)) return;
|
|
7862
7920
|
if (skipHidden && sheet?.rowInfo.get(row2)?.hidden) return;
|
|
7863
7921
|
if (skipNested && SUBTOTAL_RE.test(host.cellFormula(area.sheet, row2, col) ?? "")) return;
|
|
7864
7922
|
if (skipErrors && isError(value)) return;
|
|
@@ -8024,7 +8082,7 @@ var SUM_FUNCTIONS = [
|
|
|
8024
8082
|
const code = int(args[0]);
|
|
8025
8083
|
const base = code > 100 ? code - 100 : code;
|
|
8026
8084
|
if (base < 1 || base > 11) fail(ERR.VALUE);
|
|
8027
|
-
return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false));
|
|
8085
|
+
return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false, true, true));
|
|
8028
8086
|
},
|
|
8029
8087
|
["value", "any"]
|
|
8030
8088
|
),
|
|
@@ -13562,6 +13620,31 @@ function renameTableInFormula(formula, oldName, newName) {
|
|
|
13562
13620
|
}
|
|
13563
13621
|
return changed ? joinTokens(tokens2) : formula;
|
|
13564
13622
|
}
|
|
13623
|
+
function renameTableColumnInFormula(formula, tableName, oldName, newName, insideTable = false) {
|
|
13624
|
+
const tokens2 = safeTokens2(formula);
|
|
13625
|
+
if (!tokens2) return formula;
|
|
13626
|
+
const escaped = newName.replace(/['#@[\]]/g, "'$&");
|
|
13627
|
+
let changed = false;
|
|
13628
|
+
for (const [index2, token] of tokens2.entries()) {
|
|
13629
|
+
if (token.kind !== "structured" || token.prefix) continue;
|
|
13630
|
+
if (token.value === "" && tokens2[index2 - 1]?.prefix) continue;
|
|
13631
|
+
if (token.value === "" ? !insideTable : String(token.value).toLowerCase() !== tableName.toLowerCase())
|
|
13632
|
+
continue;
|
|
13633
|
+
const next = token.text.replace(
|
|
13634
|
+
/\[(@?)((?:[^\[\]']|'[\s\S])*)\]/g,
|
|
13635
|
+
(original, at, name) => {
|
|
13636
|
+
if (name.startsWith("#") || name.replace(/'(.)/g, "$1").toLowerCase() !== oldName.toLowerCase())
|
|
13637
|
+
return original;
|
|
13638
|
+
return `[${at}${escaped}]`;
|
|
13639
|
+
}
|
|
13640
|
+
);
|
|
13641
|
+
if (next !== token.text) {
|
|
13642
|
+
token.text = next;
|
|
13643
|
+
changed = true;
|
|
13644
|
+
}
|
|
13645
|
+
}
|
|
13646
|
+
return changed ? joinTokens(tokens2) : formula;
|
|
13647
|
+
}
|
|
13565
13648
|
|
|
13566
13649
|
// xlsx/formula/structured-to-a1.ts
|
|
13567
13650
|
var abs = (row2, col, rowAbs = true) => `$${columnLabel(col)}${rowAbs ? "$" : ""}${row2 + 1}`;
|
|
@@ -20318,6 +20401,7 @@ async function loadXlsx(input) {
|
|
|
20318
20401
|
if (!sheets.length) throw new Error("XLSX workbook has no sheets");
|
|
20319
20402
|
await resolveSmartArt(sheets, source2, warn);
|
|
20320
20403
|
liftPrintAreas(workbook);
|
|
20404
|
+
readFilteredRows(workbook);
|
|
20321
20405
|
return workbook;
|
|
20322
20406
|
}
|
|
20323
20407
|
function readProperties(core, app, custom, warn) {
|
|
@@ -24620,16 +24704,6 @@ function forEachPosition(sheet, range, visit2) {
|
|
|
24620
24704
|
for (let row2 = r.start.row; row2 <= r.end.row; row2++)
|
|
24621
24705
|
for (let col = r.start.col; col <= r.end.col; col++) visit2(row2, col);
|
|
24622
24706
|
}
|
|
24623
|
-
function displayText(workbook, cell) {
|
|
24624
|
-
if (!cell) return "";
|
|
24625
|
-
const value = cell.value;
|
|
24626
|
-
if (value === null) return "";
|
|
24627
|
-
if (isCellError(value)) return value.error;
|
|
24628
|
-
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
24629
|
-
if (cell.richText && typeof value === "string") return value;
|
|
24630
|
-
const format = styleAt(workbook, cell.styleId).numFmt;
|
|
24631
|
-
return formatValue(value, format, { date1904: workbook.date1904 }).text;
|
|
24632
|
-
}
|
|
24633
24707
|
function rawText(value) {
|
|
24634
24708
|
if (value === null) return "";
|
|
24635
24709
|
if (isCellError(value)) return value.error;
|
|
@@ -24646,19 +24720,266 @@ function pruneCell(sheet, row2, col) {
|
|
|
24646
24720
|
}
|
|
24647
24721
|
}
|
|
24648
24722
|
|
|
24723
|
+
// xlsx/edit/shift-preserved.ts
|
|
24724
|
+
var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
|
|
24725
|
+
function descendants3(root, ns, local) {
|
|
24726
|
+
return Array.from(root.getElementsByTagNameNS(ns, local));
|
|
24727
|
+
}
|
|
24728
|
+
function editEntries(sheet, key, edit, quick) {
|
|
24729
|
+
const list = sheet.preserved.get(key);
|
|
24730
|
+
if (!list) return;
|
|
24731
|
+
const next = [];
|
|
24732
|
+
for (const xml of list) {
|
|
24733
|
+
if (!quick(xml)) {
|
|
24734
|
+
next.push(xml);
|
|
24735
|
+
continue;
|
|
24736
|
+
}
|
|
24737
|
+
let doc;
|
|
24738
|
+
try {
|
|
24739
|
+
doc = parseXml(xml);
|
|
24740
|
+
} catch {
|
|
24741
|
+
next.push(xml);
|
|
24742
|
+
continue;
|
|
24743
|
+
}
|
|
24744
|
+
const outcome = edit(doc.documentElement);
|
|
24745
|
+
if (outcome === "same") next.push(xml);
|
|
24746
|
+
else if (outcome === "changed") next.push(buildXml(doc));
|
|
24747
|
+
}
|
|
24748
|
+
if (next.length) sheet.preserved.set(key, next);
|
|
24749
|
+
else sheet.preserved.delete(key);
|
|
24750
|
+
}
|
|
24751
|
+
function shiftBreaks(root, shift2) {
|
|
24752
|
+
let changed = false;
|
|
24753
|
+
for (const brk of elements(root).filter((e) => e.localName === "brk")) {
|
|
24754
|
+
const id = Number(brk.getAttribute("id") ?? "0");
|
|
24755
|
+
const moved = shiftIndex(id, shift2);
|
|
24756
|
+
if (moved === id) continue;
|
|
24757
|
+
changed = true;
|
|
24758
|
+
if (moved === void 0 || moved === 0) root.removeChild(brk);
|
|
24759
|
+
else brk.setAttribute("id", String(moved));
|
|
24760
|
+
}
|
|
24761
|
+
if (!changed) return "same";
|
|
24762
|
+
const left2 = elements(root).filter((e) => e.localName === "brk");
|
|
24763
|
+
if (!left2.length) return "drop";
|
|
24764
|
+
if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
|
|
24765
|
+
if (root.hasAttribute("manualBreakCount")) {
|
|
24766
|
+
const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
|
|
24767
|
+
root.setAttribute("manualBreakCount", String(manual));
|
|
24768
|
+
}
|
|
24769
|
+
return "changed";
|
|
24770
|
+
}
|
|
24771
|
+
function removeUpwards(node, root) {
|
|
24772
|
+
let current = node;
|
|
24773
|
+
while (current && current !== root) {
|
|
24774
|
+
const parent = current.parentNode;
|
|
24775
|
+
parent?.removeChild(current);
|
|
24776
|
+
if (!parent) break;
|
|
24777
|
+
const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
|
|
24778
|
+
if (!emptied) break;
|
|
24779
|
+
current = parent;
|
|
24780
|
+
}
|
|
24781
|
+
}
|
|
24782
|
+
function shiftSqrefs(root, moveRange) {
|
|
24783
|
+
let changed = false;
|
|
24784
|
+
for (const sqref2 of descendants3(root, XM3, "sqref")) {
|
|
24785
|
+
const old = sqref2.textContent ?? "";
|
|
24786
|
+
const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
|
|
24787
|
+
const text3 = ranges.map(formatRange).join(" ");
|
|
24788
|
+
if (text3 === old.trim()) continue;
|
|
24789
|
+
changed = true;
|
|
24790
|
+
const owner = sqref2.parentNode;
|
|
24791
|
+
if (ranges.length) sqref2.textContent = text3;
|
|
24792
|
+
else if (owner) removeUpwards(owner, root);
|
|
24793
|
+
}
|
|
24794
|
+
if (!changed) return "same";
|
|
24795
|
+
for (const list of elements(root).flatMap((ext) => elements(ext)))
|
|
24796
|
+
if (list.localName === "dataValidations" && list.hasAttribute("count"))
|
|
24797
|
+
list.setAttribute("count", String(elements(list).length));
|
|
24798
|
+
return elements(root).length > 0 ? "changed" : "drop";
|
|
24799
|
+
}
|
|
24800
|
+
function shiftPreservedXml(sheet, shift2, moveRange, banded) {
|
|
24801
|
+
if (!banded)
|
|
24802
|
+
editEntries(
|
|
24803
|
+
sheet,
|
|
24804
|
+
shift2.axis === "row" ? "rowBreaks" : "colBreaks",
|
|
24805
|
+
(root) => shiftBreaks(root, shift2),
|
|
24806
|
+
(xml) => xml.includes("brk")
|
|
24807
|
+
);
|
|
24808
|
+
editEntries(
|
|
24809
|
+
sheet,
|
|
24810
|
+
"extLst",
|
|
24811
|
+
(root) => shiftSqrefs(root, moveRange),
|
|
24812
|
+
(xml) => xml.includes("sqref")
|
|
24813
|
+
);
|
|
24814
|
+
}
|
|
24815
|
+
function rewritePreservedFormulas(sheet, rewrite2) {
|
|
24816
|
+
editEntries(
|
|
24817
|
+
sheet,
|
|
24818
|
+
"extLst",
|
|
24819
|
+
(root) => {
|
|
24820
|
+
let changed = false;
|
|
24821
|
+
for (const f6 of descendants3(root, XM3, "f")) {
|
|
24822
|
+
const text3 = f6.textContent ?? "";
|
|
24823
|
+
let next = text3;
|
|
24824
|
+
try {
|
|
24825
|
+
next = rewrite2(text3, sheet.name);
|
|
24826
|
+
} catch {
|
|
24827
|
+
next = text3;
|
|
24828
|
+
}
|
|
24829
|
+
if (next === text3) continue;
|
|
24830
|
+
f6.textContent = next;
|
|
24831
|
+
changed = true;
|
|
24832
|
+
}
|
|
24833
|
+
return changed ? "changed" : "same";
|
|
24834
|
+
},
|
|
24835
|
+
(xml) => xml.includes(":f>")
|
|
24836
|
+
);
|
|
24837
|
+
}
|
|
24838
|
+
|
|
24839
|
+
// xlsx/edit/conditional-formulas.ts
|
|
24840
|
+
function rewriteConditionalRule(rule, rewrite2) {
|
|
24841
|
+
const safe2 = (formula) => {
|
|
24842
|
+
try {
|
|
24843
|
+
return rewrite2(formula);
|
|
24844
|
+
} catch {
|
|
24845
|
+
return formula;
|
|
24846
|
+
}
|
|
24847
|
+
};
|
|
24848
|
+
if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
|
|
24849
|
+
else if (rule.type === "expression") rule.formula = safe2(rule.formula);
|
|
24850
|
+
if (rule.type === "colorScale" || rule.type === "iconSet") {
|
|
24851
|
+
for (const threshold of rule.thresholds)
|
|
24852
|
+
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
24853
|
+
}
|
|
24854
|
+
if (rule.type === "dataBar") {
|
|
24855
|
+
for (const threshold of [rule.min, rule.max])
|
|
24856
|
+
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
24857
|
+
}
|
|
24858
|
+
if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
|
|
24859
|
+
}
|
|
24860
|
+
|
|
24861
|
+
// xlsx/edit/shift-formulas.ts
|
|
24862
|
+
function safe(rewrite2, formula, formulaSheet, at) {
|
|
24863
|
+
try {
|
|
24864
|
+
return rewrite2(formula, formulaSheet, at);
|
|
24865
|
+
} catch {
|
|
24866
|
+
return formula;
|
|
24867
|
+
}
|
|
24868
|
+
}
|
|
24869
|
+
function rewriteFormulas(workbook, rewrite2, formulaCells) {
|
|
24870
|
+
const bySheet = formulaCells && /* @__PURE__ */ new Map();
|
|
24871
|
+
if (bySheet)
|
|
24872
|
+
for (const cell of formulaCells ?? []) {
|
|
24873
|
+
const positions2 = bySheet.get(cell.sheet);
|
|
24874
|
+
if (positions2) positions2.push(cell);
|
|
24875
|
+
else bySheet.set(cell.sheet, [cell]);
|
|
24876
|
+
}
|
|
24877
|
+
workbook.sheets.forEach(
|
|
24878
|
+
(sheet, index2) => rewriteSheetFormulas(sheet, rewrite2, bySheet ? bySheet.get(index2) ?? [] : void 0)
|
|
24879
|
+
);
|
|
24880
|
+
for (const definedName of workbook.definedNames) {
|
|
24881
|
+
const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
|
|
24882
|
+
definedName.formula = safe(rewrite2, definedName.formula, local?.name ?? "");
|
|
24883
|
+
}
|
|
24884
|
+
}
|
|
24885
|
+
function rewriteSheetFormulas(sheet, rewrite2, formulaCells) {
|
|
24886
|
+
rewritePreservedFormulas(sheet, rewrite2);
|
|
24887
|
+
{
|
|
24888
|
+
const name = sheet.name;
|
|
24889
|
+
for (const table2 of sheet.tables)
|
|
24890
|
+
for (const [index2, column] of table2.columns.entries())
|
|
24891
|
+
if (column.calculatedColumnFormula !== void 0)
|
|
24892
|
+
column.calculatedColumnFormula = safe(rewrite2, column.calculatedColumnFormula, name, {
|
|
24893
|
+
row: table2.range.start.row + (table2.headerRow ? 1 : 0),
|
|
24894
|
+
col: table2.range.start.col + index2
|
|
24895
|
+
});
|
|
24896
|
+
if (formulaCells) {
|
|
24897
|
+
for (const at of formulaCells) {
|
|
24898
|
+
const cell = getCell(sheet, at.row, at.col);
|
|
24899
|
+
if (cell?.formula !== void 0) cell.formula = safe(rewrite2, cell.formula, name, at);
|
|
24900
|
+
}
|
|
24901
|
+
} else {
|
|
24902
|
+
sheet.rows.forEach(
|
|
24903
|
+
(cells, row2) => cells.forEach((cell, col) => {
|
|
24904
|
+
if (cell.formula !== void 0)
|
|
24905
|
+
cell.formula = safe(rewrite2, cell.formula, name, { row: row2, col });
|
|
24906
|
+
})
|
|
24907
|
+
);
|
|
24908
|
+
}
|
|
24909
|
+
for (const cf of sheet.conditionalFormats)
|
|
24910
|
+
for (const rule of cf.rules)
|
|
24911
|
+
rewriteConditionalRule(rule, (f6) => rewrite2(f6, name, cf.ranges[0]?.start));
|
|
24912
|
+
for (const dv of sheet.dataValidations) {
|
|
24913
|
+
if (dv.formula1 !== void 0)
|
|
24914
|
+
dv.formula1 = safe(rewrite2, dv.formula1, name, dv.ranges[0]?.start);
|
|
24915
|
+
if (dv.formula2 !== void 0)
|
|
24916
|
+
dv.formula2 = safe(rewrite2, dv.formula2, name, dv.ranges[0]?.start);
|
|
24917
|
+
}
|
|
24918
|
+
for (const link of sheet.hyperlinks)
|
|
24919
|
+
if (link.location && /![A-Za-z$]/.test(link.location))
|
|
24920
|
+
link.location = safe(rewrite2, link.location, name);
|
|
24921
|
+
for (const drawing of sheet.drawings) {
|
|
24922
|
+
if (drawing.kind !== "chart") continue;
|
|
24923
|
+
for (const series of drawing.series) {
|
|
24924
|
+
if (series.nameRef) series.nameRef = safe(rewrite2, series.nameRef, name);
|
|
24925
|
+
if (series.categoriesRef) series.categoriesRef = safe(rewrite2, series.categoriesRef, name);
|
|
24926
|
+
if (series.valuesRef) series.valuesRef = safe(rewrite2, series.valuesRef, name);
|
|
24927
|
+
}
|
|
24928
|
+
}
|
|
24929
|
+
}
|
|
24930
|
+
}
|
|
24931
|
+
|
|
24932
|
+
// xlsx/edit/table-header-names.ts
|
|
24933
|
+
function uniqueHeaders(texts) {
|
|
24934
|
+
const used = /* @__PURE__ */ new Set();
|
|
24935
|
+
return texts.map((text3, i2) => {
|
|
24936
|
+
let base = text3.trim() || `Column${i2 + 1}`;
|
|
24937
|
+
if (!used.has(base.toLowerCase())) {
|
|
24938
|
+
used.add(base.toLowerCase());
|
|
24939
|
+
return base;
|
|
24940
|
+
}
|
|
24941
|
+
for (let n2 = 2; ; n2++) {
|
|
24942
|
+
const candidate = `${base}${n2}`;
|
|
24943
|
+
if (!used.has(candidate.toLowerCase())) {
|
|
24944
|
+
used.add(candidate.toLowerCase());
|
|
24945
|
+
base = candidate;
|
|
24946
|
+
return base;
|
|
24947
|
+
}
|
|
24948
|
+
}
|
|
24949
|
+
});
|
|
24950
|
+
}
|
|
24951
|
+
|
|
24649
24952
|
// xlsx/edit/cell-values.ts
|
|
24650
24953
|
function tableHeaderAt(sheet, row2, col) {
|
|
24651
24954
|
return sheet.tables.find(
|
|
24652
24955
|
(t) => t.headerRow && t.range.start.row === row2 && col >= t.range.start.col && col <= t.range.end.col
|
|
24653
24956
|
);
|
|
24654
24957
|
}
|
|
24655
|
-
function syncTableHeader(ctx, sheet, row2, col) {
|
|
24958
|
+
function syncTableHeader(ctx, sheet, row2, col, formulaCells) {
|
|
24656
24959
|
const table2 = tableHeaderAt(sheet, row2, col);
|
|
24657
24960
|
if (!table2) return;
|
|
24658
24961
|
const column = table2.columns[col - table2.range.start.col];
|
|
24659
24962
|
if (!column) return;
|
|
24660
24963
|
const text3 = displayText(ctx.workbook, getCell(sheet, row2, col)).trim();
|
|
24661
|
-
if (text3
|
|
24964
|
+
if (!text3 || column.name === text3) return;
|
|
24965
|
+
const oldName = column.name;
|
|
24966
|
+
const others = table2.columns.filter((entry3) => entry3 !== column).map((entry3) => entry3.name);
|
|
24967
|
+
const newName = uniqueHeaders([...others, text3]).at(-1);
|
|
24968
|
+
column.name = newName;
|
|
24969
|
+
if (newName !== text3) writeValue(sheet, row2, col, newName);
|
|
24970
|
+
const index2 = ctx.workbook.sheets.indexOf(sheet);
|
|
24971
|
+
const cells = formulaCells && (formulaCells.some((cell) => cell.sheet === index2 && cell.row === row2 && cell.col === col) ? formulaCells : [...formulaCells, { sheet: index2, row: row2, col }]);
|
|
24972
|
+
rewriteFormulas(
|
|
24973
|
+
ctx.workbook,
|
|
24974
|
+
(formula, formulaSheet, at) => renameTableColumnInFormula(
|
|
24975
|
+
formula,
|
|
24976
|
+
table2.name,
|
|
24977
|
+
oldName,
|
|
24978
|
+
newName,
|
|
24979
|
+
formulaSheet === sheet.name && !!at && rangeContains(table2.range, at)
|
|
24980
|
+
),
|
|
24981
|
+
cells
|
|
24982
|
+
);
|
|
24662
24983
|
}
|
|
24663
24984
|
function writeScopes(sheet, index2, range, parts = []) {
|
|
24664
24985
|
const r = normalizeRange(range);
|
|
@@ -24668,9 +24989,9 @@ function writeScopes(sheet, index2, range, parts = []) {
|
|
|
24668
24989
|
cellRange(t.range.start.row, t.range.start.col, t.range.start.row, t.range.end.col)
|
|
24669
24990
|
)
|
|
24670
24991
|
);
|
|
24671
|
-
|
|
24992
|
+
if (touchesHeader) return [{ kind: "refs" }, { kind: "cells", sheet: index2, ranges: [r] }];
|
|
24672
24993
|
const scopes = [{ kind: "cells", sheet: index2, ranges: [r] }];
|
|
24673
|
-
if (
|
|
24994
|
+
if (parts.length) scopes.push({ kind: "parts", sheet: index2, parts });
|
|
24674
24995
|
return scopes;
|
|
24675
24996
|
}
|
|
24676
24997
|
function writeInput(ctx, sheet, row2, col, text3) {
|
|
@@ -24721,9 +25042,9 @@ function setCellInput(ctx, s, row2, col, text3) {
|
|
|
24721
25042
|
`Typing in ${formatAddress({ row: row2, col })}`,
|
|
24722
25043
|
"cells",
|
|
24723
25044
|
writeScopes(sheet, s, range),
|
|
24724
|
-
() => {
|
|
25045
|
+
(formulaCells) => {
|
|
24725
25046
|
writeInput(ctx, sheet, row2, col, text3);
|
|
24726
|
-
syncTableHeader(ctx, sheet, row2, col);
|
|
25047
|
+
syncTableHeader(ctx, sheet, row2, col, formulaCells);
|
|
24727
25048
|
},
|
|
24728
25049
|
{ sheet: s, ranges: [range] }
|
|
24729
25050
|
);
|
|
@@ -24735,9 +25056,9 @@ function setCellValue(ctx, s, row2, col, value) {
|
|
|
24735
25056
|
`Edit ${formatAddress({ row: row2, col })}`,
|
|
24736
25057
|
"cells",
|
|
24737
25058
|
writeScopes(sheet, s, range),
|
|
24738
|
-
() => {
|
|
25059
|
+
(formulaCells) => {
|
|
24739
25060
|
writeValue(sheet, row2, col, value);
|
|
24740
|
-
syncTableHeader(ctx, sheet, row2, col);
|
|
25061
|
+
syncTableHeader(ctx, sheet, row2, col, formulaCells);
|
|
24741
25062
|
},
|
|
24742
25063
|
{ sheet: s, ranges: [range] }
|
|
24743
25064
|
);
|
|
@@ -25164,7 +25485,7 @@ function fillRange(ctx, s, source2, target, mode = "auto") {
|
|
|
25164
25485
|
ctx.run(
|
|
25165
25486
|
"Fill",
|
|
25166
25487
|
"cells",
|
|
25167
|
-
|
|
25488
|
+
writeScopes(sheet, s, all2),
|
|
25168
25489
|
() => {
|
|
25169
25490
|
const laneCount = vertical ? src.end.col - src.start.col + 1 : src.end.row - src.start.row + 1;
|
|
25170
25491
|
const length = vertical ? src.end.row - src.start.row + 1 : src.end.col - src.start.col + 1;
|
|
@@ -25187,6 +25508,7 @@ function fillRange(ctx, s, source2, target, mode = "auto") {
|
|
|
25187
25508
|
const step2 = series?.(k);
|
|
25188
25509
|
const cell = !step2 || step2.kind === "copy" ? copyCell(origin, row2 - srcRow, col - srcCol) : { value: step2.value, ...origin.styleId ? { styleId: origin.styleId } : {} };
|
|
25189
25510
|
putCell(sheet, row2, col, cell);
|
|
25511
|
+
syncTableHeader(ctx, sheet, row2, col);
|
|
25190
25512
|
}
|
|
25191
25513
|
}
|
|
25192
25514
|
},
|
|
@@ -25225,28 +25547,6 @@ function removeValidationArea(rules, area) {
|
|
|
25225
25547
|
});
|
|
25226
25548
|
}
|
|
25227
25549
|
|
|
25228
|
-
// xlsx/edit/conditional-formulas.ts
|
|
25229
|
-
function rewriteConditionalRule(rule, rewrite2) {
|
|
25230
|
-
const safe2 = (formula) => {
|
|
25231
|
-
try {
|
|
25232
|
-
return rewrite2(formula);
|
|
25233
|
-
} catch {
|
|
25234
|
-
return formula;
|
|
25235
|
-
}
|
|
25236
|
-
};
|
|
25237
|
-
if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
|
|
25238
|
-
else if (rule.type === "expression") rule.formula = safe2(rule.formula);
|
|
25239
|
-
if (rule.type === "colorScale" || rule.type === "iconSet") {
|
|
25240
|
-
for (const threshold of rule.thresholds)
|
|
25241
|
-
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
25242
|
-
}
|
|
25243
|
-
if (rule.type === "dataBar") {
|
|
25244
|
-
for (const threshold of [rule.min, rule.max])
|
|
25245
|
-
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
25246
|
-
}
|
|
25247
|
-
if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
|
|
25248
|
-
}
|
|
25249
|
-
|
|
25250
25550
|
// xlsx/edit/conditional-formats.ts
|
|
25251
25551
|
function formatAt(sheet, index2) {
|
|
25252
25552
|
const format = sheet.conditionalFormats[index2];
|
|
@@ -25656,168 +25956,6 @@ function setBorders(ctx, s, range, preset, edge2 = { style: "thin" }) {
|
|
|
25656
25956
|
);
|
|
25657
25957
|
}
|
|
25658
25958
|
|
|
25659
|
-
// xlsx/edit/shift-preserved.ts
|
|
25660
|
-
var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
|
|
25661
|
-
function descendants3(root, ns, local) {
|
|
25662
|
-
return Array.from(root.getElementsByTagNameNS(ns, local));
|
|
25663
|
-
}
|
|
25664
|
-
function editEntries(sheet, key, edit, quick) {
|
|
25665
|
-
const list = sheet.preserved.get(key);
|
|
25666
|
-
if (!list) return;
|
|
25667
|
-
const next = [];
|
|
25668
|
-
for (const xml of list) {
|
|
25669
|
-
if (!quick(xml)) {
|
|
25670
|
-
next.push(xml);
|
|
25671
|
-
continue;
|
|
25672
|
-
}
|
|
25673
|
-
let doc;
|
|
25674
|
-
try {
|
|
25675
|
-
doc = parseXml(xml);
|
|
25676
|
-
} catch {
|
|
25677
|
-
next.push(xml);
|
|
25678
|
-
continue;
|
|
25679
|
-
}
|
|
25680
|
-
const outcome = edit(doc.documentElement);
|
|
25681
|
-
if (outcome === "same") next.push(xml);
|
|
25682
|
-
else if (outcome === "changed") next.push(buildXml(doc));
|
|
25683
|
-
}
|
|
25684
|
-
if (next.length) sheet.preserved.set(key, next);
|
|
25685
|
-
else sheet.preserved.delete(key);
|
|
25686
|
-
}
|
|
25687
|
-
function shiftBreaks(root, shift2) {
|
|
25688
|
-
let changed = false;
|
|
25689
|
-
for (const brk of elements(root).filter((e) => e.localName === "brk")) {
|
|
25690
|
-
const id = Number(brk.getAttribute("id") ?? "0");
|
|
25691
|
-
const moved = shiftIndex(id, shift2);
|
|
25692
|
-
if (moved === id) continue;
|
|
25693
|
-
changed = true;
|
|
25694
|
-
if (moved === void 0 || moved === 0) root.removeChild(brk);
|
|
25695
|
-
else brk.setAttribute("id", String(moved));
|
|
25696
|
-
}
|
|
25697
|
-
if (!changed) return "same";
|
|
25698
|
-
const left2 = elements(root).filter((e) => e.localName === "brk");
|
|
25699
|
-
if (!left2.length) return "drop";
|
|
25700
|
-
if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
|
|
25701
|
-
if (root.hasAttribute("manualBreakCount")) {
|
|
25702
|
-
const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
|
|
25703
|
-
root.setAttribute("manualBreakCount", String(manual));
|
|
25704
|
-
}
|
|
25705
|
-
return "changed";
|
|
25706
|
-
}
|
|
25707
|
-
function removeUpwards(node, root) {
|
|
25708
|
-
let current = node;
|
|
25709
|
-
while (current && current !== root) {
|
|
25710
|
-
const parent = current.parentNode;
|
|
25711
|
-
parent?.removeChild(current);
|
|
25712
|
-
if (!parent) break;
|
|
25713
|
-
const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
|
|
25714
|
-
if (!emptied) break;
|
|
25715
|
-
current = parent;
|
|
25716
|
-
}
|
|
25717
|
-
}
|
|
25718
|
-
function shiftSqrefs(root, moveRange) {
|
|
25719
|
-
let changed = false;
|
|
25720
|
-
for (const sqref2 of descendants3(root, XM3, "sqref")) {
|
|
25721
|
-
const old = sqref2.textContent ?? "";
|
|
25722
|
-
const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
|
|
25723
|
-
const text3 = ranges.map(formatRange).join(" ");
|
|
25724
|
-
if (text3 === old.trim()) continue;
|
|
25725
|
-
changed = true;
|
|
25726
|
-
const owner = sqref2.parentNode;
|
|
25727
|
-
if (ranges.length) sqref2.textContent = text3;
|
|
25728
|
-
else if (owner) removeUpwards(owner, root);
|
|
25729
|
-
}
|
|
25730
|
-
if (!changed) return "same";
|
|
25731
|
-
for (const list of elements(root).flatMap((ext) => elements(ext)))
|
|
25732
|
-
if (list.localName === "dataValidations" && list.hasAttribute("count"))
|
|
25733
|
-
list.setAttribute("count", String(elements(list).length));
|
|
25734
|
-
return elements(root).length > 0 ? "changed" : "drop";
|
|
25735
|
-
}
|
|
25736
|
-
function shiftPreservedXml(sheet, shift2, moveRange, banded) {
|
|
25737
|
-
if (!banded)
|
|
25738
|
-
editEntries(
|
|
25739
|
-
sheet,
|
|
25740
|
-
shift2.axis === "row" ? "rowBreaks" : "colBreaks",
|
|
25741
|
-
(root) => shiftBreaks(root, shift2),
|
|
25742
|
-
(xml) => xml.includes("brk")
|
|
25743
|
-
);
|
|
25744
|
-
editEntries(
|
|
25745
|
-
sheet,
|
|
25746
|
-
"extLst",
|
|
25747
|
-
(root) => shiftSqrefs(root, moveRange),
|
|
25748
|
-
(xml) => xml.includes("sqref")
|
|
25749
|
-
);
|
|
25750
|
-
}
|
|
25751
|
-
function rewritePreservedFormulas(sheet, rewrite2) {
|
|
25752
|
-
editEntries(
|
|
25753
|
-
sheet,
|
|
25754
|
-
"extLst",
|
|
25755
|
-
(root) => {
|
|
25756
|
-
let changed = false;
|
|
25757
|
-
for (const f6 of descendants3(root, XM3, "f")) {
|
|
25758
|
-
const text3 = f6.textContent ?? "";
|
|
25759
|
-
let next = text3;
|
|
25760
|
-
try {
|
|
25761
|
-
next = rewrite2(text3, sheet.name);
|
|
25762
|
-
} catch {
|
|
25763
|
-
next = text3;
|
|
25764
|
-
}
|
|
25765
|
-
if (next === text3) continue;
|
|
25766
|
-
f6.textContent = next;
|
|
25767
|
-
changed = true;
|
|
25768
|
-
}
|
|
25769
|
-
return changed ? "changed" : "same";
|
|
25770
|
-
},
|
|
25771
|
-
(xml) => xml.includes(":f>")
|
|
25772
|
-
);
|
|
25773
|
-
}
|
|
25774
|
-
|
|
25775
|
-
// xlsx/edit/shift-formulas.ts
|
|
25776
|
-
function safe(rewrite2, formula, formulaSheet) {
|
|
25777
|
-
try {
|
|
25778
|
-
return rewrite2(formula, formulaSheet);
|
|
25779
|
-
} catch {
|
|
25780
|
-
return formula;
|
|
25781
|
-
}
|
|
25782
|
-
}
|
|
25783
|
-
function rewriteFormulas(workbook, rewrite2) {
|
|
25784
|
-
for (const sheet of workbook.sheets) rewriteSheetFormulas(sheet, rewrite2);
|
|
25785
|
-
for (const definedName of workbook.definedNames) {
|
|
25786
|
-
const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
|
|
25787
|
-
definedName.formula = safe(rewrite2, definedName.formula, local?.name ?? "");
|
|
25788
|
-
}
|
|
25789
|
-
}
|
|
25790
|
-
function rewriteSheetFormulas(sheet, rewrite2) {
|
|
25791
|
-
rewritePreservedFormulas(sheet, rewrite2);
|
|
25792
|
-
{
|
|
25793
|
-
const name = sheet.name;
|
|
25794
|
-
for (const table2 of sheet.tables)
|
|
25795
|
-
for (const column of table2.columns)
|
|
25796
|
-
if (column.calculatedColumnFormula !== void 0)
|
|
25797
|
-
column.calculatedColumnFormula = safe(rewrite2, column.calculatedColumnFormula, name);
|
|
25798
|
-
for (const cells of sheet.rows.values())
|
|
25799
|
-
for (const cell of cells.values())
|
|
25800
|
-
if (cell.formula !== void 0) cell.formula = safe(rewrite2, cell.formula, name);
|
|
25801
|
-
for (const cf of sheet.conditionalFormats)
|
|
25802
|
-
for (const rule of cf.rules) rewriteConditionalRule(rule, (f6) => rewrite2(f6, name));
|
|
25803
|
-
for (const dv of sheet.dataValidations) {
|
|
25804
|
-
if (dv.formula1 !== void 0) dv.formula1 = safe(rewrite2, dv.formula1, name);
|
|
25805
|
-
if (dv.formula2 !== void 0) dv.formula2 = safe(rewrite2, dv.formula2, name);
|
|
25806
|
-
}
|
|
25807
|
-
for (const link of sheet.hyperlinks)
|
|
25808
|
-
if (link.location && /![A-Za-z$]/.test(link.location))
|
|
25809
|
-
link.location = safe(rewrite2, link.location, name);
|
|
25810
|
-
for (const drawing of sheet.drawings) {
|
|
25811
|
-
if (drawing.kind !== "chart") continue;
|
|
25812
|
-
for (const series of drawing.series) {
|
|
25813
|
-
if (series.nameRef) series.nameRef = safe(rewrite2, series.nameRef, name);
|
|
25814
|
-
if (series.categoriesRef) series.categoriesRef = safe(rewrite2, series.categoriesRef, name);
|
|
25815
|
-
if (series.valuesRef) series.valuesRef = safe(rewrite2, series.valuesRef, name);
|
|
25816
|
-
}
|
|
25817
|
-
}
|
|
25818
|
-
}
|
|
25819
|
-
}
|
|
25820
|
-
|
|
25821
25959
|
// xlsx/edit/shift-sheet.ts
|
|
25822
25960
|
function shiftSheetContent(sheet, shift2, band) {
|
|
25823
25961
|
const moveRange = (range) => band ? shiftRangeInBand(range, shift2, band.lo, band.hi) : shiftRange(range, shift2);
|
|
@@ -25839,8 +25977,10 @@ function shiftSheetContent(sheet, shift2, band) {
|
|
|
25839
25977
|
if (sheet.autoFilter) {
|
|
25840
25978
|
const old = sheet.autoFilter.range;
|
|
25841
25979
|
const range = moveRange(old);
|
|
25842
|
-
if (!range)
|
|
25843
|
-
|
|
25980
|
+
if (!range) {
|
|
25981
|
+
delete sheet.autoFilter;
|
|
25982
|
+
clearFilteredRows(sheet);
|
|
25983
|
+
} else {
|
|
25844
25984
|
const filter2 = { ...sheet.autoFilter, range };
|
|
25845
25985
|
if (shift2.axis === "col" && filter2.columns)
|
|
25846
25986
|
filter2.columns = filter2.columns.flatMap((fc) => {
|
|
@@ -25991,6 +26131,9 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
|
|
|
25991
26131
|
const sheet = sheetAt(ctx.workbook, s);
|
|
25992
26132
|
const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
|
|
25993
26133
|
const shift2 = { axis, at, count: insert ? count2 : -count2 };
|
|
26134
|
+
const info = { sheet: s, structural: true };
|
|
26135
|
+
if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
|
|
26136
|
+
info.calc = { kind: "shift", sheet: s, shift: shift2 };
|
|
25994
26137
|
ctx.run(
|
|
25995
26138
|
`${insert ? "Insert" : "Delete"} ${noun}`,
|
|
25996
26139
|
"structure",
|
|
@@ -25999,7 +26142,7 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
|
|
|
25999
26142
|
applyAxisShift(ctx, sheet, shift2);
|
|
26000
26143
|
if (insert) inheritFormats(sheet, axis, at, count2);
|
|
26001
26144
|
},
|
|
26002
|
-
|
|
26145
|
+
info
|
|
26003
26146
|
);
|
|
26004
26147
|
}
|
|
26005
26148
|
var insertRows = (ctx, s, at, count2) => shiftAxis(ctx, s, "row", at, count2, true);
|
|
@@ -26807,14 +26950,13 @@ function pasteAt(ctx, s, at, payload, request) {
|
|
|
26807
26950
|
if (cut && operation !== "none")
|
|
26808
26951
|
throw new RangeError("Paste operations are not available for cut cells.");
|
|
26809
26952
|
const destCells = { kind: "cells", sheet: s, ranges: [dest] };
|
|
26810
|
-
const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : [
|
|
26811
|
-
|
|
26812
|
-
|
|
26813
|
-
|
|
26814
|
-
|
|
26815
|
-
|
|
26816
|
-
|
|
26817
|
-
];
|
|
26953
|
+
const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : writeScopes(sheet, s, dest, [
|
|
26954
|
+
"merges",
|
|
26955
|
+
"comments",
|
|
26956
|
+
"dataValidations",
|
|
26957
|
+
"hyperlinks",
|
|
26958
|
+
"conditionalFormats"
|
|
26959
|
+
]);
|
|
26818
26960
|
const move = cut && {
|
|
26819
26961
|
fromSheet: sheetAt(workbook, cut.sheet).name,
|
|
26820
26962
|
range: cut.range,
|
|
@@ -26887,6 +27029,8 @@ function pasteAt(ctx, s, at, payload, request) {
|
|
|
26887
27029
|
const origin = cells.source?.range.start;
|
|
26888
27030
|
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);
|
|
26889
27031
|
writeClip(workbook, sheet, row2, col, clip, mode, formula, styleOf2, operation);
|
|
27032
|
+
if (mode !== "formats" && mode !== "comments" && mode !== "validation")
|
|
27033
|
+
syncTableHeader(ctx, sheet, row2, col);
|
|
26890
27034
|
}
|
|
26891
27035
|
if (mode === "all" || mode === "mergeFormats" || mode === "noBorders" || mode === "formats") {
|
|
26892
27036
|
sheet.merges = sheet.merges.filter((m) => !rangesIntersect(m, dest));
|
|
@@ -26930,14 +27074,13 @@ function pasteSelection(ctx, sheet, selection, payload, request) {
|
|
|
26930
27074
|
return ctx.run(
|
|
26931
27075
|
"Paste",
|
|
26932
27076
|
"cells",
|
|
26933
|
-
[
|
|
26934
|
-
|
|
26935
|
-
|
|
26936
|
-
|
|
26937
|
-
|
|
26938
|
-
|
|
26939
|
-
|
|
26940
|
-
],
|
|
27077
|
+
writeScopes(sheetAt(ctx.workbook, sheet), sheet, dest, [
|
|
27078
|
+
"merges",
|
|
27079
|
+
"comments",
|
|
27080
|
+
"dataValidations",
|
|
27081
|
+
"hyperlinks",
|
|
27082
|
+
"conditionalFormats"
|
|
27083
|
+
]),
|
|
26941
27084
|
() => {
|
|
26942
27085
|
for (let row2 = dest.start.row; row2 <= dest.end.row; row2 += height)
|
|
26943
27086
|
for (let col = dest.start.col; col <= dest.end.col; col += width)
|
|
@@ -27089,9 +27232,19 @@ function setHidden(ctx, s, axis, indices, hidden) {
|
|
|
27089
27232
|
}
|
|
27090
27233
|
for (const row2 of indices) {
|
|
27091
27234
|
const info = { ...sheet.rowInfo.get(row2) };
|
|
27235
|
+
if (info.filteredOut) {
|
|
27236
|
+
if (hidden) info.manuallyHidden = true;
|
|
27237
|
+
else delete info.manuallyHidden;
|
|
27238
|
+
sheet.rowInfo.set(row2, info);
|
|
27239
|
+
continue;
|
|
27240
|
+
}
|
|
27241
|
+
const filter2 = sheet.autoFilter;
|
|
27242
|
+
if (hidden && filter2?.columns?.length && row2 > filter2.range.start.row && row2 <= filter2.range.end.row)
|
|
27243
|
+
info.filteredOut = false;
|
|
27092
27244
|
if (hidden) info.hidden = true;
|
|
27093
27245
|
else {
|
|
27094
27246
|
delete info.hidden;
|
|
27247
|
+
delete info.filteredOut;
|
|
27095
27248
|
if (info.height === 0) delete info.height;
|
|
27096
27249
|
}
|
|
27097
27250
|
if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
|
|
@@ -27243,16 +27396,8 @@ function currentRegion(sheet, at) {
|
|
|
27243
27396
|
function applyFilter(ctx, sheet, filter2) {
|
|
27244
27397
|
const { range } = filter2;
|
|
27245
27398
|
for (let row2 = range.start.row + 1; row2 <= range.end.row; row2++) {
|
|
27246
|
-
const visible = (
|
|
27247
|
-
|
|
27248
|
-
const text3 = displayText(ctx.workbook, getCell(sheet, row2, range.start.col + fc.offset));
|
|
27249
|
-
return text3 === "" ? !!fc.blank : (fc.values ?? []).includes(text3);
|
|
27250
|
-
});
|
|
27251
|
-
const info = { ...sheet.rowInfo.get(row2) };
|
|
27252
|
-
if (visible) delete info.hidden;
|
|
27253
|
-
else info.hidden = true;
|
|
27254
|
-
if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
|
|
27255
|
-
else sheet.rowInfo.delete(row2);
|
|
27399
|
+
const visible = rowMatchesFilter(ctx.workbook, sheet, row2, filter2);
|
|
27400
|
+
setRowFiltered(sheet, row2, !visible, !!filter2.columns?.length);
|
|
27256
27401
|
}
|
|
27257
27402
|
}
|
|
27258
27403
|
function setAutoFilter(ctx, s, range) {
|
|
@@ -27414,16 +27559,16 @@ var isSpilledAt = (workbook, at) => {
|
|
|
27414
27559
|
return !!sheet && isSpilledCell(getCell(sheet, at.row, at.col));
|
|
27415
27560
|
};
|
|
27416
27561
|
var replaceQuery = (query) => query.lookIn === "comments" ? query : { ...query, lookIn: "formulas" };
|
|
27417
|
-
function replaceScopes(query, sheet, matches2) {
|
|
27562
|
+
function replaceScopes(ctx, query, sheet, matches2) {
|
|
27418
27563
|
if (query.lookIn === "comments") return [{ kind: "parts", sheet, parts: ["comments"] }];
|
|
27419
27564
|
const ranges = matches2.map((m) => ({
|
|
27420
27565
|
start: { row: m.row, col: m.col },
|
|
27421
27566
|
end: { row: m.row, col: m.col }
|
|
27422
27567
|
}));
|
|
27423
|
-
|
|
27424
|
-
|
|
27425
|
-
|
|
27426
|
-
];
|
|
27568
|
+
const header = ranges.some(
|
|
27569
|
+
(range) => writeScopes(sheetAt(ctx.workbook, sheet), sheet, range).some((scope) => scope.kind === "refs")
|
|
27570
|
+
);
|
|
27571
|
+
return [...header ? [{ kind: "refs" }] : [], { kind: "cells", sheet, ranges }];
|
|
27427
27572
|
}
|
|
27428
27573
|
function applyReplace(ctx, query, replacement, matches2) {
|
|
27429
27574
|
let changed = 0;
|
|
@@ -27453,14 +27598,24 @@ function replaceAll(ctx, query, replacement) {
|
|
|
27453
27598
|
const sheets = [...new Set(matches2.map((m) => m.sheet))];
|
|
27454
27599
|
const scopes = sheets.flatMap(
|
|
27455
27600
|
(sheet) => replaceScopes(
|
|
27601
|
+
ctx,
|
|
27456
27602
|
q,
|
|
27457
27603
|
sheet,
|
|
27458
27604
|
matches2.filter((m) => m.sheet === sheet)
|
|
27459
27605
|
)
|
|
27460
27606
|
);
|
|
27461
|
-
|
|
27462
|
-
|
|
27463
|
-
|
|
27607
|
+
const uniqueScopes = scopes.filter(
|
|
27608
|
+
(scope, index2) => scope.kind !== "refs" || scopes.findIndex((entry3) => entry3.kind === "refs") === index2
|
|
27609
|
+
);
|
|
27610
|
+
return ctx.run(
|
|
27611
|
+
"Replace",
|
|
27612
|
+
"cells",
|
|
27613
|
+
uniqueScopes,
|
|
27614
|
+
() => applyReplace(ctx, q, replacement, matches2),
|
|
27615
|
+
{
|
|
27616
|
+
...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
|
|
27617
|
+
}
|
|
27618
|
+
);
|
|
27464
27619
|
}
|
|
27465
27620
|
function replaceOne(ctx, query, replacement, at) {
|
|
27466
27621
|
const q = replaceQuery(query);
|
|
@@ -27473,7 +27628,7 @@ function replaceOne(ctx, query, replacement, at) {
|
|
|
27473
27628
|
ctx.run(
|
|
27474
27629
|
"Replace",
|
|
27475
27630
|
"cells",
|
|
27476
|
-
replaceScopes(q, at.sheet, [match2]),
|
|
27631
|
+
replaceScopes(ctx, q, at.sheet, [match2]),
|
|
27477
27632
|
() => applyReplace(ctx, q, replacement, [match2]),
|
|
27478
27633
|
{ sheet: at.sheet }
|
|
27479
27634
|
);
|
|
@@ -28476,90 +28631,6 @@ function applyTotalsRow(sheet, table2) {
|
|
|
28476
28631
|
});
|
|
28477
28632
|
}
|
|
28478
28633
|
|
|
28479
|
-
// xlsx/edit/tables.ts
|
|
28480
|
-
function nextTableName(workbook) {
|
|
28481
|
-
const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
|
|
28482
|
-
const names = new Set(workbook.definedNames.map((n2) => n2.name.toLowerCase()));
|
|
28483
|
-
for (let n2 = 1; ; n2++) if (!taken.has(`table${n2}`) && !names.has(`table${n2}`)) return `Table${n2}`;
|
|
28484
|
-
}
|
|
28485
|
-
function uniqueHeaders(texts) {
|
|
28486
|
-
const used = /* @__PURE__ */ new Set();
|
|
28487
|
-
return texts.map((text3, i2) => {
|
|
28488
|
-
let base = text3.trim() || `Column${i2 + 1}`;
|
|
28489
|
-
if (!used.has(base.toLowerCase())) {
|
|
28490
|
-
used.add(base.toLowerCase());
|
|
28491
|
-
return base;
|
|
28492
|
-
}
|
|
28493
|
-
for (let n2 = 2; ; n2++) {
|
|
28494
|
-
const candidate = `${base}${n2}`;
|
|
28495
|
-
if (!used.has(candidate.toLowerCase())) {
|
|
28496
|
-
used.add(candidate.toLowerCase());
|
|
28497
|
-
base = candidate;
|
|
28498
|
-
return base;
|
|
28499
|
-
}
|
|
28500
|
-
}
|
|
28501
|
-
});
|
|
28502
|
-
}
|
|
28503
|
-
function createTable(ctx, s, range, hasHeader, styleName = "TableStyleMedium2") {
|
|
28504
|
-
const { workbook } = ctx;
|
|
28505
|
-
const sheet = sheetAt(workbook, s);
|
|
28506
|
-
let r = normalizeRange(range);
|
|
28507
|
-
if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
|
|
28508
|
-
if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
|
|
28509
|
-
throw new Error("A table cannot overlap another table.");
|
|
28510
|
-
if (sheet.merges.some((m) => rangesIntersect(m, r)))
|
|
28511
|
-
throw new Error("A table cannot contain merged cells.");
|
|
28512
|
-
return ctx.run(
|
|
28513
|
-
"Create table",
|
|
28514
|
-
"structure",
|
|
28515
|
-
[hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
|
|
28516
|
-
() => {
|
|
28517
|
-
if (!hasHeader) {
|
|
28518
|
-
const shift2 = { axis: "row", at: r.start.row, count: 1 };
|
|
28519
|
-
const band = { lo: r.start.col, hi: r.end.col };
|
|
28520
|
-
rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
|
|
28521
|
-
shiftSheetContent(sheet, shift2, band);
|
|
28522
|
-
r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
|
|
28523
|
-
}
|
|
28524
|
-
const width = r.end.col - r.start.col + 1;
|
|
28525
|
-
const texts = Array.from(
|
|
28526
|
-
{ length: width },
|
|
28527
|
-
(_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
|
|
28528
|
-
);
|
|
28529
|
-
const headers = uniqueHeaders(texts);
|
|
28530
|
-
const columns = headers.map((name2, i2) => {
|
|
28531
|
-
const cell = getCell(sheet, r.start.row, r.start.col + i2);
|
|
28532
|
-
if (cell?.value !== name2) {
|
|
28533
|
-
const styleId = cell?.styleId;
|
|
28534
|
-
writeValue(sheet, r.start.row, r.start.col + i2, name2);
|
|
28535
|
-
const written = getCell(sheet, r.start.row, r.start.col + i2);
|
|
28536
|
-
if (written && styleId) written.styleId = styleId;
|
|
28537
|
-
}
|
|
28538
|
-
return { name: name2 };
|
|
28539
|
-
});
|
|
28540
|
-
const name = nextTableName(workbook);
|
|
28541
|
-
const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
|
|
28542
|
-
const table2 = {
|
|
28543
|
-
id,
|
|
28544
|
-
name,
|
|
28545
|
-
displayName: name,
|
|
28546
|
-
range: r,
|
|
28547
|
-
headerRow: true,
|
|
28548
|
-
totalsRow: false,
|
|
28549
|
-
columns,
|
|
28550
|
-
styleName,
|
|
28551
|
-
showRowStripes: true,
|
|
28552
|
-
showColumnStripes: false,
|
|
28553
|
-
showFirstColumn: false,
|
|
28554
|
-
showLastColumn: false
|
|
28555
|
-
};
|
|
28556
|
-
sheet.tables.push(table2);
|
|
28557
|
-
return table2;
|
|
28558
|
-
},
|
|
28559
|
-
{ sheet: s, ranges: [r], structural: !hasHeader }
|
|
28560
|
-
);
|
|
28561
|
-
}
|
|
28562
|
-
|
|
28563
28634
|
// xlsx/edit/table-edits.ts
|
|
28564
28635
|
function tableIndex(sheet, ref) {
|
|
28565
28636
|
const index2 = typeof ref === "number" ? ref : sheet.tables.findIndex((t) => t.name.toLowerCase() === ref.toLowerCase());
|
|
@@ -31815,8 +31886,8 @@ function setSheetState(ctx, index2, state) {
|
|
|
31815
31886
|
const { workbook } = ctx;
|
|
31816
31887
|
const sheet = sheetAt(workbook, index2);
|
|
31817
31888
|
if (sheet.state === state) return;
|
|
31889
|
+
assertUnlocked(workbook);
|
|
31818
31890
|
if (state !== "visible") {
|
|
31819
|
-
assertUnlocked(workbook);
|
|
31820
31891
|
if (sheet.state === "visible" && visibleCount(workbook) <= 1)
|
|
31821
31892
|
throw new Error("A workbook must contain at least one visible sheet.");
|
|
31822
31893
|
}
|
|
@@ -31846,6 +31917,72 @@ function setTabColor(ctx, index2, color) {
|
|
|
31846
31917
|
);
|
|
31847
31918
|
}
|
|
31848
31919
|
|
|
31920
|
+
// xlsx/edit/tables.ts
|
|
31921
|
+
function nextTableName(workbook) {
|
|
31922
|
+
const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
|
|
31923
|
+
const names = new Set(workbook.definedNames.map((n2) => n2.name.toLowerCase()));
|
|
31924
|
+
for (let n2 = 1; ; n2++) if (!taken.has(`table${n2}`) && !names.has(`table${n2}`)) return `Table${n2}`;
|
|
31925
|
+
}
|
|
31926
|
+
function createTable(ctx, s, range, hasHeader, styleName = "TableStyleMedium2") {
|
|
31927
|
+
const { workbook } = ctx;
|
|
31928
|
+
const sheet = sheetAt(workbook, s);
|
|
31929
|
+
let r = normalizeRange(range);
|
|
31930
|
+
if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
|
|
31931
|
+
if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
|
|
31932
|
+
throw new Error("A table cannot overlap another table.");
|
|
31933
|
+
if (sheet.merges.some((m) => rangesIntersect(m, r)))
|
|
31934
|
+
throw new Error("A table cannot contain merged cells.");
|
|
31935
|
+
return ctx.run(
|
|
31936
|
+
"Create table",
|
|
31937
|
+
"structure",
|
|
31938
|
+
[hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
|
|
31939
|
+
() => {
|
|
31940
|
+
if (!hasHeader) {
|
|
31941
|
+
const shift2 = { axis: "row", at: r.start.row, count: 1 };
|
|
31942
|
+
const band = { lo: r.start.col, hi: r.end.col };
|
|
31943
|
+
rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
|
|
31944
|
+
shiftSheetContent(sheet, shift2, band);
|
|
31945
|
+
r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
|
|
31946
|
+
}
|
|
31947
|
+
const width = r.end.col - r.start.col + 1;
|
|
31948
|
+
const texts = Array.from(
|
|
31949
|
+
{ length: width },
|
|
31950
|
+
(_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
|
|
31951
|
+
);
|
|
31952
|
+
const headers = uniqueHeaders(texts);
|
|
31953
|
+
const columns = headers.map((name2, i2) => {
|
|
31954
|
+
const cell = getCell(sheet, r.start.row, r.start.col + i2);
|
|
31955
|
+
if (cell?.value !== name2) {
|
|
31956
|
+
const styleId = cell?.styleId;
|
|
31957
|
+
writeValue(sheet, r.start.row, r.start.col + i2, name2);
|
|
31958
|
+
const written = getCell(sheet, r.start.row, r.start.col + i2);
|
|
31959
|
+
if (written && styleId) written.styleId = styleId;
|
|
31960
|
+
}
|
|
31961
|
+
return { name: name2 };
|
|
31962
|
+
});
|
|
31963
|
+
const name = nextTableName(workbook);
|
|
31964
|
+
const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
|
|
31965
|
+
const table2 = {
|
|
31966
|
+
id,
|
|
31967
|
+
name,
|
|
31968
|
+
displayName: name,
|
|
31969
|
+
range: r,
|
|
31970
|
+
headerRow: true,
|
|
31971
|
+
totalsRow: false,
|
|
31972
|
+
columns,
|
|
31973
|
+
styleName,
|
|
31974
|
+
showRowStripes: true,
|
|
31975
|
+
showColumnStripes: false,
|
|
31976
|
+
showFirstColumn: false,
|
|
31977
|
+
showLastColumn: false
|
|
31978
|
+
};
|
|
31979
|
+
sheet.tables.push(table2);
|
|
31980
|
+
return table2;
|
|
31981
|
+
},
|
|
31982
|
+
{ sheet: s, ranges: [r], structural: !hasHeader }
|
|
31983
|
+
);
|
|
31984
|
+
}
|
|
31985
|
+
|
|
31849
31986
|
// xlsx/edit/validation-list.ts
|
|
31850
31987
|
function listSource(workbook, sheet, formula, evaluate, at, depth = 0) {
|
|
31851
31988
|
const text3 = formula.replace(/^=/, "").trim();
|
|
@@ -32147,7 +32284,7 @@ function createEditSession(workbook, options = {}) {
|
|
|
32147
32284
|
const befores = scopes.map((scope) => captureScope(workbook, scope));
|
|
32148
32285
|
let result2;
|
|
32149
32286
|
try {
|
|
32150
|
-
result2 = fn();
|
|
32287
|
+
result2 = fn(befores.find((snapshot) => snapshot.kind === "refs")?.data.formulas);
|
|
32151
32288
|
} catch (error) {
|
|
32152
32289
|
for (let i2 = befores.length - 1; i2 >= 0; i2--) {
|
|
32153
32290
|
const snapshot = befores[i2];
|