[Libreoffice-commits] .: 4 commits - sc/inc sc/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Sun May 13 01:10:01 PDT 2012


 sc/inc/colorscale.hxx                |    5 -
 sc/inc/document.hxx                  |    2 
 sc/source/core/data/colorscale.cxx   |   15 +++
 sc/source/core/data/documen4.cxx     |    5 +
 sc/source/filter/excel/xecontent.cxx |  144 ++++++++++++++++++++++++++++++++++-
 sc/source/filter/inc/xecontent.hxx   |   42 ++++++++++
 6 files changed, 210 insertions(+), 3 deletions(-)

New commits:
commit 851a92bd022c48c5cc5e2f9943ce550167be124b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun May 13 08:30:17 2012 +0200

    correctly export formulas in conditional formats to xlsx
    
    Change-Id: I534fb55b735f47124cd9820ba0a986315e263112

diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index d8a8391..9bf323e 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -821,6 +821,7 @@ const char* GetOperatorString(ScConditionMode eMode, bool& bFrmla2)
             pRet = "uniqueValues";
             break;
         case SC_COND_DIRECT:
+            pRet = "expression";
         case SC_COND_NONE:
         default:
             pRet = "";
@@ -850,9 +851,13 @@ void XclExpCFImpl::SaveXml( XclExpXmlStream& rStrm )
             FSEND );
     rWorksheet->startElement( XML_formula, FSEND );
     rWorksheet->write(XclXmlUtils::ToOUString( GetRoot().GetDoc(), mrFormatEntry.GetValidSrcPos(), mrFormatEntry.CreateTokenArry( 0 ) ));
+    rWorksheet->endElement( XML_formula );
     if (bFmla2)
+    {
+        rWorksheet->startElement( XML_formula, FSEND );
         rWorksheet->write(XclXmlUtils::ToOUString( GetRoot().GetDoc(), mrFormatEntry.GetValidSrcPos(), mrFormatEntry.CreateTokenArry( 1 ) ));
-    rWorksheet->endElement( XML_formula );
+        rWorksheet->endElement( XML_formula );
+    }
     // OOXTODO: XML_extLst
     rWorksheet->endElement( XML_cfRule );
 }
commit 8f531a6cd796ce759e9d68ce577d0eaf058e1a75
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun May 13 08:22:43 2012 +0200

    save unique value conditional format to xlsx
    
    Change-Id: Id126500d499e751c351d6ed499af96136039e1f1

diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index 1b0bbf4..d8a8391 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -818,6 +818,8 @@ const char* GetOperatorString(ScConditionMode eMode, bool& bFrmla2)
             pRet = "duplicateValues";
             break;
         case SC_COND_NOTDUPLICATE:
+            pRet = "uniqueValues";
+            break;
         case SC_COND_DIRECT:
         case SC_COND_NONE:
         default:
commit 9e14712f8569ac2bde0eddf058ed0b0a99303c49
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun May 13 08:19:53 2012 +0200

    support export of duplicate values conditional format to xlsx
    
    Change-Id: I35266eabcba5e063bf296fa1d4b356f247458ea1

diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index c091c79..1b0bbf4 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -815,6 +815,8 @@ const char* GetOperatorString(ScConditionMode eMode, bool& bFrmla2)
             pRet = "notBetween";
             break;
         case SC_COND_DUPLICATE:
+            pRet = "duplicateValues";
+            break;
         case SC_COND_NOTDUPLICATE:
         case SC_COND_DIRECT:
         case SC_COND_NONE:
commit 8384032fb757d42bb93f03f70f589d493ea8ef2f
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun May 13 06:11:35 2012 +0200

    export color scales to xlsx
    
    Change-Id: I251acbb66a4033f69515c1b078ed5a28d0f0cd76

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index e7d0944..61346b6 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 c867461..53adc39 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 21df634..a81b748 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 b936699..cb7d887 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 6a23166..c091c79 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 49f375c..390d49c 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 ============================================================


More information about the Libreoffice-commits mailing list