diff options
author | Eike Rathke <erack@redhat.com> | 2015-04-09 14:11:46 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-04-09 18:19:02 +0200 |
commit | d5e1b41330fdd7341415e6c34f61ec826d20e51b (patch) | |
tree | 8af1113aa95e21feb5cd791c19a8bb627e97b36a /sc | |
parent | bbb14a29905db0e1a40d852352b3bfa6490c8514 (diff) |
TableRef: lookup column specifier
Change-Id: I73109e5a862b2f4bc456dff512bddf5d23586a6d
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/compiler.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 60 |
2 files changed, 60 insertions, 1 deletions
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index b4b194598c72..3154d57e6386 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -384,6 +384,7 @@ public: bool IsErrorConstant( const OUString& ) const; bool IsTableRefItem( const OUString& ) const; + bool IsTableRefColumn( const OUString& ) const; /** * When auto correction is set, the jump command reorder must be enabled. diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index d580bb9c7437..c2ebe55b8c49 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -3349,6 +3349,56 @@ bool ScCompiler::IsTableRefItem( const OUString& rName ) const return bItem; } +bool ScCompiler::IsTableRefColumn( const OUString& rName ) const +{ + // Only called when there actually is a current TableRef, hence + // accessing maTableRefs.back() is safe. + ScTableRefToken* p = dynamic_cast<ScTableRefToken*>(maTableRefs.back().mxToken.get()); + assert(p); // not a ScTableRefToken can't be + + ScDBData* pDBData = pDoc->GetDBCollection()->getNamedDBs().findByIndex( p->GetIndex()); + if (!pDBData) + return false; + + // '#', '[', ']' and '\'' are escaped with '\'' + OUString aName( rName.replaceAll( OUString("'"), OUString())); + + ScRange aRange; + pDBData->GetArea( aRange); + aRange.aEnd.SetTab( aRange.aStart.Tab()); + aRange.aEnd.SetRow( aRange.aStart.Row()); + + // Quite similar to IsColRowName() but limited to one row of headers. + ScCellIterator aIter( pDoc, aRange); + for (bool bHas = aIter.first(); bHas; bHas = aIter.next()) + { + CellType eType = aIter.getType(); + bool bOk = false; + if (eType == CELLTYPE_FORMULA) + { + ScFormulaCell* pFC = aIter.getFormulaCell(); + bOk = (pFC->GetCode()->GetCodeLen() > 0) && (pFC->aPos != aPos); + } + else + bOk = true; + + if (bOk && aIter.hasString()) + { + OUString aStr = aIter.getString(); + if (ScGlobal::GetpTransliteration()->isEqual( aStr, aName)) + { + ScSingleRefData aRef; + aRef.InitFlags(); + aRef.SetColRel( true ); + aRef.SetAddress( aIter.GetPos(), aPos); + maRawToken.SetSingleReference( aRef ); + return true; + } + } + } + return false; +} + void ScCompiler::SetAutoCorrection( bool bVal ) { assert(mbJumpCommandReorder); @@ -3653,8 +3703,16 @@ bool ScCompiler::NextNewToken( bool bInArray ) do { - mbRewind = false; const OUString aOrg( cSymbol ); + + // Check for TableRef column specifier first, it may be anything. + if (cSymbol[0] != '#' && !maTableRefs.empty() && maTableRefs.back().mnLevel) + { + if (IsTableRefColumn( aOrg )) + return true; + } + + mbRewind = false; aUpper.clear(); bool bAsciiUpper = false; |