numbers-parser icon indicating copy to clipboard operation
numbers-parser copied to clipboard

Feature request: support resaving pivot tables

Open ralfzosel opened this issue 2 years ago • 5 comments

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

  • numbers-parser version 4.7.1
  • Numbers version 13.2 (7038.0.87)
  • macOS 13.6.4 (22G513) (M2 chip)

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. (…)

ralfzosel avatar Feb 05 '24 10:02 ralfzosel

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 avatar Feb 05 '24 12:02 masaccio

@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.

masaccio avatar Feb 06 '24 08:02 masaccio

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.

ralfzosel avatar Feb 06 '24 10:02 ralfzosel

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 avatar Feb 07 '24 08:02 masaccio

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

masaccio avatar Feb 07 '24 12:02 masaccio