[Libreoffice-commits] core.git: 3 commits - sc/inc sc/Library_scfilt.mk sc/source

Eike Rathke erack at redhat.com
Mon Aug 31 11:00:22 PDT 2015


 sc/Library_scfilt.mk                |    1 
 sc/inc/dbdata.hxx                   |    1 
 sc/source/filter/excel/excdoc.cxx   |    6 
 sc/source/filter/excel/xedbdata.cxx |  264 ++++++++++++++++++++++++++++++++++++
 sc/source/filter/excel/xeroot.cxx   |    8 +
 sc/source/filter/inc/xedbdata.hxx   |   72 +++++++++
 sc/source/filter/inc/xeroot.hxx     |    4 
 7 files changed, 356 insertions(+)

New commits:
commit f284678e334b02808a6c2d473ce683745c99d08e
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Aug 31 19:52:27 2015 +0200

    TableRef: write OOXML table autoFilter fragment
    
    ... actually we're already able to import that. Needs more work for the
    filter settings export if applied.
    
    Change-Id: I4fc596f6a69c7729fc6ca488e5f596fdbe9a79b8

diff --git a/sc/source/filter/excel/xedbdata.cxx b/sc/source/filter/excel/xedbdata.cxx
index f2cd424..69c4dcc 100644
--- a/sc/source/filter/excel/xedbdata.cxx
+++ b/sc/source/filter/excel/xedbdata.cxx
@@ -207,7 +207,20 @@ void XclExpTables::SaveTableXml( XclExpXmlStream& rStrm, const Entry& rEntry )
         // OOXTODO: XML_totalsRowDxfId, ...,
         FSEND);
 
-    // OOXTODO: write <autoFilter>
+    if (rData.HasAutoFilter())
+    {
+        /* TODO: does this need to exclude totals row? */
+
+        /* TODO: in OOXML  12.3.21 Table Definition Part  has information
+         * that an applied autoFilter has child elements
+         * <af:filterColumn><af:filters><af:filter>.
+         * When not applied but buttons hidden, Excel writes, for example,
+         * <filterColumn colId="0" hiddenButton="1"/> */
+
+        pTableStrm->singleElement( XML_autoFilter,
+                XML_ref, XclXmlUtils::ToOString(aRange),
+                FSEND);
+    }
 
     const std::vector< OUString >& rColNames = rData.GetTableColumnNames();
     if (!rColNames.empty())
@@ -222,6 +235,8 @@ void XclExpTables::SaveTableXml( XclExpXmlStream& rStrm, const Entry& rEntry )
             // which case we'd need start/endElement XML_tableColumn for such
             // column.
 
+            // OOXTODO: write <totalsRowFormula> once we support it.
+
             pTableStrm->singleElement( XML_tableColumn,
                     XML_id, OString::number(i+1).getStr(),
                     XML_name, OUStringToOString( rColNames[i], RTL_TEXTENCODING_UTF8).getStr(),
commit 8709571dc5a595fbc51b25e159fbd944fcb2ebc1
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Aug 31 18:48:46 2015 +0200

    TableRef: write OOXML tableColumns,tableColumn
    
    Change-Id: I535f2dc600f3b4fdac2c7fa817eb8430848bbae6

diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index 7508e0f..2b6dfae 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -112,6 +112,7 @@ public:
     bool        IsStripData() const             { return bStripData; }
     void        SetStripData(bool bSet)         { bStripData = bSet; }
     void        SetTableColumnNames( const ::std::vector< OUString >& rNames ) { maTableColumnNames = rNames; }
+    const ::std::vector< OUString >&    GetTableColumnNames() const { return maTableColumnNames; }
 
     /** Finds the column named rName and returns the corresponding offset
         within the table.
diff --git a/sc/source/filter/excel/xedbdata.cxx b/sc/source/filter/excel/xedbdata.cxx
index 97dbe4a..f2cd424 100644
--- a/sc/source/filter/excel/xedbdata.cxx
+++ b/sc/source/filter/excel/xedbdata.cxx
@@ -207,7 +207,41 @@ void XclExpTables::SaveTableXml( XclExpXmlStream& rStrm, const Entry& rEntry )
         // OOXTODO: XML_totalsRowDxfId, ...,
         FSEND);
 
-    /* TODO: columns and stuff */
+    // OOXTODO: write <autoFilter>
+
+    const std::vector< OUString >& rColNames = rData.GetTableColumnNames();
+    if (!rColNames.empty())
+    {
+        pTableStrm->startElement( XML_tableColumns,
+                XML_count, OString::number( aRange.aEnd.Col() - aRange.aStart.Col() + 1).getStr(),
+                FSEND);
+
+        for (size_t i=0, n=rColNames.size(); i < n; ++i)
+        {
+            // OOXTODO: write <calculatedColumnFormula> once we support it, in
+            // which case we'd need start/endElement XML_tableColumn for such
+            // column.
+
+            pTableStrm->singleElement( XML_tableColumn,
+                    XML_id, OString::number(i+1).getStr(),
+                    XML_name, OUStringToOString( rColNames[i], RTL_TEXTENCODING_UTF8).getStr(),
+                    // OOXTODO: XML_dataCellStyle, ...,
+                    // OOXTODO: XML_dataDxfId, ...,
+                    // OOXTODO: XML_headerRowCellStyle, ...,
+                    // OOXTODO: XML_headerRowDxfId, ...,
+                    // OOXTODO: XML_queryTableFieldId, ...,
+                    // OOXTODO: XML_totalsRowCellStyle, ...,
+                    // OOXTODO: XML_totalsRowDxfId, ...,
+                    // OOXTODO: XML_totalsRowFunction, ...,
+                    // OOXTODO: XML_totalsRowLabel, ...,
+                    // OOXTODO: XML_uniqueName, ...,
+                    FSEND);
+        }
+
+        pTableStrm->endElement( XML_tableColumns);
+    }
+
+    // OOXTODO: write <tableStyleInfo> once we have table styles.
 
     pTableStrm->endElement( XML_table);
 }
commit ef89f94b26e61b43451f1f4f685a55aaa959311c
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Aug 31 15:53:33 2015 +0200

    TableRef: first wave of writing ScDBData to OOXML tables
    
    Change-Id: I9102e23e347226ac82d2e806a293bfaf2727f194

diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
index 64cf36b..ed9f435 100644
--- a/sc/Library_scfilt.mk
+++ b/sc/Library_scfilt.mk
@@ -83,6 +83,7 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\
 	sc/source/filter/excel/tokstack \
 	sc/source/filter/excel/xechart \
 	sc/source/filter/excel/xecontent \
+	sc/source/filter/excel/xedbdata \
 	sc/source/filter/excel/xeescher \
 	sc/source/filter/excel/xeextlst \
 	sc/source/filter/excel/xeformula \
diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx
index 98fc175..37450ca 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -69,6 +69,7 @@
 #include "xepivot.hxx"
 #include "XclExpChangeTrack.hxx"
 #include <xepivotxml.hxx>
+#include "xedbdata.hxx"
 
 #include <math.h>
 
@@ -743,6 +744,10 @@ void ExcTable::WriteXml( XclExpXmlStream& rStrm )
     if (pPT)
         pPT->SaveXml(rStrm);
 
+    XclExpTables* pTables = GetTablesManager().GetTablesBySheet(mnScTab);
+    if (pTables)
+        pTables->SaveXml(rStrm);
+
     rStrm.GetCurrentStream()->endElement( XML_worksheet );
     rStrm.PopStream();
 }
@@ -770,6 +775,7 @@ void ExcDocument::ReadDoc()
     {
         aHeader.FillAsHeaderXml(maBoundsheetList);
         GetXmlPivotTableManager().Initialize();
+        GetTablesManager().Initialize();    // Move outside conditions if we wanted to support BIFF.
     }
 
     SCTAB nScTab = 0, nScTabCount = GetTabInfo().GetScTabCount();
diff --git a/sc/source/filter/excel/xedbdata.cxx b/sc/source/filter/excel/xedbdata.cxx
new file mode 100644
index 0000000..97dbe4a
--- /dev/null
+++ b/sc/source/filter/excel/xedbdata.cxx
@@ -0,0 +1,215 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "xedbdata.hxx"
+#include "xltools.hxx"
+#include "dbdata.hxx"
+#include "document.hxx"
+#include <oox/export/utils.hxx>
+
+using namespace oox;
+
+/** (So far) dummy implementation of table export for BIFF5/BIFF7. */
+class XclExpTablesImpl5 : public XclExpTables
+{
+public:
+    explicit            XclExpTablesImpl5( const XclExpRoot& rRoot );
+    virtual             ~XclExpTablesImpl5();
+
+    virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
+    virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
+};
+
+/** Implementation of table export for OOXML, so far dummy for BIFF8. */
+class XclExpTablesImpl8 : public XclExpTables
+{
+public:
+    explicit            XclExpTablesImpl8( const XclExpRoot& rRoot );
+    virtual             ~XclExpTablesImpl8();
+
+    virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
+    virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
+};
+
+
+XclExpTablesImpl5::XclExpTablesImpl5( const XclExpRoot& rRoot ) :
+    XclExpTables( rRoot )
+{
+}
+
+XclExpTablesImpl5::~XclExpTablesImpl5()
+{
+}
+
+void XclExpTablesImpl5::Save( XclExpStream& /*rStrm*/ )
+{
+    // not implemented
+}
+
+void XclExpTablesImpl5::SaveXml( XclExpXmlStream& /*rStrm*/ )
+{
+    // not applicable
+}
+
+
+XclExpTablesImpl8::XclExpTablesImpl8( const XclExpRoot& rRoot ) :
+    XclExpTables( rRoot )
+{
+}
+
+XclExpTablesImpl8::~XclExpTablesImpl8()
+{
+}
+
+void XclExpTablesImpl8::Save( XclExpStream& /*rStrm*/ )
+{
+    // not implemented
+}
+
+void XclExpTablesImpl8::SaveXml( XclExpXmlStream& rStrm )
+{
+
+    sax_fastparser::FSHelperPtr& pWorksheetStrm = rStrm.GetCurrentStream();
+    pWorksheetStrm->startElement( XML_tableParts, FSEND);
+    for (auto const& it : maTables)
+    {
+        OUString aRelId;
+        sax_fastparser::FSHelperPtr pTableStrm = rStrm.CreateOutputStream(
+                XclXmlUtils::GetStreamName("xl/tables/", "table", it.mnTableId),
+                XclXmlUtils::GetStreamName("../tables/", "table", it.mnTableId),
+                pWorksheetStrm->getOutputStream(),
+                CREATE_XL_CONTENT_TYPE("table"),
+                CREATE_OFFICEDOC_RELATION_TYPE("table"),
+                &aRelId);
+
+        pWorksheetStrm->singleElement( XML_tablePart,
+                FSNS(XML_r, XML_id), XclXmlUtils::ToOString(aRelId).getStr(),
+                FSEND);
+
+        rStrm.PushStream( pTableStrm);
+        SaveTableXml( rStrm, it);
+        rStrm.PopStream();
+    }
+    pWorksheetStrm->endElement( XML_tableParts);
+}
+
+
+XclExpTablesManager::XclExpTablesManager( const XclExpRoot& rRoot ) :
+    XclExpRoot( rRoot )
+{
+}
+
+XclExpTablesManager::~XclExpTablesManager()
+{
+}
+
+void XclExpTablesManager::Initialize()
+{
+    const ScDocument& rDoc = GetDoc();
+    const ScDBCollection* pDBColl = rDoc.GetDBCollection();
+    if (!pDBColl)
+        return;
+
+    const ScDBCollection::NamedDBs& rDBs = pDBColl->getNamedDBs();
+    if (rDBs.empty())
+        return;
+
+    sal_Int32 nTableId = 0;
+    for (ScDBCollection::NamedDBs::const_iterator itDB(rDBs.begin()); itDB != rDBs.end(); ++itDB)
+    {
+        const ScDBData* pDBData = &(*itDB);
+        ScRange aRange( ScAddress::UNINITIALIZED);
+        pDBData->GetArea( aRange);
+        SCTAB nTab = aRange.aStart.Tab();
+        TablesMapType::iterator it = maTablesMap.find( nTab);
+        if (it == maTablesMap.end())
+        {
+            XclExpTables* pNew;
+            switch( GetBiff() )
+            {
+                case EXC_BIFF5:
+                    pNew = new XclExpTablesImpl5( GetRoot());
+                    break;
+                case EXC_BIFF8:
+                    pNew = new XclExpTablesImpl8( GetRoot());
+                    break;
+                default:
+                    assert(!"Unknown BIFF type!");
+                    continue;   // for
+            }
+            it = maTablesMap.insert( nTab, pNew).first;
+        }
+        XclExpTables* p = it->second;
+        p->AppendTable( pDBData, ++nTableId);
+    }
+}
+
+XclExpTables* XclExpTablesManager::GetTablesBySheet( SCTAB nTab )
+{
+    TablesMapType::iterator it = maTablesMap.find(nTab);
+    return it == maTablesMap.end() ? NULL : it->second;
+}
+
+XclExpTables::Entry::Entry( const ScDBData* pData, sal_Int32 nTableId ) :
+    mpData(pData), mnTableId(nTableId)
+{
+}
+
+XclExpTables::XclExpTables( const XclExpRoot& rRoot ) :
+    XclExpRoot(rRoot)
+{
+}
+
+XclExpTables::~XclExpTables()
+{
+}
+
+void XclExpTables::AppendTable( const ScDBData* pData, sal_Int32 nTableId )
+{
+    maTables.push_back( Entry( pData, nTableId));
+}
+
+void XclExpTables::SaveTableXml( XclExpXmlStream& rStrm, const Entry& rEntry )
+{
+    const ScDBData& rData = *rEntry.mpData;
+    ScRange aRange( ScAddress::UNINITIALIZED);
+    rData.GetArea( aRange);
+    sax_fastparser::FSHelperPtr& pTableStrm = rStrm.GetCurrentStream();
+    pTableStrm->startElement( XML_table,
+        XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
+        XML_id, OString::number( rEntry.mnTableId).getStr(),
+        XML_name, XclXmlUtils::ToOString( rData.GetName()).getStr(),
+        XML_displayName, XclXmlUtils::ToOString( rData.GetName()).getStr(),
+        XML_ref, XclXmlUtils::ToOString(aRange),
+        XML_headerRowCount, BS(rData.HasHeader()),
+        XML_totalsRowCount, BS(rData.HasTotals()),
+        XML_totalsRowShown, BS(rData.HasTotals()),  // we don't support that but if there are totals they are shown
+        // OOXTODO: XML_comment, ...,
+        // OOXTODO: XML_connectionId, ...,
+        // OOXTODO: XML_dataCellStyle, ...,
+        // OOXTODO: XML_dataDxfId, ...,
+        // OOXTODO: XML_headerRowBorderDxfId, ...,
+        // OOXTODO: XML_headerRowCellStyle, ...,
+        // OOXTODO: XML_headerRowDxfId, ...,
+        // OOXTODO: XML_insertRow, ...,
+        // OOXTODO: XML_insertRowShift, ...,
+        // OOXTODO: XML_published, ...,
+        // OOXTODO: XML_tableBorderDxfId, ...,
+        // OOXTODO: XML_tableType, ...,
+        // OOXTODO: XML_totalsRowBorderDxfId, ...,
+        // OOXTODO: XML_totalsRowCellStyle, ...,
+        // OOXTODO: XML_totalsRowDxfId, ...,
+        FSEND);
+
+    /* TODO: columns and stuff */
+
+    pTableStrm->endElement( XML_table);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/excel/xeroot.cxx b/sc/source/filter/excel/xeroot.cxx
index 9c3b311..b371836 100644
--- a/sc/source/filter/excel/xeroot.cxx
+++ b/sc/source/filter/excel/xeroot.cxx
@@ -38,6 +38,7 @@
 #include "xestyle.hxx"
 #include "xeroot.hxx"
 #include <xepivotxml.hxx>
+#include "xedbdata.hxx"
 
 #include "excrecds.hxx"
 #include "tabprotection.hxx"
@@ -172,6 +173,12 @@ XclExpXmlPivotTableManager& XclExpRoot::GetXmlPivotTableManager()
     return *mrExpData.mxXmlPTableMgr;
 }
 
+XclExpTablesManager& XclExpRoot::GetTablesManager()
+{
+    assert(mrExpData.mxTablesMgr);
+    return *mrExpData.mxTablesMgr;
+}
+
 void XclExpRoot::InitializeConvert()
 {
     mrExpData.mxTabInfo.reset( new XclExpTabInfo( GetRoot() ) );
@@ -210,6 +217,7 @@ void XclExpRoot::InitializeGlobals()
     if( GetOutput() == EXC_OUTPUT_XML_2007 )
     {
         mrExpData.mxXmlPTableMgr.reset(new XclExpXmlPivotTableManager(GetRoot()));
+        mrExpData.mxTablesMgr.reset(new XclExpTablesManager(GetRoot()));
 
         do
         {
diff --git a/sc/source/filter/inc/xedbdata.hxx b/sc/source/filter/inc/xedbdata.hxx
new file mode 100644
index 0000000..5dfd1cf
--- /dev/null
+++ b/sc/source/filter/inc/xedbdata.hxx
@@ -0,0 +1,72 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SC_SOURCE_FILTER_INC_XEDBDATA_HXX
+#define INCLUDED_SC_SOURCE_FILTER_INC_XEDBDATA_HXX
+
+#include "xeroot.hxx"
+#include "xerecord.hxx"
+#include <boost/ptr_container/ptr_map.hpp>
+
+class ScDBData;
+class XclExpTablesManagerImpl;
+
+class XclExpTables : public XclExpRecordBase, protected XclExpRoot
+{
+public:
+                        XclExpTables( const XclExpRoot& rRoot );
+    virtual             ~XclExpTables();
+
+    void                AppendTable( const ScDBData* pData, sal_Int32 nTableId );
+
+protected:
+    struct Entry
+    {
+        const ScDBData* mpData;
+        sal_Int32       mnTableId;  /// used as [n] in table[n].xml part name.
+
+        Entry( const ScDBData* pData, sal_Int32 nTableId );
+    };
+
+    typedef std::vector<Entry> TablesType;
+    TablesType maTables;
+
+    void                SaveTableXml( XclExpXmlStream& rStrm, const Entry& rEntry );
+};
+
+/** Stores all data for database ranges (tables in Excel speak).
+    Only OOXML export, BIFF not implemented.*/
+class XclExpTablesManager : protected XclExpRoot
+{
+public:
+    explicit            XclExpTablesManager( const XclExpRoot& rRoot );
+    virtual             ~XclExpTablesManager();
+
+    void                Initialize();
+    bool                AppendTable( const ScDBData& rData, sal_Int32 nTableId );
+    XclExpTables*       GetTablesBySheet( SCTAB nTab );
+
+private:
+    typedef boost::ptr_map< SCTAB, XclExpTables > TablesMapType;
+    TablesMapType maTablesMap;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/inc/xeroot.hxx b/sc/source/filter/inc/xeroot.hxx
index 2693185..dd7d646 100644
--- a/sc/source/filter/inc/xeroot.hxx
+++ b/sc/source/filter/inc/xeroot.hxx
@@ -52,6 +52,7 @@ class XclExpFilterManager;
 class XclExpPivotTableManager;
 class XclExpDxfs;
 class XclExpXmlPivotTableManager;
+class XclExpTablesManager;
 namespace sc { class CompileFormulaContext; }
 
 /** Stores global buffers and data needed for Excel export filter. */
@@ -93,6 +94,7 @@ struct XclExpRootData : public XclRootData
     XclExpDxfsRef       mxDxfs;             /// All delta formatting entries
 
     std::shared_ptr<XclExpXmlPivotTableManager> mxXmlPTableMgr;
+    std::shared_ptr<XclExpTablesManager> mxTablesMgr;
     std::shared_ptr<sc::CompileFormulaContext> mpCompileFormulaCxt;
 
     ScCompiler::OpCodeMapPtr  mxOpCodeMap;  /// mapping between op-codes and names
@@ -157,6 +159,8 @@ public:
 
     XclExpXmlPivotTableManager& GetXmlPivotTableManager();
 
+    XclExpTablesManager& GetTablesManager();
+
     /** Is called when export filter starts to create the Excel document (all BIFF versions). */
     void                InitializeConvert();
     /** Is called when export filter starts to create the workbook global data (>=BIFF5). */


More information about the Libreoffice-commits mailing list