masaccio/numbers-parser

How to read multiple images from one cell?

Closed this issue · 4 comments

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

It seems caused by image as background which has a chinese filename. orz
However, still, there is no way to read multiple image from one cell.

Are you able to attach an example file? It looks from the screenshot like two images but I can’t see how to create that.

Are you able to attach an example file? It looks from the screenshot like two images but I can’t see how to create that.

It seems that I made a mistake. :( When dragging multiple images from another software to Numbers, the other software will generate one image from multiple images, but because the cells in Numbers are too small, it looks like two photos. So now, there seems to be only one problem that cannot read image files with Chinese names. I attached an example. Thanks.
test.numbers.gz

Thanks for the example and the bug report. You uncovered a problem with reading zipfiles.

For python >= 3.11, there is a fix available now in numbers-parser 4.4.8. Python's ZipFile didn't include specifying UTF-8 for zip files before this.