summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2021-09-24 15:18:13 +0200
committerThorsten Behrens <thorsten.behrens@allotropia.de>2021-10-01 14:00:46 +0200
commit6f908b48373b71d45c8119b296b0504fb586f6f8 (patch)
tree9159e329efa4cb08c23066f6e88ff8f53f4bebf0 /sc/source
parent7a8f7f802a342c2bc301f5d313001829a07a7c92 (diff)
tdf#143104 Fix xlsx import/export of color filter colors
1. In XLSX filter colors are always stored in dxf as foreground colors, so Calc should keep them, if possible. So practically use only one color during import. 3. On export we need to distinguish type of filter, this is done with cellColor=0 or cellColor=1 attribute of <colorFilter>. 4. Since p.1 there is no need to keep on export separate dxf structures for fg and bg colors: we always use only foreground color for color filters. Co-authored-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> Change-Id: Iacd352ae46bf84859dc15ee695b6dc63240afe7d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122593 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/filter/excel/excrecds.cxx15
-rw-r--r--sc/source/filter/excel/xestyle.cxx22
-rw-r--r--sc/source/filter/inc/xestyle.hxx6
-rw-r--r--sc/source/filter/oox/autofilterbuffer.cxx14
-rw-r--r--sc/source/filter/oox/stylesbuffer.cxx7
5 files changed, 28 insertions, 36 deletions
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx
index a09312d665de..65edd87ee5bc 100644
--- a/sc/source/filter/excel/excrecds.cxx
+++ b/sc/source/filter/excel/excrecds.cxx
@@ -850,13 +850,18 @@ void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm )
if (!maColorValues.empty())
{
Color color = maColorValues[0].first;
- sal_Int32 nDxfId;
+ rtl::Reference<sax_fastparser::FastAttributeList> pAttrList = sax_fastparser::FastSerializerHelper::createAttrList();
+
if (maColorValues[0].second) // is background color
- nDxfId = GetDxfs().GetDxfByBackColor(color);
+ {
+ pAttrList->add(XML_cellColor, OString::number(1));
+ }
else
- nDxfId = GetDxfs().GetDxfByForeColor(color);
- nDxfId++; // Count is 1-based
- rWorksheet->singleElement(XML_colorFilter, XML_dxfId, OString::number(nDxfId));
+ {
+ pAttrList->add(XML_cellColor, OString::number(0));
+ }
+ pAttrList->add(XML_dxfId, OString::number(GetDxfs().GetDxfByColor(color)));
+ rWorksheet->singleElement(XML_colorFilter, pAttrList);
}
}
break;
diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx
index e9eccbfabc05..7032a2667a5b 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -3070,18 +3070,20 @@ XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot )
rRoot.GetDoc().GetFilterEntriesArea(nCol, aRange.aStart.Row(),
aRange.aEnd.Row(), nTab, true, aFilterEntries);
+ // Excel has all filter values stored as forground colors
+ // Does not matter it is text color or cell background color
for (auto& rColor : aFilterEntries.getBackgroundColors())
{
- if (!maBackColorToDxfId.emplace(rColor, nColorIndex).second)
+ if (!maColorToDxfId.emplace(rColor, nColorIndex).second)
continue;
- std::unique_ptr<XclExpCellArea> pExpCellArea(new XclExpCellArea(0, rColor));
+ std::unique_ptr<XclExpCellArea> pExpCellArea(new XclExpCellArea(rColor, 0));
maDxf.push_back(std::make_unique<XclExpDxf>(rRoot, std::move(pExpCellArea)));
nColorIndex++;
}
for (auto& rColor : aFilterEntries.getTextColors())
{
- if (!maForeColorToDxfId.emplace(rColor, nColorIndex).second)
+ if (!maColorToDxfId.emplace(rColor, nColorIndex).second)
continue;
std::unique_ptr<XclExpCellArea> pExpCellArea(new XclExpCellArea(rColor, 0));
@@ -3182,18 +3184,10 @@ sal_Int32 XclExpDxfs::GetDxfId( const OUString& rStyleName )
return -1;
}
-sal_Int32 XclExpDxfs::GetDxfByBackColor(Color aColor)
-{
- std::map<Color, sal_Int32>::iterator itr = maBackColorToDxfId.find(aColor);
- if (itr != maBackColorToDxfId.end())
- return itr->second;
- return -1;
-}
-
-sal_Int32 XclExpDxfs::GetDxfByForeColor(Color aColor)
+sal_Int32 XclExpDxfs::GetDxfByColor(Color aColor)
{
- std::map<Color, sal_Int32>::iterator itr = maForeColorToDxfId.find(aColor);
- if (itr != maForeColorToDxfId.end())
+ std::map<Color, sal_Int32>::iterator itr = maColorToDxfId.find(aColor);
+ if (itr != maColorToDxfId.end())
return itr->second;
return -1;
}
diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx
index d7588c72067a..ec68176d3195 100644
--- a/sc/source/filter/inc/xestyle.hxx
+++ b/sc/source/filter/inc/xestyle.hxx
@@ -749,15 +749,13 @@ public:
XclExpDxfs( const XclExpRoot& rRoot );
sal_Int32 GetDxfId(const OUString& rName);
- sal_Int32 GetDxfByBackColor(Color aColor);
- sal_Int32 GetDxfByForeColor(Color aColor);
+ sal_Int32 GetDxfByColor(Color aColor);
virtual void SaveXml( XclExpXmlStream& rStrm) override;
private:
typedef std::vector< std::unique_ptr<XclExpDxf> > DxfContainer;
std::map<OUString, sal_Int32> maStyleNameToDxfId;
- std::map<Color, sal_Int32> maBackColorToDxfId;
- std::map<Color, sal_Int32> maForeColorToDxfId;
+ std::map<Color, sal_Int32> maColorToDxfId;
DxfContainer maDxf;
std::unique_ptr<NfKeywordTable> mpKeywordTable; /// Replacement table.
};
diff --git a/sc/source/filter/oox/autofilterbuffer.cxx b/sc/source/filter/oox/autofilterbuffer.cxx
index ab0ff9a43c68..951347b62fcd 100644
--- a/sc/source/filter/oox/autofilterbuffer.cxx
+++ b/sc/source/filter/oox/autofilterbuffer.cxx
@@ -435,17 +435,9 @@ ApiFilterSettings ColorFilter::finalizeImport()
return aSettings;
const SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
- ::Color aColor;
- if (mbIsBackgroundColor)
- {
- const SvxBrushItem* pItem = rItemSet.GetItem<SvxBrushItem>(ATTR_BACKGROUND);
- aColor = pItem->GetColor();
- }
- else
- {
- const SvxColorItem* pItem = rItemSet.GetItem<SvxColorItem>(ATTR_FONT_COLOR);
- aColor = pItem->GetValue();
- }
+ // Color (whether text or background color) is always stored in ATTR_BACKGROUND
+ const SvxBrushItem* pItem = rItemSet.GetItem<SvxBrushItem>(ATTR_BACKGROUND);
+ ::Color aColor = pItem->GetColor();
util::Color nColor(aColor);
aSettings.appendField(true, nColor, mbIsBackgroundColor);
return aSettings;
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index b0c574f09378..7b02c2a36dcf 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -1825,11 +1825,14 @@ void Fill::finalizeImport()
{
if( rModel.mbFillColorUsed && (!rModel.mbPatternUsed || (rModel.mnPattern == XML_solid)) )
{
- rModel.maPatternColor = rModel.maFillColor;
+ if (!rModel.mbPatternUsed)
+ rModel.maPatternColor = rModel.maFillColor;
rModel.mnPattern = XML_solid;
rModel.mbPattColorUsed = rModel.mbPatternUsed = true;
}
- else if( !rModel.mbFillColorUsed && rModel.mbPatternUsed && (rModel.mnPattern == XML_solid) )
+ else if(
+ !rModel.mbFillColorUsed && !rModel.mbPattColorUsed &&
+ rModel.mbPatternUsed && rModel.mnPattern == XML_solid )
{
rModel.mbPatternUsed = false;
}