sc/qa/unit/uicalc/data/tdf140027.ods |binary
 sc/qa/unit/uicalc/uicalc2.cxx        |   24 ++++++++++++++++++++++++
 sc/source/core/data/attarray.cxx     |    8 +++++++-
 3 files changed, 31 insertions(+), 1 deletion(-)

New commits:
commit 9920cf0642b175798afb319cc4b9d8b2bef4e67c
Author:     Balazs Varga <balazs.va...@collabora.com>
AuthorDate: Thu Aug 14 17:30:48 2025 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Sat Aug 16 00:26:48 2025 +0200

    tdf#140027 - sc fix inserting rows before pivot table in row 1
    
    Do not copy flags except Scenario when we insert a new row before/
    after. Also remove hard attributes when we insert a very new first
    row on the sheet. (Same what MSO does.)
    
    Change-Id: Ia825683ab221f445b1c9977006b3f1cdffb2ea24
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189614
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.va...@collabora.com>
    (cherry picked from commit f85188809d28dfe01ac8ed8b93e62e17f59773d2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189720
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/unit/uicalc/data/tdf140027.ods 
b/sc/qa/unit/uicalc/data/tdf140027.ods
new file mode 100644
index 000000000000..35cc3089dbfa
Binary files /dev/null and b/sc/qa/unit/uicalc/data/tdf140027.ods differ
diff --git a/sc/qa/unit/uicalc/uicalc2.cxx b/sc/qa/unit/uicalc/uicalc2.cxx
index 253fb35c4b9d..d228ee82717a 100644
--- a/sc/qa/unit/uicalc/uicalc2.cxx
+++ b/sc/qa/unit/uicalc/uicalc2.cxx
@@ -1654,6 +1654,30 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf154044)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf140027)
+{
+    // testing the correct import of autofilter from XLSB
+    createScDoc("tdf140027.ods");
+
+    goToCell(u"A1"_ustr);
+
+    ScDocShell* pDocSh = getScDocShell();
+    lcl_AssertCurrentCursorPosition(*pDocSh, u"A1");
+
+    dispatchCommand(mxComponent, u".uno:SelectRow"_ustr, {});
+    dispatchCommand(mxComponent, u".uno:InsertRowsBefore"_ustr, {});
+
+    // check we have no any unnecessary flags
+    ScDocument* pDoc = getScDoc();
+    auto nFlag = pDoc->GetAttr(0, 0, 1, ATTR_MERGE_FLAG)->GetValue();
+    CPPUNIT_ASSERT_EQUAL(ScMF::NONE, nFlag);
+
+    const ScPatternAttr* pPattern = pDoc->GetPattern(1, 0, 1);
+    const ScPatternAttr aDefPattern = 
pPattern->getCellAttributeHelper().getDefaultCellAttribute();
+    // check that the default pattern is not changed
+    CPPUNIT_ASSERT(ScPatternAttr::areSame(pPattern, &aDefPattern));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 852db370cf54..044ef2102916 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -2255,7 +2255,13 @@ void ScAttrArray::InsertRow( SCROW nStartRow, SCSIZE 
nSize )
 
     // Don't duplicate the merge flags in the inserted row.
     // #i108488# ScMF::Scenario has to be allowed.
-    RemoveFlags( nStartRow, nStartRow+nSize-1, ScMF::Hor | ScMF::Ver | 
ScMF::Auto | ScMF::Button );
+    RemoveFlags(nStartRow, nStartRow + nSize - 1, (ScMF::All & 
~ScMF::Scenario));
+    // tdf#140027: set new default attributes if we insert very first rows.
+    if (nStartRow == 0)
+    {
+        const CellAttributeHolder 
aDefHolder(&rDocument.getCellAttributeHelper().getDefaultCellAttribute());
+        SetPatternArea(nStartRow, nStartRow + nSize - 1, aDefHolder);
+    }
 }
 
 void ScAttrArray::DeleteRow( SCROW nStartRow, SCSIZE nSize )

Reply via email to