pjfanning opened a new pull request, #1332: URL: https://github.com/apache/poi/pull/1332
Fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=67442 ### Problem When the master cell of a shared formula group is removed (`setBlank`, `setCellType`, `setCellFormula`), `XSSFSheet.onDeleteFormula` promotes the next cell of the group to master. It narrowed the new `ref` to the columns at and to the right of the new master, so members of a 2D range lying in later rows *to the left* of it were no longer covered. Once the master had moved to the last column, no successor was found inside the ref; the cached master stayed pointing at the live `<f>` that was then `unsetF()`'d, and the next `getCellFormula()` on any member of the group threw `XmlValueDisconnectedException`. The workbook attached to the bug (`testSharedFormulasRangeSetBlankBug.xlsx`, already in `test-data` since r1912366) has a shared group `H2:J17` interrupted by cells with their own formulas and nested shared groups; the test added with it back in 2023 opened the wrong workbook, which is why it passed without a code change. ### Fix Excel-written files show the intended semantics (see `51710.xlsx`: master `E60`, ref `C60:M83`): the `ref` is the bounding box of the group's cells and the formula text is relative to the master cell, which `onReadCell` already handles by caching a trimmed detached copy. `onDeleteFormula` now - searches for the successor over the rest of the master's row and then the full width of the range in the rows below, - gives the new master a `ref` that is the bounding box of the remaining cells (like Excel), and - caches a trimmed detached copy of it via the same code path as `onReadCell` (factored out into `registerSharedFormula`), instead of the live `CTCellFormula`. ### Tests - `testSetBlankOnSharedFormulaRangeBug67442`: blanks every cell of the sheet; each formula cell must still resolve to the formula it had before anything was blanked, and the round-tripped workbook has no formulas left. - `testSharedFormulaMasterMovesToNextRowBug67442`: blanks the first row of the group; checks the new master (`H3`, ref `H3:J17`, rewritten text), that all other formulas are unchanged, and that after write/read-back `evaluateAll` reproduces the cached values. 🤖 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]
