Bug 147221

Summary: Cell references not updated correctly during merge cells
Product: LibreOffice Reporter: Jim Avera <jim.avera>
Component: CalcAssignee: Not Assigned <libreoffice-bugs>
Status: UNCONFIRMED ---    
Severity: normal CC: aron.budea, erack
Priority: medium    
Version: 7.4.0.0 alpha0+   
Hardware: All   
OS: All   
Whiteboard:
Crash report or crash signature: Regression By:
Attachments: Test case (test.ods)

Description Jim Avera 2022-02-05 18:26:16 UTC

    
Comment 1 Jim Avera 2022-02-05 18:33:26 UTC
When a cell is referenced in a formula in another cell:

If the referenced cell content moves as a result of merging adjacent cells, the reference is not updated to refer to the new position.

STEPS TO REPRODUCE:
(See attached test.ods spreadsheet)

1. Create a spreadsheet with something in cell B2
2. Reference B2 in a formula in some other cell e.g. "=1/B2"
3. Select B1 & B2
4. Format->Merge and Unmerge Cells->Merge

RESULTS: The formula breaks, because the value which was in B2 is moved to B1 but the reference was not updated to track it.

NOTE: When merging cells, if more than one of the merged cells contains content the user is offered a choice of how to handle the conflict (move all content to the first cell, which is the default; keep hidden cell content as-is; or delete the content of now-hidden cells).  

References should be updated only when content is moved, i.e. when combining all merged cells into the first cell.
Comment 2 Jim Avera 2022-02-05 18:38:24 UTC
There is an additional problem when cells are merged:

If only one of the merged cells contains content, and that content is a formula, the formula is replaced by the current value and the formula is lost (so the value will not update any longer).

If merging empty cells with a single non-empty cell containing a formula, the formula should be preserved IMO (and any relative cell references updated to reflect the moved position of the formula if it was not in the first cell in the merge group).
Comment 3 Jim Avera 2022-02-05 18:39:04 UTC
Created attachment 178084 [details]
Test case (test.ods)
Comment 4 Mike Kaganski 2022-02-06 11:10:45 UTC
IMO this is correct behavior, since merging cells does not destroy cells, only hides them; and they may even have their separate values. But maybe merging could ask for this detail, as it does in case of merging cells with values?
Comment 5 Jim Avera 2022-02-07 04:47:16 UTC
Merging *moves content* in the common case rather than just hiding it.

That is why references to the (moved) content break.