sc/inc/document.hxx              |    2 ++
 sc/source/core/tool/compiler.cxx |   16 ++++++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

New commits:
commit 61cb699e88b3680becf78dc7b8bd514b2b7318a4
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Sun Jan 30 23:36:53 2022 +0100
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Jan 31 00:30:50 2022 +0100

    Resolves: tdf#146722 Force row label for single text with numeric to the 
right
    
    Note this *might* break other uses of the non-deterministic
    automatic labels where exactly this constellation previously lead
    to a column label. For which expecting a column label though makes
    less sense..
    
    Change-Id: Id85df7485f9b71620d8cbc404a981852d1567a54
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129187
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 87fb59e8980d..33e529d0b426 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2610,7 +2610,9 @@ private:
 
     bool    HasPartOfMerged( const ScRange& rRange );
 
+public:
     ScRefCellValue GetRefCellValue( const ScAddress& rPos );
+private:
     ScRefCellValue GetRefCellValue( const ScAddress& rPos, 
sc::ColumnBlockPosition& rBlockPos );
 
     std::map< SCTAB, ScSortParam > mSheetSortParams;
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 0858487b2836..aa65019434ea 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3889,10 +3889,18 @@ bool ScCompiler::IsColRowName( const OUString& rName )
             else
                 aAdr = aOne;
             aRef.InitAddress( aAdr );
-            if ( (aAdr.Row() != rDoc.MaxRow() && rDoc.HasStringData(
-                    aAdr.Col(), aAdr.Row() + 1, aAdr.Tab()))
-              || (aAdr.Row() != 0 && rDoc.HasStringData(
-                    aAdr.Col(), aAdr.Row() - 1, aAdr.Tab())))
+            // Prioritize on column label; row label only if the next cell
+            // above/below the found label cell is text, or if both are not and
+            // the cell below is empty and the next cell to the right is
+            // numeric.
+            if ((aAdr.Row() < rDoc.MaxRow() && rDoc.HasStringData(
+                            aAdr.Col(), aAdr.Row() + 1, aAdr.Tab()))
+                    || (aAdr.Row() > 0 && rDoc.HasStringData(
+                            aAdr.Col(), aAdr.Row() - 1, aAdr.Tab()))
+                    || (aAdr.Row() < rDoc.MaxRow() && rDoc.GetRefCellValue(
+                            ScAddress( aAdr.Col(), aAdr.Row() + 1, 
aAdr.Tab())).isEmpty()
+                        && aAdr.Col() < rDoc.MaxCol() && rDoc.GetRefCellValue(
+                            ScAddress( aAdr.Col() + 1, aAdr.Row(), 
aAdr.Tab())).hasNumeric()))
                 aRef.SetRowRel( true );     // RowName
             else
                 aRef.SetColRel( true );     // ColName

Reply via email to