@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.cjs
CHANGED
|
@@ -6707,13 +6707,52 @@ function hasUnresolvedSheetReferences(workbook) {
|
|
|
6707
6707
|
}
|
|
6708
6708
|
return false;
|
|
6709
6709
|
}
|
|
6710
|
+
function collectFormulaCellsWithSavedValues(workbook) {
|
|
6711
|
+
const positions = [];
|
|
6712
|
+
for (let sheetIdx = 0; sheetIdx < workbook.sheetCount; sheetIdx += 1) {
|
|
6713
|
+
let sheet;
|
|
6714
|
+
try {
|
|
6715
|
+
sheet = workbook.getSheet(sheetIdx);
|
|
6716
|
+
} catch {
|
|
6717
|
+
continue;
|
|
6718
|
+
}
|
|
6719
|
+
const cells = sheet.formulaCells;
|
|
6720
|
+
if (!Array.isArray(cells)) {
|
|
6721
|
+
continue;
|
|
6722
|
+
}
|
|
6723
|
+
for (const cell of cells) {
|
|
6724
|
+
if (typeof cell?.row !== "number" || typeof cell?.col !== "number") {
|
|
6725
|
+
continue;
|
|
6726
|
+
}
|
|
6727
|
+
let saved;
|
|
6728
|
+
try {
|
|
6729
|
+
saved = sheet.getCalculatedValueAt(cell.row, cell.col);
|
|
6730
|
+
} catch {
|
|
6731
|
+
continue;
|
|
6732
|
+
}
|
|
6733
|
+
if (!saved.is_empty && !saved.is_error) {
|
|
6734
|
+
positions.push({ sheetIdx, row: cell.row, col: cell.col });
|
|
6735
|
+
}
|
|
6736
|
+
}
|
|
6737
|
+
}
|
|
6738
|
+
return positions;
|
|
6739
|
+
}
|
|
6740
|
+
function anyBecameError(workbook, positions) {
|
|
6741
|
+
return positions.some(({ sheetIdx, row, col }) => {
|
|
6742
|
+
try {
|
|
6743
|
+
return workbook.getSheet(sheetIdx).getCalculatedValueAt(row, col).is_error;
|
|
6744
|
+
} catch {
|
|
6745
|
+
return false;
|
|
6746
|
+
}
|
|
6747
|
+
});
|
|
6748
|
+
}
|
|
6710
6749
|
function safeCalculate(workbook, options = {}) {
|
|
6711
6750
|
if (hasUnresolvedSheetReferences(workbook)) {
|
|
6712
6751
|
return { workbook, calculated: false, skipReason: "unresolved-sheet-refs" };
|
|
6713
6752
|
}
|
|
6753
|
+
const withSavedValues = options.reparse ? collectFormulaCellsWithSavedValues(workbook) : [];
|
|
6714
6754
|
try {
|
|
6715
6755
|
workbook.calculate();
|
|
6716
|
-
return { workbook, calculated: true, skipReason: null };
|
|
6717
6756
|
} catch (err) {
|
|
6718
6757
|
console.warn("[react-xlsx] workbook.calculate() trapped; falling back to cached formula values", err);
|
|
6719
6758
|
if (options.reparse) {
|
|
@@ -6725,6 +6764,14 @@ function safeCalculate(workbook, options = {}) {
|
|
|
6725
6764
|
}
|
|
6726
6765
|
return { workbook, calculated: false, skipReason: "calculate-trapped" };
|
|
6727
6766
|
}
|
|
6767
|
+
if (options.reparse && anyBecameError(workbook, withSavedValues)) {
|
|
6768
|
+
try {
|
|
6769
|
+
return { workbook: options.reparse(), calculated: false, skipReason: "calculate-regressed" };
|
|
6770
|
+
} catch (reparseErr) {
|
|
6771
|
+
console.warn("[react-xlsx] workbook reparse after calculate regression failed", reparseErr);
|
|
6772
|
+
}
|
|
6773
|
+
}
|
|
6774
|
+
return { workbook, calculated: true, skipReason: null };
|
|
6728
6775
|
}
|
|
6729
6776
|
function tryRecalculate(workbook) {
|
|
6730
6777
|
try {
|