Kaydet (Commit) ef89f94b authored tarafından Eike Rathke's avatar Eike Rathke

TableRef: first wave of writing ScDBData to OOXML tables

Change-Id: I9102e23e347226ac82d2e806a293bfaf2727f194
üst 3dabb069
...@@ -83,6 +83,7 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\ ...@@ -83,6 +83,7 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\
sc/source/filter/excel/tokstack \ sc/source/filter/excel/tokstack \
sc/source/filter/excel/xechart \ sc/source/filter/excel/xechart \
sc/source/filter/excel/xecontent \ sc/source/filter/excel/xecontent \
sc/source/filter/excel/xedbdata \
sc/source/filter/excel/xeescher \ sc/source/filter/excel/xeescher \
sc/source/filter/excel/xeextlst \ sc/source/filter/excel/xeextlst \
sc/source/filter/excel/xeformula \ sc/source/filter/excel/xeformula \
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
#include "xepivot.hxx" #include "xepivot.hxx"
#include "XclExpChangeTrack.hxx" #include "XclExpChangeTrack.hxx"
#include <xepivotxml.hxx> #include <xepivotxml.hxx>
#include "xedbdata.hxx"
#include <math.h> #include <math.h>
...@@ -743,6 +744,10 @@ void ExcTable::WriteXml( XclExpXmlStream& rStrm ) ...@@ -743,6 +744,10 @@ void ExcTable::WriteXml( XclExpXmlStream& rStrm )
if (pPT) if (pPT)
pPT->SaveXml(rStrm); pPT->SaveXml(rStrm);
XclExpTables* pTables = GetTablesManager().GetTablesBySheet(mnScTab);
if (pTables)
pTables->SaveXml(rStrm);
rStrm.GetCurrentStream()->endElement( XML_worksheet ); rStrm.GetCurrentStream()->endElement( XML_worksheet );
rStrm.PopStream(); rStrm.PopStream();
} }
...@@ -770,6 +775,7 @@ void ExcDocument::ReadDoc() ...@@ -770,6 +775,7 @@ void ExcDocument::ReadDoc()
{ {
aHeader.FillAsHeaderXml(maBoundsheetList); aHeader.FillAsHeaderXml(maBoundsheetList);
GetXmlPivotTableManager().Initialize(); GetXmlPivotTableManager().Initialize();
GetTablesManager().Initialize(); // Move outside conditions if we wanted to support BIFF.
} }
SCTAB nScTab = 0, nScTabCount = GetTabInfo().GetScTabCount(); SCTAB nScTab = 0, nScTabCount = GetTabInfo().GetScTabCount();
......
/* -*- 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: */
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "xestyle.hxx" #include "xestyle.hxx"
#include "xeroot.hxx" #include "xeroot.hxx"
#include <xepivotxml.hxx> #include <xepivotxml.hxx>
#include "xedbdata.hxx"
#include "excrecds.hxx" #include "excrecds.hxx"
#include "tabprotection.hxx" #include "tabprotection.hxx"
...@@ -172,6 +173,12 @@ XclExpXmlPivotTableManager& XclExpRoot::GetXmlPivotTableManager() ...@@ -172,6 +173,12 @@ XclExpXmlPivotTableManager& XclExpRoot::GetXmlPivotTableManager()
return *mrExpData.mxXmlPTableMgr; return *mrExpData.mxXmlPTableMgr;
} }
XclExpTablesManager& XclExpRoot::GetTablesManager()
{
assert(mrExpData.mxTablesMgr);
return *mrExpData.mxTablesMgr;
}
void XclExpRoot::InitializeConvert() void XclExpRoot::InitializeConvert()
{ {
mrExpData.mxTabInfo.reset( new XclExpTabInfo( GetRoot() ) ); mrExpData.mxTabInfo.reset( new XclExpTabInfo( GetRoot() ) );
...@@ -210,6 +217,7 @@ void XclExpRoot::InitializeGlobals() ...@@ -210,6 +217,7 @@ void XclExpRoot::InitializeGlobals()
if( GetOutput() == EXC_OUTPUT_XML_2007 ) if( GetOutput() == EXC_OUTPUT_XML_2007 )
{ {
mrExpData.mxXmlPTableMgr.reset(new XclExpXmlPivotTableManager(GetRoot())); mrExpData.mxXmlPTableMgr.reset(new XclExpXmlPivotTableManager(GetRoot()));
mrExpData.mxTablesMgr.reset(new XclExpTablesManager(GetRoot()));
do do
{ {
......
/* -*- 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: */
...@@ -52,6 +52,7 @@ class XclExpFilterManager; ...@@ -52,6 +52,7 @@ class XclExpFilterManager;
class XclExpPivotTableManager; class XclExpPivotTableManager;
class XclExpDxfs; class XclExpDxfs;
class XclExpXmlPivotTableManager; class XclExpXmlPivotTableManager;
class XclExpTablesManager;
namespace sc { class CompileFormulaContext; } namespace sc { class CompileFormulaContext; }
/** Stores global buffers and data needed for Excel export filter. */ /** Stores global buffers and data needed for Excel export filter. */
...@@ -93,6 +94,7 @@ struct XclExpRootData : public XclRootData ...@@ -93,6 +94,7 @@ struct XclExpRootData : public XclRootData
XclExpDxfsRef mxDxfs; /// All delta formatting entries XclExpDxfsRef mxDxfs; /// All delta formatting entries
std::shared_ptr<XclExpXmlPivotTableManager> mxXmlPTableMgr; std::shared_ptr<XclExpXmlPivotTableManager> mxXmlPTableMgr;
std::shared_ptr<XclExpTablesManager> mxTablesMgr;
std::shared_ptr<sc::CompileFormulaContext> mpCompileFormulaCxt; std::shared_ptr<sc::CompileFormulaContext> mpCompileFormulaCxt;
ScCompiler::OpCodeMapPtr mxOpCodeMap; /// mapping between op-codes and names ScCompiler::OpCodeMapPtr mxOpCodeMap; /// mapping between op-codes and names
...@@ -157,6 +159,8 @@ public: ...@@ -157,6 +159,8 @@ public:
XclExpXmlPivotTableManager& GetXmlPivotTableManager(); XclExpXmlPivotTableManager& GetXmlPivotTableManager();
XclExpTablesManager& GetTablesManager();
/** Is called when export filter starts to create the Excel document (all BIFF versions). */ /** Is called when export filter starts to create the Excel document (all BIFF versions). */
void InitializeConvert(); void InitializeConvert();
/** Is called when export filter starts to create the workbook global data (>=BIFF5). */ /** Is called when export filter starts to create the workbook global data (>=BIFF5). */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment