diff options
-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() |