masaccio / numbers-parser

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

Create cell with a background image #75

Closed wrc-marek closed 4 months ago

wrc-marek commented 4 months ago

Is there a way to create a cell with a background image? I was trying this:

from numbers_parser import Document, BackgroundImage

picture_path = "./test.jpg"
doc = Document("./template.numbers")

f = open(picture_path, mode="rb")
picture_data = f.read()
style = doc.add_style(
    name="Test",
    bg_image=BackgroundImage(picture_data, picture_path)
)

table = doc.sheets[0].tables[0]
table.write(0, 0, "Test", style=style)
table.set_cell_style(0, 1, style)

doc.save("new.numbers")
masaccio commented 4 months ago

Implemented in v4.9.0; publishing pending including an implementation of #74

masaccio commented 4 months ago

Now published. There's an example in this test.

wrc-marek commented 4 months ago

Thanks, it's working!

The only problem that I see is that it's still have some problems with documents that contain already some background image. I created manually document with image:

Screenshot 2024-02-25 at 20 20 37

And after executing the script:

from numbers_parser import Document
doc = Document("./test.numbers")
doc.save("test2.numbers")

New file is missing a cat:

Screenshot 2024-02-25 at 20 22 17
masaccio commented 4 months ago

Is that cell otherwise empty?

masaccio commented 4 months ago

I am figuring yes (it failed when I tried). Fixed in v4.9.4.

wrc-marek commented 4 months ago

It's working, great job, thanks! 👍