diff options
author | Eike Rathke <erack@redhat.com> | 2015-08-31 15:53:33 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-08-31 19:59:37 +0200 |
commit | ef89f94b26e61b43451f1f4f685a55aaa959311c (patch) | |
tree | f8d705faf97cca6cf66244514a7830b153350e3e /sc | |
parent | 3dabb0692d496684ba145cc95884a731ca1cd5b0 (diff) |
TableRef: first wave of writing ScDBData to OOXML tables
Change-Id: I9102e23e347226ac82d2e806a293bfaf2727f194
Diffstat (limited to 'sc')
-rw-r--r-- | sc/Library_scfilt.mk | 1 | ||||
-rw-r--r-- | sc/source/filter/excel/excdoc.cxx | 6 | ||||
-rw-r--r-- | sc/source/filter/excel/xedbdata.cxx | 215 | ||||
-rw-r--r-- | sc/source/filter/excel/xeroot.cxx | 8 | ||||
-rw-r--r-- | sc/source/filter/inc/xedbdata.hxx | 72 | ||||
-rw-r--r-- | sc/source/filter/inc/xeroot.hxx | 4 |
6 files changed, 306 insertions, 0 deletions
diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk index 64cf36b155f0..ed9f4357a7e3 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 98fc175cff4d..37450ca9e445 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 000000000000..97dbe4ad702e --- /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 9c3b311b1504..b3718366d1af 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 000000000000..5dfd1cf3ae6b --- /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 2693185e301e..dd7d646031dd 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). */ |