1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <xeextlst.hxx>
12 #include <stlsheet.hxx>
14 #include <xestyle.hxx>
15 #include <stlpool.hxx>
16 #include <scitems.hxx>
17 #include <svl/itemset.hxx>
18 #include <svl/intitem.hxx>
20 #include <oox/export/utils.hxx>
21 #include <oox/token/namespaces.hxx>
22 #include <comphelper/processfactory.hxx>
24 using namespace ::oox
;
26 XclExpExt::XclExpExt( const XclExpRoot
& rRoot
):
31 XclExtLst::XclExtLst( const XclExpRoot
& rRoot
):
36 XclExpExtNegativeColor::XclExpExtNegativeColor( const Color
& rColor
):
41 void XclExpExtNegativeColor::SaveXml( XclExpXmlStream
& rStrm
)
43 rStrm
.GetCurrentStream()->singleElementNS( XML_x14
, XML_negativeFillColor
,
44 XML_rgb
, XclXmlUtils::ToOString(maColor
) );
47 XclExpExtAxisColor::XclExpExtAxisColor( const Color
& rColor
):
52 void XclExpExtAxisColor::SaveXml( XclExpXmlStream
& rStrm
)
54 rStrm
.GetCurrentStream()->singleElementNS( XML_x14
, XML_axisColor
,
55 XML_rgb
, XclXmlUtils::ToOString(maAxisColor
) );
58 XclExpExtIcon::XclExpExtIcon(const XclExpRoot
& rRoot
, const std::pair
<ScIconSetType
, sal_Int32
>& rCustomEntry
):
60 nIndex(rCustomEntry
.second
)
62 pIconSetName
= ScIconSetFormat::getIconSetName(rCustomEntry
.first
);
65 void XclExpExtIcon::SaveXml(XclExpXmlStream
& rStrm
)
67 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
72 pIconSetName
= "NoIcons";
75 rWorksheet
->singleElementNS(XML_x14
, XML_cfIcon
,
76 XML_iconSet
, pIconSetName
,
77 XML_iconId
, OString::number(nIndex
));
80 XclExpExtCfvo::XclExpExtCfvo( const XclExpRoot
& rRoot
, const ScColorScaleEntry
& rEntry
, const ScAddress
& rSrcPos
, bool bFirst
):
82 meType(rEntry
.GetType()),
85 if( rEntry
.GetType() == COLORSCALE_FORMULA
)
87 const ScTokenArray
* pArr
= rEntry
.GetFormula();
91 aFormula
= XclXmlUtils::ToOUString( GetCompileFormulaContext(), rSrcPos
, pArr
);
93 maValue
= OUStringToOString(aFormula
, RTL_TEXTENCODING_UTF8
);
96 maValue
= OString::number(rEntry
.GetValue());
101 const char* getColorScaleType( ScColorScaleEntryType eType
, bool bFirst
)
109 case COLORSCALE_PERCENT
:
111 case COLORSCALE_FORMULA
:
113 case COLORSCALE_AUTO
:
118 case COLORSCALE_PERCENTILE
:
128 void XclExpExtCfvo::SaveXml( XclExpXmlStream
& rStrm
)
130 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
131 rWorksheet
->startElementNS(XML_x14
, XML_cfvo
, XML_type
, getColorScaleType(meType
, mbFirst
));
133 if (meType
== COLORSCALE_FORMULA
||
134 meType
== COLORSCALE_PERCENT
||
135 meType
== COLORSCALE_PERCENTILE
||
136 meType
== COLORSCALE_VALUE
)
138 rWorksheet
->startElementNS(XML_xm
, XML_f
);
139 rWorksheet
->writeEscaped(maValue
.getStr());
140 rWorksheet
->endElementNS(XML_xm
, XML_f
);
143 rWorksheet
->endElementNS(XML_x14
, XML_cfvo
);
146 XclExpExtCF::XclExpExtCF( const XclExpRoot
& rRoot
, const ScCondFormatEntry
& rFormat
):
152 void XclExpExtCF::SaveXml( XclExpXmlStream
& rStrm
)
154 OUString aStyleName
= mrFormat
.GetStyle();
155 SfxStyleSheetBase
* pStyle
= GetDoc().GetStyleSheetPool()->Find(aStyleName
);
156 SfxItemSet
& rSet
= pStyle
->GetItemSet();
158 std::unique_ptr
<ScTokenArray
> pTokenArray(mrFormat
.CreateFlatCopiedTokenArray(0));
159 aFormula
= XclXmlUtils::ToOUString( GetCompileFormulaContext(), mrFormat
.GetValidSrcPos(), pTokenArray
.get());
161 std::unique_ptr
<XclExpColor
> pColor(new XclExpColor
);
162 if(!pColor
->FillFromItemSet( rSet
))
165 std::unique_ptr
<XclExpCellBorder
> pBorder(new XclExpCellBorder
);
166 if (!pBorder
->FillFromItemSet( rSet
, GetPalette(), GetBiff()) )
169 std::unique_ptr
<XclExpCellAlign
> pAlign(new XclExpCellAlign
);
170 if (!pAlign
->FillFromItemSet( rSet
, false, GetBiff()))
173 std::unique_ptr
<XclExpCellProt
> pCellProt(new XclExpCellProt
);
174 if (!pCellProt
->FillFromItemSet( rSet
))
177 std::unique_ptr
<XclExpDxfFont
> pFont(new XclExpDxfFont(GetRoot(), rSet
));
179 std::unique_ptr
<XclExpNumFmt
> pNumFormat
;
180 const SfxPoolItem
*pPoolItem
= nullptr;
181 if( rSet
.GetItemState( ATTR_VALUE_FORMAT
, true, &pPoolItem
) == SfxItemState::SET
)
183 sal_uInt32 nScNumFmt
= static_cast< const SfxUInt32Item
* >(pPoolItem
)->GetValue();
184 XclExpNumFmtBuffer
& rNumFmtBuffer
= GetRoot().GetNumFmtBuffer();
185 sal_uInt32 nXclNumFmt
= rNumFmtBuffer
.Insert(nScNumFmt
);
186 pNumFormat
.reset(new XclExpNumFmt(nScNumFmt
, nXclNumFmt
, rNumFmtBuffer
.GetFormatCode(nScNumFmt
)));
189 XclExpDxf
rDxf( GetRoot(),
193 std::move(pNumFormat
),
194 std::move(pCellProt
),
197 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
199 rWorksheet
->startElementNS( XML_xm
, XML_f
);
200 rWorksheet
->writeEscaped( aFormula
);
201 rWorksheet
->endElementNS( XML_xm
, XML_f
);
202 rDxf
.SaveXmlExt( rStrm
);
205 XclExpExtDataBar::XclExpExtDataBar( const XclExpRoot
& rRoot
, const ScDataBarFormat
& rFormat
, const ScAddress
& rPos
):
208 const ScDataBarFormatData
& rFormatData
= *rFormat
.GetDataBarData();
209 mpLowerLimit
.reset(new XclExpExtCfvo(*this, *rFormatData
.mpLowerLimit
, rPos
, true));
210 mpUpperLimit
.reset(new XclExpExtCfvo(*this, *rFormatData
.mpUpperLimit
, rPos
, false));
211 if (rFormatData
.mpNegativeColor
)
212 mpNegativeColor
.reset(new XclExpExtNegativeColor(*rFormatData
.mpNegativeColor
));
214 mpNegativeColor
.reset( new XclExpExtNegativeColor( rFormatData
.maPositiveColor
) );
215 mpAxisColor
.reset( new XclExpExtAxisColor( rFormatData
.maAxisColor
) );
217 meAxisPosition
= rFormatData
.meAxisPosition
;
218 mbGradient
= rFormatData
.mbGradient
;
219 mnMinLength
= rFormatData
.mnMinLength
;
220 mnMaxLength
= rFormatData
.mnMaxLength
;
225 const char* getAxisPosition(databar::ScAxisPosition eAxisPosition
)
227 switch(eAxisPosition
)
231 case databar::AUTOMATIC
:
233 case databar::MIDDLE
:
239 const char* GetOperatorString(ScConditionMode eMode
)
241 const char* pRet
= nullptr;
244 case ScConditionMode::Equal
:
247 case ScConditionMode::Less
:
250 case ScConditionMode::Greater
:
251 pRet
= "greaterThan";
253 case ScConditionMode::EqLess
:
254 pRet
= "lessThanOrEqual";
256 case ScConditionMode::EqGreater
:
257 pRet
= "greaterThanOrEqual";
259 case ScConditionMode::NotEqual
:
262 case ScConditionMode::Between
:
265 case ScConditionMode::NotBetween
:
268 case ScConditionMode::Duplicate
:
271 case ScConditionMode::NotDuplicate
:
274 case ScConditionMode::BeginsWith
:
277 case ScConditionMode::EndsWith
:
280 case ScConditionMode::ContainsText
:
281 pRet
= "containsText";
283 case ScConditionMode::NotContainsText
:
284 pRet
= "notContains";
286 case ScConditionMode::Direct
:
288 case ScConditionMode::NONE
:
297 void XclExpExtDataBar::SaveXml( XclExpXmlStream
& rStrm
)
299 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
300 rWorksheet
->startElementNS( XML_x14
, XML_dataBar
,
301 XML_minLength
, OString::number(mnMinLength
),
302 XML_maxLength
, OString::number(mnMaxLength
),
303 XML_axisPosition
, getAxisPosition(meAxisPosition
),
304 XML_gradient
, ToPsz(mbGradient
) );
306 mpLowerLimit
->SaveXml( rStrm
);
307 mpUpperLimit
->SaveXml( rStrm
);
308 mpNegativeColor
->SaveXml( rStrm
);
309 mpAxisColor
->SaveXml( rStrm
);
311 rWorksheet
->endElementNS( XML_x14
, XML_dataBar
);
314 XclExpExtIconSet::XclExpExtIconSet(const XclExpRoot
& rRoot
, const ScIconSetFormat
& rFormat
, const ScAddress
& rPos
):
317 const ScIconSetFormatData
& rData
= *rFormat
.GetIconSetData();
318 for (auto const& itr
: rData
.m_Entries
)
320 maCfvos
.AppendNewRecord(new XclExpExtCfvo(*this, *itr
, rPos
, false));
322 mbCustom
= rData
.mbCustom
;
323 mbReverse
= rData
.mbReverse
;
324 mbShowValue
= rData
.mbShowValue
;
325 mpIconSetName
= ScIconSetFormat::getIconSetName(rData
.eIconSetType
);
329 for (const auto& rItem
: rData
.maCustomVector
)
331 maCustom
.AppendNewRecord(new XclExpExtIcon(*this, rItem
));
336 void XclExpExtIconSet::SaveXml(XclExpXmlStream
& rStrm
)
338 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
340 rWorksheet
->startElementNS(XML_x14
, XML_iconSet
,
341 XML_iconSet
, mpIconSetName
,
342 XML_custom
, mbCustom
? ToPsz10(mbCustom
) : nullptr,
343 XML_reverse
, ToPsz10(mbReverse
),
344 XML_showValue
, ToPsz10(mbShowValue
));
346 maCfvos
.SaveXml(rStrm
);
350 maCustom
.SaveXml(rStrm
);
353 rWorksheet
->endElementNS(XML_x14
, XML_iconSet
);
356 XclExpExtCfRule::XclExpExtCfRule( const XclExpRoot
& rRoot
, const ScFormatEntry
& rFormat
, const ScAddress
& rPos
, const OString
& rId
, sal_Int32 nPriority
):
360 mnPriority(nPriority
),
363 switch (rFormat
.GetType())
365 case ScFormatEntry::Type::Databar
:
367 const ScDataBarFormat
& rDataBar
= static_cast<const ScDataBarFormat
&>(rFormat
);
368 mxEntry
.reset( new XclExpExtDataBar( *this, rDataBar
, rPos
) );
372 case ScFormatEntry::Type::Iconset
:
374 const ScIconSetFormat
& rIconSet
= static_cast<const ScIconSetFormat
&>(rFormat
);
375 mxEntry
.reset(new XclExpExtIconSet(*this, rIconSet
, rPos
));
379 case ScFormatEntry::Type::ExtCondition
:
381 const ScCondFormatEntry
& rCondFormat
= static_cast<const ScCondFormatEntry
&>(rFormat
);
382 mxEntry
.reset(new XclExpExtCF(*this, rCondFormat
));
384 mOperator
= GetOperatorString( rCondFormat
.GetOperation() );
392 void XclExpExtCfRule::SaveXml( XclExpXmlStream
& rStrm
)
397 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
398 rWorksheet
->startElementNS( XML_x14
, XML_cfRule
,
400 XML_priority
, mnPriority
== -1 ? nullptr : OString::number(mnPriority
+ 1).getStr(),
401 XML_operator
, mOperator
,
404 mxEntry
->SaveXml( rStrm
);
406 rWorksheet
->endElementNS( XML_x14
, XML_cfRule
);
410 XclExpExtConditionalFormatting::XclExpExtConditionalFormatting( const XclExpRoot
& rRoot
,
411 std::vector
<XclExpExtCondFormatData
>& rData
, const ScRangeList
& rRange
):
415 ScAddress aAddr
= maRange
.front().aStart
;
416 for (const auto& rItem
: rData
)
418 const ScFormatEntry
* pEntry
= rItem
.pEntry
;
419 switch (pEntry
->GetType())
421 case ScFormatEntry::Type::Iconset
:
423 const ScIconSetFormat
& rIconSet
= static_cast<const ScIconSetFormat
&>(*pEntry
);
424 bool bNeedsExt
= false;
425 switch (rIconSet
.GetIconSetData()->eIconSetType
)
427 case IconSet_3Triangles
:
428 case IconSet_3Smilies
:
429 case IconSet_3ColorSmilies
:
438 if (rIconSet
.GetIconSetData()->mbCustom
)
443 maCfRules
.AppendNewRecord(new XclExpExtCfRule(*this, *pEntry
, aAddr
, rItem
.aGUID
, rItem
.nPriority
));
447 case ScFormatEntry::Type::Databar
:
448 maCfRules
.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry
, aAddr
, rItem
.aGUID
, rItem
.nPriority
));
450 case ScFormatEntry::Type::ExtCondition
:
451 maCfRules
.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry
, aAddr
, rItem
.aGUID
, rItem
.nPriority
));
459 void XclExpExtConditionalFormatting::SaveXml( XclExpXmlStream
& rStrm
)
461 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
462 rWorksheet
->startElementNS( XML_x14
, XML_conditionalFormatting
,
463 FSNS( XML_xmlns
, XML_xm
), rStrm
.getNamespaceURL(OOX_NS(xm
)).toUtf8() );
465 maCfRules
.SaveXml( rStrm
);
466 rWorksheet
->startElementNS(XML_xm
, XML_sqref
);
467 rWorksheet
->write(XclXmlUtils::ToOString(&rStrm
.GetRoot().GetDoc(), maRange
));
469 rWorksheet
->endElementNS( XML_xm
, XML_sqref
);
471 rWorksheet
->endElementNS( XML_x14
, XML_conditionalFormatting
);
474 XclExpExtCalcPr::XclExpExtCalcPr( const XclExpRoot
& rRoot
, formula::FormulaGrammar::AddressConvention eConv
):
477 maURI
= OString("{7626C862-2A13-11E5-B345-FEFF819CDC9F}");
481 case formula::FormulaGrammar::CONV_OOO
:
482 maSyntax
= OString("CalcA1");
484 case formula::FormulaGrammar::CONV_XL_A1
:
485 maSyntax
= OString("ExcelA1");
487 case formula::FormulaGrammar::CONV_XL_R1C1
:
488 maSyntax
= OString("ExcelR1C1");
490 case formula::FormulaGrammar::CONV_A1_XL_A1
:
491 maSyntax
= OString("CalcA1ExcelA1");
493 case formula::FormulaGrammar::CONV_UNSPECIFIED
:
494 case formula::FormulaGrammar::CONV_ODF
:
495 case formula::FormulaGrammar::CONV_XL_OOX
:
496 case formula::FormulaGrammar::CONV_LOTUS_A1
:
497 case formula::FormulaGrammar::CONV_LAST
:
498 maSyntax
= OString("Unspecified");
503 void XclExpExtCalcPr::SaveXml( XclExpXmlStream
& rStrm
)
505 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
506 rWorksheet
->startElement( XML_ext
,
507 FSNS(XML_xmlns
, XML_loext
), rStrm
.getNamespaceURL(OOX_NS(loext
)).toUtf8(),
510 rWorksheet
->singleElementNS(XML_loext
, XML_extCalcPr
, XML_stringRefSyntax
, maSyntax
);
512 rWorksheet
->endElement( XML_ext
);
515 XclExpExtCondFormat::XclExpExtCondFormat( const XclExpRoot
& rRoot
):
518 maURI
= OString("{78C0D931-6437-407d-A8EE-F0AAD7539E65}");
521 void XclExpExtCondFormat::SaveXml( XclExpXmlStream
& rStrm
)
523 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
524 rWorksheet
->startElement( XML_ext
,
525 FSNS(XML_xmlns
, XML_x14
), rStrm
.getNamespaceURL(OOX_NS(xls14Lst
)).toUtf8(),
528 rWorksheet
->startElementNS(XML_x14
, XML_conditionalFormattings
);
530 maCF
.SaveXml( rStrm
);
532 rWorksheet
->endElementNS( XML_x14
, XML_conditionalFormattings
);
533 rWorksheet
->endElement( XML_ext
);
536 void XclExpExtCondFormat::AddRecord( const XclExpExtConditionalFormattingRef
& aEntry
)
538 maCF
.AppendRecord( aEntry
);
541 void XclExtLst::SaveXml( XclExpXmlStream
& rStrm
)
543 if(maExtEntries
.IsEmpty())
546 sax_fastparser::FSHelperPtr
& rWorksheet
= rStrm
.GetCurrentStream();
547 rWorksheet
->startElement(XML_extLst
);
549 maExtEntries
.SaveXml(rStrm
);
551 rWorksheet
->endElement( XML_extLst
);
554 void XclExtLst::AddRecord( const XclExpExtRef
& aEntry
)
556 maExtEntries
.AppendRecord( aEntry
);
559 XclExpExtRef
XclExtLst::GetItem( XclExpExtType eType
)
561 size_t n
= maExtEntries
.GetSize();
562 for( size_t i
= 0; i
< n
; ++i
)
564 if (maExtEntries
.GetRecord( i
)->GetType() == eType
)
565 return maExtEntries
.GetRecord( i
);
568 return XclExpExtRef();
572 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */