From 513260d29d23e583bb10c060c7030d899cc72ffb Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 20 Mar 2025 16:16:58 +0100 Subject: [PATCH] Sheet: Improve handling of unsupported formulas With the example file of issue 20299 the parser stops with an exception and reads in the formulas only partially. This PR doesn't fix the issue but avoids to raise an exception so that as much as possible will be read in. For unsupported formulas a suitable message is printed with the content of the cell. --- src/Mod/Spreadsheet/importXLSX.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Mod/Spreadsheet/importXLSX.py b/src/Mod/Spreadsheet/importXLSX.py index 6c28188544..2fb7dc4f42 100644 --- a/src/Mod/Spreadsheet/importXLSX.py +++ b/src/Mod/Spreadsheet/importXLSX.py @@ -346,9 +346,18 @@ def handleCells(cellList, actCellSheet, sList): formulaRef = cell.getElementsByTagName("f") if len(formulaRef) == 1: theFormula = getText(formulaRef[0].childNodes) - # print("theFormula: ", theFormula) - fTrans = FormulaTranslator() - actCellSheet.set(ref, fTrans.translateForm(theFormula)) + if theFormula: + # print("theFormula: ", theFormula) + fTrans = FormulaTranslator() + actCellSheet.set(ref, fTrans.translateForm(theFormula)) + else: + attrs = formulaRef[0].attributes + attrRef = attrs.getNamedItem("t") + attrName = getText(attrRef.childNodes) + indexRef = attrs.getNamedItem("si") + indexName = getText(indexRef.childNodes) + content = "".format(attrName, indexName) + print(f"Unsupported formula in cell {ref}: {content}") else: valueRef = cell.getElementsByTagName("v")