pjfanning opened a new pull request, #1319:
URL: https://github.com/apache/poi/pull/1319
Stacked on #1318 (the last commit is the change; merge #1318 first, or I
rebase once it lands).
## The bug
`XSSFCell.setCellFormula` on a cell of a shared formula group:
- **on the master**: kept the group and re-registered it with the *new* text
(`onReadCell(this)`), so every follower silently changed meaning — `D2 :=
A2*100` made `D3` report and evaluate `A3*100`.
- **on a follower**: stored the text in the cell's `<f>` but left
`t="shared"`/`si`, and `getCellFormula()`/evaluation derive a shared cell from
the master — so the new formula was written to the file but ignored by POI.
Excel un-shares the edited cell: it becomes an ordinary formula cell, the
other cells keep the formula they had, and if the edited cell was the master
the next cell of the group becomes master with the old formula shifted to its
position.
## The fix
In `XSSFCell.setFormula`, when the existing `<f>` is shared: if it is the
master, run `XSSFSheet.onDeleteFormula` first (the promotion of the next cell
that already exists for a *removed* master, bug 58106) and drop `ref`; in both
cases drop `t` and `si`; then set the text. One method, ~10 lines.
This reverses the expectation recorded in `test61869` ("c2 remains the
master formula … formula in the follower cell is rebuilt"), which pinned the
previous behaviour when the unreadable-file problem was fixed. The rewritten
test checks the Excel semantics and that the file still round-trips;
`settingAFormulaOnASharedFormulaFollowerUnsharesIt` covers the follower case on
the 58106 sample;
`TestXSSFFormulaTokenCache.aChangedSharedMasterLeavesTheGroupToTheNextCell`
(from #1318, adjusted here) checks the evaluator side.
Locally green: `TestXSSFCell` (86), `TestXSSFFormulaTokenCache`, all
`TestXSSFFormulaEvaluator*` incl. the shared-formula variants, `TestXSSFSheet`,
`TestXSSFBugs`, `TestXSSFSheetShiftRows*`, `TestFormulaEvaluatorOnXSSF`,
`xssf.streaming.*`, `ss.usermodel.*` — apart from the pre-existing font-metrics
failures (`stackoverflow23114397`, `TestSXSSFSheetAutoSizeColumn`).
`changes.xml` left for you (this one is user-visible).
🤖 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]