Bug 147221 - Cell references not updated correctly during merge cells
Summary: Cell references not updated correctly during merge cells
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.4.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-05 18:26 UTC by Jim Avera
Modified: 2023-06-12 20:50 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Test case (test.ods) (13.45 KB, application/vnd.oasis.opendocument.spreadsheet)
2022-02-05 18:39 UTC, Jim Avera
Details

Note You need to log in before you can comment on or make changes to this bug.
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.