diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2021-12-30 15:32:37 +0300 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2022-01-11 09:39:05 +0100 |
commit | d4c9f299145635cb1cba3365dfe5533ba3636572 (patch) | |
tree | effd1144c1503c9548516d49847a51533fee6647 | |
parent | only use X509Data (diff) | |
download | core-d4c9f299145635cb1cba3365dfe5533ba3636572.tar.gz core-d4c9f299145635cb1cba3365dfe5533ba3636572.zip |
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>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128249
Tested-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
-rw-r--r-- | sc/qa/unit/data/ods/tdf145059.ods | bin | 0 -> 15610 bytes | |||
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 41 | ||||
-rw-r--r-- | sc/source/filter/excel/excrecds.cxx | 4 | ||||
-rw-r--r-- | sc/source/filter/excel/xestyle.cxx | 16 | ||||
-rw-r--r-- | sc/source/filter/inc/xestyle.hxx | 5 |
5 files changed, 60 insertions, 6 deletions
diff --git a/sc/qa/unit/data/ods/tdf145059.ods b/sc/qa/unit/data/ods/tdf145059.ods Binary files differnew file mode 100644 index 000000000000..a76da3b5cb4e --- /dev/null +++ b/sc/qa/unit/data/ods/tdf145059.ods diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index f54cb966bacc..74fce93a9296 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -244,6 +244,7 @@ public: void testTdf128976(); void testTdf120502(); void testTdf142578(); + void testTdf145059(); CPPUNIT_TEST_SUITE(ScExportTest); CPPUNIT_TEST(test); @@ -384,6 +385,7 @@ public: CPPUNIT_TEST(testTdf128976); CPPUNIT_TEST(testTdf120502); CPPUNIT_TEST(testTdf142578); + CPPUNIT_TEST(testTdf145059); CPPUNIT_TEST_SUITE_END(); @@ -4875,6 +4877,45 @@ void ScExportTest::testTdf142578() xDocSh->DoClose(); } +void ScExportTest::testTdf145059() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf142578.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX); + xmlDocPtr pSheet + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheet); + + // Get DxfId for color filter + sal_Int32 nDxfIdColorFilter + = getXPath(pSheet, "/x:worksheet/x:autoFilter/x:filterColumn/x:colorFilter", "dxfId") + .toInt32() + + 1; + + // Get DxfId for conditional formatting + sal_Int32 nDxfIdCondFormat + = getXPath(pSheet, "/x:worksheet/x:conditionalFormatting/x:cfRule", "dxfId").toInt32() + 1; + + // Ensure they are using different dxfs + CPPUNIT_ASSERT_MESSAGE("dxfID's should be different!", nDxfIdColorFilter != nDxfIdCondFormat); + + // Check colors used by these dxfs + xmlDocPtr pStyles = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/styles.xml"); + CPPUNIT_ASSERT(pStyles); + + OString sDxfColorFilterXPath("/x:styleSheet/x:dxfs/x:dxf[" + OString::number(nDxfIdColorFilter) + + "]/x:fill/x:patternFill/x:fgColor"); + assertXPath(pStyles, sDxfColorFilterXPath, "rgb", "FF81D41A"); + + OString sDxfCondFormatXPath("/x:styleSheet/x:dxfs/x:dxf[" + OString::number(nDxfIdCondFormat) + + "]/x:fill/x:patternFill/x:bgColor"); + assertXPath(pStyles, sDxfCondFormatXPath, "rgb", "FFFFCCCC"); + + xDocSh->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 35a19585ba97..90d60dbce92d 100644 --- a/sc/source/filter/excel/excrecds.cxx +++ b/sc/source/filter/excel/excrecds.cxx @@ -788,6 +788,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 77a73ee19f57..bedf7d7f77d1 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -3159,22 +3159,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(const 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 d111aee33c16..ecd97890556f 100644 --- a/sc/source/filter/inc/xestyle.hxx +++ b/sc/source/filter/inc/xestyle.hxx @@ -750,8 +750,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(const Color& aColor) const; + void AddColor(Color aColor); virtual void SaveXml( XclExpXmlStream& rStrm) override; private: |