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 b17df21168796c0b6907200f8600b065d7e602ad
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Fri Jul 2 14:19:16 2021 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jul 15 10:47:34 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 <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit d79de2a2975db6b34f47b7ccfe8d18692373d6f0)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118808
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.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 55faefb0ddb3..2b1dda267fed 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();
@@ -210,6 +211,7 @@ public:
     CPPUNIT_TEST(testAutofilterColorsODF);
     CPPUNIT_TEST(testAutofilterColorsOOXML);
     CPPUNIT_TEST(testAutofilterColorsStyleOOXML);
+    CPPUNIT_TEST(testAutofilterTop10XLSX);
 
     CPPUNIT_TEST(testRefStringXLSX);
     CPPUNIT_TEST(testRefStringConfigXLSX);
@@ -734,6 +736,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;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to