diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e545334..24adbbc 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ Changes ======= +2.0.2 (14 June 2025) +-------------------- + +- Fix bug reading sheets containing invalid formulae. + +Thanks to sanshi42 for the fix! + 2.0.1 (11 December 2020) ------------------------ diff --git a/README.rst b/README.rst index a0551e7..e3b8077 100644 --- a/README.rst +++ b/README.rst @@ -37,6 +37,10 @@ Password-protected files are not supported and cannot be read by this library. Quick start: +.. code-block:: bash + + pip install xlrd + .. code-block:: python import xlrd diff --git a/docs/conf.py b/docs/conf.py index 38f974a..2e786c1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,7 +10,10 @@ source_suffix = '.rst' master_doc = 'index' project = u'xlrd' -copyright = '2005-%s Stephen John Machin, Lingfo Pty Ltd' % datetime.datetime.now().year +copyright = ( + '2005-2019 Stephen John Machin, Lingfo Pty Ltd. ' + '2019-%s Chris Withers' +) % datetime.datetime.now().year version = release = __VERSION__ exclude_patterns = ['_build'] pygments_style = 'sphinx' diff --git a/tests/samples/invalid_formula.xls b/tests/samples/invalid_formula.xls new file mode 100644 index 0000000..6fa82df Binary files /dev/null and b/tests/samples/invalid_formula.xls differ diff --git a/tests/test_formulas.py b/tests/test_formulas.py index c178a8f..2b1a906 100644 --- a/tests/test_formulas.py +++ b/tests/test_formulas.py @@ -79,3 +79,12 @@ def test_if(self): def test_choose(self): self.assertEqual(self.get_value(1, 6), "'C'") + + def test_evaluate_name_formula_with_invalid_operand(self): + book = xlrd.open_workbook(from_sample('invalid_formula.xls')) + sheet = book.sheet_by_index(0) + cell = sheet.cell(0, 0) + + self.assertEqual(cell.ctype, xlrd.XL_CELL_ERROR) + self.assertIn(cell.value, xlrd.error_text_from_code) + diff --git a/xlrd/formula.py b/xlrd/formula.py index e26639b..00e4464 100644 --- a/xlrd/formula.py +++ b/xlrd/formula.py @@ -953,7 +953,7 @@ def not_in_name_formula(op_arg, oname_arg): ]) res = Operand(oREF, None, rank, otext) if bop.kind == oERR or aop.kind == oERR: - res = oERR + res.kind = oERR elif bop.kind == oREF == aop.kind: if aop.value is not None and bop.value is not None: assert len(aop.value) == 1 diff --git a/xlrd/info.py b/xlrd/info.py index f26b6bb..eb7de6f 100644 --- a/xlrd/info.py +++ b/xlrd/info.py @@ -1 +1 @@ -__version__ = __VERSION__ = "2.0.1" +__version__ = __VERSION__ = "2.0.2"