diff options
author | Eike Rathke <erack@redhat.com> | 2016-03-18 14:07:55 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-03-18 14:36:28 +0100 |
commit | cf56d2449c27130ae40dc940ddcdb13de1128b7f (patch) | |
tree | 735108733454a11874551a432e73160e27d078b7 | |
parent | 090de0e963fd3b0c7c4f8db4124b71b0fd92f61f (diff) |
adjust other-sheet-local relative sheet references, tdf#96915
... so they still point to the same sheet as if used on the original
local sheet.
Change-Id: Id40378deaf70c1645bfa52ea28aa39775d16aec5
-rw-r--r-- | sc/inc/compiler.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index e1887aa10d27..a0370233a6ff 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -324,6 +324,7 @@ private: bool IsBoolean( const OUString& ); void AutoCorrectParsedSymbol(); + void AdjustSheetLocalNameRelReferences( SCTAB nDelta ); void SetRelNameReference(); /** Obtain range data for ocName token, global or sheet local. diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index c57f192bf38a..15b193907025 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -4462,6 +4462,14 @@ bool ScCompiler::HandleRange() PushTokenArray( pNew, true ); if( pRangeData->HasReferences() ) { + // Relative sheet references in sheet-local named expressions + // shall still point to the same sheet as if used on the + // original sheet, not shifted to the current position where + // they are used. + SCTAB nSheetTab = mpToken->GetSheet(); + if (nSheetTab >= 0 && nSheetTab != aPos.Tab()) + AdjustSheetLocalNameRelReferences( nSheetTab - aPos.Tab()); + SetRelNameReference(); MoveRelWrap(pRangeData->GetMaxCol(), pRangeData->GetMaxRow()); } @@ -4526,6 +4534,23 @@ bool ScCompiler::HandleExternalReference(const FormulaToken& _aToken) return true; } +void ScCompiler::AdjustSheetLocalNameRelReferences( SCTAB nDelta ) +{ + pArr->Reset(); + for (formula::FormulaToken* t = pArr->GetNextReference(); t; t = pArr->GetNextReference()) + { + ScSingleRefData& rRef1 = *t->GetSingleRef(); + if (rRef1.IsTabRel()) + rRef1.IncTab( nDelta); + if ( t->GetType() == svDoubleRef ) + { + ScSingleRefData& rRef2 = t->GetDoubleRef()->Ref2; + if (rRef2.IsTabRel()) + rRef2.IncTab( nDelta); + } + } +} + // reference of named range with relative references void ScCompiler::SetRelNameReference() |