[Libreoffice-commits] core.git: sc/qa sc/source

Tünde Tóth (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 13 16:24:17 UTC 2021


 sc/qa/unit/data/xlsx/tdf143068_top10filter.xlsx |binary
 sc/qa/unit/subsequent_export-test2.cxx          |   16 ++++++++++++++++
 sc/source/filter/excel/excrecds.cxx             |   16 +++++++++-------
 3 files changed, 25 insertions(+), 7 deletions(-)

New commits:
commit d79de2a2975db6b34f47b7ccfe8d18692373d6f0
Author:     Tünde Tóth <toth.tunde at nisz.hu>
AuthorDate: Fri Jul 2 14:19:16 2021 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Tue Jul 13 18:23:43 2021 +0200

    tdf#143068 XLSX: fix export of top10 filter condition
    
    Top10 filter condition lost after XLSX export.
    
    Change-Id: I5f9974e7d73f9ada84e284790c2928547f9ec7e7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118291
    Tested-by: Jenkins
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sc/qa/unit/data/xlsx/tdf143068_top10filter.xlsx b/sc/qa/unit/data/xlsx/tdf143068_top10filter.xlsx
new file mode 100644
index 000000000000..8626e74e60dc
Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf143068_top10filter.xlsx differ
diff --git a/sc/qa/unit/subsequent_export-test2.cxx b/sc/qa/unit/subsequent_export-test2.cxx
index e222c202e885..0a0a7cff9f8c 100644
--- a/sc/qa/unit/subsequent_export-test2.cxx
+++ b/sc/qa/unit/subsequent_export-test2.cxx
@@ -113,6 +113,7 @@ public:
     void testAutofilterColorsODF();
     void testAutofilterColorsOOXML();
     void testAutofilterColorsStyleOOXML();
+    void testAutofilterTop10XLSX();
 
     void testRefStringXLSX();
     void testRefStringConfigXLSX();
@@ -213,6 +214,7 @@ public:
     CPPUNIT_TEST(testAutofilterColorsODF);
     CPPUNIT_TEST(testAutofilterColorsOOXML);
     CPPUNIT_TEST(testAutofilterColorsStyleOOXML);
+    CPPUNIT_TEST(testAutofilterTop10XLSX);
 
     CPPUNIT_TEST(testRefStringXLSX);
     CPPUNIT_TEST(testRefStringConfigXLSX);
@@ -740,6 +742,20 @@ void ScExportTest2::testAutofilterColorsStyleOOXML()
                 "FFFFD7D7");
 }
 
+void ScExportTest2::testAutofilterTop10XLSX()
+{
+    ScDocShellRef xDocSh = loadDoc(u"tdf143068_top10filter.", FORMAT_XLSX);
+    CPPUNIT_ASSERT(xDocSh.is());
+
+    xmlDocUniquePtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory,
+                                                     "xl/worksheets/sheet1.xml", FORMAT_XLSX);
+    CPPUNIT_ASSERT(pDoc);
+    assertXPath(pDoc, "//x:autoFilter/x:filterColumn", "colId", "0");
+    assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:top10", "val", "4");
+
+    xDocSh->DoClose();
+}
+
 void ScExportTest2::testTdf88657ODS()
 {
     ScDocShellRef xDocSh = loadDoc(u"tdf88657.", FORMAT_ODS);
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx
index 8c66caebdea5..8ce820bb2389 100644
--- a/sc/source/filter/excel/excrecds.cxx
+++ b/sc/source/filter/excel/excrecds.cxx
@@ -809,7 +809,7 @@ void XclExpAutofilter::WriteBody( XclExpStream& rStrm )
 
 void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm )
 {
-    if (meType == FilterCondition && !HasCondition())
+    if (meType == FilterCondition && !HasCondition() && !HasTop10())
         return;
 
     sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
@@ -833,12 +833,14 @@ void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm )
                         // OOXTODO: XML_filterVal
                 );
             }
-
-            rWorksheet->startElement( XML_customFilters,
-                    XML_and, ToPsz((nFlags & EXC_AFFLAG_ANDORMASK) == EXC_AFFLAG_AND) );
-            aCond[ 0 ].SaveXml( rStrm );
-            aCond[ 1 ].SaveXml( rStrm );
-            rWorksheet->endElement( XML_customFilters );
+            else
+            {
+                rWorksheet->startElement(XML_customFilters, XML_and,
+                                         ToPsz((nFlags & EXC_AFFLAG_ANDORMASK) == EXC_AFFLAG_AND));
+                aCond[0].SaveXml(rStrm);
+                aCond[1].SaveXml(rStrm);
+                rWorksheet->endElement(XML_customFilters);
+            }
             // OOXTODO: XML_dynamicFilter, XML_extLst, XML_filters, XML_iconFilter
         }
         break;


More information about the Libreoffice-commits mailing list