pjfanning opened a new pull request, #1563:
URL: https://github.com/apache/poi/pull/1563

   Point 2 of #1554.
   
   `XSSFWorkbook.removeSheetAt` removed the sheet's pivot table parts but left 
the workbook's `<pivotCache>` entry and its relationship to the 
`pivotCacheDefinition` part. That kept the cache definition and the 
`pivotCacheRecords` part, which holds a full copy of the pivot's source data, 
in the written file. This is the same data-remnant problem as #1543.
   
   Changes:
   - `removeSheetAt` takes the removed sheet's pivot tables out of 
`XSSFWorkbook.getPivotTables()`, which used to keep returning them.
   - For each of their caches that no remaining pivot table uses (matched on 
`cacheId`), it removes the `<pivotCache>` entry and the workbook relationship. 
The existing #1543 logic then removes the cache definition and records parts. 
If no caches remain, the empty `<pivotCaches>` element is removed too.
   - Because the list can now shrink, `createPivotTable` can no longer use 
`getPivotTables().size() + 1` as an id. It now asks for free part numbers 
(`getNextPartNumber`) and gives the new cache the next unused `cacheId`. 
Workbooks with no removals get the same numbers as before. This also covers 
loaded files whose cache ids have gaps, e.g. `0` and `2` in 
`ExcelPivotTableSample.xlsx`.
   
   Tests cover a loaded file (removing one pivot sheet and then the other), and 
pivot tables created by POI, including creating a new pivot table after a 
removal and writing the workbook out and reading it back.
   
   Not covered: Excel 2010+ extension data that refers to a pivot cache by id 
(slicer or timeline caches in the workbook `extLst`) is left as it is.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to