masaccio / numbers-parser

Python module for parsing Apple Numbers .numbers files
MIT License
201 stars 14 forks source link

Some merge cells occurs TypeError #59

Closed donly closed 1 year ago

donly commented 1 year ago

the test Numbers file merge_cells.numbers.zip, base on tests/data/custom-format-stress-template.numbers.

Example code:

from numbers_parser import Document
doc = Document("merge_cells.numbers") # see the attachment merge_cells.numbers.zip
sheets = doc.sheets()
for s in sheets:
    print(s.name)
tables = sheets[0].tables()
for t in tables:
    print(t.name)
    rows = t.rows(values_only=True)

Result:

Sheet 1
Table 1
Traceback (most recent call last):
  File "parser.py", line 15, in <module>
    rows = t.rows(values_only=True)
  File "/Users/donly/.pyenv/versions/3.6.15/lib/python3.6/site-packages/numbers_parser/document.py", line 69, in rows
    for col_num in range(self.num_cols)
  File "/Users/donly/.pyenv/versions/3.6.15/lib/python3.6/site-packages/numbers_parser/document.py", line 69, in <listcomp>
    for col_num in range(self.num_cols)
  File "/Users/donly/.pyenv/versions/3.6.15/lib/python3.6/site-packages/numbers_parser/document.py", line 109, in cell
    return Cell.factory(self._model, self._table_id, row_num, col_num)
  File "/Users/donly/.pyenv/versions/3.6.15/lib/python3.6/site-packages/numbers_parser/cell.py", line 44, in factory
    cell = BulletedTextCell(row_num, col_num, cell_value.bullets)
  File "/Users/donly/.pyenv/versions/3.6.15/lib/python3.6/site-packages/numbers_parser/cell.py", line 141, in __init__
    super().__init__(row_num, col_num, value["text"])
TypeError: 'NoneType' object is not subscriptable

Testing Environment:

masaccio commented 1 year ago

I see no errors in version 4.0.0. The method API for sheets and tables was deprecated in 3.0 and has now been removed in 4.0. This is the new API:

from numbers_parser import Document

doc = Document("tests/data/issue-59.numbers")
sheets = doc.sheets
tables = sheets[0].tables
assert tables[0].cell("J2").value == "Saturday, 15 May 2021"
donly commented 1 year ago

You're right, @masaccio. This problem comes from numbers-parser 2.3.13 which I installed using python3 -m pip install numbers-parser. How to install the latest version 4.0.0?

masaccio commented 1 year ago

pip won't upgrade major versions automatically so you need to explicitly tell it to upgrade using python3 -m pip install --upgrade numbers-parser.