Bug 73822

Summary: EDITING: Reference to local Names become invalid after adding new sheet before the current one
Product: LibreOffice Reporter: Olivier Mehani <shtrom-freedesktop>
Component: CalcAssignee: Not Assigned <libreoffice-bugs>
Status: RESOLVED WORKSFORME    
Severity: normal CC: jmadero.dev
Priority: medium    
Version: 4.1.4.2 release   
Hardware: Other   
OS: Linux (All)   
Whiteboard: BSA
Crash report or crash signature: Regression By:
Attachments: Spreadsheet with two sheet and Name 'test' defined and used from Sheet1
Same spreadsheet with Sheet3 added before Sheet1; doing so, Name 'test' gets changed to point to Sheet2 instead of Sheet1 as it was before.

Description Olivier Mehani 2014-01-20 08:03:02 UTC
Created attachment 92427 [details]
Spreadsheet with two sheet and Name 'test' defined and used from Sheet1

Problem description: 

Steps to reproduce:
1. Input a column of data (say, 1,2,3,4 it A1:A4) in Sheet 1, and select it
2. Insert/Names/Define
2.1. Name: test
2.2. Range: the data column (should already be initialised)
2.3. Scope: Sheet1
3. Select B1:B4, and enter '=test' then Ctrl+Shift+Enter to create an array filled from the data contained in named reference 'test' just defined
4. Insert a new sheet after Sheet1
5. Select Sheet2.B1:B4, and enter '=Sheet1.B1:B4' then Ctrl+Shift+Enter
=> it works: it contains data initially entered in Sheet1.A1:A4 and repeated in Sheet1.B1:B4 through the Sheet reference
6. Go to Sheet1
7. Insert/Names/Manage
=> the Range for Name test appears as Sheet1.A1:A4, as defined
6. Insert a new sheet before Sheet1
7. Hit F9 to recalculate or, sometimes, save the document, close it and reopen it
8. Go to Sheet1 (now the second one)
9. Insert/Names/Manage

Current behavior:
=> test now appears as Sheet2.A1:A4, rather than the previous Sheet1.A1:A4 (still in Scope Sheet1, though)
=> no data is present anymore in Sheet1.B1:B4 and Sheet1.A1:A4 as they now refer to a set of empty cells in Sheet2, rather than Sheet1 as defined

Deleting/readding Sheet3 toggles Name 'test' to refer to the range in Sheet1 or Sheet2 (try in after.ods, attached)

Expected behavior:

The range for name test should not change, and the recalculated data should be identical to before recalculating.

              
Operating System: Linux (Other)
Version: 4.1.4.2 release
Comment 1 Olivier Mehani 2014-01-20 08:04:32 UTC
Created attachment 92428 [details]
Same spreadsheet with Sheet3 added before Sheet1; doing so, Name 'test' gets changed to point to Sheet2 instead of Sheet1 as it was before.
Comment 2 Olivier Mehani 2014-01-20 08:07:55 UTC
Forgot the human-readable description. Here goes:

When I define (local) names in a sheet (say, Sheet1) to reference a group of cells, than add a new sheet before that one (say, Sheet3), the range of the name gets mangled, and ends up pointing to another sheet (e..g, Sheet2, just after), therefore making the data incorrect in all cells using that Name as a reference.
Comment 3 Joel Madero 2014-02-26 02:27:42 UTC
Well - that's a strange one ;) Verified on 4.1.5.3 but it's fixed in 4.3 so marking as WFM - you'll see a fix either in 4.2 or 4.3 depending on if the fix was backported. The problem isn't substantial enough to request additional backporting.

If you'd like to test you can download 4.2.1.1 release and see if it's working there.

Thanks for reporting!