sc/qa/unit/data/xlsx/freezePaneStartCell.xlsx |binary
 sc/qa/unit/subsequent_export_test2.cxx        |   16 ++++++++++++++++
 sc/source/filter/excel/xeview.cxx             |    7 +++++++
 3 files changed, 23 insertions(+)

New commits:
commit 5ef44a0b2ad238fbd13196e2f602de71f42a34d1
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Feb 7 14:08:42 2025 -0500
Commit:     Justin Luth <justin.l...@collabora.com>
CommitDate: Sat Feb 8 18:40:32 2025 +0100

    tdf#165130 sc: prevent pane's topLeftCell from being in frozen zone
    
    While Excel 2010 opens this unit test just fine
    (and looks like a split window)
    Excel 2019 complains it is corrupt.
    
    So, this patch just prevents writing an invalid topLeftCell
    which will avoid us from causing such a problem
    as well as fixing documents that already exhibit the problem.
    
    make CppunitTest_sc_subsequent_export_test2 \
        CPPUNIT_TEST_NAME=testFreezePaneStartCellXLSX
    
    Change-Id: I32888d7d020ec16dca436686cd76008ed417d699
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181275
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins

diff --git a/sc/qa/unit/data/xlsx/freezePaneStartCell.xlsx 
b/sc/qa/unit/data/xlsx/freezePaneStartCell.xlsx
new file mode 100644
index 000000000000..9bce2671009c
Binary files /dev/null and b/sc/qa/unit/data/xlsx/freezePaneStartCell.xlsx 
differ
diff --git a/sc/qa/unit/subsequent_export_test2.cxx 
b/sc/qa/unit/subsequent_export_test2.cxx
index ea9374da09ce..bda3aa7d5ea0 100644
--- a/sc/qa/unit/subsequent_export_test2.cxx
+++ b/sc/qa/unit/subsequent_export_test2.cxx
@@ -50,6 +50,22 @@ CPPUNIT_TEST_FIXTURE(ScExportTest2, testGroupShape)
     assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor/xdr:grpSp/xdr:grpSpPr");
 }
 
+CPPUNIT_TEST_FIXTURE(ScExportTest2, testFreezePaneStartCellXLSX)
+{
+    // given a hand-mangled document with a newly-invalid topLeftCell for the 
active pane
+    // where pane xSplit="5" ySplit="10" topLeftCell="A1" state="frozen"
+
+    createScDoc("xlsx/freezePaneStartCell.xlsx");
+
+    save(u"Calc Office Open XML"_ustr);
+
+    xmlDocUniquePtr pDoc = parseExport(u"xl/worksheets/sheet1.xml"_ustr);
+    OUString sFirstNonFrozenCell = getXPath(pDoc, "//x:sheetViews//x:pane", 
"topLeftCell");
+
+    // new versions of Excel complain if the start of the non-frozen section 
is inside the freeze
+    CPPUNIT_ASSERT_EQUAL(u"F11"_ustr, sFirstNonFrozenCell);
+}
+
 CPPUNIT_TEST_FIXTURE(ScExportTest2, testMatrixMultiplicationXLSX)
 {
     createScDoc("xlsx/matrix-multiplication.xlsx");
diff --git a/sc/source/filter/excel/xeview.cxx 
b/sc/source/filter/excel/xeview.cxx
index 5db6de1c2fff..c5760fafcdb7 100644
--- a/sc/source/filter/excel/xeview.cxx
+++ b/sc/source/filter/excel/xeview.cxx
@@ -348,6 +348,13 @@ XclExpTabViewSettings::XclExpTabViewSettings( const 
XclExpRoot& rRoot, SCTAB nSc
                 maData.mnActivePane = EXC_PANE_TOPRIGHT;
             else if( maData.HasPane( EXC_PANE_BOTTOMLEFT ) )
                 maData.mnActivePane = EXC_PANE_BOTTOMLEFT;
+
+            // Starting cell for active, frozen pane must not be less than the 
split position
+            // i.e. it must not be in the frozen section (or Excel 2019 
considers the file corrupt).
+            if (maData.maSecondXclPos.mnCol < maData.mnSplitX)
+                maData.maSecondXclPos.mnCol = maData.mnSplitX;
+            if (maData.maSecondXclPos.mnRow < maData.mnSplitY)
+                maData.maSecondXclPos.mnRow = maData.mnSplitY;
         }
         else
         {

Reply via email to