Bug 43330 - TransferTab mixes rangeNames
Summary: TransferTab mixes rangeNames
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
Master old -3.6
Hardware: Other All
: medium major
Assignee: Markus Mohrhard
URL:
Whiteboard: target:3.5
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-29 02:06 UTC by Laurent Godard
Modified: 2011-12-29 09:16 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
the file to import (8.53 KB, application/vnd.oasis.opendocument.spreadsheet)
2011-11-29 02:06 UTC, Laurent Godard
Details
the target file, the thisComponent in the macro (7.31 KB, application/vnd.oasis.opendocument.spreadsheet)
2011-11-29 02:07 UTC, Laurent Godard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Laurent Godard 2011-11-29 02:06:56 UTC
Created attachment 53945 [details]
the file to import

using the following macro, imported rangenames are not correctly defined


if targetPos > srcPos, seems ok for global range names
	result = theSheets.importSheet(srcDoc, srcName,3)

if targetPos = pos of the source sheet where named raneg are defined  --> do not poiint on the ocrrect sheet
	result = theSheets.importSheet(srcDoc, srcName,0)

in fact, named ranges are based on indexes but should refer at sheetname

gdb analysis pointed problems on sc/source/core/data/cell.cxx:183
 created wrong rangenames

'----

the macro

sub newApi


	destDoc = thisComponent

	theSheets = destDoc.sheets

	SrcUrl = convertToUrl("/home/lgodard/Bureau/DTEPoc/smallGlobal.ods")
	
	srcName = "autreFeuille"
	
	srcDoc = StarDesktop.loadComponentFromUrl(SrcUrl, "_blank", 1, array() )

	result = theSheets.importSheet(srcDoc, srcName,0)

	srcDoc.close(true)

	print result	

end sub
Comment 1 Laurent Godard 2011-11-29 02:07:26 UTC
Created attachment 53946 [details]
the target file, the thisComponent in the macro
Comment 2 Laurent Godard 2011-11-29 02:10:27 UTC
the bt that shows the creation of rangeName at formulaCell level which lead to some unused code at ScDocument::TransferTab (loop over range names to see if need to create and correct indexes, but has just been crated)


#0  ScRangeData::ScRangeData (this=0x90526e0, rScRangeData=...,
pDocument=0x909eb20)
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/core/tool/rangenam.cxx:166
#1  0xad73a55e in (anonymous namespace)::adjustRangeName
(pToken=0x9024788, rNewDoc=...,
    pOldDoc=0x8ad3ac8, aNewPos=..., aOldPos=...)
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/core/data/cell.cxx:183
#2  0xad73d713 in ScFormulaCell::ScFormulaCell (this=0xac441140,
rCell=..., rDoc=...,
    rPos=..., nCloneFlags=0)
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/core/data/cell.cxx:881
#3  0xad73a186 in (anonymous namespace)::lclCloneCell (rSrcCell=...,
rDestDoc=...,
    rDestPos=..., nCloneFlags=0)
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/core/data/cell.cxx:127
#4  0xad73a8be in ScBaseCell::CloneWithoutNote (this=0xac441058,
rDestDoc=...,
    rDestPos=..., nCloneFlags=0)
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/core/data/cell.cxx:243
#5  0xad7654a8 in ScColumn::CloneCell (this=0x8ae0f00, nIndex=1,
nFlags=255,
---Type <return> to continue, or q <return> to quit---
    rDestDoc=..., rDestPos=...)
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/core/data/column3.cxx:922
#6  0xad757650 in ScColumn::CopyToColumn (this=0x8ae0f00, nRow1=0,
nRow2=1048575,
    nFlags=255, bMarked=false, rColumn=..., pMarkData=0x0, bAsLink=false)
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/core/data/column.cxx:1332
#7  0xad8c8c60 in ScTable::CopyToTable (this=0x8ae0f00, nCol1=0,
nRow1=0, nCol2=1023,
    nRow2=1048575, nFlags=255, bMarked=false, pDestTab=0x900ed48,
pMarkData=0x0,
    bAsLink=false, bColRowFlags=true)
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/core/data/table2.cxx:780
#8  0xad78eed5 in ScDocument::TransferTab (this=0x909eb20,
pSrcDoc=0x8ad3ac8, nSrcPos=2,
    nDestPos=1, bInsertNew=true, bResultsOnly=false)
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/core/data/documen2.cxx:983
#9  0xadc67311 in ScDocShell::TransferTab (this=0x909eae0,
rSrcDocShell=..., nSrcPos=2,
    nDestPos=1, bInsertNew=1 '\001', bNotifyAndPaint=1 '\001')
    at
/home/lgodard/projets/libreoffice/build/git/master/libo/sc/source/ui/docshell/docsh5.cxx:857
Comment 3 Markus Mohrhard 2011-12-08 15:58:12 UTC
Laurent, didn't we have two similar problems here? I don't recall what is all wrong in the ScDocument::TransferTab method.

I think I can explain the problems with wrong references but I thought that we had an additional problem with range names here.

Some comments for me:

local range names are not adjusted or copied in ScDocument::TransferTab but in adjustRangeNames.

Is it possible to move the whole logic into adjust range name? What is with TransferTabRef if range names are created in adjustRangeName? How do we deal with the formulas in adjustRangeName?

I'm not sure if we will find a solution for every use case because there are some tricky points in there.
Comment 4 Laurent Godard 2011-12-09 02:20:12 UTC
hi, before diving into code (i'll do), here are some views on the different cases we can encounter

S = source sheet
D = destination sheet
NR = Nammed range (global in my mind at the moment), defines by its name and target sheet name (not index) and cell coordinates

* S contains NR definition (a target of a NR)

        - D document contains this NR targeting another sheet --> do nothing
        - D document does not contains this NR at all --> create it in D
        
* S uses NR in formulas

        - NR already exists in D document  --> do nothing
        - NR does not exists in D document
            - NR target cell and sheetByName does not exists in D --> do nothing, formula will end with #REF
            - NR target cell and sheetByName do exists in D
                - it is free of existing NR --> create it 
                - it already has another NR pointing on it
                    --> we can create 2 NR pointing on the same cell, so ok create it
                    --> BUT, may be a bug, formulas seems to use the first named range encountered, so formula is changed --> bad, a bug ?
                            --> eg. name1, name2 points on A1
                            --> we import(or paste, same problem) a formula =name2 --> the formula is changed as =name1
Comment 5 Laurent Godard 2011-12-09 02:35:45 UTC
so what is wrong, 2 things :

* name ranges index import focus on sheet index they refer too, and not sheet name
if a S NR points on mySheet!A1, sheet1 being at index say 2
in D, the NR points on A1 of the sheet that has index 2, may by named "otherSheet", even if "mySheet" exists at anoter index.

* we can create 2 NR pointing on the same cell, but  formulas seems to use the first named range encountered, so formula is changed --> bad, a bug ?
 --> eg. name1, name2 points on A1
--> we import(or paste, same problem) a formula =name2 --> the formula is changed as =name1
Comment 6 Markus Mohrhard 2011-12-20 22:52:38 UTC
Should be fixed with the latest patches in master.

One follow up patch is still missing for adjusting absolute refs to copied areas to the target document.