summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2021-12-30 15:32:37 +0300
committerThorsten Behrens <thorsten.behrens@allotropia.de>2022-01-11 09:11:54 +0100
commitd73cf0abc3d1bfd7e3a1d3d1b41c63bbb17d61bb (patch)
tree65d7da9bf65bb98f01a72e53f4d059051ca26182
parentfedf5599d7aa80bd5b794a5ea85111f014b782f8 (diff)
tdf#145059: sc: always write dxf node for color filter for XLSX
If there is no dxf reference to color filter (for example if selected color is not in range of available colors for current range) Excel is not able to show color filter correctly: it is not marked as used filter, no ability to reset, etc. Change-Id: I65378ddd6f8f8233cda147ff9dcd28f455a58225 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127745 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de> (cherry picked from commit f0ad6ec2a23a36ade407db8cda36655ba2f144c1) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128159
-rw-r--r--sc/qa/unit/data/ods/tdf145059.odsbin0 -> 15610 bytes
-rw-r--r--sc/qa/unit/subsequent_export_test2.cxx31
-rw-r--r--sc/source/filter/excel/excrecds.cxx4
-rw-r--r--sc/source/filter/excel/xestyle.cxx16
-rw-r--r--sc/source/filter/inc/xestyle.hxx5
5 files changed, 50 insertions, 6 deletions
diff --git a/sc/qa/unit/data/ods/tdf145059.ods b/sc/qa/unit/data/ods/tdf145059.ods
new file mode 100644
index 000000000000..a76da3b5cb4e
--- /dev/null
+++ b/sc/qa/unit/data/ods/tdf145059.ods
Binary files differ
diff --git a/sc/qa/unit/subsequent_export_test2.cxx b/sc/qa/unit/subsequent_export_test2.cxx
index 20be9da85bfb..f035efba1aac 100644
--- a/sc/qa/unit/subsequent_export_test2.cxx
+++ b/sc/qa/unit/subsequent_export_test2.cxx
@@ -214,6 +214,7 @@ public:
void testTdf142264ManyChartsToXLSX();
void testTdf143929MultiColumnToODS();
void testTdf142578();
+ void testTdf145059();
void testTdf130104_XLSXIndent();
CPPUNIT_TEST_SUITE(ScExportTest2);
@@ -328,6 +329,7 @@ public:
CPPUNIT_TEST(testTdf142264ManyChartsToXLSX);
CPPUNIT_TEST(testTdf143929MultiColumnToODS);
CPPUNIT_TEST(testTdf142578);
+ CPPUNIT_TEST(testTdf145059);
CPPUNIT_TEST(testTdf130104_XLSXIndent);
CPPUNIT_TEST_SUITE_END();
@@ -2993,6 +2995,35 @@ void ScExportTest2::testTdf142578()
xDocSh->DoClose();
}
+void ScExportTest2::testTdf145059()
+{
+ ScDocShellRef xDocSh = loadDoc(u"tdf145059.", FORMAT_ODS);
+ CPPUNIT_ASSERT(xDocSh);
+
+ // Export to xlsx.
+ std::shared_ptr<utl::TempFile> pXPathFile
+ = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX);
+ xmlDocUniquePtr pSheet
+ = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml");
+ CPPUNIT_ASSERT(pSheet);
+ xmlDocUniquePtr pStyle = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/styles.xml");
+ CPPUNIT_ASSERT(pStyle);
+
+ sal_Int32 nColorFilterDxdId
+ = getXPath(pSheet, "/x:worksheet/x:autoFilter/x:filterColumn/x:colorFilter", "dxfId")
+ .toInt32();
+
+ // Ensure that dxf id is not -1
+ CPPUNIT_ASSERT(nColorFilterDxdId >= 0);
+
+ // Find color by this dxfid
+ OString sDxfIdPath = "/x:styleSheet/x:dxfs/x:dxf[" + OString::number(nColorFilterDxdId + 1)
+ + "]/x:fill/x:patternFill/x:fgColor";
+ assertXPath(pStyle, sDxfIdPath, "rgb", "FF4472C4");
+
+ xDocSh->DoClose();
+}
+
void ScExportTest2::testTdf130104_XLSXIndent()
{
ScDocShellRef xDocSh = loadDoc(u"tdf130104_indent.", FORMAT_XLSX);
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx
index 65edd87ee5bc..570167b8014b 100644
--- a/sc/source/filter/excel/excrecds.cxx
+++ b/sc/source/filter/excel/excrecds.cxx
@@ -796,6 +796,10 @@ void XclExpAutofilter::AddColorEntry(const ScQueryEntry& rEntry)
{
maColorValues.push_back(
std::make_pair(rItem.maColor, rItem.meType == ScQueryEntry::ByBackgroundColor));
+ // Ensure that selected color(s) will be added to dxf: selection can be not in list
+ // of already added to dfx colors taken from filter range
+ if (GetDxfs().GetDxfByColor(rItem.maColor) == -1)
+ GetDxfs().AddColor(rItem.maColor);
}
}
diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx
index 3898c5cad9b6..291b51c6c83e 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -3176,22 +3176,30 @@ XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot )
}
}
-sal_Int32 XclExpDxfs::GetDxfId( const OUString& rStyleName )
+sal_Int32 XclExpDxfs::GetDxfId( const OUString& rStyleName ) const
{
- std::map<OUString, sal_Int32>::iterator itr = maStyleNameToDxfId.find(rStyleName);
+ std::map<OUString, sal_Int32>::const_iterator itr = maStyleNameToDxfId.find(rStyleName);
if(itr!= maStyleNameToDxfId.end())
return itr->second;
return -1;
}
-sal_Int32 XclExpDxfs::GetDxfByColor(Color aColor)
+sal_Int32 XclExpDxfs::GetDxfByColor(Color aColor) const
{
- std::map<Color, sal_Int32>::iterator itr = maColorToDxfId.find(aColor);
+ std::map<Color, sal_Int32>::const_iterator itr = maColorToDxfId.find(aColor);
if (itr != maColorToDxfId.end())
return itr->second;
return -1;
}
+void XclExpDxfs::AddColor(Color aColor)
+{
+ maColorToDxfId.emplace(aColor, maDxf.size());
+
+ std::unique_ptr<XclExpCellArea> pExpCellArea(new XclExpCellArea(aColor, 0));
+ maDxf.push_back(std::make_unique<XclExpDxf>(GetRoot(), std::move(pExpCellArea)));
+}
+
void XclExpDxfs::SaveXml( XclExpXmlStream& rStrm )
{
if(maDxf.empty())
diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx
index 7bacfb6eccb4..d922b45399e2 100644
--- a/sc/source/filter/inc/xestyle.hxx
+++ b/sc/source/filter/inc/xestyle.hxx
@@ -748,8 +748,9 @@ class XclExpDxfs : public XclExpRecordBase, protected XclExpRoot
public:
XclExpDxfs( const XclExpRoot& rRoot );
- sal_Int32 GetDxfId(const OUString& rName);
- sal_Int32 GetDxfByColor(Color aColor);
+ sal_Int32 GetDxfId(const OUString& rName) const;
+ sal_Int32 GetDxfByColor(Color aColor) const;
+ void AddColor(Color aColor);
virtual void SaveXml( XclExpXmlStream& rStrm) override;
private: