sc/inc/rangeutl.hxx | 3 ++- sc/source/core/tool/interpr1.cxx | 2 +- sc/source/core/tool/rangeutl.cxx | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-)
New commits: commit 075da6f2463c922bcb8c553949756af4e8e103e0 Author: Eike Rathke <er...@redhat.com> AuthorDate: Sat Oct 31 01:20:55 2020 +0100 Commit: Eike Rathke <er...@redhat.com> CommitDate: Sat Oct 31 11:47:00 2020 +0100 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 <er...@redhat.com> 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); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits