tdf#123353 XLSX export: fix lost AutoFilter on empty cells
The AutoFilter button was lost during export when only the
rows with empty cells were visible and everything else was
hidden. The filter itself was still active, but the button
itself was gone.
Co-authored-by: Attila Szűcs (NISZ)
Change-Id: Ia0b16bf4f15303d1320081cb62090368a0ce3908
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101847
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sc/qa/unit/data/xlsx/tdf123353.xlsx b/sc/qa/unit/data/xlsx/tdf123353.xlsx
new file mode 100644
index 0000000..f37f072
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/tdf123353.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 8172ae5..efe44fc 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -259,6 +259,7 @@ public:
void testTdf121718_UseFirstPageNumberXLSX();
void testHeaderFontStyleXLSX();
void testTdf135828_Shape_Rect();
void testTdf123353();
CPPUNIT_TEST_SUITE(ScExportTest);
CPPUNIT_TEST(test);
@@ -416,6 +417,7 @@ public:
CPPUNIT_TEST(testTdf121718_UseFirstPageNumberXLSX);
CPPUNIT_TEST(testHeaderFontStyleXLSX);
CPPUNIT_TEST(testTdf135828_Shape_Rect);
CPPUNIT_TEST(testTdf123353);
CPPUNIT_TEST_SUITE_END();
@@ -5314,6 +5316,7 @@ void ScExportTest::testTdf135828_Shape_Rect()
CPPUNIT_ASSERT(xDocSh.is());
std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX);
xmlDocUniquePtr pDrawing = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml");
CPPUNIT_ASSERT(pDrawing);
@@ -5321,6 +5324,24 @@ void ScExportTest::testTdf135828_Shape_Rect()
assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:ext", "cy", "1990440"); // height
}
void ScExportTest::testTdf123353()
{
ScDocShellRef xShell = loadDoc("tdf123353.", FORMAT_XLSX);
CPPUNIT_ASSERT(xShell.is());
ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX);
CPPUNIT_ASSERT(xDocSh.is());
std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX);
xmlDocUniquePtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml");
CPPUNIT_ASSERT(pDoc);
assertXPath(pDoc, "/x:worksheet/x:autoFilter/x:filterColumn/x:filters", "blank", "1");
xShell->DoClose();
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx
index 3298d42..945748b 100644
--- a/sc/source/filter/excel/excrecds.cxx
+++ b/sc/source/filter/excel/excrecds.cxx
@@ -649,9 +649,12 @@ bool XclExpAutofilter::HasCondition() const
bool XclExpAutofilter::AddEntry( const ScQueryEntry& rEntry )
{
const ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
if (rItems.empty())
return true;
if (GetOutput() != EXC_OUTPUT_BINARY && rItems.empty())
{
meType = BlankValue;
return false;
}
if (GetOutput() != EXC_OUTPUT_BINARY && rItems.size() > 1)
{
AddMultiValueEntry(rEntry);
@@ -817,6 +820,11 @@ void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm )
// XML_extLst, XML_filters, XML_iconFilter, XML_top10
}
break;
case BlankValue:
{
rWorksheet->singleElement(XML_filters, XML_blank, "1");
}
break;
case MultiValue:
{
rWorksheet->startElement(XML_filters);
diff --git a/sc/source/filter/inc/excrecds.hxx b/sc/source/filter/inc/excrecds.hxx
index 147808e..33c24eb 100644
--- a/sc/source/filter/inc/excrecds.hxx
+++ b/sc/source/filter/inc/excrecds.hxx
@@ -361,7 +361,7 @@ public:
class XclExpAutofilter : public XclExpRecord, protected XclExpRoot
{
private:
enum FilterType { FilterCondition, MultiValue };
enum FilterType { FilterCondition, MultiValue, BlankValue };
FilterType meType;
sal_uInt16 nCol;
sal_uInt16 nFlags;