diff options
author | Eike Rathke <erack@redhat.com> | 2015-07-23 14:29:20 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-07-23 14:33:36 +0200 |
commit | d77947929c7f02cebe3d3e5d79c78642a8a439ba (patch) | |
tree | 20c6092f34ac3836ee36d89f7c8f001ba8025707 | |
parent | 22c9977d70e4812bca4bc038b775bb7eddb19bab (diff) |
TableRef: generate error for header-less column references, tdf#91278 related
... instead of using an arbitray first data record's string as column
name. We don't support header-less tables properly yet, so don't pretend
to.
Change-Id: Ia42619ec800291b6617a61c8a89a2d54ef231cec
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 901261b7f25b..dc46edb0e148 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -3517,35 +3517,38 @@ bool ScCompiler::IsTableRefColumn( const OUString& rName ) const 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()) + if (pDBData->HasHeader()) { - CellType eType = aIter.getType(); - bool bOk = false; - if (eType == CELLTYPE_FORMULA) + // Quite similar to IsColRowName() but limited to one row of headers. + ScCellIterator aIter( pDoc, aRange); + for (bool bHas = aIter.first(); bHas; bHas = aIter.next()) { - ScFormulaCell* pFC = aIter.getFormulaCell(); - bOk = (pFC->GetCode()->GetCodeLen() > 0) && (pFC->aPos != aPos); - } - else - bOk = true; + 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)) + if (bOk && aIter.hasString()) { - /* XXX NOTE: we could init the column as relative so copying a - * formula across columns would point to the relative column, - * but do it absolute because: - * a) it makes the reference work in named expressions without - * having to distinguish - * b) Excel does it the same. */ - ScSingleRefData aRef; - aRef.InitAddress( aIter.GetPos()); - maRawToken.SetSingleReference( aRef ); - return true; + OUString aStr = aIter.getString(); + if (ScGlobal::GetpTransliteration()->isEqual( aStr, aName)) + { + /* XXX NOTE: we could init the column as relative so copying a + * formula across columns would point to the relative column, + * but do it absolute because: + * a) it makes the reference work in named expressions without + * having to distinguish + * b) Excel does it the same. */ + ScSingleRefData aRef; + aRef.InitAddress( aIter.GetPos()); + maRawToken.SetSingleReference( aRef ); + return true; + } } } } @@ -3557,11 +3560,26 @@ bool ScCompiler::IsTableRefColumn( const OUString& rName ) const sal_Int32 nOffset = pDBData->GetColumnNameOffset( aName); if (nOffset >= 0) { - ScSingleRefData aRef; - ScAddress aAdr( aRange.aStart); - aAdr.IncCol( nOffset); - aRef.InitAddress( aAdr); - maRawToken.SetSingleReference( aRef ); + if (pDBData->HasHeader()) + { + ScSingleRefData aRef; + ScAddress aAdr( aRange.aStart); + aAdr.IncCol( nOffset); + aRef.InitAddress( aAdr); + maRawToken.SetSingleReference( aRef ); + } + else + { + /* TODO: this probably needs a new token type to hold offset and + * name, to be handled in HandleTableRef(). We can't use a + * reference token here because any reference would be wrong as + * there are no header cells to be referenced. However, it would + * only work as long as the ScDBData column names are not + * invalidated during document structure changes, otherwise + * recompiling the same formula could not resolve the name again. + * As long as this doesn't work generate an error. */ + return false; + } return true; } |