sc/qa/unit/subsequent_export-test.cxx |   29 +++++++++++++++++++++++++++++
 sc/source/filter/xml/xmltabi.cxx      |   22 +++++++++++++---------
 2 files changed, 42 insertions(+), 9 deletions(-)

New commits:
commit 88476a6f89f2908fc8083dbbb53391b75192c783
Author:     Attila Szűcs <szucs.atti...@nisz.hu>
AuthorDate: Thu Jan 14 15:01:13 2021 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jan 21 16:37:23 2021 +0100

    tdf#51022 sc import: fix lost print ranges of last sheet
    
    of documents with external references.
    
    Processing external sheets could remove (or extend) the
    print ranges of the last non-external sheet (indexed by
    nCurTab).
    
    Co-authored-by: Tibor Nagy (NISZ)
    
    Change-Id: Ifc44148875106dad791de61953f3b046b6f2b188
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109295
    Tested-by: László Németh <nem...@numbertext.org>
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit bd6214e2aa6f25e013eef769529b75c1e3b580cb)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109741
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/unit/subsequent_export-test.cxx 
b/sc/qa/unit/subsequent_export-test.cxx
index e2da767d9bbb..a64a14ec96a9 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -273,6 +273,7 @@ public:
     void testTdf126305_DataValidatyErrorAlert();
     void testTdf76047_externalLink();
     void testTdf87973_externalLinkSkipUnuseds();
+    void testTdf51022_lostPrintRange();
     void testTdf138741_externalLinkSkipUnusedsCrash();
     void testTdf138824_linkToParentDirectory();
     void testTdf129969();
@@ -450,6 +451,7 @@ public:
     CPPUNIT_TEST(testTdf126305_DataValidatyErrorAlert);
     CPPUNIT_TEST(testTdf76047_externalLink);
     CPPUNIT_TEST(testTdf87973_externalLinkSkipUnuseds);
+    CPPUNIT_TEST(testTdf51022_lostPrintRange);
     CPPUNIT_TEST(testTdf138741_externalLinkSkipUnusedsCrash);
     CPPUNIT_TEST(testTdf138824_linkToParentDirectory);
     CPPUNIT_TEST(testTdf129969);
@@ -5669,6 +5671,33 @@ void ScExportTest::testTdf87973_externalLinkSkipUnuseds()
     pDocSh->DoClose();
 }
 
+void ScExportTest::testTdf51022_lostPrintRange()
+{
+    ScDocShellRef pShell = loadDoc(u"tdf87973_externalLinkSkipUnuseds.", 
FORMAT_ODS);
+    CPPUNIT_ASSERT(pShell.is());
+
+    pShell->ReloadAllLinks();
+    ScDocument& rDoc = pShell->GetDocument();
+
+    //Add print ranges
+    ScRange aRange1(1, 2, 0, 3, 4, 0);
+    ScRange aRange2(1, 6, 0, 3, 7, 0);
+    rDoc.AddPrintRange(0, aRange1);
+    rDoc.AddPrintRange(0, aRange2);
+
+    // save and load back
+    ScDocShellRef pDocSh = saveAndReload(&(*pShell), FORMAT_ODS);
+    CPPUNIT_ASSERT(pDocSh.is());
+
+    // check if the same print ranges are present
+    ScDocument& rDoc2 = pDocSh->GetDocument();
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2), 
rDoc2.GetPrintRangeCount(0));
+    CPPUNIT_ASSERT_EQUAL(aRange1, *rDoc2.GetPrintRange(0, 0));
+    CPPUNIT_ASSERT_EQUAL(aRange2, *rDoc2.GetPrintRange(0, 1));
+
+    pDocSh->DoClose();
+}
+
 void ScExportTest::testTdf138741_externalLinkSkipUnusedsCrash()
 {
     ScDocShellRef xShell = loadDoc("tdf138741_externalLinkSkipUnusedsCrash.", 
FORMAT_XLSX);
diff --git a/sc/source/filter/xml/xmltabi.cxx b/sc/source/filter/xml/xmltabi.cxx
index 55394c370fe8..abc82e02746a 100644
--- a/sc/source/filter/xml/xmltabi.cxx
+++ b/sc/source/filter/xml/xmltabi.cxx
@@ -353,19 +353,23 @@ void SAL_CALL ScXMLTableContext::endFastElement(sal_Int32 
/*nElement*/)
 
     ScMyTables& rTables = rImport.GetTables();
     SCTAB nCurTab = rTables.GetCurrentSheet();
-    if (!sPrintRanges.isEmpty())
+    // tdf#51022 process only print ranges of internal sheets
+    if (!pExternalRefInfo)
     {
-        ScRangeList aRangeList;
-        ScRangeStringConverter::GetRangeListFromString( aRangeList, 
sPrintRanges, *pDoc, ::formula::FormulaGrammar::CONV_OOO );
-        size_t nCount = aRangeList.size();
-        for (size_t i=0; i< nCount; i++ )
+        if (!sPrintRanges.isEmpty())
         {
-            pDoc->AddPrintRange( nCurTab, aRangeList[i] );
+            ScRangeList aRangeList;
+            ScRangeStringConverter::GetRangeListFromString(aRangeList, 
sPrintRanges, *pDoc, ::formula::FormulaGrammar::CONV_OOO);
+            size_t nCount = aRangeList.size();
+            for (size_t i = 0; i < nCount; i++)
+            {
+                pDoc->AddPrintRange(nCurTab, aRangeList[i]);
+            }
         }
+        else if (!bPrintEntireSheet)
+            // Sheet has "print entire sheet" option by default.  Remove it.
+            pDoc->ClearPrintRanges(nCurTab);
     }
-    else if (!bPrintEntireSheet)
-        // Sheet has "print entire sheet" option by default.  Remove it.
-        pDoc->ClearPrintRanges(nCurTab);
 
     ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(nCurTab));
     if (pOutlineTable)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to