@extend-ai/react-xlsx 0.17.1 → 0.17.2
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/dist/index.cjs +48 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/dist/xlsx-worker.js +48 -1
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6656,13 +6656,52 @@ function hasUnresolvedSheetReferences(workbook) {
|
|
|
6656
6656
|
}
|
|
6657
6657
|
return false;
|
|
6658
6658
|
}
|
|
6659
|
+
function collectFormulaCellsWithSavedValues(workbook) {
|
|
6660
|
+
const positions = [];
|
|
6661
|
+
for (let sheetIdx = 0; sheetIdx < workbook.sheetCount; sheetIdx += 1) {
|
|
6662
|
+
let sheet;
|
|
6663
|
+
try {
|
|
6664
|
+
sheet = workbook.getSheet(sheetIdx);
|
|
6665
|
+
} catch {
|
|
6666
|
+
continue;
|
|
6667
|
+
}
|
|
6668
|
+
const cells = sheet.formulaCells;
|
|
6669
|
+
if (!Array.isArray(cells)) {
|
|
6670
|
+
continue;
|
|
6671
|
+
}
|
|
6672
|
+
for (const cell of cells) {
|
|
6673
|
+
if (typeof cell?.row !== "number" || typeof cell?.col !== "number") {
|
|
6674
|
+
continue;
|
|
6675
|
+
}
|
|
6676
|
+
let saved;
|
|
6677
|
+
try {
|
|
6678
|
+
saved = sheet.getCalculatedValueAt(cell.row, cell.col);
|
|
6679
|
+
} catch {
|
|
6680
|
+
continue;
|
|
6681
|
+
}
|
|
6682
|
+
if (!saved.is_empty && !saved.is_error) {
|
|
6683
|
+
positions.push({ sheetIdx, row: cell.row, col: cell.col });
|
|
6684
|
+
}
|
|
6685
|
+
}
|
|
6686
|
+
}
|
|
6687
|
+
return positions;
|
|
6688
|
+
}
|
|
6689
|
+
function anyBecameError(workbook, positions) {
|
|
6690
|
+
return positions.some(({ sheetIdx, row, col }) => {
|
|
6691
|
+
try {
|
|
6692
|
+
return workbook.getSheet(sheetIdx).getCalculatedValueAt(row, col).is_error;
|
|
6693
|
+
} catch {
|
|
6694
|
+
return false;
|
|
6695
|
+
}
|
|
6696
|
+
});
|
|
6697
|
+
}
|
|
6659
6698
|
function safeCalculate(workbook, options = {}) {
|
|
6660
6699
|
if (hasUnresolvedSheetReferences(workbook)) {
|
|
6661
6700
|
return { workbook, calculated: false, skipReason: "unresolved-sheet-refs" };
|
|
6662
6701
|
}
|
|
6702
|
+
const withSavedValues = options.reparse ? collectFormulaCellsWithSavedValues(workbook) : [];
|
|
6663
6703
|
try {
|
|
6664
6704
|
workbook.calculate();
|
|
6665
|
-
return { workbook, calculated: true, skipReason: null };
|
|
6666
6705
|
} catch (err) {
|
|
6667
6706
|
console.warn("[react-xlsx] workbook.calculate() trapped; falling back to cached formula values", err);
|
|
6668
6707
|
if (options.reparse) {
|
|
@@ -6674,6 +6713,14 @@ function safeCalculate(workbook, options = {}) {
|
|
|
6674
6713
|
}
|
|
6675
6714
|
return { workbook, calculated: false, skipReason: "calculate-trapped" };
|
|
6676
6715
|
}
|
|
6716
|
+
if (options.reparse && anyBecameError(workbook, withSavedValues)) {
|
|
6717
|
+
try {
|
|
6718
|
+
return { workbook: options.reparse(), calculated: false, skipReason: "calculate-regressed" };
|
|
6719
|
+
} catch (reparseErr) {
|
|
6720
|
+
console.warn("[react-xlsx] workbook reparse after calculate regression failed", reparseErr);
|
|
6721
|
+
}
|
|
6722
|
+
}
|
|
6723
|
+
return { workbook, calculated: true, skipReason: null };
|
|
6677
6724
|
}
|
|
6678
6725
|
function tryRecalculate(workbook) {
|
|
6679
6726
|
try {
|