masaccio / numbers-parser

Python module for parsing Apple Numbers .numbers files
MIT License
208 stars 15 forks source link

Pivot Table Missing Data on Save #73

Open ralfzosel opened 9 months ago

ralfzosel commented 9 months ago

Describe the bug I open a Numbers file that contains a pivot table (doc = Document("dummy.numbers")). When I save this file (doc.save("dummy_new.numbers")) and open it with Numbers, data in the pivot table is missing.

To Reproduce

from numbers_parser import Document

doc = Document("dummy.numbers")
doc.save("dummy_new.numbers")

Expected behavior The data in the pivot table should not vanish.

Attachments numbers-files.zip

screenshot_1 screenshot_2 screenshot_3

Additional information

When I try to refresh the pivot table in Numbers, a message pops up:

(…) This pivot table uses data that was removed from its source table. (…)

masaccio commented 9 months ago

Thank you for the thorough test case. It does seem that if you accept the refresh and then undo, the resulting data is valid. I can certainly take a look at this though. Might take a few days -- don't know if I will have time this weekend.

masaccio commented 9 months ago

@ralfzosel would you mind expanding on your use case for how you want to edit Numbers documents? There are two options for supporting pivot tables in numbers-parser: leaving pivot tables alone and not trying to rebuild them on save (which is failing) or fully support pivot table creation. The latter would be difficult having taken a quick look at the data structures used. Leaving them untouched would be a quick fix, but I do wonder if references might get broken if rows/columns in source tables are inserted or deleted.

ralfzosel commented 9 months ago

Basically, I am working with a Numbers file that includes one large table containing all the data and many pivot tables for specific views on that data. Whenever I modify data or add data to the table, Numbers itself does not automatically refresh the pivot tables, so I am used to clicking on them all the time to update them. I guess, if numbers-parser would not touch the pivot tables, it should be fine. I can check out whether there are any problems when data is inserted into or deleted from the table.

masaccio commented 9 months ago

I've added a test to skip modifying pivot tables which was a small change so quicker than I thought. I've tested on your example and it looks good, but I've not tested on larger examples.

It's published as version 4.8.0.

masaccio commented 9 months ago

Actually I tried it on a larger example and it still exhibits the refresh error.