Skip to content

How to read multiple images from one cell? #69

@lazystitan

Description

@lazystitan

Wish to read images from cell like this:
image
Code:

from numbers_parser import Document
doc = Document("data3.numbers")
sheets = doc.sheets
tables = sheets[2].tables
tables[0].rows()[36][10].image_data

Error:

Cell In[3], line 1
----> 1 tables[0].rows()[36][10].image_data

File ~/PycharmProjects/timez-scripts/venv/lib/python3.11/site-packages/numbers_parser/cell.py:543, in Cell.image_data(self)
    536 @property
    537 def image_data(self):
    538     warn(
    539         "image_data is deprecated and will be removed in the future. "
    540         + "Please use the style property",
    541         DeprecationWarning,
    542     )
--> 543     if self.style is not None and self.style.bg_image is not None:
    544         return self.style.bg_image.data
    545     else:

File ~/PycharmProjects/timez-scripts/venv/lib/python3.11/site-packages/numbers_parser/cell.py:578, in Cell.style(self)
    574     self._storage = CellStorage(
    575         self._model, self._table_id, EMPTY_STORAGE_BUFFER, self.row, self.col
    576     )
    577 if self._style is None:
--> 578     self._style = Style.from_storage(self._storage, self._model)
    579 return self._style

File ~/PycharmProjects/timez-scripts/venv/lib/python3.11/site-packages/numbers_parser/cell.py:191, in Style.from_storage(cls, cell_storage, model)
    187 @classmethod
    188 def from_storage(cls, cell_storage: object, model: object):
    189     style = Style()
--> 191     if cell_storage.image_data is not None:
    192         bg_image = BackgroundImage(*cell_storage.image_data)
    193     else:

File ~/PycharmProjects/timez-scripts/venv/lib/python3.11/site-packages/numbers_parser/numbers_cache.py:31, in cache.<locals>.cache_decorator.<locals>.inner_no_args(self)
     29 method = func.__name__
     30 if method not in self._cache:
---> 31     self._cache[method] = func(self)
     32 return self._cache[method]

File ~/PycharmProjects/timez-scripts/venv/lib/python3.11/site-packages/numbers_parser/cell_storage.py:291, in CellStorage.image_data(self)
    289 image_filename = [x.file_name for x in datas if x.identifier == image_id][0]
    290 all_paths = self.model.objects.file_store.keys()
--> 291 image_pathname = [x for x in all_paths if x == f"Data/{image_filename}"][0]
    292 return (self.model.objects.file_store[image_pathname], image_filename)

IndexError: list index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions