[Libreoffice-commits] core.git: Branch 'feature/gsoc-calc-enhanced-db-range' - sc/source

Akash Shetye shetyeakash at gmail.com
Mon Jul 22 13:28:49 PDT 2013


 sc/source/filter/excel/xeroot.cxx  |    2 
 sc/source/filter/excel/xestyle.cxx |   92 ++++++++++++++++++++++++++++++++++---
 sc/source/filter/inc/xestyle.hxx   |   14 +++--
 3 files changed, 96 insertions(+), 12 deletions(-)

New commits:
commit 1f78fb99c4b36b5cc437b7008cc2e0c99bb5d28c
Author: Akash Shetye <shetyeakash at gmail.com>
Date:   Tue Jul 23 01:55:56 2013 +0530

    Completed the export of table formatting data to excel.
    
    The patch has not yet been tested nicely, improvements will come soon. The basics are all in place though. Will be doing the export of DB Ranges as well.
    
    Change-Id: I237b0311ed2247f8fd884545e9a5741c60ea9242

diff --git a/sc/source/filter/excel/xeroot.cxx b/sc/source/filter/excel/xeroot.cxx
index 9df6afe..31ad08b 100644
--- a/sc/source/filter/excel/xeroot.cxx
+++ b/sc/source/filter/excel/xeroot.cxx
@@ -212,7 +212,7 @@ void XclExpRoot::InitializeGlobals()
         // BIFF8: only one link manager for all sheets
         mrExpData.mxLocLinkMgr = mrExpData.mxGlobLinkMgr;
         mrExpData.mxDxfs.reset( new XclExpDxfs( GetRoot() ) );
-        mrExpData.mxTableStyles.reset( new XclExpTableStyles( GetRoot() ) );
+        mrExpData.mxTableStyles.reset( new XclExpTableStyles( GetRoot(), GetDxfs() ) );
     }
 
     if( GetOutput() == EXC_OUTPUT_XML_2007 )
diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx
index 9b52289..11c3faf 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -3133,8 +3133,8 @@ void XclExpDxf::SaveXml( XclExpXmlStream& rStrm )
 XclExpTableStyleElement::XclExpTableStyleElement( const XclExpRoot& rRoot, OUString& rType, int iSize, int iDxfId )
     :XclExpRoot( rRoot),
     maType( rType ),
-    maDxfId( iDxfId ),
-    maSize( iSize )
+    miSize( iSize ),
+    miDxfId( iDxfId )
 {
 }
 
@@ -3142,16 +3142,54 @@ XclExpTableStyleElement::~XclExpTableStyleElement()
 {
 }
 
-void XclExpTableStyleElement::SaveXml( XclExpStream& rStrm )
+void XclExpTableStyleElement::SaveXml( XclExpXmlStream& rStrm )
 {
+    sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
+    rStyleSheet->singleElement( XML_tableStyleElement,
+            XML_type, OUStringToOString(maType, RTL_TEXTENCODING_UTF8 ).getStr(),
+            XML_size, OString::number(miSize).getStr(),
+            XML_dxfId, OString::number(miDxfId).getStr(),
+            FSEND );
 }
 
 // ============================================================================
 
-XclExpTableStyle::XclExpTableStyle( const XclExpRoot& rRoot, OUString& rTableStyleName )
+XclExpTableStyle::XclExpTableStyle( const XclExpRoot& rRoot, ScDBDataFormatting& rTableStyle, XclExpDxfs& rDxfs )
     :XclExpRoot( rRoot ),
-    maTableStyleName( rTableStyleName )
+    maTableStyle( rTableStyle )
 {
+    //Get the table style name
+    maTableStyleName = maTableStyle.GetTableStyleName();
+    //Keep adding table style elements
+    OUString aStyleString;
+    OUString aElementType;
+    int aiDxfId;
+    if( !(aStyleString = maTableStyle.GetFirstRowStripeStyle()).isEmpty() )
+    {
+        //Resolve this string style sheet name to a dxf id
+        aiDxfId = rDxfs.GetDxfId( aStyleString );
+        aElementType = "firstRowStripe";
+        maStyleElementContainer.push_back( new XclExpTableStyleElement( rRoot, aElementType, 1, aiDxfId ) );
+    }
+    if( !(aStyleString = maTableStyle.GetSecondRowStripeStyle()).isEmpty() )
+    {
+        aiDxfId = rDxfs.GetDxfId( aStyleString );
+        aElementType = "secondRowStripe";
+        maStyleElementContainer.push_back( new XclExpTableStyleElement( rRoot, aElementType, 1, aiDxfId ) );
+    }
+    if( !(aStyleString = maTableStyle.GetFirstColStripeStyle()).isEmpty() )
+    {
+        aiDxfId = rDxfs.GetDxfId( aStyleString );
+        aElementType = "firstColumnStripe";
+        maStyleElementContainer.push_back( new XclExpTableStyleElement( rRoot, aElementType, 1, aiDxfId ) );
+    }
+    if( !(aStyleString = maTableStyle.GetSecondColStripeStyle()).isEmpty() )
+    {
+        aiDxfId = rDxfs.GetDxfId( aStyleString );
+        aElementType = "secondColumnStripe";
+        maStyleElementContainer.push_back( new XclExpTableStyleElement( rRoot, aElementType, 1, aiDxfId ) );
+    }
+    miCount = maStyleElementContainer.size();
 }
 
 XclExpTableStyle::~XclExpTableStyle()
@@ -3160,13 +3198,47 @@ XclExpTableStyle::~XclExpTableStyle()
 
 void XclExpTableStyle::SaveXml( XclExpXmlStream& rStrm )
 {
+    sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
+    rStyleSheet->startElement( XML_tableStyle,  XML_name, OUStringToOString(maTableStyleName, RTL_TEXTENCODING_UTF8 ).getStr(), XML_count, OString::number(miCount).getStr(), FSEND );
+    for ( StyleElementContainer::iterator itr = maStyleElementContainer.begin(); itr != maStyleElementContainer.end(); ++itr )
+    {
+        itr->SaveXml( rStrm );
+    }
+    rStyleSheet->endElement( XML_tableStyle );
 }
 
 // ===========================================================================
 
-XclExpTableStyles::XclExpTableStyles( const XclExpRoot& rRoot )
+XclExpTableStyles::XclExpTableStyles( const XclExpRoot& rRoot, XclExpDxfs& rDxfs )
     :XclExpRoot( rRoot )
 {
+    //Search through the collection of ScDBData (Database Ranges)
+    //checking for any table styles associated with them
+    miCount = 0;
+    ScDBCollection* pDBCollection = rRoot.GetDoc().GetDBCollection();
+    //Now iterate through this collection gathering style names
+    if( pDBCollection )
+    {
+        ScDBCollection::NamedDBs& aNamedDBs = pDBCollection->getNamedDBs();
+        ScDBCollection::NamedDBs::iterator itr = aNamedDBs.begin();
+        ScDBCollection::NamedDBs::iterator itrEnd = aNamedDBs.end();
+        for(; itr!= itrEnd; ++itr)
+        {
+            /*Probably have an issue here..looks like the imported DB is
+            taken into the DBCollection as a named DB, but the DB Range
+            we define by Data->define range is not classified as a named DB.
+            I haven't investigated why yet. For now allow me to consider only
+            the named DBs for table style information.
+            */
+            ScDBDataFormatting aDBFormatting;
+            (*itr).GetTableFormatting( aDBFormatting );
+            if( &(aDBFormatting) )//Probably non-standard?
+            {
+                miCount++;
+                maStyleContainer.push_back( new XclExpTableStyle( rRoot, aDBFormatting, rDxfs ) );
+            }
+        }
+    }
 }
 
 XclExpTableStyles::~XclExpTableStyles()
@@ -3175,6 +3247,13 @@ XclExpTableStyles::~XclExpTableStyles()
 
 void XclExpTableStyles::SaveXml( XclExpXmlStream& rStrm )
 {
+    sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
+    rStyleSheet->startElement( XML_tableStyles, XML_count, OString::number(miCount).getStr(), FSEND );
+    for ( StyleContainer::iterator itr = maStyleContainer.begin(); itr != maStyleContainer.end(); ++itr )
+    {
+        itr->SaveXml( rStrm );
+    }
+    rStyleSheet->endElement( XML_tableStyles );
 }
 
 // ============================================================================
@@ -3203,6 +3282,7 @@ void XclExpXmlStyleSheet::SaveXml( XclExpXmlStream& rStrm )
     CreateRecord( EXC_ID_XFLIST )->SaveXml( rStrm );
     CreateRecord( EXC_ID_DXFS )->SaveXml( rStrm );
     CreateRecord( EXC_ID_PALETTE )->SaveXml( rStrm );
+    CreateRecord( EXC_ID_TABLESTYLES )->SaveXml( rStrm );
 
     aStyleSheet->endElement( XML_styleSheet );
 
diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx
index 6f22449..a4e6017 100644
--- a/sc/source/filter/inc/xestyle.hxx
+++ b/sc/source/filter/inc/xestyle.hxx
@@ -30,6 +30,7 @@
 #include "xlstyle.hxx"
 #include "xeroot.hxx"
 #include "conditio.hxx"
+#include "dbdata.hxx"
 #include <boost/shared_ptr.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
@@ -772,34 +773,37 @@ class XclExpTableStyleElement : public XclExpRecordBase, protected XclExpRoot
 public:
     XclExpTableStyleElement( const XclExpRoot& rRoot, OUString& rType, int iSize, int iDxfId );
     virtual ~XclExpTableStyleElement();
-    virtual void SaveXml( XclExpStream& rStrm );
+    virtual void SaveXml( XclExpXmlStream& rStrm );
 private:
     OUString maType;
-    int maSize;
-    int maDxfId;
+    int miSize;
+    int miDxfId;
 };
 
 class XclExpTableStyle : public XclExpRecordBase, protected XclExpRoot
 {
 public:
-    XclExpTableStyle( const XclExpRoot& rRoot, OUString& rTableStyleName );
+    XclExpTableStyle( const XclExpRoot& rRoot, ScDBDataFormatting& rTableStyle, XclExpDxfs& rDxfs );
     virtual ~XclExpTableStyle();
     virtual void SaveXml( XclExpXmlStream& rStrm );
 private:
     typedef boost::ptr_vector< XclExpTableStyleElement > StyleElementContainer;
     StyleElementContainer maStyleElementContainer;
+    ScDBDataFormatting maTableStyle;
     OUString maTableStyleName;
+    int miCount;
 };
 
 class XclExpTableStyles : public XclExpRecordBase, protected XclExpRoot
 {
 public:
-    XclExpTableStyles( const XclExpRoot& rRoot );
+    XclExpTableStyles( const XclExpRoot& rRoot, XclExpDxfs& rDxfs );
     virtual ~XclExpTableStyles();
     virtual void SaveXml( XclExpXmlStream& rStrm );
 private:
     typedef boost::ptr_vector< XclExpTableStyle > StyleContainer;
     StyleContainer maStyleContainer;
+    int miCount;
 };
 
 // ============================================================================


More information about the Libreoffice-commits mailing list