diff options
author | Eike Rathke <erack@redhat.com> | 2021-04-07 00:55:51 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-04-07 02:22:54 +0200 |
commit | d0b4719ca3d4608bcb7431dbeb097146dd5a5127 (patch) | |
tree | 45bb5e98b7f487d87ec2b9880916e4a16d69c5f8 /sc | |
parent | ea4fb1559f7b99a0bfaf18f26cb3b6972c9cde1c (diff) |
Related: tdf#128334 Make VBA Range getFormula(R1C1) work not only by accident
i.e. if document native grammar was very similar to the API
grammar (English UI function names, English locale and
separators, address convention).
Also alloc and init second string and conversion only if necessary.
These Formula and FormulaR1C1 properties still behave like
FormulaLocal and FormulaR1C1Local, which is wrong, see
https://bugs.documentfoundation.org/show_bug.cgi?id=128334#c12
Change-Id: I589b36c2cd51d5bbba767a309ccf61bd051928a4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113711
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/vba/vbarange.cxx | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 138857b54dfb..bb732f56feb8 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -876,7 +876,7 @@ protected: ScCompiler aCompiler( m_rDoc, aCellRanges.front().aStart, m_eGrammar ); // compile the string in the format passed in std::unique_ptr<ScTokenArray> pArray(aCompiler.CompileString(sFormula)); - // set desired convention to that of the document + // convert to API grammar aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_API ); OUString sConverted; aCompiler.CreateStringFromTokenArray(sConverted); @@ -908,22 +908,27 @@ public: { uno::Any aValue; aValue <<= xCell->getFormula(); - OUString sVal; - aValue >>= sVal; - uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW ); - ScCellRangesBase* pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() ); - if ( ( xCell->getType() == table::CellContentType_FORMULA ) && - pUnoRangesBase ) + // XCell::getFormula() returns the formula in API grammar, convert. + if ((xCell->getType() == table::CellContentType_FORMULA) + && m_eGrammar != formula::FormulaGrammar::GRAM_API) { - ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); - ScCompiler aCompiler( m_rDoc, aCellRanges.front().aStart, formula::FormulaGrammar::GRAM_DEFAULT ); - std::unique_ptr<ScTokenArray> pArray(aCompiler.CompileString(sVal)); - // set desired convention - aCompiler.SetGrammar( m_eGrammar ); - OUString sConverted; - aCompiler.CreateStringFromTokenArray(sConverted); - sVal = EQUALS + sConverted; - aValue <<= sVal; + uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW ); + ScCellRangesBase* pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() ); + if (pUnoRangesBase) + { + OUString sVal; + aValue >>= sVal; + ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); + // Compile string from API grammar. + ScCompiler aCompiler( m_rDoc, aCellRanges.front().aStart, formula::FormulaGrammar::GRAM_API ); + std::unique_ptr<ScTokenArray> pArray(aCompiler.CompileString(sVal)); + // Convert to desired grammar. + aCompiler.SetGrammar( m_eGrammar ); + OUString sConverted; + aCompiler.CreateStringFromTokenArray(sConverted); + sVal = EQUALS + sConverted; + aValue <<= sVal; + } } processValue( aValue ); |