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.
This commit is contained in:
wmayer
2025-03-20 16:16:58 +01:00
committed by Ladislav Michl
parent a46f79aa68
commit 513260d29d

View File

@@ -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 = "<f t='{}' si='{}'/>".format(attrName, indexName)
print(f"Unsupported formula in cell {ref}: {content}")
else:
valueRef = cell.getElementsByTagName("v")