summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2020-10-31 01:20:55 +0100
committerEike Rathke <erack@redhat.com>2020-10-31 11:47:00 +0100
commit075da6f2463c922bcb8c553949756af4e8e103e0 (patch)
tree57133789045d2ea953ba9fef0afc2f93426c6393
parentfc92e4e8c51cee379781b15670507e72510a9f60 (diff)
Resolves: tdf#100818 Support sheet-local scoped names in INDIRECT()
Change-Id: Iae1ef07bf735b5886e391dced9984acee617f051 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105091 Tested-by: Jenkins Reviewed-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/inc/rangeutl.hxx3
-rw-r--r--sc/source/core/tool/interpr1.cxx2
-rw-r--r--sc/source/core/tool/rangeutl.cxx36
3 files changed, 38 insertions, 3 deletions
diff --git a/sc/inc/rangeutl.hxx b/sc/inc/rangeutl.hxx
index 2212d6bb9a41..7f68a25a9af7 100644
--- a/sc/inc/rangeutl.hxx
+++ b/sc/inc/rangeutl.hxx
@@ -221,7 +221,8 @@ public:
const ScDocument& rDoc );
/// String to RangeData core
- static ScRangeData* GetRangeDataFromString(const OUString& rString, const SCTAB nTab, const ScDocument& rDoc);
+ static ScRangeData* GetRangeDataFromString( const OUString& rString, const SCTAB nTab,
+ const ScDocument& rDoc, formula::FormulaGrammar::AddressConvention eConv );
};
class ScArea
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 321f80328095..8e50ae7303c5 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -8128,7 +8128,7 @@ void ScInterpreter::ScIndirect()
{
do
{
- ScRangeData* pData = ScRangeStringConverter::GetRangeDataFromString(sRefStr, nTab, mrDoc);
+ ScRangeData* pData = ScRangeStringConverter::GetRangeDataFromString( sRefStr, nTab, mrDoc, eConv);
if (!pData)
break;
diff --git a/sc/source/core/tool/rangeutl.cxx b/sc/source/core/tool/rangeutl.cxx
index 39c4a1a26f58..eb6737f34879 100644
--- a/sc/source/core/tool/rangeutl.cxx
+++ b/sc/source/core/tool/rangeutl.cxx
@@ -894,8 +894,42 @@ void ScRangeStringConverter::GetStringFromXMLRangeString( OUString& rString, con
rString = aRetStr.makeStringAndClear();
}
-ScRangeData* ScRangeStringConverter::GetRangeDataFromString(const OUString& rString, const SCTAB nTab, const ScDocument& rDoc)
+ScRangeData* ScRangeStringConverter::GetRangeDataFromString( const OUString& rString, const SCTAB nTab,
+ const ScDocument& rDoc, formula::FormulaGrammar::AddressConvention eConv )
{
+ // This may be called with an external 'doc'#name but wouldn't find any.
+
+ // Dot '.' is not allowed in range names, if present only lookup if it's a
+ // sheet-local name. Same for '!' Excel syntax.
+ // If eConv == FormulaGrammar::CONV_A1_XL_A1 then try both, first our own.
+ sal_Int32 nIndex = -1;
+ if (eConv == FormulaGrammar::CONV_OOO || eConv == FormulaGrammar::CONV_A1_XL_A1)
+ nIndex = ScGlobal::FindUnquoted( rString, '.');
+ if (nIndex < 0 && (eConv == FormulaGrammar::CONV_A1_XL_A1
+ || eConv == FormulaGrammar::CONV_XL_A1
+ || eConv == FormulaGrammar::CONV_XL_R1C1
+ || eConv == FormulaGrammar::CONV_XL_OOX))
+ nIndex = ScGlobal::FindUnquoted( rString, '!');
+
+ if (nIndex >= 0)
+ {
+ if (nIndex == 0)
+ return nullptr; // Can't be a name.
+
+ OUString aTab( rString.copy( 0, nIndex));
+ ScGlobal::EraseQuotes( aTab, '\'');
+ SCTAB nLocalTab;
+ if (!rDoc.GetTable( aTab, nLocalTab))
+ return nullptr;
+
+ ScRangeName* pLocalRangeName = rDoc.GetRangeName(nLocalTab);
+ if (!pLocalRangeName)
+ return nullptr;
+
+ const OUString aName( rString.copy( nIndex+1));
+ return pLocalRangeName->findByUpperName( ScGlobal::getCharClassPtr()->uppercase( aName));
+ }
+
ScRangeName* pLocalRangeName = rDoc.GetRangeName(nTab);
ScRangeData* pData = nullptr;
OUString aUpperName = ScGlobal::getCharClassPtr()->uppercase(rString);