Skip to content

Commit ec76160

Browse files
committed
[FIX] XLSXImport: Fix crash on incomplete xlsx file with external reference
In Excel, there is a mecanism for spreadsheets to cross-reference themselves, with cells of the form `[otherSpreadsheetFileName]Sheet1!A1`. Luckily, the saved files contain a cache of the values from other spreadsheets and we use this cache during our import process to replace the cross-sheet references with their cached value. Google sheet, and possibly other spreadsheets engines, do not support xlsx files with cross references to other spreadsheets. More specifically, they let them *as is* even though the reference will not work, and they throw the cache away. This means that an xlsx file generated from Google Sheet will not contain the cache either. The code was designed with the assumption that the cache would always be present, which led to crashes when trying to upload an xlsx file (with cross-references) that was obtain through Google Sheets. closes #7879 Task: 5499753 X-original-commit: 2ed5b7c Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
1 parent 2d9316b commit ec76160

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/xlsx/conversion/formula_conversion.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ function convertFormula(formula: string, data: XLSXImportData): string {
6565
formula = formula.replace(externalReferenceRegex, (match, externalRefId, sheetName, cellRef) => {
6666
externalRefId = Number(externalRefId) - 1;
6767
cellRef = cellRef.replace(/\$/g, "");
68-
69-
const sheetIndex = data.externalBooks[externalRefId].sheetNames.findIndex((name) =>
70-
isSheetNameEqual(name, sheetName)
71-
);
68+
const sheetIndex =
69+
data.externalBooks[externalRefId]?.sheetNames.findIndex((name) =>
70+
isSheetNameEqual(name, sheetName)
71+
) ?? -1;
7272
if (sheetIndex === -1) {
7373
return match;
7474
}

0 commit comments

Comments
 (0)