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.cjs
CHANGED
|
@@ -7815,6 +7815,63 @@ function liftCriteria(ctx, pairs, fn) {
|
|
|
7815
7815
|
});
|
|
7816
7816
|
}
|
|
7817
7817
|
|
|
7818
|
+
// xlsx/display-text.ts
|
|
7819
|
+
function displayText(workbook, cell) {
|
|
7820
|
+
if (!cell || cell.value === null) return "";
|
|
7821
|
+
const value = cell.value;
|
|
7822
|
+
if (isCellError(value)) return value.error;
|
|
7823
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
7824
|
+
if (cell.richText && typeof value === "string") return value;
|
|
7825
|
+
return formatValue(value, styleAt(workbook, cell.styleId).numFmt, {
|
|
7826
|
+
date1904: workbook.date1904
|
|
7827
|
+
}).text;
|
|
7828
|
+
}
|
|
7829
|
+
|
|
7830
|
+
// xlsx/filter-rows.ts
|
|
7831
|
+
function rowMatchesFilter(workbook, sheet, row2, filter2) {
|
|
7832
|
+
return (filter2.columns ?? []).every((column) => {
|
|
7833
|
+
if (!column.values && !column.blank) return true;
|
|
7834
|
+
const text3 = displayText(workbook, getCell(sheet, row2, filter2.range.start.col + column.offset));
|
|
7835
|
+
return text3 === "" ? !!column.blank : (column.values ?? []).includes(text3);
|
|
7836
|
+
});
|
|
7837
|
+
}
|
|
7838
|
+
function setRowFiltered(sheet, row2, filteredOut, hasCriteria = false) {
|
|
7839
|
+
const info = { ...sheet.rowInfo.get(row2) };
|
|
7840
|
+
const manual = info.manuallyHidden || info.hidden && !info.filteredOut;
|
|
7841
|
+
if (filteredOut) {
|
|
7842
|
+
info.hidden = true;
|
|
7843
|
+
info.filteredOut = true;
|
|
7844
|
+
if (manual) info.manuallyHidden = true;
|
|
7845
|
+
} else {
|
|
7846
|
+
delete info.filteredOut;
|
|
7847
|
+
delete info.manuallyHidden;
|
|
7848
|
+
if (manual) {
|
|
7849
|
+
info.hidden = true;
|
|
7850
|
+
if (hasCriteria) info.filteredOut = false;
|
|
7851
|
+
} else delete info.hidden;
|
|
7852
|
+
}
|
|
7853
|
+
if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
|
|
7854
|
+
else sheet.rowInfo.delete(row2);
|
|
7855
|
+
}
|
|
7856
|
+
function clearFilteredRows(sheet) {
|
|
7857
|
+
for (const [row2, info] of sheet.rowInfo)
|
|
7858
|
+
if (info.filteredOut !== void 0 || info.manuallyHidden !== void 0)
|
|
7859
|
+
setRowFiltered(sheet, row2, false);
|
|
7860
|
+
}
|
|
7861
|
+
function isFilteredRow(workbook, sheet, row2) {
|
|
7862
|
+
const filter2 = sheet.autoFilter;
|
|
7863
|
+
if (!filter2) return false;
|
|
7864
|
+
const info = sheet.rowInfo.get(row2);
|
|
7865
|
+
if (info?.filteredOut !== void 0) return info.filteredOut;
|
|
7866
|
+
return !!info?.hidden && row2 > filter2.range.start.row && row2 <= filter2.range.end.row && !rowMatchesFilter(workbook, sheet, row2, filter2);
|
|
7867
|
+
}
|
|
7868
|
+
function readFilteredRows(workbook) {
|
|
7869
|
+
for (const sheet of workbook.sheets)
|
|
7870
|
+
for (const [row2, info] of sheet.rowInfo)
|
|
7871
|
+
if (sheet.autoFilter && row2 > sheet.autoFilter.range.start.row && row2 <= sheet.autoFilter.range.end.row && info.hidden)
|
|
7872
|
+
info.filteredOut = isFilteredRow(workbook, sheet, row2);
|
|
7873
|
+
}
|
|
7874
|
+
|
|
7818
7875
|
// xlsx/formula/functions/math-sum.ts
|
|
7819
7876
|
var C18 = "Math & Trig";
|
|
7820
7877
|
var numbersOf = (values2) => values2.filter((v) => typeof v === "number");
|
|
@@ -7852,7 +7909,7 @@ function pairwise(ctx, args, fn) {
|
|
|
7852
7909
|
return total2;
|
|
7853
7910
|
}
|
|
7854
7911
|
var SUBTOTAL_RE = /\b(?:_xlfn\.)?(?:SUBTOTAL|AGGREGATE)\s*\(/i;
|
|
7855
|
-
function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
|
|
7912
|
+
function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true, skipFiltered = false) {
|
|
7856
7913
|
const out = [];
|
|
7857
7914
|
const host = ctx.frame.host;
|
|
7858
7915
|
for (const arg of args) {
|
|
@@ -7865,6 +7922,7 @@ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
|
|
|
7865
7922
|
for (const area of arg.areas) {
|
|
7866
7923
|
const sheet = ctx.workbook.sheets[area.sheet];
|
|
7867
7924
|
host.forEachStored(area.sheet, area.range, (value, row2, col) => {
|
|
7925
|
+
if (skipFiltered && sheet && isFilteredRow(ctx.workbook, sheet, row2)) return;
|
|
7868
7926
|
if (skipHidden && sheet?.rowInfo.get(row2)?.hidden) return;
|
|
7869
7927
|
if (skipNested && SUBTOTAL_RE.test(host.cellFormula(area.sheet, row2, col) ?? "")) return;
|
|
7870
7928
|
if (skipErrors && isError(value)) return;
|
|
@@ -8030,7 +8088,7 @@ var SUM_FUNCTIONS = [
|
|
|
8030
8088
|
const code = int(args[0]);
|
|
8031
8089
|
const base = code > 100 ? code - 100 : code;
|
|
8032
8090
|
if (base < 1 || base > 11) fail(ERR.VALUE);
|
|
8033
|
-
return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false));
|
|
8091
|
+
return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false, true, true));
|
|
8034
8092
|
},
|
|
8035
8093
|
["value", "any"]
|
|
8036
8094
|
),
|
|
@@ -13568,6 +13626,31 @@ function renameTableInFormula(formula, oldName, newName) {
|
|
|
13568
13626
|
}
|
|
13569
13627
|
return changed ? joinTokens(tokens2) : formula;
|
|
13570
13628
|
}
|
|
13629
|
+
function renameTableColumnInFormula(formula, tableName, oldName, newName, insideTable = false) {
|
|
13630
|
+
const tokens2 = safeTokens2(formula);
|
|
13631
|
+
if (!tokens2) return formula;
|
|
13632
|
+
const escaped = newName.replace(/['#@[\]]/g, "'$&");
|
|
13633
|
+
let changed = false;
|
|
13634
|
+
for (const [index2, token] of tokens2.entries()) {
|
|
13635
|
+
if (token.kind !== "structured" || token.prefix) continue;
|
|
13636
|
+
if (token.value === "" && tokens2[index2 - 1]?.prefix) continue;
|
|
13637
|
+
if (token.value === "" ? !insideTable : String(token.value).toLowerCase() !== tableName.toLowerCase())
|
|
13638
|
+
continue;
|
|
13639
|
+
const next = token.text.replace(
|
|
13640
|
+
/\[(@?)((?:[^\[\]']|'[\s\S])*)\]/g,
|
|
13641
|
+
(original, at, name) => {
|
|
13642
|
+
if (name.startsWith("#") || name.replace(/'(.)/g, "$1").toLowerCase() !== oldName.toLowerCase())
|
|
13643
|
+
return original;
|
|
13644
|
+
return `[${at}${escaped}]`;
|
|
13645
|
+
}
|
|
13646
|
+
);
|
|
13647
|
+
if (next !== token.text) {
|
|
13648
|
+
token.text = next;
|
|
13649
|
+
changed = true;
|
|
13650
|
+
}
|
|
13651
|
+
}
|
|
13652
|
+
return changed ? joinTokens(tokens2) : formula;
|
|
13653
|
+
}
|
|
13571
13654
|
|
|
13572
13655
|
// xlsx/formula/structured-to-a1.ts
|
|
13573
13656
|
var abs = (row2, col, rowAbs = true) => `$${columnLabel(col)}${rowAbs ? "$" : ""}${row2 + 1}`;
|
|
@@ -20324,6 +20407,7 @@ async function loadXlsx(input) {
|
|
|
20324
20407
|
if (!sheets.length) throw new Error("XLSX workbook has no sheets");
|
|
20325
20408
|
await resolveSmartArt(sheets, source2, warn);
|
|
20326
20409
|
liftPrintAreas(workbook);
|
|
20410
|
+
readFilteredRows(workbook);
|
|
20327
20411
|
return workbook;
|
|
20328
20412
|
}
|
|
20329
20413
|
function readProperties(core, app, custom, warn) {
|
|
@@ -24626,16 +24710,6 @@ function forEachPosition(sheet, range, visit2) {
|
|
|
24626
24710
|
for (let row2 = r.start.row; row2 <= r.end.row; row2++)
|
|
24627
24711
|
for (let col = r.start.col; col <= r.end.col; col++) visit2(row2, col);
|
|
24628
24712
|
}
|
|
24629
|
-
function displayText(workbook, cell) {
|
|
24630
|
-
if (!cell) return "";
|
|
24631
|
-
const value = cell.value;
|
|
24632
|
-
if (value === null) return "";
|
|
24633
|
-
if (isCellError(value)) return value.error;
|
|
24634
|
-
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
24635
|
-
if (cell.richText && typeof value === "string") return value;
|
|
24636
|
-
const format = styleAt(workbook, cell.styleId).numFmt;
|
|
24637
|
-
return formatValue(value, format, { date1904: workbook.date1904 }).text;
|
|
24638
|
-
}
|
|
24639
24713
|
function rawText(value) {
|
|
24640
24714
|
if (value === null) return "";
|
|
24641
24715
|
if (isCellError(value)) return value.error;
|
|
@@ -24652,19 +24726,266 @@ function pruneCell(sheet, row2, col) {
|
|
|
24652
24726
|
}
|
|
24653
24727
|
}
|
|
24654
24728
|
|
|
24729
|
+
// xlsx/edit/shift-preserved.ts
|
|
24730
|
+
var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
|
|
24731
|
+
function descendants3(root, ns, local) {
|
|
24732
|
+
return Array.from(root.getElementsByTagNameNS(ns, local));
|
|
24733
|
+
}
|
|
24734
|
+
function editEntries(sheet, key, edit, quick) {
|
|
24735
|
+
const list = sheet.preserved.get(key);
|
|
24736
|
+
if (!list) return;
|
|
24737
|
+
const next = [];
|
|
24738
|
+
for (const xml of list) {
|
|
24739
|
+
if (!quick(xml)) {
|
|
24740
|
+
next.push(xml);
|
|
24741
|
+
continue;
|
|
24742
|
+
}
|
|
24743
|
+
let doc;
|
|
24744
|
+
try {
|
|
24745
|
+
doc = parseXml(xml);
|
|
24746
|
+
} catch {
|
|
24747
|
+
next.push(xml);
|
|
24748
|
+
continue;
|
|
24749
|
+
}
|
|
24750
|
+
const outcome = edit(doc.documentElement);
|
|
24751
|
+
if (outcome === "same") next.push(xml);
|
|
24752
|
+
else if (outcome === "changed") next.push(buildXml(doc));
|
|
24753
|
+
}
|
|
24754
|
+
if (next.length) sheet.preserved.set(key, next);
|
|
24755
|
+
else sheet.preserved.delete(key);
|
|
24756
|
+
}
|
|
24757
|
+
function shiftBreaks(root, shift2) {
|
|
24758
|
+
let changed = false;
|
|
24759
|
+
for (const brk of elements(root).filter((e) => e.localName === "brk")) {
|
|
24760
|
+
const id = Number(brk.getAttribute("id") ?? "0");
|
|
24761
|
+
const moved = shiftIndex(id, shift2);
|
|
24762
|
+
if (moved === id) continue;
|
|
24763
|
+
changed = true;
|
|
24764
|
+
if (moved === void 0 || moved === 0) root.removeChild(brk);
|
|
24765
|
+
else brk.setAttribute("id", String(moved));
|
|
24766
|
+
}
|
|
24767
|
+
if (!changed) return "same";
|
|
24768
|
+
const left2 = elements(root).filter((e) => e.localName === "brk");
|
|
24769
|
+
if (!left2.length) return "drop";
|
|
24770
|
+
if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
|
|
24771
|
+
if (root.hasAttribute("manualBreakCount")) {
|
|
24772
|
+
const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
|
|
24773
|
+
root.setAttribute("manualBreakCount", String(manual));
|
|
24774
|
+
}
|
|
24775
|
+
return "changed";
|
|
24776
|
+
}
|
|
24777
|
+
function removeUpwards(node, root) {
|
|
24778
|
+
let current = node;
|
|
24779
|
+
while (current && current !== root) {
|
|
24780
|
+
const parent = current.parentNode;
|
|
24781
|
+
parent?.removeChild(current);
|
|
24782
|
+
if (!parent) break;
|
|
24783
|
+
const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
|
|
24784
|
+
if (!emptied) break;
|
|
24785
|
+
current = parent;
|
|
24786
|
+
}
|
|
24787
|
+
}
|
|
24788
|
+
function shiftSqrefs(root, moveRange) {
|
|
24789
|
+
let changed = false;
|
|
24790
|
+
for (const sqref2 of descendants3(root, XM3, "sqref")) {
|
|
24791
|
+
const old = sqref2.textContent ?? "";
|
|
24792
|
+
const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
|
|
24793
|
+
const text3 = ranges.map(formatRange).join(" ");
|
|
24794
|
+
if (text3 === old.trim()) continue;
|
|
24795
|
+
changed = true;
|
|
24796
|
+
const owner = sqref2.parentNode;
|
|
24797
|
+
if (ranges.length) sqref2.textContent = text3;
|
|
24798
|
+
else if (owner) removeUpwards(owner, root);
|
|
24799
|
+
}
|
|
24800
|
+
if (!changed) return "same";
|
|
24801
|
+
for (const list of elements(root).flatMap((ext) => elements(ext)))
|
|
24802
|
+
if (list.localName === "dataValidations" && list.hasAttribute("count"))
|
|
24803
|
+
list.setAttribute("count", String(elements(list).length));
|
|
24804
|
+
return elements(root).length > 0 ? "changed" : "drop";
|
|
24805
|
+
}
|
|
24806
|
+
function shiftPreservedXml(sheet, shift2, moveRange, banded) {
|
|
24807
|
+
if (!banded)
|
|
24808
|
+
editEntries(
|
|
24809
|
+
sheet,
|
|
24810
|
+
shift2.axis === "row" ? "rowBreaks" : "colBreaks",
|
|
24811
|
+
(root) => shiftBreaks(root, shift2),
|
|
24812
|
+
(xml) => xml.includes("brk")
|
|
24813
|
+
);
|
|
24814
|
+
editEntries(
|
|
24815
|
+
sheet,
|
|
24816
|
+
"extLst",
|
|
24817
|
+
(root) => shiftSqrefs(root, moveRange),
|
|
24818
|
+
(xml) => xml.includes("sqref")
|
|
24819
|
+
);
|
|
24820
|
+
}
|
|
24821
|
+
function rewritePreservedFormulas(sheet, rewrite2) {
|
|
24822
|
+
editEntries(
|
|
24823
|
+
sheet,
|
|
24824
|
+
"extLst",
|
|
24825
|
+
(root) => {
|
|
24826
|
+
let changed = false;
|
|
24827
|
+
for (const f6 of descendants3(root, XM3, "f")) {
|
|
24828
|
+
const text3 = f6.textContent ?? "";
|
|
24829
|
+
let next = text3;
|
|
24830
|
+
try {
|
|
24831
|
+
next = rewrite2(text3, sheet.name);
|
|
24832
|
+
} catch {
|
|
24833
|
+
next = text3;
|
|
24834
|
+
}
|
|
24835
|
+
if (next === text3) continue;
|
|
24836
|
+
f6.textContent = next;
|
|
24837
|
+
changed = true;
|
|
24838
|
+
}
|
|
24839
|
+
return changed ? "changed" : "same";
|
|
24840
|
+
},
|
|
24841
|
+
(xml) => xml.includes(":f>")
|
|
24842
|
+
);
|
|
24843
|
+
}
|
|
24844
|
+
|
|
24845
|
+
// xlsx/edit/conditional-formulas.ts
|
|
24846
|
+
function rewriteConditionalRule(rule, rewrite2) {
|
|
24847
|
+
const safe2 = (formula) => {
|
|
24848
|
+
try {
|
|
24849
|
+
return rewrite2(formula);
|
|
24850
|
+
} catch {
|
|
24851
|
+
return formula;
|
|
24852
|
+
}
|
|
24853
|
+
};
|
|
24854
|
+
if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
|
|
24855
|
+
else if (rule.type === "expression") rule.formula = safe2(rule.formula);
|
|
24856
|
+
if (rule.type === "colorScale" || rule.type === "iconSet") {
|
|
24857
|
+
for (const threshold of rule.thresholds)
|
|
24858
|
+
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
24859
|
+
}
|
|
24860
|
+
if (rule.type === "dataBar") {
|
|
24861
|
+
for (const threshold of [rule.min, rule.max])
|
|
24862
|
+
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
24863
|
+
}
|
|
24864
|
+
if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
|
|
24865
|
+
}
|
|
24866
|
+
|
|
24867
|
+
// xlsx/edit/shift-formulas.ts
|
|
24868
|
+
function safe(rewrite2, formula, formulaSheet, at) {
|
|
24869
|
+
try {
|
|
24870
|
+
return rewrite2(formula, formulaSheet, at);
|
|
24871
|
+
} catch {
|
|
24872
|
+
return formula;
|
|
24873
|
+
}
|
|
24874
|
+
}
|
|
24875
|
+
function rewriteFormulas(workbook, rewrite2, formulaCells) {
|
|
24876
|
+
const bySheet = formulaCells && /* @__PURE__ */ new Map();
|
|
24877
|
+
if (bySheet)
|
|
24878
|
+
for (const cell of formulaCells ?? []) {
|
|
24879
|
+
const positions2 = bySheet.get(cell.sheet);
|
|
24880
|
+
if (positions2) positions2.push(cell);
|
|
24881
|
+
else bySheet.set(cell.sheet, [cell]);
|
|
24882
|
+
}
|
|
24883
|
+
workbook.sheets.forEach(
|
|
24884
|
+
(sheet, index2) => rewriteSheetFormulas(sheet, rewrite2, bySheet ? bySheet.get(index2) ?? [] : void 0)
|
|
24885
|
+
);
|
|
24886
|
+
for (const definedName of workbook.definedNames) {
|
|
24887
|
+
const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
|
|
24888
|
+
definedName.formula = safe(rewrite2, definedName.formula, local?.name ?? "");
|
|
24889
|
+
}
|
|
24890
|
+
}
|
|
24891
|
+
function rewriteSheetFormulas(sheet, rewrite2, formulaCells) {
|
|
24892
|
+
rewritePreservedFormulas(sheet, rewrite2);
|
|
24893
|
+
{
|
|
24894
|
+
const name = sheet.name;
|
|
24895
|
+
for (const table2 of sheet.tables)
|
|
24896
|
+
for (const [index2, column] of table2.columns.entries())
|
|
24897
|
+
if (column.calculatedColumnFormula !== void 0)
|
|
24898
|
+
column.calculatedColumnFormula = safe(rewrite2, column.calculatedColumnFormula, name, {
|
|
24899
|
+
row: table2.range.start.row + (table2.headerRow ? 1 : 0),
|
|
24900
|
+
col: table2.range.start.col + index2
|
|
24901
|
+
});
|
|
24902
|
+
if (formulaCells) {
|
|
24903
|
+
for (const at of formulaCells) {
|
|
24904
|
+
const cell = getCell(sheet, at.row, at.col);
|
|
24905
|
+
if (cell?.formula !== void 0) cell.formula = safe(rewrite2, cell.formula, name, at);
|
|
24906
|
+
}
|
|
24907
|
+
} else {
|
|
24908
|
+
sheet.rows.forEach(
|
|
24909
|
+
(cells, row2) => cells.forEach((cell, col) => {
|
|
24910
|
+
if (cell.formula !== void 0)
|
|
24911
|
+
cell.formula = safe(rewrite2, cell.formula, name, { row: row2, col });
|
|
24912
|
+
})
|
|
24913
|
+
);
|
|
24914
|
+
}
|
|
24915
|
+
for (const cf of sheet.conditionalFormats)
|
|
24916
|
+
for (const rule of cf.rules)
|
|
24917
|
+
rewriteConditionalRule(rule, (f6) => rewrite2(f6, name, cf.ranges[0]?.start));
|
|
24918
|
+
for (const dv of sheet.dataValidations) {
|
|
24919
|
+
if (dv.formula1 !== void 0)
|
|
24920
|
+
dv.formula1 = safe(rewrite2, dv.formula1, name, dv.ranges[0]?.start);
|
|
24921
|
+
if (dv.formula2 !== void 0)
|
|
24922
|
+
dv.formula2 = safe(rewrite2, dv.formula2, name, dv.ranges[0]?.start);
|
|
24923
|
+
}
|
|
24924
|
+
for (const link of sheet.hyperlinks)
|
|
24925
|
+
if (link.location && /![A-Za-z$]/.test(link.location))
|
|
24926
|
+
link.location = safe(rewrite2, link.location, name);
|
|
24927
|
+
for (const drawing of sheet.drawings) {
|
|
24928
|
+
if (drawing.kind !== "chart") continue;
|
|
24929
|
+
for (const series of drawing.series) {
|
|
24930
|
+
if (series.nameRef) series.nameRef = safe(rewrite2, series.nameRef, name);
|
|
24931
|
+
if (series.categoriesRef) series.categoriesRef = safe(rewrite2, series.categoriesRef, name);
|
|
24932
|
+
if (series.valuesRef) series.valuesRef = safe(rewrite2, series.valuesRef, name);
|
|
24933
|
+
}
|
|
24934
|
+
}
|
|
24935
|
+
}
|
|
24936
|
+
}
|
|
24937
|
+
|
|
24938
|
+
// xlsx/edit/table-header-names.ts
|
|
24939
|
+
function uniqueHeaders(texts) {
|
|
24940
|
+
const used = /* @__PURE__ */ new Set();
|
|
24941
|
+
return texts.map((text3, i2) => {
|
|
24942
|
+
let base = text3.trim() || `Column${i2 + 1}`;
|
|
24943
|
+
if (!used.has(base.toLowerCase())) {
|
|
24944
|
+
used.add(base.toLowerCase());
|
|
24945
|
+
return base;
|
|
24946
|
+
}
|
|
24947
|
+
for (let n2 = 2; ; n2++) {
|
|
24948
|
+
const candidate = `${base}${n2}`;
|
|
24949
|
+
if (!used.has(candidate.toLowerCase())) {
|
|
24950
|
+
used.add(candidate.toLowerCase());
|
|
24951
|
+
base = candidate;
|
|
24952
|
+
return base;
|
|
24953
|
+
}
|
|
24954
|
+
}
|
|
24955
|
+
});
|
|
24956
|
+
}
|
|
24957
|
+
|
|
24655
24958
|
// xlsx/edit/cell-values.ts
|
|
24656
24959
|
function tableHeaderAt(sheet, row2, col) {
|
|
24657
24960
|
return sheet.tables.find(
|
|
24658
24961
|
(t) => t.headerRow && t.range.start.row === row2 && col >= t.range.start.col && col <= t.range.end.col
|
|
24659
24962
|
);
|
|
24660
24963
|
}
|
|
24661
|
-
function syncTableHeader(ctx, sheet, row2, col) {
|
|
24964
|
+
function syncTableHeader(ctx, sheet, row2, col, formulaCells) {
|
|
24662
24965
|
const table2 = tableHeaderAt(sheet, row2, col);
|
|
24663
24966
|
if (!table2) return;
|
|
24664
24967
|
const column = table2.columns[col - table2.range.start.col];
|
|
24665
24968
|
if (!column) return;
|
|
24666
24969
|
const text3 = displayText(ctx.workbook, getCell(sheet, row2, col)).trim();
|
|
24667
|
-
if (text3
|
|
24970
|
+
if (!text3 || column.name === text3) return;
|
|
24971
|
+
const oldName = column.name;
|
|
24972
|
+
const others = table2.columns.filter((entry3) => entry3 !== column).map((entry3) => entry3.name);
|
|
24973
|
+
const newName = uniqueHeaders([...others, text3]).at(-1);
|
|
24974
|
+
column.name = newName;
|
|
24975
|
+
if (newName !== text3) writeValue(sheet, row2, col, newName);
|
|
24976
|
+
const index2 = ctx.workbook.sheets.indexOf(sheet);
|
|
24977
|
+
const cells = formulaCells && (formulaCells.some((cell) => cell.sheet === index2 && cell.row === row2 && cell.col === col) ? formulaCells : [...formulaCells, { sheet: index2, row: row2, col }]);
|
|
24978
|
+
rewriteFormulas(
|
|
24979
|
+
ctx.workbook,
|
|
24980
|
+
(formula, formulaSheet, at) => renameTableColumnInFormula(
|
|
24981
|
+
formula,
|
|
24982
|
+
table2.name,
|
|
24983
|
+
oldName,
|
|
24984
|
+
newName,
|
|
24985
|
+
formulaSheet === sheet.name && !!at && rangeContains(table2.range, at)
|
|
24986
|
+
),
|
|
24987
|
+
cells
|
|
24988
|
+
);
|
|
24668
24989
|
}
|
|
24669
24990
|
function writeScopes(sheet, index2, range, parts = []) {
|
|
24670
24991
|
const r = normalizeRange(range);
|
|
@@ -24674,9 +24995,9 @@ function writeScopes(sheet, index2, range, parts = []) {
|
|
|
24674
24995
|
cellRange(t.range.start.row, t.range.start.col, t.range.start.row, t.range.end.col)
|
|
24675
24996
|
)
|
|
24676
24997
|
);
|
|
24677
|
-
|
|
24998
|
+
if (touchesHeader) return [{ kind: "refs" }, { kind: "cells", sheet: index2, ranges: [r] }];
|
|
24678
24999
|
const scopes = [{ kind: "cells", sheet: index2, ranges: [r] }];
|
|
24679
|
-
if (
|
|
25000
|
+
if (parts.length) scopes.push({ kind: "parts", sheet: index2, parts });
|
|
24680
25001
|
return scopes;
|
|
24681
25002
|
}
|
|
24682
25003
|
function writeInput(ctx, sheet, row2, col, text3) {
|
|
@@ -24727,9 +25048,9 @@ function setCellInput(ctx, s, row2, col, text3) {
|
|
|
24727
25048
|
`Typing in ${formatAddress({ row: row2, col })}`,
|
|
24728
25049
|
"cells",
|
|
24729
25050
|
writeScopes(sheet, s, range),
|
|
24730
|
-
() => {
|
|
25051
|
+
(formulaCells) => {
|
|
24731
25052
|
writeInput(ctx, sheet, row2, col, text3);
|
|
24732
|
-
syncTableHeader(ctx, sheet, row2, col);
|
|
25053
|
+
syncTableHeader(ctx, sheet, row2, col, formulaCells);
|
|
24733
25054
|
},
|
|
24734
25055
|
{ sheet: s, ranges: [range] }
|
|
24735
25056
|
);
|
|
@@ -24741,9 +25062,9 @@ function setCellValue(ctx, s, row2, col, value) {
|
|
|
24741
25062
|
`Edit ${formatAddress({ row: row2, col })}`,
|
|
24742
25063
|
"cells",
|
|
24743
25064
|
writeScopes(sheet, s, range),
|
|
24744
|
-
() => {
|
|
25065
|
+
(formulaCells) => {
|
|
24745
25066
|
writeValue(sheet, row2, col, value);
|
|
24746
|
-
syncTableHeader(ctx, sheet, row2, col);
|
|
25067
|
+
syncTableHeader(ctx, sheet, row2, col, formulaCells);
|
|
24747
25068
|
},
|
|
24748
25069
|
{ sheet: s, ranges: [range] }
|
|
24749
25070
|
);
|
|
@@ -25170,7 +25491,7 @@ function fillRange(ctx, s, source2, target, mode = "auto") {
|
|
|
25170
25491
|
ctx.run(
|
|
25171
25492
|
"Fill",
|
|
25172
25493
|
"cells",
|
|
25173
|
-
|
|
25494
|
+
writeScopes(sheet, s, all2),
|
|
25174
25495
|
() => {
|
|
25175
25496
|
const laneCount = vertical ? src.end.col - src.start.col + 1 : src.end.row - src.start.row + 1;
|
|
25176
25497
|
const length = vertical ? src.end.row - src.start.row + 1 : src.end.col - src.start.col + 1;
|
|
@@ -25193,6 +25514,7 @@ function fillRange(ctx, s, source2, target, mode = "auto") {
|
|
|
25193
25514
|
const step2 = series?.(k);
|
|
25194
25515
|
const cell = !step2 || step2.kind === "copy" ? copyCell(origin, row2 - srcRow, col - srcCol) : { value: step2.value, ...origin.styleId ? { styleId: origin.styleId } : {} };
|
|
25195
25516
|
putCell(sheet, row2, col, cell);
|
|
25517
|
+
syncTableHeader(ctx, sheet, row2, col);
|
|
25196
25518
|
}
|
|
25197
25519
|
}
|
|
25198
25520
|
},
|
|
@@ -25231,28 +25553,6 @@ function removeValidationArea(rules, area) {
|
|
|
25231
25553
|
});
|
|
25232
25554
|
}
|
|
25233
25555
|
|
|
25234
|
-
// xlsx/edit/conditional-formulas.ts
|
|
25235
|
-
function rewriteConditionalRule(rule, rewrite2) {
|
|
25236
|
-
const safe2 = (formula) => {
|
|
25237
|
-
try {
|
|
25238
|
-
return rewrite2(formula);
|
|
25239
|
-
} catch {
|
|
25240
|
-
return formula;
|
|
25241
|
-
}
|
|
25242
|
-
};
|
|
25243
|
-
if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
|
|
25244
|
-
else if (rule.type === "expression") rule.formula = safe2(rule.formula);
|
|
25245
|
-
if (rule.type === "colorScale" || rule.type === "iconSet") {
|
|
25246
|
-
for (const threshold of rule.thresholds)
|
|
25247
|
-
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
25248
|
-
}
|
|
25249
|
-
if (rule.type === "dataBar") {
|
|
25250
|
-
for (const threshold of [rule.min, rule.max])
|
|
25251
|
-
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
25252
|
-
}
|
|
25253
|
-
if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
|
|
25254
|
-
}
|
|
25255
|
-
|
|
25256
25556
|
// xlsx/edit/conditional-formats.ts
|
|
25257
25557
|
function formatAt(sheet, index2) {
|
|
25258
25558
|
const format = sheet.conditionalFormats[index2];
|
|
@@ -25662,168 +25962,6 @@ function setBorders(ctx, s, range, preset, edge2 = { style: "thin" }) {
|
|
|
25662
25962
|
);
|
|
25663
25963
|
}
|
|
25664
25964
|
|
|
25665
|
-
// xlsx/edit/shift-preserved.ts
|
|
25666
|
-
var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
|
|
25667
|
-
function descendants3(root, ns, local) {
|
|
25668
|
-
return Array.from(root.getElementsByTagNameNS(ns, local));
|
|
25669
|
-
}
|
|
25670
|
-
function editEntries(sheet, key, edit, quick) {
|
|
25671
|
-
const list = sheet.preserved.get(key);
|
|
25672
|
-
if (!list) return;
|
|
25673
|
-
const next = [];
|
|
25674
|
-
for (const xml of list) {
|
|
25675
|
-
if (!quick(xml)) {
|
|
25676
|
-
next.push(xml);
|
|
25677
|
-
continue;
|
|
25678
|
-
}
|
|
25679
|
-
let doc;
|
|
25680
|
-
try {
|
|
25681
|
-
doc = parseXml(xml);
|
|
25682
|
-
} catch {
|
|
25683
|
-
next.push(xml);
|
|
25684
|
-
continue;
|
|
25685
|
-
}
|
|
25686
|
-
const outcome = edit(doc.documentElement);
|
|
25687
|
-
if (outcome === "same") next.push(xml);
|
|
25688
|
-
else if (outcome === "changed") next.push(buildXml(doc));
|
|
25689
|
-
}
|
|
25690
|
-
if (next.length) sheet.preserved.set(key, next);
|
|
25691
|
-
else sheet.preserved.delete(key);
|
|
25692
|
-
}
|
|
25693
|
-
function shiftBreaks(root, shift2) {
|
|
25694
|
-
let changed = false;
|
|
25695
|
-
for (const brk of elements(root).filter((e) => e.localName === "brk")) {
|
|
25696
|
-
const id = Number(brk.getAttribute("id") ?? "0");
|
|
25697
|
-
const moved = shiftIndex(id, shift2);
|
|
25698
|
-
if (moved === id) continue;
|
|
25699
|
-
changed = true;
|
|
25700
|
-
if (moved === void 0 || moved === 0) root.removeChild(brk);
|
|
25701
|
-
else brk.setAttribute("id", String(moved));
|
|
25702
|
-
}
|
|
25703
|
-
if (!changed) return "same";
|
|
25704
|
-
const left2 = elements(root).filter((e) => e.localName === "brk");
|
|
25705
|
-
if (!left2.length) return "drop";
|
|
25706
|
-
if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
|
|
25707
|
-
if (root.hasAttribute("manualBreakCount")) {
|
|
25708
|
-
const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
|
|
25709
|
-
root.setAttribute("manualBreakCount", String(manual));
|
|
25710
|
-
}
|
|
25711
|
-
return "changed";
|
|
25712
|
-
}
|
|
25713
|
-
function removeUpwards(node, root) {
|
|
25714
|
-
let current = node;
|
|
25715
|
-
while (current && current !== root) {
|
|
25716
|
-
const parent = current.parentNode;
|
|
25717
|
-
parent?.removeChild(current);
|
|
25718
|
-
if (!parent) break;
|
|
25719
|
-
const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
|
|
25720
|
-
if (!emptied) break;
|
|
25721
|
-
current = parent;
|
|
25722
|
-
}
|
|
25723
|
-
}
|
|
25724
|
-
function shiftSqrefs(root, moveRange) {
|
|
25725
|
-
let changed = false;
|
|
25726
|
-
for (const sqref2 of descendants3(root, XM3, "sqref")) {
|
|
25727
|
-
const old = sqref2.textContent ?? "";
|
|
25728
|
-
const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
|
|
25729
|
-
const text3 = ranges.map(formatRange).join(" ");
|
|
25730
|
-
if (text3 === old.trim()) continue;
|
|
25731
|
-
changed = true;
|
|
25732
|
-
const owner = sqref2.parentNode;
|
|
25733
|
-
if (ranges.length) sqref2.textContent = text3;
|
|
25734
|
-
else if (owner) removeUpwards(owner, root);
|
|
25735
|
-
}
|
|
25736
|
-
if (!changed) return "same";
|
|
25737
|
-
for (const list of elements(root).flatMap((ext) => elements(ext)))
|
|
25738
|
-
if (list.localName === "dataValidations" && list.hasAttribute("count"))
|
|
25739
|
-
list.setAttribute("count", String(elements(list).length));
|
|
25740
|
-
return elements(root).length > 0 ? "changed" : "drop";
|
|
25741
|
-
}
|
|
25742
|
-
function shiftPreservedXml(sheet, shift2, moveRange, banded) {
|
|
25743
|
-
if (!banded)
|
|
25744
|
-
editEntries(
|
|
25745
|
-
sheet,
|
|
25746
|
-
shift2.axis === "row" ? "rowBreaks" : "colBreaks",
|
|
25747
|
-
(root) => shiftBreaks(root, shift2),
|
|
25748
|
-
(xml) => xml.includes("brk")
|
|
25749
|
-
);
|
|
25750
|
-
editEntries(
|
|
25751
|
-
sheet,
|
|
25752
|
-
"extLst",
|
|
25753
|
-
(root) => shiftSqrefs(root, moveRange),
|
|
25754
|
-
(xml) => xml.includes("sqref")
|
|
25755
|
-
);
|
|
25756
|
-
}
|
|
25757
|
-
function rewritePreservedFormulas(sheet, rewrite2) {
|
|
25758
|
-
editEntries(
|
|
25759
|
-
sheet,
|
|
25760
|
-
"extLst",
|
|
25761
|
-
(root) => {
|
|
25762
|
-
let changed = false;
|
|
25763
|
-
for (const f6 of descendants3(root, XM3, "f")) {
|
|
25764
|
-
const text3 = f6.textContent ?? "";
|
|
25765
|
-
let next = text3;
|
|
25766
|
-
try {
|
|
25767
|
-
next = rewrite2(text3, sheet.name);
|
|
25768
|
-
} catch {
|
|
25769
|
-
next = text3;
|
|
25770
|
-
}
|
|
25771
|
-
if (next === text3) continue;
|
|
25772
|
-
f6.textContent = next;
|
|
25773
|
-
changed = true;
|
|
25774
|
-
}
|
|
25775
|
-
return changed ? "changed" : "same";
|
|
25776
|
-
},
|
|
25777
|
-
(xml) => xml.includes(":f>")
|
|
25778
|
-
);
|
|
25779
|
-
}
|
|
25780
|
-
|
|
25781
|
-
// xlsx/edit/shift-formulas.ts
|
|
25782
|
-
function safe(rewrite2, formula, formulaSheet) {
|
|
25783
|
-
try {
|
|
25784
|
-
return rewrite2(formula, formulaSheet);
|
|
25785
|
-
} catch {
|
|
25786
|
-
return formula;
|
|
25787
|
-
}
|
|
25788
|
-
}
|
|
25789
|
-
function rewriteFormulas(workbook, rewrite2) {
|
|
25790
|
-
for (const sheet of workbook.sheets) rewriteSheetFormulas(sheet, rewrite2);
|
|
25791
|
-
for (const definedName of workbook.definedNames) {
|
|
25792
|
-
const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
|
|
25793
|
-
definedName.formula = safe(rewrite2, definedName.formula, local?.name ?? "");
|
|
25794
|
-
}
|
|
25795
|
-
}
|
|
25796
|
-
function rewriteSheetFormulas(sheet, rewrite2) {
|
|
25797
|
-
rewritePreservedFormulas(sheet, rewrite2);
|
|
25798
|
-
{
|
|
25799
|
-
const name = sheet.name;
|
|
25800
|
-
for (const table2 of sheet.tables)
|
|
25801
|
-
for (const column of table2.columns)
|
|
25802
|
-
if (column.calculatedColumnFormula !== void 0)
|
|
25803
|
-
column.calculatedColumnFormula = safe(rewrite2, column.calculatedColumnFormula, name);
|
|
25804
|
-
for (const cells of sheet.rows.values())
|
|
25805
|
-
for (const cell of cells.values())
|
|
25806
|
-
if (cell.formula !== void 0) cell.formula = safe(rewrite2, cell.formula, name);
|
|
25807
|
-
for (const cf of sheet.conditionalFormats)
|
|
25808
|
-
for (const rule of cf.rules) rewriteConditionalRule(rule, (f6) => rewrite2(f6, name));
|
|
25809
|
-
for (const dv of sheet.dataValidations) {
|
|
25810
|
-
if (dv.formula1 !== void 0) dv.formula1 = safe(rewrite2, dv.formula1, name);
|
|
25811
|
-
if (dv.formula2 !== void 0) dv.formula2 = safe(rewrite2, dv.formula2, name);
|
|
25812
|
-
}
|
|
25813
|
-
for (const link of sheet.hyperlinks)
|
|
25814
|
-
if (link.location && /![A-Za-z$]/.test(link.location))
|
|
25815
|
-
link.location = safe(rewrite2, link.location, name);
|
|
25816
|
-
for (const drawing of sheet.drawings) {
|
|
25817
|
-
if (drawing.kind !== "chart") continue;
|
|
25818
|
-
for (const series of drawing.series) {
|
|
25819
|
-
if (series.nameRef) series.nameRef = safe(rewrite2, series.nameRef, name);
|
|
25820
|
-
if (series.categoriesRef) series.categoriesRef = safe(rewrite2, series.categoriesRef, name);
|
|
25821
|
-
if (series.valuesRef) series.valuesRef = safe(rewrite2, series.valuesRef, name);
|
|
25822
|
-
}
|
|
25823
|
-
}
|
|
25824
|
-
}
|
|
25825
|
-
}
|
|
25826
|
-
|
|
25827
25965
|
// xlsx/edit/shift-sheet.ts
|
|
25828
25966
|
function shiftSheetContent(sheet, shift2, band) {
|
|
25829
25967
|
const moveRange = (range) => band ? shiftRangeInBand(range, shift2, band.lo, band.hi) : shiftRange(range, shift2);
|
|
@@ -25845,8 +25983,10 @@ function shiftSheetContent(sheet, shift2, band) {
|
|
|
25845
25983
|
if (sheet.autoFilter) {
|
|
25846
25984
|
const old = sheet.autoFilter.range;
|
|
25847
25985
|
const range = moveRange(old);
|
|
25848
|
-
if (!range)
|
|
25849
|
-
|
|
25986
|
+
if (!range) {
|
|
25987
|
+
delete sheet.autoFilter;
|
|
25988
|
+
clearFilteredRows(sheet);
|
|
25989
|
+
} else {
|
|
25850
25990
|
const filter2 = { ...sheet.autoFilter, range };
|
|
25851
25991
|
if (shift2.axis === "col" && filter2.columns)
|
|
25852
25992
|
filter2.columns = filter2.columns.flatMap((fc) => {
|
|
@@ -25997,6 +26137,9 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
|
|
|
25997
26137
|
const sheet = sheetAt(ctx.workbook, s);
|
|
25998
26138
|
const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
|
|
25999
26139
|
const shift2 = { axis, at, count: insert ? count2 : -count2 };
|
|
26140
|
+
const info = { sheet: s, structural: true };
|
|
26141
|
+
if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
|
|
26142
|
+
info.calc = { kind: "shift", sheet: s, shift: shift2 };
|
|
26000
26143
|
ctx.run(
|
|
26001
26144
|
`${insert ? "Insert" : "Delete"} ${noun}`,
|
|
26002
26145
|
"structure",
|
|
@@ -26005,7 +26148,7 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
|
|
|
26005
26148
|
applyAxisShift(ctx, sheet, shift2);
|
|
26006
26149
|
if (insert) inheritFormats(sheet, axis, at, count2);
|
|
26007
26150
|
},
|
|
26008
|
-
|
|
26151
|
+
info
|
|
26009
26152
|
);
|
|
26010
26153
|
}
|
|
26011
26154
|
var insertRows = (ctx, s, at, count2) => shiftAxis(ctx, s, "row", at, count2, true);
|
|
@@ -26813,14 +26956,13 @@ function pasteAt(ctx, s, at, payload, request) {
|
|
|
26813
26956
|
if (cut && operation !== "none")
|
|
26814
26957
|
throw new RangeError("Paste operations are not available for cut cells.");
|
|
26815
26958
|
const destCells = { kind: "cells", sheet: s, ranges: [dest] };
|
|
26816
|
-
const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : [
|
|
26817
|
-
|
|
26818
|
-
|
|
26819
|
-
|
|
26820
|
-
|
|
26821
|
-
|
|
26822
|
-
|
|
26823
|
-
];
|
|
26959
|
+
const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : writeScopes(sheet, s, dest, [
|
|
26960
|
+
"merges",
|
|
26961
|
+
"comments",
|
|
26962
|
+
"dataValidations",
|
|
26963
|
+
"hyperlinks",
|
|
26964
|
+
"conditionalFormats"
|
|
26965
|
+
]);
|
|
26824
26966
|
const move = cut && {
|
|
26825
26967
|
fromSheet: sheetAt(workbook, cut.sheet).name,
|
|
26826
26968
|
range: cut.range,
|
|
@@ -26893,6 +27035,8 @@ function pasteAt(ctx, s, at, payload, request) {
|
|
|
26893
27035
|
const origin = cells.source?.range.start;
|
|
26894
27036
|
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);
|
|
26895
27037
|
writeClip(workbook, sheet, row2, col, clip, mode, formula, styleOf2, operation);
|
|
27038
|
+
if (mode !== "formats" && mode !== "comments" && mode !== "validation")
|
|
27039
|
+
syncTableHeader(ctx, sheet, row2, col);
|
|
26896
27040
|
}
|
|
26897
27041
|
if (mode === "all" || mode === "mergeFormats" || mode === "noBorders" || mode === "formats") {
|
|
26898
27042
|
sheet.merges = sheet.merges.filter((m) => !rangesIntersect(m, dest));
|
|
@@ -26936,14 +27080,13 @@ function pasteSelection(ctx, sheet, selection, payload, request) {
|
|
|
26936
27080
|
return ctx.run(
|
|
26937
27081
|
"Paste",
|
|
26938
27082
|
"cells",
|
|
26939
|
-
[
|
|
26940
|
-
|
|
26941
|
-
|
|
26942
|
-
|
|
26943
|
-
|
|
26944
|
-
|
|
26945
|
-
|
|
26946
|
-
],
|
|
27083
|
+
writeScopes(sheetAt(ctx.workbook, sheet), sheet, dest, [
|
|
27084
|
+
"merges",
|
|
27085
|
+
"comments",
|
|
27086
|
+
"dataValidations",
|
|
27087
|
+
"hyperlinks",
|
|
27088
|
+
"conditionalFormats"
|
|
27089
|
+
]),
|
|
26947
27090
|
() => {
|
|
26948
27091
|
for (let row2 = dest.start.row; row2 <= dest.end.row; row2 += height)
|
|
26949
27092
|
for (let col = dest.start.col; col <= dest.end.col; col += width)
|
|
@@ -27095,9 +27238,19 @@ function setHidden(ctx, s, axis, indices, hidden) {
|
|
|
27095
27238
|
}
|
|
27096
27239
|
for (const row2 of indices) {
|
|
27097
27240
|
const info = { ...sheet.rowInfo.get(row2) };
|
|
27241
|
+
if (info.filteredOut) {
|
|
27242
|
+
if (hidden) info.manuallyHidden = true;
|
|
27243
|
+
else delete info.manuallyHidden;
|
|
27244
|
+
sheet.rowInfo.set(row2, info);
|
|
27245
|
+
continue;
|
|
27246
|
+
}
|
|
27247
|
+
const filter2 = sheet.autoFilter;
|
|
27248
|
+
if (hidden && filter2?.columns?.length && row2 > filter2.range.start.row && row2 <= filter2.range.end.row)
|
|
27249
|
+
info.filteredOut = false;
|
|
27098
27250
|
if (hidden) info.hidden = true;
|
|
27099
27251
|
else {
|
|
27100
27252
|
delete info.hidden;
|
|
27253
|
+
delete info.filteredOut;
|
|
27101
27254
|
if (info.height === 0) delete info.height;
|
|
27102
27255
|
}
|
|
27103
27256
|
if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
|
|
@@ -27249,16 +27402,8 @@ function currentRegion(sheet, at) {
|
|
|
27249
27402
|
function applyFilter(ctx, sheet, filter2) {
|
|
27250
27403
|
const { range } = filter2;
|
|
27251
27404
|
for (let row2 = range.start.row + 1; row2 <= range.end.row; row2++) {
|
|
27252
|
-
const visible = (
|
|
27253
|
-
|
|
27254
|
-
const text3 = displayText(ctx.workbook, getCell(sheet, row2, range.start.col + fc.offset));
|
|
27255
|
-
return text3 === "" ? !!fc.blank : (fc.values ?? []).includes(text3);
|
|
27256
|
-
});
|
|
27257
|
-
const info = { ...sheet.rowInfo.get(row2) };
|
|
27258
|
-
if (visible) delete info.hidden;
|
|
27259
|
-
else info.hidden = true;
|
|
27260
|
-
if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
|
|
27261
|
-
else sheet.rowInfo.delete(row2);
|
|
27405
|
+
const visible = rowMatchesFilter(ctx.workbook, sheet, row2, filter2);
|
|
27406
|
+
setRowFiltered(sheet, row2, !visible, !!filter2.columns?.length);
|
|
27262
27407
|
}
|
|
27263
27408
|
}
|
|
27264
27409
|
function setAutoFilter(ctx, s, range) {
|
|
@@ -27420,16 +27565,16 @@ var isSpilledAt = (workbook, at) => {
|
|
|
27420
27565
|
return !!sheet && isSpilledCell(getCell(sheet, at.row, at.col));
|
|
27421
27566
|
};
|
|
27422
27567
|
var replaceQuery = (query) => query.lookIn === "comments" ? query : { ...query, lookIn: "formulas" };
|
|
27423
|
-
function replaceScopes(query, sheet, matches2) {
|
|
27568
|
+
function replaceScopes(ctx, query, sheet, matches2) {
|
|
27424
27569
|
if (query.lookIn === "comments") return [{ kind: "parts", sheet, parts: ["comments"] }];
|
|
27425
27570
|
const ranges = matches2.map((m) => ({
|
|
27426
27571
|
start: { row: m.row, col: m.col },
|
|
27427
27572
|
end: { row: m.row, col: m.col }
|
|
27428
27573
|
}));
|
|
27429
|
-
|
|
27430
|
-
|
|
27431
|
-
|
|
27432
|
-
];
|
|
27574
|
+
const header = ranges.some(
|
|
27575
|
+
(range) => writeScopes(sheetAt(ctx.workbook, sheet), sheet, range).some((scope) => scope.kind === "refs")
|
|
27576
|
+
);
|
|
27577
|
+
return [...header ? [{ kind: "refs" }] : [], { kind: "cells", sheet, ranges }];
|
|
27433
27578
|
}
|
|
27434
27579
|
function applyReplace(ctx, query, replacement, matches2) {
|
|
27435
27580
|
let changed = 0;
|
|
@@ -27459,14 +27604,24 @@ function replaceAll(ctx, query, replacement) {
|
|
|
27459
27604
|
const sheets = [...new Set(matches2.map((m) => m.sheet))];
|
|
27460
27605
|
const scopes = sheets.flatMap(
|
|
27461
27606
|
(sheet) => replaceScopes(
|
|
27607
|
+
ctx,
|
|
27462
27608
|
q,
|
|
27463
27609
|
sheet,
|
|
27464
27610
|
matches2.filter((m) => m.sheet === sheet)
|
|
27465
27611
|
)
|
|
27466
27612
|
);
|
|
27467
|
-
|
|
27468
|
-
|
|
27469
|
-
|
|
27613
|
+
const uniqueScopes = scopes.filter(
|
|
27614
|
+
(scope, index2) => scope.kind !== "refs" || scopes.findIndex((entry3) => entry3.kind === "refs") === index2
|
|
27615
|
+
);
|
|
27616
|
+
return ctx.run(
|
|
27617
|
+
"Replace",
|
|
27618
|
+
"cells",
|
|
27619
|
+
uniqueScopes,
|
|
27620
|
+
() => applyReplace(ctx, q, replacement, matches2),
|
|
27621
|
+
{
|
|
27622
|
+
...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
|
|
27623
|
+
}
|
|
27624
|
+
);
|
|
27470
27625
|
}
|
|
27471
27626
|
function replaceOne(ctx, query, replacement, at) {
|
|
27472
27627
|
const q = replaceQuery(query);
|
|
@@ -27479,7 +27634,7 @@ function replaceOne(ctx, query, replacement, at) {
|
|
|
27479
27634
|
ctx.run(
|
|
27480
27635
|
"Replace",
|
|
27481
27636
|
"cells",
|
|
27482
|
-
replaceScopes(q, at.sheet, [match2]),
|
|
27637
|
+
replaceScopes(ctx, q, at.sheet, [match2]),
|
|
27483
27638
|
() => applyReplace(ctx, q, replacement, [match2]),
|
|
27484
27639
|
{ sheet: at.sheet }
|
|
27485
27640
|
);
|
|
@@ -28482,90 +28637,6 @@ function applyTotalsRow(sheet, table2) {
|
|
|
28482
28637
|
});
|
|
28483
28638
|
}
|
|
28484
28639
|
|
|
28485
|
-
// xlsx/edit/tables.ts
|
|
28486
|
-
function nextTableName(workbook) {
|
|
28487
|
-
const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
|
|
28488
|
-
const names = new Set(workbook.definedNames.map((n2) => n2.name.toLowerCase()));
|
|
28489
|
-
for (let n2 = 1; ; n2++) if (!taken.has(`table${n2}`) && !names.has(`table${n2}`)) return `Table${n2}`;
|
|
28490
|
-
}
|
|
28491
|
-
function uniqueHeaders(texts) {
|
|
28492
|
-
const used = /* @__PURE__ */ new Set();
|
|
28493
|
-
return texts.map((text3, i2) => {
|
|
28494
|
-
let base = text3.trim() || `Column${i2 + 1}`;
|
|
28495
|
-
if (!used.has(base.toLowerCase())) {
|
|
28496
|
-
used.add(base.toLowerCase());
|
|
28497
|
-
return base;
|
|
28498
|
-
}
|
|
28499
|
-
for (let n2 = 2; ; n2++) {
|
|
28500
|
-
const candidate = `${base}${n2}`;
|
|
28501
|
-
if (!used.has(candidate.toLowerCase())) {
|
|
28502
|
-
used.add(candidate.toLowerCase());
|
|
28503
|
-
base = candidate;
|
|
28504
|
-
return base;
|
|
28505
|
-
}
|
|
28506
|
-
}
|
|
28507
|
-
});
|
|
28508
|
-
}
|
|
28509
|
-
function createTable(ctx, s, range, hasHeader, styleName = "TableStyleMedium2") {
|
|
28510
|
-
const { workbook } = ctx;
|
|
28511
|
-
const sheet = sheetAt(workbook, s);
|
|
28512
|
-
let r = normalizeRange(range);
|
|
28513
|
-
if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
|
|
28514
|
-
if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
|
|
28515
|
-
throw new Error("A table cannot overlap another table.");
|
|
28516
|
-
if (sheet.merges.some((m) => rangesIntersect(m, r)))
|
|
28517
|
-
throw new Error("A table cannot contain merged cells.");
|
|
28518
|
-
return ctx.run(
|
|
28519
|
-
"Create table",
|
|
28520
|
-
"structure",
|
|
28521
|
-
[hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
|
|
28522
|
-
() => {
|
|
28523
|
-
if (!hasHeader) {
|
|
28524
|
-
const shift2 = { axis: "row", at: r.start.row, count: 1 };
|
|
28525
|
-
const band = { lo: r.start.col, hi: r.end.col };
|
|
28526
|
-
rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
|
|
28527
|
-
shiftSheetContent(sheet, shift2, band);
|
|
28528
|
-
r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
|
|
28529
|
-
}
|
|
28530
|
-
const width = r.end.col - r.start.col + 1;
|
|
28531
|
-
const texts = Array.from(
|
|
28532
|
-
{ length: width },
|
|
28533
|
-
(_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
|
|
28534
|
-
);
|
|
28535
|
-
const headers = uniqueHeaders(texts);
|
|
28536
|
-
const columns = headers.map((name2, i2) => {
|
|
28537
|
-
const cell = getCell(sheet, r.start.row, r.start.col + i2);
|
|
28538
|
-
if (cell?.value !== name2) {
|
|
28539
|
-
const styleId = cell?.styleId;
|
|
28540
|
-
writeValue(sheet, r.start.row, r.start.col + i2, name2);
|
|
28541
|
-
const written = getCell(sheet, r.start.row, r.start.col + i2);
|
|
28542
|
-
if (written && styleId) written.styleId = styleId;
|
|
28543
|
-
}
|
|
28544
|
-
return { name: name2 };
|
|
28545
|
-
});
|
|
28546
|
-
const name = nextTableName(workbook);
|
|
28547
|
-
const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
|
|
28548
|
-
const table2 = {
|
|
28549
|
-
id,
|
|
28550
|
-
name,
|
|
28551
|
-
displayName: name,
|
|
28552
|
-
range: r,
|
|
28553
|
-
headerRow: true,
|
|
28554
|
-
totalsRow: false,
|
|
28555
|
-
columns,
|
|
28556
|
-
styleName,
|
|
28557
|
-
showRowStripes: true,
|
|
28558
|
-
showColumnStripes: false,
|
|
28559
|
-
showFirstColumn: false,
|
|
28560
|
-
showLastColumn: false
|
|
28561
|
-
};
|
|
28562
|
-
sheet.tables.push(table2);
|
|
28563
|
-
return table2;
|
|
28564
|
-
},
|
|
28565
|
-
{ sheet: s, ranges: [r], structural: !hasHeader }
|
|
28566
|
-
);
|
|
28567
|
-
}
|
|
28568
|
-
|
|
28569
28640
|
// xlsx/edit/table-edits.ts
|
|
28570
28641
|
function tableIndex(sheet, ref) {
|
|
28571
28642
|
const index2 = typeof ref === "number" ? ref : sheet.tables.findIndex((t) => t.name.toLowerCase() === ref.toLowerCase());
|
|
@@ -31821,8 +31892,8 @@ function setSheetState(ctx, index2, state) {
|
|
|
31821
31892
|
const { workbook } = ctx;
|
|
31822
31893
|
const sheet = sheetAt(workbook, index2);
|
|
31823
31894
|
if (sheet.state === state) return;
|
|
31895
|
+
assertUnlocked(workbook);
|
|
31824
31896
|
if (state !== "visible") {
|
|
31825
|
-
assertUnlocked(workbook);
|
|
31826
31897
|
if (sheet.state === "visible" && visibleCount(workbook) <= 1)
|
|
31827
31898
|
throw new Error("A workbook must contain at least one visible sheet.");
|
|
31828
31899
|
}
|
|
@@ -31852,6 +31923,72 @@ function setTabColor(ctx, index2, color) {
|
|
|
31852
31923
|
);
|
|
31853
31924
|
}
|
|
31854
31925
|
|
|
31926
|
+
// xlsx/edit/tables.ts
|
|
31927
|
+
function nextTableName(workbook) {
|
|
31928
|
+
const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
|
|
31929
|
+
const names = new Set(workbook.definedNames.map((n2) => n2.name.toLowerCase()));
|
|
31930
|
+
for (let n2 = 1; ; n2++) if (!taken.has(`table${n2}`) && !names.has(`table${n2}`)) return `Table${n2}`;
|
|
31931
|
+
}
|
|
31932
|
+
function createTable(ctx, s, range, hasHeader, styleName = "TableStyleMedium2") {
|
|
31933
|
+
const { workbook } = ctx;
|
|
31934
|
+
const sheet = sheetAt(workbook, s);
|
|
31935
|
+
let r = normalizeRange(range);
|
|
31936
|
+
if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
|
|
31937
|
+
if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
|
|
31938
|
+
throw new Error("A table cannot overlap another table.");
|
|
31939
|
+
if (sheet.merges.some((m) => rangesIntersect(m, r)))
|
|
31940
|
+
throw new Error("A table cannot contain merged cells.");
|
|
31941
|
+
return ctx.run(
|
|
31942
|
+
"Create table",
|
|
31943
|
+
"structure",
|
|
31944
|
+
[hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
|
|
31945
|
+
() => {
|
|
31946
|
+
if (!hasHeader) {
|
|
31947
|
+
const shift2 = { axis: "row", at: r.start.row, count: 1 };
|
|
31948
|
+
const band = { lo: r.start.col, hi: r.end.col };
|
|
31949
|
+
rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
|
|
31950
|
+
shiftSheetContent(sheet, shift2, band);
|
|
31951
|
+
r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
|
|
31952
|
+
}
|
|
31953
|
+
const width = r.end.col - r.start.col + 1;
|
|
31954
|
+
const texts = Array.from(
|
|
31955
|
+
{ length: width },
|
|
31956
|
+
(_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
|
|
31957
|
+
);
|
|
31958
|
+
const headers = uniqueHeaders(texts);
|
|
31959
|
+
const columns = headers.map((name2, i2) => {
|
|
31960
|
+
const cell = getCell(sheet, r.start.row, r.start.col + i2);
|
|
31961
|
+
if (cell?.value !== name2) {
|
|
31962
|
+
const styleId = cell?.styleId;
|
|
31963
|
+
writeValue(sheet, r.start.row, r.start.col + i2, name2);
|
|
31964
|
+
const written = getCell(sheet, r.start.row, r.start.col + i2);
|
|
31965
|
+
if (written && styleId) written.styleId = styleId;
|
|
31966
|
+
}
|
|
31967
|
+
return { name: name2 };
|
|
31968
|
+
});
|
|
31969
|
+
const name = nextTableName(workbook);
|
|
31970
|
+
const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
|
|
31971
|
+
const table2 = {
|
|
31972
|
+
id,
|
|
31973
|
+
name,
|
|
31974
|
+
displayName: name,
|
|
31975
|
+
range: r,
|
|
31976
|
+
headerRow: true,
|
|
31977
|
+
totalsRow: false,
|
|
31978
|
+
columns,
|
|
31979
|
+
styleName,
|
|
31980
|
+
showRowStripes: true,
|
|
31981
|
+
showColumnStripes: false,
|
|
31982
|
+
showFirstColumn: false,
|
|
31983
|
+
showLastColumn: false
|
|
31984
|
+
};
|
|
31985
|
+
sheet.tables.push(table2);
|
|
31986
|
+
return table2;
|
|
31987
|
+
},
|
|
31988
|
+
{ sheet: s, ranges: [r], structural: !hasHeader }
|
|
31989
|
+
);
|
|
31990
|
+
}
|
|
31991
|
+
|
|
31855
31992
|
// xlsx/edit/validation-list.ts
|
|
31856
31993
|
function listSource(workbook, sheet, formula, evaluate, at, depth = 0) {
|
|
31857
31994
|
const text3 = formula.replace(/^=/, "").trim();
|
|
@@ -32153,7 +32290,7 @@ function createEditSession(workbook, options = {}) {
|
|
|
32153
32290
|
const befores = scopes.map((scope) => captureScope(workbook, scope));
|
|
32154
32291
|
let result2;
|
|
32155
32292
|
try {
|
|
32156
|
-
result2 = fn();
|
|
32293
|
+
result2 = fn(befores.find((snapshot) => snapshot.kind === "refs")?.data.formulas);
|
|
32157
32294
|
} catch (error) {
|
|
32158
32295
|
for (let i2 = befores.length - 1; i2 >= 0; i2--) {
|
|
32159
32296
|
const snapshot = befores[i2];
|