diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-05-13 06:11:35 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-05-13 08:44:39 +0200 |
commit | 8384032fb757d42bb93f03f70f589d493ea8ef2f (patch) | |
tree | 9e5d5ce8330af5b522d2bd6a88d0eb69c4d9e2ec | |
parent | e3bc45b8079228ca25e70ac5a51b6977afd6f61e (diff) |
export color scales to xlsx
Change-Id: I251acbb66a4033f69515c1b078ed5a28d0f0cd76
-rw-r--r-- | sc/inc/colorscale.hxx | 5 | ||||
-rw-r--r-- | sc/inc/document.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/colorscale.cxx | 15 | ||||
-rw-r--r-- | sc/source/core/data/documen4.cxx | 5 | ||||
-rw-r--r-- | sc/source/filter/excel/xecontent.cxx | 133 | ||||
-rw-r--r-- | sc/source/filter/inc/xecontent.hxx | 42 |
6 files changed, 200 insertions, 2 deletions
diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx index e7d09442796f..61346b6873cb 100644 --- a/sc/inc/colorscale.hxx +++ b/sc/inc/colorscale.hxx @@ -36,6 +36,7 @@ class ScDocument; class ScFormulaCell; +class ScTokenArray; class SC_DLLPUBLIC ScColorScaleEntry { @@ -64,6 +65,7 @@ public: bool GetMax() const; bool GetPercent() const; bool HasFormula() const; + const ScTokenArray* GetFormula() const; void SetMin(bool bMin); void SetMax(bool bMax); void SetPercent(bool bPercent); @@ -89,6 +91,7 @@ public: Color* GetColor(const ScAddress& rAddr) const; void AddEntry(ScColorScaleEntry* pEntry); void SetRange(const ScRangeList& rList); + const ScRangeList& GetRange() const; void DataChanged(const ScRange& rRange); void UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab); @@ -103,7 +106,7 @@ public: const_iterator end() const; }; -class ScColorScaleFormatList +class SC_DLLPUBLIC ScColorScaleFormatList { private: typedef boost::ptr_vector<ScColorScaleFormat> ColorScaleFormatContainer; diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index c867461a412f..53adc397cd88 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1212,7 +1212,7 @@ public: { return pCondFormList; } void SetCondFormList(ScConditionalFormatList* pNew); - ScColorScaleFormatList* GetColorScaleList() const; + SC_DLLPUBLIC const ScColorScaleFormatList* GetColorScaleList() const; ScValidationDataList* GetValidationList() const { return pValidationList; } diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index 21df634a16eb..a81b7485c59d 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -70,6 +70,16 @@ void ScColorScaleEntry::SetFormula( const rtl::OUString& rFormula, ScDocument* p mpCell->StartListeningTo( pDoc ); } +const ScTokenArray* ScColorScaleEntry::GetFormula() const +{ + if(mpCell) + { + return mpCell->GetCode(); + } + + return NULL; +} + double ScColorScaleEntry::GetValue() const { if(mpCell) @@ -283,6 +293,11 @@ void ScColorScaleFormat::SetRange(const ScRangeList& rList) maRanges = rList; } +const ScRangeList& ScColorScaleFormat::GetRange() const +{ + return maRanges; +} + namespace { sal_uInt8 GetColorValue( double nVal, double nVal1, sal_uInt8 nColVal1, double nVal2, sal_uInt8 nColVal2 ) diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index b936699d88d7..cb7d8875bd2d 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -628,6 +628,11 @@ sal_uLong ScDocument::AddCondFormat( const ScConditionalFormat& rNew ) return nNewKey; } +const ScColorScaleFormatList* ScDocument::GetColorScaleList() const +{ + return mpColorScaleList.get(); +} + //takes ownership // returns a 1-based index, 0 is reserved for no entry sal_uLong ScDocument::AddColorScaleFormat( ScColorScaleFormat* pNew ) diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx index 6a23166aa09a..c091c799d8b5 100644 --- a/sc/source/filter/excel/xecontent.cxx +++ b/sc/source/filter/excel/xecontent.cxx @@ -876,6 +876,76 @@ void XclExpCF::SaveXml( XclExpXmlStream& rStrm ) mxImpl->SaveXml( rStrm ); } +XclExpCfvo::XclExpCfvo(const XclExpRoot& rRoot, const ScColorScaleEntry& rEntry, const ScAddress& rAddr): + XclExpRecord(), + XclExpRoot( rRoot ), + mrEntry(rEntry), + maSrcPos(rAddr) +{ +} + +namespace { + +rtl::OString getColorScaleType( const ScColorScaleEntry& rEntry ) +{ + if (rEntry.GetMin()) + return "min"; + if(rEntry.GetMax()) + return "max"; + if(rEntry.GetPercent()) + return "percent"; + if(rEntry.HasFormula()) + return "formula"; + + return "num"; +} + +} + +void XclExpCfvo::SaveXml( XclExpXmlStream& rStrm ) +{ + sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream(); + + rtl::OString aValue; + if(mrEntry.HasFormula()) + { + rtl::OUString aFormula = XclXmlUtils::ToOUString( GetRoot().GetDoc(), maSrcPos, mrEntry.GetFormula()->Clone() ); + aValue = rtl::OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8 ); + } + else + { + aValue = OString::valueOf( mrEntry.GetValue() ); + } + + rWorksheet->startElement( XML_cfvo, + XML_type, getColorScaleType(mrEntry).getStr(), + XML_val, aValue.getStr(), + FSEND ); + + rWorksheet->endElement( XML_cfvo ); +} + +XclExpColScaleCol::XclExpColScaleCol( const XclExpRoot& rRoot, const ScColorScaleEntry& rEntry ): + XclExpRecord(), + XclExpRoot( rRoot ), + mrEntry( rEntry ) +{ +} + +XclExpColScaleCol::~XclExpColScaleCol() +{ +} + +void XclExpColScaleCol::SaveXml( XclExpXmlStream& rStrm ) +{ + sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream(); + + rWorksheet->startElement( XML_color, + XML_rgb, XclXmlUtils::ToOString( mrEntry.GetColor() ).getStr(), + FSEND ); + + rWorksheet->endElement( XML_color ); +} // ---------------------------------------------------------------------------- XclExpCondfmt::XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat& rCondFormat ) : @@ -933,7 +1003,58 @@ void XclExpCondfmt::SaveXml( XclExpXmlStream& rStrm ) XML_sqref, XclXmlUtils::ToOString( msSeqRef ).getStr(), // OOXTODO: XML_pivot, FSEND ); + maCFList.SaveXml( rStrm ); + + // OOXTODO: XML_extLst + rWorksheet->endElement( XML_conditionalFormatting ); +} + +// ---------------------------------------------------------------------------- + +XclExpColorScale::XclExpColorScale( const XclExpRoot& rRoot, const ScColorScaleFormat& rFormat ): + XclExpRecord(), + XclExpRoot( rRoot ), + mrFormat( rFormat ) +{ + const ScRange* pRange = rFormat.GetRange().front(); + ScAddress aAddr = pRange->aStart; + for(ScColorScaleFormat::const_iterator itr = rFormat.begin(); + itr != rFormat.end(); ++itr) + { + // exact position is not important, we allow only absolute refs + + XclExpCfvoList::RecordRefType xCfvo( new XclExpCfvo( GetRoot(), *itr, aAddr ) ); + maCfvoList.AppendRecord( xCfvo ); + XclExpColScaleColList::RecordRefType xClo( new XclExpColScaleCol( GetRoot(), *itr ) ); + maColList.AppendRecord( xClo ); + } +} + +void XclExpColorScale::SaveXml( XclExpXmlStream& rStrm ) +{ + rtl::OUString sSeqRef; + const ScRangeList& rRanges = mrFormat.GetRange(); + + sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream(); + rWorksheet->startElement( XML_conditionalFormatting, + XML_sqref, XclXmlUtils::ToOString(rRanges).getStr(), + FSEND ); + + rWorksheet->startElement( XML_cfRule, + XML_type, "colorScale", + XML_priority, "1", + FSEND ); + + rWorksheet->startElement( XML_colorScale, FSEND ); + + maCfvoList.SaveXml(rStrm); + maColList.SaveXml(rStrm); + + rWorksheet->endElement( XML_colorScale ); + + rWorksheet->endElement( XML_cfRule ); + // OOXTODO: XML_extLst rWorksheet->endElement( XML_conditionalFormatting ); } @@ -953,6 +1074,15 @@ XclExpCondFormatBuffer::XclExpCondFormatBuffer( const XclExpRoot& rRoot ) : maCondfmtList.AppendRecord( xCondfmtRec ); } } + if( const ScColorScaleFormatList* pColorScaleList = GetDoc().GetColorScaleList() ) + { + for( ScColorScaleFormatList::const_iterator itr = pColorScaleList->begin(); + itr != pColorScaleList->end(); ++itr) + { + XclExpColorScaleList::RecordRefType xColorScaleRec( new XclExpColorScale( GetRoot(), *itr ) ); + maColorScaleList.AppendRecord( xColorScaleRec ); + } + } } void XclExpCondFormatBuffer::Save( XclExpStream& rStrm ) @@ -962,7 +1092,10 @@ void XclExpCondFormatBuffer::Save( XclExpStream& rStrm ) void XclExpCondFormatBuffer::SaveXml( XclExpXmlStream& rStrm ) { + maCondfmtList.SaveXml( rStrm ); + maColorScaleList.SaveXml( rStrm ); + } // Validation ================================================================= diff --git a/sc/source/filter/inc/xecontent.hxx b/sc/source/filter/inc/xecontent.hxx index 49f375cd6c11..390d49c18ee2 100644 --- a/sc/source/filter/inc/xecontent.hxx +++ b/sc/source/filter/inc/xecontent.hxx @@ -37,6 +37,8 @@ #include "xestring.hxx" #include "xeformula.hxx" +#include "colorscale.hxx" + /* ============================================================================ Classes to export the big Excel document contents (related to several cells or globals for the sheet or document). @@ -195,6 +197,29 @@ private: XclExpCFImplPtr mxImpl; }; +class XclExpCfvo : public XclExpRecord, protected XclExpRoot +{ +public: + explicit XclExpCfvo( const XclExpRoot& rRoot, const ScColorScaleEntry& rFormatEntry, const ScAddress& rPos); + virtual ~XclExpCfvo() {} + + virtual void SaveXml( XclExpXmlStream& rStrm ); +private: + const ScColorScaleEntry& mrEntry; + ScAddress maSrcPos; +}; + +class XclExpColScaleCol : public XclExpRecord, protected XclExpRoot +{ +public: + explicit XclExpColScaleCol( const XclExpRoot& rRoot, const ScColorScaleEntry& rFormatEntry); + virtual ~XclExpColScaleCol(); + + virtual void SaveXml( XclExpXmlStream& rStrm ); +private: + const ScColorScaleEntry& mrEntry; +}; + // ---------------------------------------------------------------------------- class ScConditionalFormat; @@ -226,6 +251,21 @@ private: String msSeqRef; /// OOXML Sequence of References }; +class XclExpColorScale: public XclExpRecord, protected XclExpRoot +{ +public: + explicit XclExpColorScale( const XclExpRoot& rRoot, const ScColorScaleFormat& rFormat ); + + virtual void SaveXml( XclExpXmlStream& rStrm ); +private: + typedef XclExpRecordList< XclExpCfvo > XclExpCfvoList; + typedef XclExpRecordList< XclExpColScaleCol > XclExpColScaleColList; + + XclExpCfvoList maCfvoList; + XclExpColScaleColList maColList; + const ScColorScaleFormat& mrFormat; +}; + // ---------------------------------------------------------------------------- /** Contains all conditional formats of a specific sheet. */ @@ -241,7 +281,9 @@ public: private: typedef XclExpRecordList< XclExpCondfmt > XclExpCondfmtList; + typedef XclExpRecordList< XclExpColorScale > XclExpColorScaleList; XclExpCondfmtList maCondfmtList; /// List of CONDFMT records. + XclExpColorScaleList maColorScaleList; // Color scale entries }; // Data Validation ============================================================ |