PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
290 stars 47 forks source link

Error when access formula with None stored #59

Closed Spectre5 closed 2 years ago

Spectre5 commented 2 years ago

Pylightxl Version: 1.58 Python Version: 3.7

Summary of Bug/Feature: When using sheet.row with output='f', I get the traceback shown below. I've printed the sheet._data dictionary and it does in fact have None for some of the formulas. It is an array formula that I see it.

Traceback:

Traceback (most recent call last):
  File "testing.py", line 285, in test_read
    result = read_pylightxl(path)
  File "testing.py", line 158, in read_with_pylightxl
    page.append(sheet.row(row, output=output))
  File "<snip>\site-packages\pylightxl\pylightxl.py", line 1796, in row
    val = self.index(row, c, output=output)
  File "<snip>\site-packages\pylightxl\pylightxl.py", line 1733, in index
    return self.address(address, output=output)
  File "<snip>\site-packages\pylightxl\pylightxl.py", line 1656, in address
    rv = '=' + self._data[address]['f']
TypeError: can only concatenate str (not "NoneType") to str

Suggestion for fix (Option 1): Fix the immediate issue only

Change this https://github.com/PydPiper/pylightxl/blob/3729d0a056770809da46f88fb83bc87772a6e3d3/pylightxl/pylightxl.py#L1656 to:

                rv = '=' + self._data[address]['f'] or ''

Suggestion for fix (Option 2): Avoid None earlier in the code for values, formulas, and comments

Change this https://github.com/PydPiper/pylightxl/blob/3729d0a056770809da46f88fb83bc87772a6e3d3/pylightxl/pylightxl.py#L494 to:

        data.update({cell_address: {'v': cell_val or '', 'f': cell_formula or '', 's': '', 'c': comment or ''}})
PydPiper commented 2 years ago

Hi @Spectre5 thank you for considering using pylightxl. It does in deed look like a bug, let me address it this week and ill get back to you. Thanks for submitting this!

PydPiper commented 2 years ago

Hi @Spectre5, thank you for submitting this comprehensive issue. It was really easy to go back and make the changes. I have updated the master, but will hold off on releasing a new version till we get a more more improvements in.