[Libreoffice-commits] core.git: sc/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 7 00:23:37 UTC 2021


 sc/source/ui/vba/vbarange.cxx |   37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

New commits:
commit d0b4719ca3d4608bcb7431dbeb097146dd5a5127
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Wed Apr 7 00:55:51 2021 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Wed Apr 7 02:22:54 2021 +0200

    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 at redhat.com>

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 );


More information about the Libreoffice-commits mailing list