sc/source/core/tool/interpr1.cxx |   42 +++++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 12 deletions(-)

New commits:
commit 74d1aad00b1dad10534ecd80a845ae182fbd08c3
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Tue Jul 25 23:41:23 2023 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Jul 28 10:03:26 2023 +0200

    Resolves: tdf#156467 Let array ROW() and COLUMN() return a scalar value
    
    ... instead of a single element matrix.
    
    Change-Id: I8307e24ef68dc54350fbdda74bc61b1df6a5107b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154908
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit 49b601937f5ba7739198a1b16ba6da2351897750)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154952
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index a8fba640b732..56840ceaeff3 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -4457,20 +4457,29 @@ void ScInterpreter::ScColumn()
             SCROW nRows = 0;
             if (pMyFormulaCell)
                 pMyFormulaCell->GetMatColsRows( nCols, nRows);
+            bool bMayBeScalar;
             if (nCols == 0)
             {
                 // Happens if called via ScViewFunc::EnterMatrix()
                 // ScFormulaCell::GetResultDimensions() as of course a
                 // matrix result is not available yet.
                 nCols = 1;
+                bMayBeScalar = false;
             }
-            ScMatrixRef pResMat = GetNewMat( static_cast<SCSIZE>(nCols), 1, 
/*bEmpty*/true );
-            if (pResMat)
+            else
             {
-                for (SCCOL i=0; i < nCols; ++i)
-                    pResMat->PutDouble( nVal + i, static_cast<SCSIZE>(i), 0);
-                PushMatrix( pResMat);
-                return;
+                bMayBeScalar = true;
+            }
+            if (!bMayBeScalar || nCols != 1 || nRows != 1)
+            {
+                ScMatrixRef pResMat = GetNewMat( static_cast<SCSIZE>(nCols), 
1, /*bEmpty*/true );
+                if (pResMat)
+                {
+                    for (SCCOL i=0; i < nCols; ++i)
+                        pResMat->PutDouble( nVal + i, static_cast<SCSIZE>(i), 
0);
+                    PushMatrix( pResMat);
+                    return;
+                }
             }
         }
     }
@@ -4561,20 +4570,29 @@ void ScInterpreter::ScRow()
             SCROW nRows = 0;
             if (pMyFormulaCell)
                 pMyFormulaCell->GetMatColsRows( nCols, nRows);
+            bool bMayBeScalar;
             if (nRows == 0)
             {
                 // Happens if called via ScViewFunc::EnterMatrix()
                 // ScFormulaCell::GetResultDimensions() as of course a
                 // matrix result is not available yet.
                 nRows = 1;
+                bMayBeScalar = false;
             }
-            ScMatrixRef pResMat = GetNewMat( 1, static_cast<SCSIZE>(nRows), 
/*bEmpty*/true);
-            if (pResMat)
+            else
             {
-                for (SCROW i=0; i < nRows; i++)
-                    pResMat->PutDouble( nVal + i, 0, static_cast<SCSIZE>(i));
-                PushMatrix( pResMat);
-                return;
+                bMayBeScalar = true;
+            }
+            if (!bMayBeScalar || nCols != 1 || nRows != 1)
+            {
+                ScMatrixRef pResMat = GetNewMat( 1, 
static_cast<SCSIZE>(nRows), /*bEmpty*/true);
+                if (pResMat)
+                {
+                    for (SCROW i=0; i < nRows; i++)
+                        pResMat->PutDouble( nVal + i, 0, 
static_cast<SCSIZE>(i));
+                    PushMatrix( pResMat);
+                    return;
+                }
             }
         }
     }

Reply via email to