ooxml-core 1.2.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/{PptxHandler-VQQS4VS6.mjs → PptxHandler-ZPJNHEZZ.mjs} +2 -2
- package/dist/automation/index.cjs +7972 -5580
- package/dist/automation/index.mjs +7972 -5580
- package/dist/{chunk-5U27IVB7.mjs → chunk-BB55ASTX.mjs} +3 -3
- package/dist/{chunk-V2BIGIH4.mjs → chunk-H4TPDZV4.mjs} +1 -1
- package/dist/{chunk-5VLNF4OX.mjs → chunk-IVDC75E5.mjs} +1 -1
- package/dist/{chunk-XBNSBDNT.mjs → chunk-QPQDLSJQ.mjs} +1 -1
- package/dist/{chunk-XSFHGZFH.mjs → chunk-XGLKW3JJ.mjs} +5 -3
- package/dist/pptx/automation/index.cjs +4 -2
- package/dist/pptx/automation/index.mjs +5 -5
- package/dist/pptx/cli/index.cjs +4 -2
- package/dist/pptx/cli/index.mjs +4 -4
- package/dist/pptx/converter/index.mjs +2 -2
- package/dist/pptx/index.cjs +4 -2
- package/dist/pptx/index.mjs +5 -5
- package/dist/teams/index.cjs +91 -33
- package/dist/teams/index.mjs +91 -33
- package/dist/visio/clipboard-resources.d.ts +11 -0
- package/dist/visio/clipboard-resources.d.ts.map +1 -0
- package/dist/visio/clipboard-types.d.ts +26 -0
- package/dist/visio/clipboard-types.d.ts.map +1 -0
- package/dist/visio/clipboard-xml.d.ts +8 -0
- package/dist/visio/clipboard-xml.d.ts.map +1 -0
- package/dist/visio/clipboard.d.ts +7 -0
- package/dist/visio/clipboard.d.ts.map +1 -0
- package/dist/visio/create-document.d.ts +8 -0
- package/dist/visio/create-document.d.ts.map +1 -0
- package/dist/visio/edit-commands.d.ts +29 -3
- package/dist/visio/edit-commands.d.ts.map +1 -1
- package/dist/visio/edit-delete.d.ts +9 -0
- package/dist/visio/edit-delete.d.ts.map +1 -0
- package/dist/visio/edit-duplicate-commands.d.ts +14 -0
- package/dist/visio/edit-duplicate-commands.d.ts.map +1 -0
- package/dist/visio/edit-duplicate-scope.d.ts +4 -0
- package/dist/visio/edit-duplicate-scope.d.ts.map +1 -0
- package/dist/visio/edit-duplicate.d.ts +10 -0
- package/dist/visio/edit-duplicate.d.ts.map +1 -0
- package/dist/visio/edit-formatting-cell-admission.d.ts +3 -0
- package/dist/visio/edit-formatting-cell-admission.d.ts.map +1 -0
- package/dist/visio/edit-formatting-commands.d.ts +46 -0
- package/dist/visio/edit-formatting-commands.d.ts.map +1 -0
- package/dist/visio/edit-formatting-font.d.ts +6 -0
- package/dist/visio/edit-formatting-font.d.ts.map +1 -0
- package/dist/visio/edit-formatting-paint-scope.d.ts +6 -0
- package/dist/visio/edit-formatting-paint-scope.d.ts.map +1 -0
- package/dist/visio/edit-formatting-paint.d.ts +6 -0
- package/dist/visio/edit-formatting-paint.d.ts.map +1 -0
- package/dist/visio/edit-formatting-rows.d.ts +14 -0
- package/dist/visio/edit-formatting-rows.d.ts.map +1 -0
- package/dist/visio/edit-formatting-scope.d.ts +6 -0
- package/dist/visio/edit-formatting-scope.d.ts.map +1 -0
- package/dist/visio/edit-formatting-text.d.ts +8 -0
- package/dist/visio/edit-formatting-text.d.ts.map +1 -0
- package/dist/visio/edit-formatting.d.ts +12 -0
- package/dist/visio/edit-formatting.d.ts.map +1 -0
- package/dist/visio/edit-geometry.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-paste-commands.d.ts +15 -0
- package/dist/visio/edit-paste-commands.d.ts.map +1 -0
- package/dist/visio/edit-paste.d.ts +5 -0
- package/dist/visio/edit-paste.d.ts.map +1 -0
- package/dist/visio/edit-recalculate.d.ts +3 -1
- package/dist/visio/edit-recalculate.d.ts.map +1 -1
- package/dist/visio/edit-resize-anchor.d.ts +8 -0
- package/dist/visio/edit-resize-anchor.d.ts.map +1 -0
- package/dist/visio/edit-scope.d.ts.map +1 -1
- package/dist/visio/edit-shape-create.d.ts +1 -1
- package/dist/visio/edit-shape-create.d.ts.map +1 -1
- package/dist/visio/edit-shape-order.d.ts +7 -0
- package/dist/visio/edit-shape-order.d.ts.map +1 -0
- package/dist/visio/edit-style-admission.d.ts +17 -0
- package/dist/visio/edit-style-admission.d.ts.map +1 -0
- 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-scope.d.ts +7 -0
- package/dist/visio/edit-text-scope.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 +1 -1
- 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 +3612 -1076
- package/dist/visio/index.d.ts +3 -1
- package/dist/visio/index.d.ts.map +1 -1
- package/dist/visio/index.mjs +3608 -1078
- package/dist/visio/line-pattern.d.ts +1 -1
- package/dist/visio/line-pattern.d.ts.map +1 -1
- package/dist/visio/line-style.d.ts.map +1 -1
- package/dist/visio/model.d.ts +26 -3
- package/dist/visio/model.d.ts.map +1 -1
- package/dist/visio/parser.d.ts.map +1 -1
- package/dist/visio/plain-text.d.ts +5 -0
- package/dist/visio/plain-text.d.ts.map +1 -0
- package/dist/visio/resize-anchor.d.ts +27 -0
- package/dist/visio/resize-anchor.d.ts.map +1 -0
- package/dist/visio/source-paint.d.ts +5 -0
- package/dist/visio/source-paint.d.ts.map +1 -0
- package/dist/visio/style.d.ts.map +1 -1
- package/dist/visio/theme-root.d.ts.map +1 -1
- package/dist/visio/ui/contract.d.ts +10 -6
- package/dist/visio/ui/contract.d.ts.map +1 -1
- package/dist/visio/ui/draw-plan.d.ts +32 -0
- package/dist/visio/ui/draw-plan.d.ts.map +1 -0
- package/dist/visio/ui/edit-commands.d.ts.map +1 -1
- package/dist/visio/ui/formatting.d.ts +28 -0
- package/dist/visio/ui/formatting.d.ts.map +1 -0
- package/dist/visio/ui/index.cjs +1429 -16
- package/dist/visio/ui/index.d.ts +16 -0
- package/dist/visio/ui/index.d.ts.map +1 -1
- package/dist/visio/ui/index.mjs +1380 -17
- package/dist/visio/ui/line-dash.d.ts +4 -0
- package/dist/visio/ui/line-dash.d.ts.map +1 -0
- package/dist/visio/ui/marquee.d.ts +15 -0
- package/dist/visio/ui/marquee.d.ts.map +1 -0
- package/dist/visio/ui/page-edit.d.ts.map +1 -1
- 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/selection.d.ts +12 -0
- package/dist/visio/ui/selection.d.ts.map +1 -0
- package/dist/visio/ui/shape-arrange.d.ts +17 -0
- package/dist/visio/ui/shape-arrange.d.ts.map +1 -0
- package/dist/visio/ui/shape-clipboard.d.ts +10 -0
- package/dist/visio/ui/shape-clipboard.d.ts.map +1 -0
- package/dist/visio/ui/shape-duplicate.d.ts +5 -0
- package/dist/visio/ui/shape-duplicate.d.ts.map +1 -0
- package/dist/visio/ui/shape-formatting.d.ts +14 -0
- package/dist/visio/ui/shape-formatting.d.ts.map +1 -0
- package/dist/visio/ui/shape-move.d.ts +14 -0
- package/dist/visio/ui/shape-move.d.ts.map +1 -0
- package/dist/visio/ui/shape-order.d.ts +4 -0
- package/dist/visio/ui/shape-order.d.ts.map +1 -0
- package/dist/visio/ui/shape-resize.d.ts +61 -0
- package/dist/visio/ui/shape-resize.d.ts.map +1 -0
- package/dist/visio/ui/size-position.d.ts +19 -0
- package/dist/visio/ui/size-position.d.ts.map +1 -0
- package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
- package/dist/visio/ui/svg-stroke.d.ts +8 -0
- package/dist/visio/ui/svg-stroke.d.ts.map +1 -0
- package/dist/visio/ui/text-replace-selection.d.ts +9 -0
- package/dist/visio/ui/text-replace-selection.d.ts.map +1 -0
- package/dist/visio/ui/text-replace-snapshot.d.ts +14 -0
- package/dist/visio/ui/text-replace-snapshot.d.ts.map +1 -0
- package/dist/visio/ui/text-replace-types.d.ts +52 -0
- package/dist/visio/ui/text-replace-types.d.ts.map +1 -0
- package/dist/visio/ui/text-replace.d.ts +17 -0
- package/dist/visio/ui/text-replace.d.ts.map +1 -0
- 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/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 +8 -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/lexemes.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 +463 -332
- package/dist/xlsx/index.mjs +463 -332
- package/dist/xlsx/load/index.cjs +7628 -7583
- package/dist/xlsx/load/index.mjs +7628 -7583
- 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 +461 -332
- package/dist/xlsx/ui/index.mjs +461 -332
- 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
|
@@ -2268,14 +2268,13 @@ function splitSheets(text3) {
|
|
|
2268
2268
|
if (book !== void 0) out.book = book;
|
|
2269
2269
|
return out;
|
|
2270
2270
|
}
|
|
2271
|
-
var PREFIX_AT = /(\[\d+\])?([A-Za-z0-9_.\u00A1-\uFFFF]+)(?::([A-Za-z0-9_.\u00A1-\uFFFF]+))?!/y;
|
|
2272
2271
|
function readPrefix(source2, at) {
|
|
2273
2272
|
const ch = source2[at];
|
|
2274
2273
|
if (ch === "'") {
|
|
2275
2274
|
const quoted = readQuoted(source2, at);
|
|
2276
2275
|
if (source2[at + quoted.length] !== "!") return void 0;
|
|
2277
|
-
const
|
|
2278
|
-
return { prefix: { text: source2.slice(at, at +
|
|
2276
|
+
const length2 = quoted.length + 1;
|
|
2277
|
+
return { prefix: { text: source2.slice(at, at + length2), ...splitSheets(quoted.name) }, length: length2 };
|
|
2279
2278
|
}
|
|
2280
2279
|
let i2 = at;
|
|
2281
2280
|
if (ch === "[") {
|
|
@@ -2284,13 +2283,23 @@ function readPrefix(source2, at) {
|
|
|
2284
2283
|
if (i2 === at + 1 || source2[i2] !== "]") return void 0;
|
|
2285
2284
|
i2++;
|
|
2286
2285
|
}
|
|
2286
|
+
const sheetFrom = i2;
|
|
2287
2287
|
while (i2 < source2.length && isSheetCharCode(source2.charCodeAt(i2))) i2++;
|
|
2288
|
-
if (
|
|
2289
|
-
|
|
2290
|
-
if (
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2288
|
+
if (i2 === sheetFrom) return void 0;
|
|
2289
|
+
let lastFrom = -1;
|
|
2290
|
+
if (source2[i2] === ":") {
|
|
2291
|
+
lastFrom = i2 + 1;
|
|
2292
|
+
i2 = lastFrom;
|
|
2293
|
+
while (i2 < source2.length && isSheetCharCode(source2.charCodeAt(i2))) i2++;
|
|
2294
|
+
if (i2 === lastFrom) return void 0;
|
|
2295
|
+
}
|
|
2296
|
+
if (source2[i2] !== "!") return void 0;
|
|
2297
|
+
if (ch !== "[" && lastFrom < 0 && isDigitCode(source2.charCodeAt(sheetFrom))) return void 0;
|
|
2298
|
+
const length = i2 + 1 - at;
|
|
2299
|
+
return {
|
|
2300
|
+
prefix: { text: source2.slice(at, at + length), ...splitSheets(source2.slice(at, i2)) },
|
|
2301
|
+
length
|
|
2302
|
+
};
|
|
2294
2303
|
}
|
|
2295
2304
|
function numberLiteral(text3) {
|
|
2296
2305
|
if (text3.length <= 15) return Number(text3);
|
|
@@ -7806,6 +7815,39 @@ function liftCriteria(ctx, pairs, fn) {
|
|
|
7806
7815
|
});
|
|
7807
7816
|
}
|
|
7808
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 isFilteredRow(workbook, sheet, row2) {
|
|
7839
|
+
const info = sheet.rowInfo.get(row2);
|
|
7840
|
+
if (info?.filteredOut !== void 0) return info.filteredOut;
|
|
7841
|
+
const filter2 = sheet.autoFilter;
|
|
7842
|
+
return !!info?.hidden && !!filter2 && row2 > filter2.range.start.row && row2 <= filter2.range.end.row && !rowMatchesFilter(workbook, sheet, row2, filter2);
|
|
7843
|
+
}
|
|
7844
|
+
function readFilteredRows(workbook) {
|
|
7845
|
+
for (const sheet of workbook.sheets)
|
|
7846
|
+
for (const [row2, info] of sheet.rowInfo)
|
|
7847
|
+
if (sheet.autoFilter && row2 > sheet.autoFilter.range.start.row && row2 <= sheet.autoFilter.range.end.row && info.hidden)
|
|
7848
|
+
info.filteredOut = isFilteredRow(workbook, sheet, row2);
|
|
7849
|
+
}
|
|
7850
|
+
|
|
7809
7851
|
// xlsx/formula/functions/math-sum.ts
|
|
7810
7852
|
var C18 = "Math & Trig";
|
|
7811
7853
|
var numbersOf = (values2) => values2.filter((v) => typeof v === "number");
|
|
@@ -7843,7 +7885,7 @@ function pairwise(ctx, args, fn) {
|
|
|
7843
7885
|
return total2;
|
|
7844
7886
|
}
|
|
7845
7887
|
var SUBTOTAL_RE = /\b(?:_xlfn\.)?(?:SUBTOTAL|AGGREGATE)\s*\(/i;
|
|
7846
|
-
function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
|
|
7888
|
+
function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true, skipFiltered = false) {
|
|
7847
7889
|
const out = [];
|
|
7848
7890
|
const host = ctx.frame.host;
|
|
7849
7891
|
for (const arg of args) {
|
|
@@ -7856,6 +7898,7 @@ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
|
|
|
7856
7898
|
for (const area of arg.areas) {
|
|
7857
7899
|
const sheet = ctx.workbook.sheets[area.sheet];
|
|
7858
7900
|
host.forEachStored(area.sheet, area.range, (value, row2, col) => {
|
|
7901
|
+
if (skipFiltered && sheet && isFilteredRow(ctx.workbook, sheet, row2)) return;
|
|
7859
7902
|
if (skipHidden && sheet?.rowInfo.get(row2)?.hidden) return;
|
|
7860
7903
|
if (skipNested && SUBTOTAL_RE.test(host.cellFormula(area.sheet, row2, col) ?? "")) return;
|
|
7861
7904
|
if (skipErrors && isError(value)) return;
|
|
@@ -8021,7 +8064,7 @@ var SUM_FUNCTIONS = [
|
|
|
8021
8064
|
const code = int(args[0]);
|
|
8022
8065
|
const base = code > 100 ? code - 100 : code;
|
|
8023
8066
|
if (base < 1 || base > 11) fail(ERR.VALUE);
|
|
8024
|
-
return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false));
|
|
8067
|
+
return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false, true, true));
|
|
8025
8068
|
},
|
|
8026
8069
|
["value", "any"]
|
|
8027
8070
|
),
|
|
@@ -13559,6 +13602,31 @@ function renameTableInFormula(formula, oldName, newName) {
|
|
|
13559
13602
|
}
|
|
13560
13603
|
return changed ? joinTokens(tokens2) : formula;
|
|
13561
13604
|
}
|
|
13605
|
+
function renameTableColumnInFormula(formula, tableName, oldName, newName, insideTable = false) {
|
|
13606
|
+
const tokens2 = safeTokens2(formula);
|
|
13607
|
+
if (!tokens2) return formula;
|
|
13608
|
+
const escaped = newName.replace(/['#@[\]]/g, "'$&");
|
|
13609
|
+
let changed = false;
|
|
13610
|
+
for (const [index2, token] of tokens2.entries()) {
|
|
13611
|
+
if (token.kind !== "structured" || token.prefix) continue;
|
|
13612
|
+
if (token.value === "" && tokens2[index2 - 1]?.prefix) continue;
|
|
13613
|
+
if (token.value === "" ? !insideTable : String(token.value).toLowerCase() !== tableName.toLowerCase())
|
|
13614
|
+
continue;
|
|
13615
|
+
const next = token.text.replace(
|
|
13616
|
+
/\[(@?)((?:[^\[\]']|'[\s\S])*)\]/g,
|
|
13617
|
+
(original, at, name) => {
|
|
13618
|
+
if (name.startsWith("#") || name.replace(/'(.)/g, "$1").toLowerCase() !== oldName.toLowerCase())
|
|
13619
|
+
return original;
|
|
13620
|
+
return `[${at}${escaped}]`;
|
|
13621
|
+
}
|
|
13622
|
+
);
|
|
13623
|
+
if (next !== token.text) {
|
|
13624
|
+
token.text = next;
|
|
13625
|
+
changed = true;
|
|
13626
|
+
}
|
|
13627
|
+
}
|
|
13628
|
+
return changed ? joinTokens(tokens2) : formula;
|
|
13629
|
+
}
|
|
13562
13630
|
|
|
13563
13631
|
// xlsx/formula/structured-to-a1.ts
|
|
13564
13632
|
var abs = (row2, col, rowAbs = true) => `$${columnLabel(col)}${rowAbs ? "$" : ""}${row2 + 1}`;
|
|
@@ -20315,6 +20383,7 @@ async function loadXlsx(input) {
|
|
|
20315
20383
|
if (!sheets.length) throw new Error("XLSX workbook has no sheets");
|
|
20316
20384
|
await resolveSmartArt(sheets, source2, warn);
|
|
20317
20385
|
liftPrintAreas(workbook);
|
|
20386
|
+
readFilteredRows(workbook);
|
|
20318
20387
|
return workbook;
|
|
20319
20388
|
}
|
|
20320
20389
|
function readProperties(core, app, custom, warn) {
|
|
@@ -24617,16 +24686,6 @@ function forEachPosition(sheet, range, visit2) {
|
|
|
24617
24686
|
for (let row2 = r.start.row; row2 <= r.end.row; row2++)
|
|
24618
24687
|
for (let col = r.start.col; col <= r.end.col; col++) visit2(row2, col);
|
|
24619
24688
|
}
|
|
24620
|
-
function displayText(workbook, cell) {
|
|
24621
|
-
if (!cell) return "";
|
|
24622
|
-
const value = cell.value;
|
|
24623
|
-
if (value === null) return "";
|
|
24624
|
-
if (isCellError(value)) return value.error;
|
|
24625
|
-
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
24626
|
-
if (cell.richText && typeof value === "string") return value;
|
|
24627
|
-
const format = styleAt(workbook, cell.styleId).numFmt;
|
|
24628
|
-
return formatValue(value, format, { date1904: workbook.date1904 }).text;
|
|
24629
|
-
}
|
|
24630
24689
|
function rawText(value) {
|
|
24631
24690
|
if (value === null) return "";
|
|
24632
24691
|
if (isCellError(value)) return value.error;
|
|
@@ -24643,19 +24702,266 @@ function pruneCell(sheet, row2, col) {
|
|
|
24643
24702
|
}
|
|
24644
24703
|
}
|
|
24645
24704
|
|
|
24705
|
+
// xlsx/edit/shift-preserved.ts
|
|
24706
|
+
var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
|
|
24707
|
+
function descendants3(root, ns, local) {
|
|
24708
|
+
return Array.from(root.getElementsByTagNameNS(ns, local));
|
|
24709
|
+
}
|
|
24710
|
+
function editEntries(sheet, key, edit, quick) {
|
|
24711
|
+
const list = sheet.preserved.get(key);
|
|
24712
|
+
if (!list) return;
|
|
24713
|
+
const next = [];
|
|
24714
|
+
for (const xml of list) {
|
|
24715
|
+
if (!quick(xml)) {
|
|
24716
|
+
next.push(xml);
|
|
24717
|
+
continue;
|
|
24718
|
+
}
|
|
24719
|
+
let doc;
|
|
24720
|
+
try {
|
|
24721
|
+
doc = parseXml(xml);
|
|
24722
|
+
} catch {
|
|
24723
|
+
next.push(xml);
|
|
24724
|
+
continue;
|
|
24725
|
+
}
|
|
24726
|
+
const outcome = edit(doc.documentElement);
|
|
24727
|
+
if (outcome === "same") next.push(xml);
|
|
24728
|
+
else if (outcome === "changed") next.push(buildXml(doc));
|
|
24729
|
+
}
|
|
24730
|
+
if (next.length) sheet.preserved.set(key, next);
|
|
24731
|
+
else sheet.preserved.delete(key);
|
|
24732
|
+
}
|
|
24733
|
+
function shiftBreaks(root, shift2) {
|
|
24734
|
+
let changed = false;
|
|
24735
|
+
for (const brk of elements(root).filter((e) => e.localName === "brk")) {
|
|
24736
|
+
const id = Number(brk.getAttribute("id") ?? "0");
|
|
24737
|
+
const moved = shiftIndex(id, shift2);
|
|
24738
|
+
if (moved === id) continue;
|
|
24739
|
+
changed = true;
|
|
24740
|
+
if (moved === void 0 || moved === 0) root.removeChild(brk);
|
|
24741
|
+
else brk.setAttribute("id", String(moved));
|
|
24742
|
+
}
|
|
24743
|
+
if (!changed) return "same";
|
|
24744
|
+
const left2 = elements(root).filter((e) => e.localName === "brk");
|
|
24745
|
+
if (!left2.length) return "drop";
|
|
24746
|
+
if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
|
|
24747
|
+
if (root.hasAttribute("manualBreakCount")) {
|
|
24748
|
+
const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
|
|
24749
|
+
root.setAttribute("manualBreakCount", String(manual));
|
|
24750
|
+
}
|
|
24751
|
+
return "changed";
|
|
24752
|
+
}
|
|
24753
|
+
function removeUpwards(node, root) {
|
|
24754
|
+
let current = node;
|
|
24755
|
+
while (current && current !== root) {
|
|
24756
|
+
const parent = current.parentNode;
|
|
24757
|
+
parent?.removeChild(current);
|
|
24758
|
+
if (!parent) break;
|
|
24759
|
+
const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
|
|
24760
|
+
if (!emptied) break;
|
|
24761
|
+
current = parent;
|
|
24762
|
+
}
|
|
24763
|
+
}
|
|
24764
|
+
function shiftSqrefs(root, moveRange) {
|
|
24765
|
+
let changed = false;
|
|
24766
|
+
for (const sqref2 of descendants3(root, XM3, "sqref")) {
|
|
24767
|
+
const old = sqref2.textContent ?? "";
|
|
24768
|
+
const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
|
|
24769
|
+
const text3 = ranges.map(formatRange).join(" ");
|
|
24770
|
+
if (text3 === old.trim()) continue;
|
|
24771
|
+
changed = true;
|
|
24772
|
+
const owner = sqref2.parentNode;
|
|
24773
|
+
if (ranges.length) sqref2.textContent = text3;
|
|
24774
|
+
else if (owner) removeUpwards(owner, root);
|
|
24775
|
+
}
|
|
24776
|
+
if (!changed) return "same";
|
|
24777
|
+
for (const list of elements(root).flatMap((ext) => elements(ext)))
|
|
24778
|
+
if (list.localName === "dataValidations" && list.hasAttribute("count"))
|
|
24779
|
+
list.setAttribute("count", String(elements(list).length));
|
|
24780
|
+
return elements(root).length > 0 ? "changed" : "drop";
|
|
24781
|
+
}
|
|
24782
|
+
function shiftPreservedXml(sheet, shift2, moveRange, banded) {
|
|
24783
|
+
if (!banded)
|
|
24784
|
+
editEntries(
|
|
24785
|
+
sheet,
|
|
24786
|
+
shift2.axis === "row" ? "rowBreaks" : "colBreaks",
|
|
24787
|
+
(root) => shiftBreaks(root, shift2),
|
|
24788
|
+
(xml) => xml.includes("brk")
|
|
24789
|
+
);
|
|
24790
|
+
editEntries(
|
|
24791
|
+
sheet,
|
|
24792
|
+
"extLst",
|
|
24793
|
+
(root) => shiftSqrefs(root, moveRange),
|
|
24794
|
+
(xml) => xml.includes("sqref")
|
|
24795
|
+
);
|
|
24796
|
+
}
|
|
24797
|
+
function rewritePreservedFormulas(sheet, rewrite2) {
|
|
24798
|
+
editEntries(
|
|
24799
|
+
sheet,
|
|
24800
|
+
"extLst",
|
|
24801
|
+
(root) => {
|
|
24802
|
+
let changed = false;
|
|
24803
|
+
for (const f6 of descendants3(root, XM3, "f")) {
|
|
24804
|
+
const text3 = f6.textContent ?? "";
|
|
24805
|
+
let next = text3;
|
|
24806
|
+
try {
|
|
24807
|
+
next = rewrite2(text3, sheet.name);
|
|
24808
|
+
} catch {
|
|
24809
|
+
next = text3;
|
|
24810
|
+
}
|
|
24811
|
+
if (next === text3) continue;
|
|
24812
|
+
f6.textContent = next;
|
|
24813
|
+
changed = true;
|
|
24814
|
+
}
|
|
24815
|
+
return changed ? "changed" : "same";
|
|
24816
|
+
},
|
|
24817
|
+
(xml) => xml.includes(":f>")
|
|
24818
|
+
);
|
|
24819
|
+
}
|
|
24820
|
+
|
|
24821
|
+
// xlsx/edit/conditional-formulas.ts
|
|
24822
|
+
function rewriteConditionalRule(rule, rewrite2) {
|
|
24823
|
+
const safe2 = (formula) => {
|
|
24824
|
+
try {
|
|
24825
|
+
return rewrite2(formula);
|
|
24826
|
+
} catch {
|
|
24827
|
+
return formula;
|
|
24828
|
+
}
|
|
24829
|
+
};
|
|
24830
|
+
if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
|
|
24831
|
+
else if (rule.type === "expression") rule.formula = safe2(rule.formula);
|
|
24832
|
+
if (rule.type === "colorScale" || rule.type === "iconSet") {
|
|
24833
|
+
for (const threshold of rule.thresholds)
|
|
24834
|
+
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
24835
|
+
}
|
|
24836
|
+
if (rule.type === "dataBar") {
|
|
24837
|
+
for (const threshold of [rule.min, rule.max])
|
|
24838
|
+
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
24839
|
+
}
|
|
24840
|
+
if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
|
|
24841
|
+
}
|
|
24842
|
+
|
|
24843
|
+
// xlsx/edit/shift-formulas.ts
|
|
24844
|
+
function safe(rewrite2, formula, formulaSheet, at) {
|
|
24845
|
+
try {
|
|
24846
|
+
return rewrite2(formula, formulaSheet, at);
|
|
24847
|
+
} catch {
|
|
24848
|
+
return formula;
|
|
24849
|
+
}
|
|
24850
|
+
}
|
|
24851
|
+
function rewriteFormulas(workbook, rewrite2, formulaCells) {
|
|
24852
|
+
const bySheet = formulaCells && /* @__PURE__ */ new Map();
|
|
24853
|
+
if (bySheet)
|
|
24854
|
+
for (const cell of formulaCells ?? []) {
|
|
24855
|
+
const positions2 = bySheet.get(cell.sheet);
|
|
24856
|
+
if (positions2) positions2.push(cell);
|
|
24857
|
+
else bySheet.set(cell.sheet, [cell]);
|
|
24858
|
+
}
|
|
24859
|
+
workbook.sheets.forEach(
|
|
24860
|
+
(sheet, index2) => rewriteSheetFormulas(sheet, rewrite2, bySheet ? bySheet.get(index2) ?? [] : void 0)
|
|
24861
|
+
);
|
|
24862
|
+
for (const definedName of workbook.definedNames) {
|
|
24863
|
+
const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
|
|
24864
|
+
definedName.formula = safe(rewrite2, definedName.formula, local?.name ?? "");
|
|
24865
|
+
}
|
|
24866
|
+
}
|
|
24867
|
+
function rewriteSheetFormulas(sheet, rewrite2, formulaCells) {
|
|
24868
|
+
rewritePreservedFormulas(sheet, rewrite2);
|
|
24869
|
+
{
|
|
24870
|
+
const name = sheet.name;
|
|
24871
|
+
for (const table2 of sheet.tables)
|
|
24872
|
+
for (const [index2, column] of table2.columns.entries())
|
|
24873
|
+
if (column.calculatedColumnFormula !== void 0)
|
|
24874
|
+
column.calculatedColumnFormula = safe(rewrite2, column.calculatedColumnFormula, name, {
|
|
24875
|
+
row: table2.range.start.row + (table2.headerRow ? 1 : 0),
|
|
24876
|
+
col: table2.range.start.col + index2
|
|
24877
|
+
});
|
|
24878
|
+
if (formulaCells) {
|
|
24879
|
+
for (const at of formulaCells) {
|
|
24880
|
+
const cell = getCell(sheet, at.row, at.col);
|
|
24881
|
+
if (cell?.formula !== void 0) cell.formula = safe(rewrite2, cell.formula, name, at);
|
|
24882
|
+
}
|
|
24883
|
+
} else {
|
|
24884
|
+
sheet.rows.forEach(
|
|
24885
|
+
(cells, row2) => cells.forEach((cell, col) => {
|
|
24886
|
+
if (cell.formula !== void 0)
|
|
24887
|
+
cell.formula = safe(rewrite2, cell.formula, name, { row: row2, col });
|
|
24888
|
+
})
|
|
24889
|
+
);
|
|
24890
|
+
}
|
|
24891
|
+
for (const cf of sheet.conditionalFormats)
|
|
24892
|
+
for (const rule of cf.rules)
|
|
24893
|
+
rewriteConditionalRule(rule, (f6) => rewrite2(f6, name, cf.ranges[0]?.start));
|
|
24894
|
+
for (const dv of sheet.dataValidations) {
|
|
24895
|
+
if (dv.formula1 !== void 0)
|
|
24896
|
+
dv.formula1 = safe(rewrite2, dv.formula1, name, dv.ranges[0]?.start);
|
|
24897
|
+
if (dv.formula2 !== void 0)
|
|
24898
|
+
dv.formula2 = safe(rewrite2, dv.formula2, name, dv.ranges[0]?.start);
|
|
24899
|
+
}
|
|
24900
|
+
for (const link of sheet.hyperlinks)
|
|
24901
|
+
if (link.location && /![A-Za-z$]/.test(link.location))
|
|
24902
|
+
link.location = safe(rewrite2, link.location, name);
|
|
24903
|
+
for (const drawing of sheet.drawings) {
|
|
24904
|
+
if (drawing.kind !== "chart") continue;
|
|
24905
|
+
for (const series of drawing.series) {
|
|
24906
|
+
if (series.nameRef) series.nameRef = safe(rewrite2, series.nameRef, name);
|
|
24907
|
+
if (series.categoriesRef) series.categoriesRef = safe(rewrite2, series.categoriesRef, name);
|
|
24908
|
+
if (series.valuesRef) series.valuesRef = safe(rewrite2, series.valuesRef, name);
|
|
24909
|
+
}
|
|
24910
|
+
}
|
|
24911
|
+
}
|
|
24912
|
+
}
|
|
24913
|
+
|
|
24914
|
+
// xlsx/edit/table-header-names.ts
|
|
24915
|
+
function uniqueHeaders(texts) {
|
|
24916
|
+
const used = /* @__PURE__ */ new Set();
|
|
24917
|
+
return texts.map((text3, i2) => {
|
|
24918
|
+
let base = text3.trim() || `Column${i2 + 1}`;
|
|
24919
|
+
if (!used.has(base.toLowerCase())) {
|
|
24920
|
+
used.add(base.toLowerCase());
|
|
24921
|
+
return base;
|
|
24922
|
+
}
|
|
24923
|
+
for (let n2 = 2; ; n2++) {
|
|
24924
|
+
const candidate = `${base}${n2}`;
|
|
24925
|
+
if (!used.has(candidate.toLowerCase())) {
|
|
24926
|
+
used.add(candidate.toLowerCase());
|
|
24927
|
+
base = candidate;
|
|
24928
|
+
return base;
|
|
24929
|
+
}
|
|
24930
|
+
}
|
|
24931
|
+
});
|
|
24932
|
+
}
|
|
24933
|
+
|
|
24646
24934
|
// xlsx/edit/cell-values.ts
|
|
24647
24935
|
function tableHeaderAt(sheet, row2, col) {
|
|
24648
24936
|
return sheet.tables.find(
|
|
24649
24937
|
(t) => t.headerRow && t.range.start.row === row2 && col >= t.range.start.col && col <= t.range.end.col
|
|
24650
24938
|
);
|
|
24651
24939
|
}
|
|
24652
|
-
function syncTableHeader(ctx, sheet, row2, col) {
|
|
24940
|
+
function syncTableHeader(ctx, sheet, row2, col, formulaCells) {
|
|
24653
24941
|
const table2 = tableHeaderAt(sheet, row2, col);
|
|
24654
24942
|
if (!table2) return;
|
|
24655
24943
|
const column = table2.columns[col - table2.range.start.col];
|
|
24656
24944
|
if (!column) return;
|
|
24657
24945
|
const text3 = displayText(ctx.workbook, getCell(sheet, row2, col)).trim();
|
|
24658
|
-
if (text3
|
|
24946
|
+
if (!text3 || column.name === text3) return;
|
|
24947
|
+
const oldName = column.name;
|
|
24948
|
+
const others = table2.columns.filter((entry3) => entry3 !== column).map((entry3) => entry3.name);
|
|
24949
|
+
const newName = uniqueHeaders([...others, text3]).at(-1);
|
|
24950
|
+
column.name = newName;
|
|
24951
|
+
if (newName !== text3) writeValue(sheet, row2, col, newName);
|
|
24952
|
+
const index2 = ctx.workbook.sheets.indexOf(sheet);
|
|
24953
|
+
const cells = formulaCells && (formulaCells.some((cell) => cell.sheet === index2 && cell.row === row2 && cell.col === col) ? formulaCells : [...formulaCells, { sheet: index2, row: row2, col }]);
|
|
24954
|
+
rewriteFormulas(
|
|
24955
|
+
ctx.workbook,
|
|
24956
|
+
(formula, formulaSheet, at) => renameTableColumnInFormula(
|
|
24957
|
+
formula,
|
|
24958
|
+
table2.name,
|
|
24959
|
+
oldName,
|
|
24960
|
+
newName,
|
|
24961
|
+
formulaSheet === sheet.name && !!at && rangeContains(table2.range, at)
|
|
24962
|
+
),
|
|
24963
|
+
cells
|
|
24964
|
+
);
|
|
24659
24965
|
}
|
|
24660
24966
|
function writeScopes(sheet, index2, range, parts = []) {
|
|
24661
24967
|
const r = normalizeRange(range);
|
|
@@ -24665,9 +24971,9 @@ function writeScopes(sheet, index2, range, parts = []) {
|
|
|
24665
24971
|
cellRange(t.range.start.row, t.range.start.col, t.range.start.row, t.range.end.col)
|
|
24666
24972
|
)
|
|
24667
24973
|
);
|
|
24668
|
-
|
|
24974
|
+
if (touchesHeader) return [{ kind: "refs" }, { kind: "cells", sheet: index2, ranges: [r] }];
|
|
24669
24975
|
const scopes = [{ kind: "cells", sheet: index2, ranges: [r] }];
|
|
24670
|
-
if (
|
|
24976
|
+
if (parts.length) scopes.push({ kind: "parts", sheet: index2, parts });
|
|
24671
24977
|
return scopes;
|
|
24672
24978
|
}
|
|
24673
24979
|
function writeInput(ctx, sheet, row2, col, text3) {
|
|
@@ -24718,9 +25024,9 @@ function setCellInput(ctx, s, row2, col, text3) {
|
|
|
24718
25024
|
`Typing in ${formatAddress({ row: row2, col })}`,
|
|
24719
25025
|
"cells",
|
|
24720
25026
|
writeScopes(sheet, s, range),
|
|
24721
|
-
() => {
|
|
25027
|
+
(formulaCells) => {
|
|
24722
25028
|
writeInput(ctx, sheet, row2, col, text3);
|
|
24723
|
-
syncTableHeader(ctx, sheet, row2, col);
|
|
25029
|
+
syncTableHeader(ctx, sheet, row2, col, formulaCells);
|
|
24724
25030
|
},
|
|
24725
25031
|
{ sheet: s, ranges: [range] }
|
|
24726
25032
|
);
|
|
@@ -24732,9 +25038,9 @@ function setCellValue(ctx, s, row2, col, value) {
|
|
|
24732
25038
|
`Edit ${formatAddress({ row: row2, col })}`,
|
|
24733
25039
|
"cells",
|
|
24734
25040
|
writeScopes(sheet, s, range),
|
|
24735
|
-
() => {
|
|
25041
|
+
(formulaCells) => {
|
|
24736
25042
|
writeValue(sheet, row2, col, value);
|
|
24737
|
-
syncTableHeader(ctx, sheet, row2, col);
|
|
25043
|
+
syncTableHeader(ctx, sheet, row2, col, formulaCells);
|
|
24738
25044
|
},
|
|
24739
25045
|
{ sheet: s, ranges: [range] }
|
|
24740
25046
|
);
|
|
@@ -25161,7 +25467,7 @@ function fillRange(ctx, s, source2, target, mode = "auto") {
|
|
|
25161
25467
|
ctx.run(
|
|
25162
25468
|
"Fill",
|
|
25163
25469
|
"cells",
|
|
25164
|
-
|
|
25470
|
+
writeScopes(sheet, s, all2),
|
|
25165
25471
|
() => {
|
|
25166
25472
|
const laneCount = vertical ? src.end.col - src.start.col + 1 : src.end.row - src.start.row + 1;
|
|
25167
25473
|
const length = vertical ? src.end.row - src.start.row + 1 : src.end.col - src.start.col + 1;
|
|
@@ -25184,6 +25490,7 @@ function fillRange(ctx, s, source2, target, mode = "auto") {
|
|
|
25184
25490
|
const step2 = series?.(k);
|
|
25185
25491
|
const cell = !step2 || step2.kind === "copy" ? copyCell(origin, row2 - srcRow, col - srcCol) : { value: step2.value, ...origin.styleId ? { styleId: origin.styleId } : {} };
|
|
25186
25492
|
putCell(sheet, row2, col, cell);
|
|
25493
|
+
syncTableHeader(ctx, sheet, row2, col);
|
|
25187
25494
|
}
|
|
25188
25495
|
}
|
|
25189
25496
|
},
|
|
@@ -25222,28 +25529,6 @@ function removeValidationArea(rules, area) {
|
|
|
25222
25529
|
});
|
|
25223
25530
|
}
|
|
25224
25531
|
|
|
25225
|
-
// xlsx/edit/conditional-formulas.ts
|
|
25226
|
-
function rewriteConditionalRule(rule, rewrite2) {
|
|
25227
|
-
const safe2 = (formula) => {
|
|
25228
|
-
try {
|
|
25229
|
-
return rewrite2(formula);
|
|
25230
|
-
} catch {
|
|
25231
|
-
return formula;
|
|
25232
|
-
}
|
|
25233
|
-
};
|
|
25234
|
-
if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
|
|
25235
|
-
else if (rule.type === "expression") rule.formula = safe2(rule.formula);
|
|
25236
|
-
if (rule.type === "colorScale" || rule.type === "iconSet") {
|
|
25237
|
-
for (const threshold of rule.thresholds)
|
|
25238
|
-
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
25239
|
-
}
|
|
25240
|
-
if (rule.type === "dataBar") {
|
|
25241
|
-
for (const threshold of [rule.min, rule.max])
|
|
25242
|
-
if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
|
|
25243
|
-
}
|
|
25244
|
-
if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
|
|
25245
|
-
}
|
|
25246
|
-
|
|
25247
25532
|
// xlsx/edit/conditional-formats.ts
|
|
25248
25533
|
function formatAt(sheet, index2) {
|
|
25249
25534
|
const format = sheet.conditionalFormats[index2];
|
|
@@ -25653,168 +25938,6 @@ function setBorders(ctx, s, range, preset, edge2 = { style: "thin" }) {
|
|
|
25653
25938
|
);
|
|
25654
25939
|
}
|
|
25655
25940
|
|
|
25656
|
-
// xlsx/edit/shift-preserved.ts
|
|
25657
|
-
var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
|
|
25658
|
-
function descendants3(root, ns, local) {
|
|
25659
|
-
return Array.from(root.getElementsByTagNameNS(ns, local));
|
|
25660
|
-
}
|
|
25661
|
-
function editEntries(sheet, key, edit, quick) {
|
|
25662
|
-
const list = sheet.preserved.get(key);
|
|
25663
|
-
if (!list) return;
|
|
25664
|
-
const next = [];
|
|
25665
|
-
for (const xml of list) {
|
|
25666
|
-
if (!quick(xml)) {
|
|
25667
|
-
next.push(xml);
|
|
25668
|
-
continue;
|
|
25669
|
-
}
|
|
25670
|
-
let doc;
|
|
25671
|
-
try {
|
|
25672
|
-
doc = parseXml(xml);
|
|
25673
|
-
} catch {
|
|
25674
|
-
next.push(xml);
|
|
25675
|
-
continue;
|
|
25676
|
-
}
|
|
25677
|
-
const outcome = edit(doc.documentElement);
|
|
25678
|
-
if (outcome === "same") next.push(xml);
|
|
25679
|
-
else if (outcome === "changed") next.push(buildXml(doc));
|
|
25680
|
-
}
|
|
25681
|
-
if (next.length) sheet.preserved.set(key, next);
|
|
25682
|
-
else sheet.preserved.delete(key);
|
|
25683
|
-
}
|
|
25684
|
-
function shiftBreaks(root, shift2) {
|
|
25685
|
-
let changed = false;
|
|
25686
|
-
for (const brk of elements(root).filter((e) => e.localName === "brk")) {
|
|
25687
|
-
const id = Number(brk.getAttribute("id") ?? "0");
|
|
25688
|
-
const moved = shiftIndex(id, shift2);
|
|
25689
|
-
if (moved === id) continue;
|
|
25690
|
-
changed = true;
|
|
25691
|
-
if (moved === void 0 || moved === 0) root.removeChild(brk);
|
|
25692
|
-
else brk.setAttribute("id", String(moved));
|
|
25693
|
-
}
|
|
25694
|
-
if (!changed) return "same";
|
|
25695
|
-
const left2 = elements(root).filter((e) => e.localName === "brk");
|
|
25696
|
-
if (!left2.length) return "drop";
|
|
25697
|
-
if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
|
|
25698
|
-
if (root.hasAttribute("manualBreakCount")) {
|
|
25699
|
-
const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
|
|
25700
|
-
root.setAttribute("manualBreakCount", String(manual));
|
|
25701
|
-
}
|
|
25702
|
-
return "changed";
|
|
25703
|
-
}
|
|
25704
|
-
function removeUpwards(node, root) {
|
|
25705
|
-
let current = node;
|
|
25706
|
-
while (current && current !== root) {
|
|
25707
|
-
const parent = current.parentNode;
|
|
25708
|
-
parent?.removeChild(current);
|
|
25709
|
-
if (!parent) break;
|
|
25710
|
-
const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
|
|
25711
|
-
if (!emptied) break;
|
|
25712
|
-
current = parent;
|
|
25713
|
-
}
|
|
25714
|
-
}
|
|
25715
|
-
function shiftSqrefs(root, moveRange) {
|
|
25716
|
-
let changed = false;
|
|
25717
|
-
for (const sqref2 of descendants3(root, XM3, "sqref")) {
|
|
25718
|
-
const old = sqref2.textContent ?? "";
|
|
25719
|
-
const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
|
|
25720
|
-
const text3 = ranges.map(formatRange).join(" ");
|
|
25721
|
-
if (text3 === old.trim()) continue;
|
|
25722
|
-
changed = true;
|
|
25723
|
-
const owner = sqref2.parentNode;
|
|
25724
|
-
if (ranges.length) sqref2.textContent = text3;
|
|
25725
|
-
else if (owner) removeUpwards(owner, root);
|
|
25726
|
-
}
|
|
25727
|
-
if (!changed) return "same";
|
|
25728
|
-
for (const list of elements(root).flatMap((ext) => elements(ext)))
|
|
25729
|
-
if (list.localName === "dataValidations" && list.hasAttribute("count"))
|
|
25730
|
-
list.setAttribute("count", String(elements(list).length));
|
|
25731
|
-
return elements(root).length > 0 ? "changed" : "drop";
|
|
25732
|
-
}
|
|
25733
|
-
function shiftPreservedXml(sheet, shift2, moveRange, banded) {
|
|
25734
|
-
if (!banded)
|
|
25735
|
-
editEntries(
|
|
25736
|
-
sheet,
|
|
25737
|
-
shift2.axis === "row" ? "rowBreaks" : "colBreaks",
|
|
25738
|
-
(root) => shiftBreaks(root, shift2),
|
|
25739
|
-
(xml) => xml.includes("brk")
|
|
25740
|
-
);
|
|
25741
|
-
editEntries(
|
|
25742
|
-
sheet,
|
|
25743
|
-
"extLst",
|
|
25744
|
-
(root) => shiftSqrefs(root, moveRange),
|
|
25745
|
-
(xml) => xml.includes("sqref")
|
|
25746
|
-
);
|
|
25747
|
-
}
|
|
25748
|
-
function rewritePreservedFormulas(sheet, rewrite2) {
|
|
25749
|
-
editEntries(
|
|
25750
|
-
sheet,
|
|
25751
|
-
"extLst",
|
|
25752
|
-
(root) => {
|
|
25753
|
-
let changed = false;
|
|
25754
|
-
for (const f6 of descendants3(root, XM3, "f")) {
|
|
25755
|
-
const text3 = f6.textContent ?? "";
|
|
25756
|
-
let next = text3;
|
|
25757
|
-
try {
|
|
25758
|
-
next = rewrite2(text3, sheet.name);
|
|
25759
|
-
} catch {
|
|
25760
|
-
next = text3;
|
|
25761
|
-
}
|
|
25762
|
-
if (next === text3) continue;
|
|
25763
|
-
f6.textContent = next;
|
|
25764
|
-
changed = true;
|
|
25765
|
-
}
|
|
25766
|
-
return changed ? "changed" : "same";
|
|
25767
|
-
},
|
|
25768
|
-
(xml) => xml.includes(":f>")
|
|
25769
|
-
);
|
|
25770
|
-
}
|
|
25771
|
-
|
|
25772
|
-
// xlsx/edit/shift-formulas.ts
|
|
25773
|
-
function safe(rewrite2, formula, formulaSheet) {
|
|
25774
|
-
try {
|
|
25775
|
-
return rewrite2(formula, formulaSheet);
|
|
25776
|
-
} catch {
|
|
25777
|
-
return formula;
|
|
25778
|
-
}
|
|
25779
|
-
}
|
|
25780
|
-
function rewriteFormulas(workbook, rewrite2) {
|
|
25781
|
-
for (const sheet of workbook.sheets) rewriteSheetFormulas(sheet, rewrite2);
|
|
25782
|
-
for (const definedName of workbook.definedNames) {
|
|
25783
|
-
const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
|
|
25784
|
-
definedName.formula = safe(rewrite2, definedName.formula, local?.name ?? "");
|
|
25785
|
-
}
|
|
25786
|
-
}
|
|
25787
|
-
function rewriteSheetFormulas(sheet, rewrite2) {
|
|
25788
|
-
rewritePreservedFormulas(sheet, rewrite2);
|
|
25789
|
-
{
|
|
25790
|
-
const name = sheet.name;
|
|
25791
|
-
for (const table2 of sheet.tables)
|
|
25792
|
-
for (const column of table2.columns)
|
|
25793
|
-
if (column.calculatedColumnFormula !== void 0)
|
|
25794
|
-
column.calculatedColumnFormula = safe(rewrite2, column.calculatedColumnFormula, name);
|
|
25795
|
-
for (const cells of sheet.rows.values())
|
|
25796
|
-
for (const cell of cells.values())
|
|
25797
|
-
if (cell.formula !== void 0) cell.formula = safe(rewrite2, cell.formula, name);
|
|
25798
|
-
for (const cf of sheet.conditionalFormats)
|
|
25799
|
-
for (const rule of cf.rules) rewriteConditionalRule(rule, (f6) => rewrite2(f6, name));
|
|
25800
|
-
for (const dv of sheet.dataValidations) {
|
|
25801
|
-
if (dv.formula1 !== void 0) dv.formula1 = safe(rewrite2, dv.formula1, name);
|
|
25802
|
-
if (dv.formula2 !== void 0) dv.formula2 = safe(rewrite2, dv.formula2, name);
|
|
25803
|
-
}
|
|
25804
|
-
for (const link of sheet.hyperlinks)
|
|
25805
|
-
if (link.location && /![A-Za-z$]/.test(link.location))
|
|
25806
|
-
link.location = safe(rewrite2, link.location, name);
|
|
25807
|
-
for (const drawing of sheet.drawings) {
|
|
25808
|
-
if (drawing.kind !== "chart") continue;
|
|
25809
|
-
for (const series of drawing.series) {
|
|
25810
|
-
if (series.nameRef) series.nameRef = safe(rewrite2, series.nameRef, name);
|
|
25811
|
-
if (series.categoriesRef) series.categoriesRef = safe(rewrite2, series.categoriesRef, name);
|
|
25812
|
-
if (series.valuesRef) series.valuesRef = safe(rewrite2, series.valuesRef, name);
|
|
25813
|
-
}
|
|
25814
|
-
}
|
|
25815
|
-
}
|
|
25816
|
-
}
|
|
25817
|
-
|
|
25818
25941
|
// xlsx/edit/shift-sheet.ts
|
|
25819
25942
|
function shiftSheetContent(sheet, shift2, band) {
|
|
25820
25943
|
const moveRange = (range) => band ? shiftRangeInBand(range, shift2, band.lo, band.hi) : shiftRange(range, shift2);
|
|
@@ -26804,14 +26927,13 @@ function pasteAt(ctx, s, at, payload, request) {
|
|
|
26804
26927
|
if (cut && operation !== "none")
|
|
26805
26928
|
throw new RangeError("Paste operations are not available for cut cells.");
|
|
26806
26929
|
const destCells = { kind: "cells", sheet: s, ranges: [dest] };
|
|
26807
|
-
const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : [
|
|
26808
|
-
|
|
26809
|
-
|
|
26810
|
-
|
|
26811
|
-
|
|
26812
|
-
|
|
26813
|
-
|
|
26814
|
-
];
|
|
26930
|
+
const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : writeScopes(sheet, s, dest, [
|
|
26931
|
+
"merges",
|
|
26932
|
+
"comments",
|
|
26933
|
+
"dataValidations",
|
|
26934
|
+
"hyperlinks",
|
|
26935
|
+
"conditionalFormats"
|
|
26936
|
+
]);
|
|
26815
26937
|
const move = cut && {
|
|
26816
26938
|
fromSheet: sheetAt(workbook, cut.sheet).name,
|
|
26817
26939
|
range: cut.range,
|
|
@@ -26884,6 +27006,8 @@ function pasteAt(ctx, s, at, payload, request) {
|
|
|
26884
27006
|
const origin = cells.source?.range.start;
|
|
26885
27007
|
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);
|
|
26886
27008
|
writeClip(workbook, sheet, row2, col, clip, mode, formula, styleOf2, operation);
|
|
27009
|
+
if (mode !== "formats" && mode !== "comments" && mode !== "validation")
|
|
27010
|
+
syncTableHeader(ctx, sheet, row2, col);
|
|
26887
27011
|
}
|
|
26888
27012
|
if (mode === "all" || mode === "mergeFormats" || mode === "noBorders" || mode === "formats") {
|
|
26889
27013
|
sheet.merges = sheet.merges.filter((m) => !rangesIntersect(m, dest));
|
|
@@ -26927,14 +27051,13 @@ function pasteSelection(ctx, sheet, selection, payload, request) {
|
|
|
26927
27051
|
return ctx.run(
|
|
26928
27052
|
"Paste",
|
|
26929
27053
|
"cells",
|
|
26930
|
-
[
|
|
26931
|
-
|
|
26932
|
-
|
|
26933
|
-
|
|
26934
|
-
|
|
26935
|
-
|
|
26936
|
-
|
|
26937
|
-
],
|
|
27054
|
+
writeScopes(sheetAt(ctx.workbook, sheet), sheet, dest, [
|
|
27055
|
+
"merges",
|
|
27056
|
+
"comments",
|
|
27057
|
+
"dataValidations",
|
|
27058
|
+
"hyperlinks",
|
|
27059
|
+
"conditionalFormats"
|
|
27060
|
+
]),
|
|
26938
27061
|
() => {
|
|
26939
27062
|
for (let row2 = dest.start.row; row2 <= dest.end.row; row2 += height)
|
|
26940
27063
|
for (let col = dest.start.col; col <= dest.end.col; col += width)
|
|
@@ -27086,6 +27209,15 @@ function setHidden(ctx, s, axis, indices, hidden) {
|
|
|
27086
27209
|
}
|
|
27087
27210
|
for (const row2 of indices) {
|
|
27088
27211
|
const info = { ...sheet.rowInfo.get(row2) };
|
|
27212
|
+
if (info.filteredOut) {
|
|
27213
|
+
if (hidden) info.manuallyHidden = true;
|
|
27214
|
+
else delete info.manuallyHidden;
|
|
27215
|
+
sheet.rowInfo.set(row2, info);
|
|
27216
|
+
continue;
|
|
27217
|
+
}
|
|
27218
|
+
const filter2 = sheet.autoFilter;
|
|
27219
|
+
if (filter2?.columns?.length && row2 > filter2.range.start.row && row2 <= filter2.range.end.row)
|
|
27220
|
+
info.filteredOut = false;
|
|
27089
27221
|
if (hidden) info.hidden = true;
|
|
27090
27222
|
else {
|
|
27091
27223
|
delete info.hidden;
|
|
@@ -27240,14 +27372,21 @@ function currentRegion(sheet, at) {
|
|
|
27240
27372
|
function applyFilter(ctx, sheet, filter2) {
|
|
27241
27373
|
const { range } = filter2;
|
|
27242
27374
|
for (let row2 = range.start.row + 1; row2 <= range.end.row; row2++) {
|
|
27243
|
-
const visible = (
|
|
27244
|
-
if (!fc.values && !fc.blank) return true;
|
|
27245
|
-
const text3 = displayText(ctx.workbook, getCell(sheet, row2, range.start.col + fc.offset));
|
|
27246
|
-
return text3 === "" ? !!fc.blank : (fc.values ?? []).includes(text3);
|
|
27247
|
-
});
|
|
27375
|
+
const visible = rowMatchesFilter(ctx.workbook, sheet, row2, filter2);
|
|
27248
27376
|
const info = { ...sheet.rowInfo.get(row2) };
|
|
27249
|
-
|
|
27250
|
-
|
|
27377
|
+
const manual = info.manuallyHidden || info.hidden && !info.filteredOut;
|
|
27378
|
+
if (visible) {
|
|
27379
|
+
delete info.filteredOut;
|
|
27380
|
+
delete info.manuallyHidden;
|
|
27381
|
+
if (manual) {
|
|
27382
|
+
info.hidden = true;
|
|
27383
|
+
if (filter2.columns?.length) info.filteredOut = false;
|
|
27384
|
+
} else delete info.hidden;
|
|
27385
|
+
} else {
|
|
27386
|
+
info.hidden = true;
|
|
27387
|
+
info.filteredOut = true;
|
|
27388
|
+
if (manual) info.manuallyHidden = true;
|
|
27389
|
+
}
|
|
27251
27390
|
if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
|
|
27252
27391
|
else sheet.rowInfo.delete(row2);
|
|
27253
27392
|
}
|
|
@@ -27411,16 +27550,16 @@ var isSpilledAt = (workbook, at) => {
|
|
|
27411
27550
|
return !!sheet && isSpilledCell(getCell(sheet, at.row, at.col));
|
|
27412
27551
|
};
|
|
27413
27552
|
var replaceQuery = (query) => query.lookIn === "comments" ? query : { ...query, lookIn: "formulas" };
|
|
27414
|
-
function replaceScopes(query, sheet, matches2) {
|
|
27553
|
+
function replaceScopes(ctx, query, sheet, matches2) {
|
|
27415
27554
|
if (query.lookIn === "comments") return [{ kind: "parts", sheet, parts: ["comments"] }];
|
|
27416
27555
|
const ranges = matches2.map((m) => ({
|
|
27417
27556
|
start: { row: m.row, col: m.col },
|
|
27418
27557
|
end: { row: m.row, col: m.col }
|
|
27419
27558
|
}));
|
|
27420
|
-
|
|
27421
|
-
|
|
27422
|
-
|
|
27423
|
-
];
|
|
27559
|
+
const header = ranges.some(
|
|
27560
|
+
(range) => writeScopes(sheetAt(ctx.workbook, sheet), sheet, range).some((scope) => scope.kind === "refs")
|
|
27561
|
+
);
|
|
27562
|
+
return [...header ? [{ kind: "refs" }] : [], { kind: "cells", sheet, ranges }];
|
|
27424
27563
|
}
|
|
27425
27564
|
function applyReplace(ctx, query, replacement, matches2) {
|
|
27426
27565
|
let changed = 0;
|
|
@@ -27450,14 +27589,24 @@ function replaceAll(ctx, query, replacement) {
|
|
|
27450
27589
|
const sheets = [...new Set(matches2.map((m) => m.sheet))];
|
|
27451
27590
|
const scopes = sheets.flatMap(
|
|
27452
27591
|
(sheet) => replaceScopes(
|
|
27592
|
+
ctx,
|
|
27453
27593
|
q,
|
|
27454
27594
|
sheet,
|
|
27455
27595
|
matches2.filter((m) => m.sheet === sheet)
|
|
27456
27596
|
)
|
|
27457
27597
|
);
|
|
27458
|
-
|
|
27459
|
-
|
|
27460
|
-
|
|
27598
|
+
const uniqueScopes = scopes.filter(
|
|
27599
|
+
(scope, index2) => scope.kind !== "refs" || scopes.findIndex((entry3) => entry3.kind === "refs") === index2
|
|
27600
|
+
);
|
|
27601
|
+
return ctx.run(
|
|
27602
|
+
"Replace",
|
|
27603
|
+
"cells",
|
|
27604
|
+
uniqueScopes,
|
|
27605
|
+
() => applyReplace(ctx, q, replacement, matches2),
|
|
27606
|
+
{
|
|
27607
|
+
...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
|
|
27608
|
+
}
|
|
27609
|
+
);
|
|
27461
27610
|
}
|
|
27462
27611
|
function replaceOne(ctx, query, replacement, at) {
|
|
27463
27612
|
const q = replaceQuery(query);
|
|
@@ -27470,7 +27619,7 @@ function replaceOne(ctx, query, replacement, at) {
|
|
|
27470
27619
|
ctx.run(
|
|
27471
27620
|
"Replace",
|
|
27472
27621
|
"cells",
|
|
27473
|
-
replaceScopes(q, at.sheet, [match2]),
|
|
27622
|
+
replaceScopes(ctx, q, at.sheet, [match2]),
|
|
27474
27623
|
() => applyReplace(ctx, q, replacement, [match2]),
|
|
27475
27624
|
{ sheet: at.sheet }
|
|
27476
27625
|
);
|
|
@@ -28473,90 +28622,6 @@ function applyTotalsRow(sheet, table2) {
|
|
|
28473
28622
|
});
|
|
28474
28623
|
}
|
|
28475
28624
|
|
|
28476
|
-
// xlsx/edit/tables.ts
|
|
28477
|
-
function nextTableName(workbook) {
|
|
28478
|
-
const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
|
|
28479
|
-
const names = new Set(workbook.definedNames.map((n2) => n2.name.toLowerCase()));
|
|
28480
|
-
for (let n2 = 1; ; n2++) if (!taken.has(`table${n2}`) && !names.has(`table${n2}`)) return `Table${n2}`;
|
|
28481
|
-
}
|
|
28482
|
-
function uniqueHeaders(texts) {
|
|
28483
|
-
const used = /* @__PURE__ */ new Set();
|
|
28484
|
-
return texts.map((text3, i2) => {
|
|
28485
|
-
let base = text3.trim() || `Column${i2 + 1}`;
|
|
28486
|
-
if (!used.has(base.toLowerCase())) {
|
|
28487
|
-
used.add(base.toLowerCase());
|
|
28488
|
-
return base;
|
|
28489
|
-
}
|
|
28490
|
-
for (let n2 = 2; ; n2++) {
|
|
28491
|
-
const candidate = `${base}${n2}`;
|
|
28492
|
-
if (!used.has(candidate.toLowerCase())) {
|
|
28493
|
-
used.add(candidate.toLowerCase());
|
|
28494
|
-
base = candidate;
|
|
28495
|
-
return base;
|
|
28496
|
-
}
|
|
28497
|
-
}
|
|
28498
|
-
});
|
|
28499
|
-
}
|
|
28500
|
-
function createTable(ctx, s, range, hasHeader, styleName = "TableStyleMedium2") {
|
|
28501
|
-
const { workbook } = ctx;
|
|
28502
|
-
const sheet = sheetAt(workbook, s);
|
|
28503
|
-
let r = normalizeRange(range);
|
|
28504
|
-
if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
|
|
28505
|
-
if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
|
|
28506
|
-
throw new Error("A table cannot overlap another table.");
|
|
28507
|
-
if (sheet.merges.some((m) => rangesIntersect(m, r)))
|
|
28508
|
-
throw new Error("A table cannot contain merged cells.");
|
|
28509
|
-
return ctx.run(
|
|
28510
|
-
"Create table",
|
|
28511
|
-
"structure",
|
|
28512
|
-
[hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
|
|
28513
|
-
() => {
|
|
28514
|
-
if (!hasHeader) {
|
|
28515
|
-
const shift2 = { axis: "row", at: r.start.row, count: 1 };
|
|
28516
|
-
const band = { lo: r.start.col, hi: r.end.col };
|
|
28517
|
-
rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
|
|
28518
|
-
shiftSheetContent(sheet, shift2, band);
|
|
28519
|
-
r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
|
|
28520
|
-
}
|
|
28521
|
-
const width = r.end.col - r.start.col + 1;
|
|
28522
|
-
const texts = Array.from(
|
|
28523
|
-
{ length: width },
|
|
28524
|
-
(_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
|
|
28525
|
-
);
|
|
28526
|
-
const headers = uniqueHeaders(texts);
|
|
28527
|
-
const columns = headers.map((name2, i2) => {
|
|
28528
|
-
const cell = getCell(sheet, r.start.row, r.start.col + i2);
|
|
28529
|
-
if (cell?.value !== name2) {
|
|
28530
|
-
const styleId = cell?.styleId;
|
|
28531
|
-
writeValue(sheet, r.start.row, r.start.col + i2, name2);
|
|
28532
|
-
const written = getCell(sheet, r.start.row, r.start.col + i2);
|
|
28533
|
-
if (written && styleId) written.styleId = styleId;
|
|
28534
|
-
}
|
|
28535
|
-
return { name: name2 };
|
|
28536
|
-
});
|
|
28537
|
-
const name = nextTableName(workbook);
|
|
28538
|
-
const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
|
|
28539
|
-
const table2 = {
|
|
28540
|
-
id,
|
|
28541
|
-
name,
|
|
28542
|
-
displayName: name,
|
|
28543
|
-
range: r,
|
|
28544
|
-
headerRow: true,
|
|
28545
|
-
totalsRow: false,
|
|
28546
|
-
columns,
|
|
28547
|
-
styleName,
|
|
28548
|
-
showRowStripes: true,
|
|
28549
|
-
showColumnStripes: false,
|
|
28550
|
-
showFirstColumn: false,
|
|
28551
|
-
showLastColumn: false
|
|
28552
|
-
};
|
|
28553
|
-
sheet.tables.push(table2);
|
|
28554
|
-
return table2;
|
|
28555
|
-
},
|
|
28556
|
-
{ sheet: s, ranges: [r], structural: !hasHeader }
|
|
28557
|
-
);
|
|
28558
|
-
}
|
|
28559
|
-
|
|
28560
28625
|
// xlsx/edit/table-edits.ts
|
|
28561
28626
|
function tableIndex(sheet, ref) {
|
|
28562
28627
|
const index2 = typeof ref === "number" ? ref : sheet.tables.findIndex((t) => t.name.toLowerCase() === ref.toLowerCase());
|
|
@@ -31812,8 +31877,8 @@ function setSheetState(ctx, index2, state) {
|
|
|
31812
31877
|
const { workbook } = ctx;
|
|
31813
31878
|
const sheet = sheetAt(workbook, index2);
|
|
31814
31879
|
if (sheet.state === state) return;
|
|
31880
|
+
assertUnlocked(workbook);
|
|
31815
31881
|
if (state !== "visible") {
|
|
31816
|
-
assertUnlocked(workbook);
|
|
31817
31882
|
if (sheet.state === "visible" && visibleCount(workbook) <= 1)
|
|
31818
31883
|
throw new Error("A workbook must contain at least one visible sheet.");
|
|
31819
31884
|
}
|
|
@@ -31843,6 +31908,72 @@ function setTabColor(ctx, index2, color) {
|
|
|
31843
31908
|
);
|
|
31844
31909
|
}
|
|
31845
31910
|
|
|
31911
|
+
// xlsx/edit/tables.ts
|
|
31912
|
+
function nextTableName(workbook) {
|
|
31913
|
+
const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
|
|
31914
|
+
const names = new Set(workbook.definedNames.map((n2) => n2.name.toLowerCase()));
|
|
31915
|
+
for (let n2 = 1; ; n2++) if (!taken.has(`table${n2}`) && !names.has(`table${n2}`)) return `Table${n2}`;
|
|
31916
|
+
}
|
|
31917
|
+
function createTable(ctx, s, range, hasHeader, styleName = "TableStyleMedium2") {
|
|
31918
|
+
const { workbook } = ctx;
|
|
31919
|
+
const sheet = sheetAt(workbook, s);
|
|
31920
|
+
let r = normalizeRange(range);
|
|
31921
|
+
if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
|
|
31922
|
+
if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
|
|
31923
|
+
throw new Error("A table cannot overlap another table.");
|
|
31924
|
+
if (sheet.merges.some((m) => rangesIntersect(m, r)))
|
|
31925
|
+
throw new Error("A table cannot contain merged cells.");
|
|
31926
|
+
return ctx.run(
|
|
31927
|
+
"Create table",
|
|
31928
|
+
"structure",
|
|
31929
|
+
[hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
|
|
31930
|
+
() => {
|
|
31931
|
+
if (!hasHeader) {
|
|
31932
|
+
const shift2 = { axis: "row", at: r.start.row, count: 1 };
|
|
31933
|
+
const band = { lo: r.start.col, hi: r.end.col };
|
|
31934
|
+
rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
|
|
31935
|
+
shiftSheetContent(sheet, shift2, band);
|
|
31936
|
+
r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
|
|
31937
|
+
}
|
|
31938
|
+
const width = r.end.col - r.start.col + 1;
|
|
31939
|
+
const texts = Array.from(
|
|
31940
|
+
{ length: width },
|
|
31941
|
+
(_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
|
|
31942
|
+
);
|
|
31943
|
+
const headers = uniqueHeaders(texts);
|
|
31944
|
+
const columns = headers.map((name2, i2) => {
|
|
31945
|
+
const cell = getCell(sheet, r.start.row, r.start.col + i2);
|
|
31946
|
+
if (cell?.value !== name2) {
|
|
31947
|
+
const styleId = cell?.styleId;
|
|
31948
|
+
writeValue(sheet, r.start.row, r.start.col + i2, name2);
|
|
31949
|
+
const written = getCell(sheet, r.start.row, r.start.col + i2);
|
|
31950
|
+
if (written && styleId) written.styleId = styleId;
|
|
31951
|
+
}
|
|
31952
|
+
return { name: name2 };
|
|
31953
|
+
});
|
|
31954
|
+
const name = nextTableName(workbook);
|
|
31955
|
+
const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
|
|
31956
|
+
const table2 = {
|
|
31957
|
+
id,
|
|
31958
|
+
name,
|
|
31959
|
+
displayName: name,
|
|
31960
|
+
range: r,
|
|
31961
|
+
headerRow: true,
|
|
31962
|
+
totalsRow: false,
|
|
31963
|
+
columns,
|
|
31964
|
+
styleName,
|
|
31965
|
+
showRowStripes: true,
|
|
31966
|
+
showColumnStripes: false,
|
|
31967
|
+
showFirstColumn: false,
|
|
31968
|
+
showLastColumn: false
|
|
31969
|
+
};
|
|
31970
|
+
sheet.tables.push(table2);
|
|
31971
|
+
return table2;
|
|
31972
|
+
},
|
|
31973
|
+
{ sheet: s, ranges: [r], structural: !hasHeader }
|
|
31974
|
+
);
|
|
31975
|
+
}
|
|
31976
|
+
|
|
31846
31977
|
// xlsx/edit/validation-list.ts
|
|
31847
31978
|
function listSource(workbook, sheet, formula, evaluate, at, depth = 0) {
|
|
31848
31979
|
const text3 = formula.replace(/^=/, "").trim();
|
|
@@ -32144,7 +32275,7 @@ function createEditSession(workbook, options = {}) {
|
|
|
32144
32275
|
const befores = scopes.map((scope) => captureScope(workbook, scope));
|
|
32145
32276
|
let result2;
|
|
32146
32277
|
try {
|
|
32147
|
-
result2 = fn();
|
|
32278
|
+
result2 = fn(befores.find((snapshot) => snapshot.kind === "refs")?.data.formulas);
|
|
32148
32279
|
} catch (error) {
|
|
32149
32280
|
for (let i2 = befores.length - 1; i2 >= 0; i2--) {
|
|
32150
32281
|
const snapshot = befores[i2];
|