summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-04-19 00:11:03 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-04-19 15:51:00 +0200
commit54e2c44a0cb20f265e3703f898c7e99e0ee77692 (patch)
tree24dea0d26b24b564dc00371329d470cff92eaf9a /sc/source
parent6d97ea37bba52b21648c91276bc9281d06cdd148 (diff)
export differential formatting to xlsx
This is the first step into exporting conditional formatting to xlsx Currently we are missing the number format entries and the font entries. The patch will need some more clean up. New exported entries: - dxf - dxfs
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/filter/excel/xecontent.cxx70
-rw-r--r--sc/source/filter/excel/xeroot.cxx2
-rw-r--r--sc/source/filter/excel/xestyle.cxx156
-rw-r--r--sc/source/filter/inc/xecontent.hxx4
-rw-r--r--sc/source/filter/inc/xeroot.hxx5
-rw-r--r--sc/source/filter/inc/xestyle.hxx42
6 files changed, 267 insertions, 12 deletions
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index f0193d3229a0..17bd7e324d4c 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -573,10 +573,11 @@ void XclExpLabelranges::Save( XclExpStream& rStrm )
class XclExpCFImpl : protected XclExpRoot
{
public:
- explicit XclExpCFImpl( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry );
+ explicit XclExpCFImpl( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry, sal_Int32 nPriority = 0 );
/** Writes the body of the CF record. */
void WriteBody( XclExpStream& rStrm );
+ void SaveXml( XclExpXmlStream& rStrm );
private:
const ScCondFormatEntry& mrFormatEntry; /// Calc conditional format entry.
@@ -588,6 +589,7 @@ private:
sal_uInt32 mnFontColorId; /// Font color ID.
sal_uInt8 mnType; /// Type of the condition (cell/formula).
sal_uInt8 mnOperator; /// Comparison operator for cell type.
+ sal_Int32 mnPriority; /// Priority of this entry; needed for oox export
bool mbFontUsed; /// true = Any font attribute used.
bool mbHeightUsed; /// true = Font height used.
bool mbWeightUsed; /// true = Font weight used.
@@ -601,12 +603,13 @@ private:
// ----------------------------------------------------------------------------
-XclExpCFImpl::XclExpCFImpl( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry ) :
+XclExpCFImpl::XclExpCFImpl( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry, sal_Int32 nPriority ) :
XclExpRoot( rRoot ),
mrFormatEntry( rFormatEntry ),
mnFontColorId( 0 ),
mnType( EXC_CF_TYPE_CELL ),
mnOperator( EXC_CF_CMP_NONE ),
+ mnPriority( nPriority ),
mbFontUsed( false ),
mbHeightUsed( false ),
mbWeightUsed( false ),
@@ -778,12 +781,64 @@ void XclExpCFImpl::WriteBody( XclExpStream& rStrm )
mxTokArr2->WriteArray( rStrm );
}
+namespace {
+
+const char* GetOperatorString(ScConditionMode eMode)
+{
+ switch(eMode)
+ {
+ case SC_COND_EQUAL:
+ return "equal";
+ case SC_COND_LESS:
+ return "lessThan";
+ case SC_COND_GREATER:
+ return "greaterThan";
+ case SC_COND_EQLESS:
+ return "lessThanOrEqual";
+ case SC_COND_EQGREATER:
+ return "greaterThanOrEqual";
+ case SC_COND_NOTEQUAL:
+ return "notEqual";
+ case SC_COND_BETWEEN:
+ return "between";
+ case SC_COND_NOTBETWEEN:
+ return "notBetween";
+ case SC_COND_DUPLICATE:
+ case SC_COND_NOTDUPLICATE:
+ case SC_COND_DIRECT:
+ case SC_COND_NONE:
+ default:
+ return "";
+ break;
+ }
+ return "";
+}
+
+const char* GetTypeString()
+{
+ return "cellIs";
+}
+
+}
+
+void XclExpCFImpl::SaveXml( XclExpXmlStream& rStrm )
+{
+ sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
+ rWorksheet->startElement( XML_cfRule,
+ XML_type, GetTypeString(),
+ XML_priority, OString::valueOf( mnPriority + 1 ).getStr(),
+ XML_operator, GetOperatorString( mrFormatEntry.GetOperation() ),
+ FSEND );
+ // OOXTODO: XML_extLst
+ rWorksheet->endElement( XML_cfRule );
+}
+
// ----------------------------------------------------------------------------
-XclExpCF::XclExpCF( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry ) :
+XclExpCF::XclExpCF( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry, sal_Int32 nPriority = 0 ) :
XclExpRecord( EXC_ID_CF ),
XclExpRoot( rRoot ),
- mxImpl( new XclExpCFImpl( rRoot, rFormatEntry ) )
+ mxImpl( new XclExpCFImpl( rRoot, rFormatEntry, nPriority ) )
{
}
@@ -796,6 +851,11 @@ void XclExpCF::WriteBody( XclExpStream& rStrm )
mxImpl->WriteBody( rStrm );
}
+void XclExpCF::SaveXml( XclExpXmlStream& rStrm )
+{
+ mxImpl->SaveXml( rStrm );
+}
+
// ----------------------------------------------------------------------------
XclExpCondfmt::XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat& rCondFormat ) :
@@ -809,7 +869,7 @@ XclExpCondfmt::XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat
{
for( sal_uInt16 nIndex = 0, nCount = rCondFormat.Count(); nIndex < nCount; ++nIndex )
if( const ScCondFormatEntry* pEntry = rCondFormat.GetEntry( nIndex ) )
- maCFList.AppendNewRecord( new XclExpCF( GetRoot(), *pEntry ) );
+ maCFList.AppendNewRecord( new XclExpCF( GetRoot(), *pEntry, nIndex ) );
aScRanges.Format( msSeqRef, SCA_VALID, NULL, formula::FormulaGrammar::CONV_XL_A1 );
}
}
diff --git a/sc/source/filter/excel/xeroot.cxx b/sc/source/filter/excel/xeroot.cxx
index bf8609dd0568..bff5368a1c07 100644
--- a/sc/source/filter/excel/xeroot.cxx
+++ b/sc/source/filter/excel/xeroot.cxx
@@ -199,6 +199,7 @@ void XclExpRoot::InitializeGlobals()
mrExpData.mxPTableMgr.reset( new XclExpPivotTableManager( GetRoot() ) );
// BIFF8: only one link manager for all sheets
mrExpData.mxLocLinkMgr = mrExpData.mxGlobLinkMgr;
+ mrExpData.mxDxfs.reset( new XclExpDxfs( GetRoot() ) );
}
GetXFBuffer().Initialize();
@@ -233,6 +234,7 @@ XclExpRecordRef XclExpRoot::CreateRecord( sal_uInt16 nRecId ) const
case EXC_ID_SST: xRec = mrExpData.mxSst; break;
case EXC_ID_EXTERNSHEET: xRec = GetLocalLinkMgrRef(); break;
case EXC_ID_NAME: xRec = mrExpData.mxNameMgr; break;
+ case EXC_ID_DXFS: xRec = mrExpData.mxDxfs; break;
}
OSL_ENSURE( xRec, "XclExpRoot::CreateRecord - unknown record ID or missing object" );
return xRec;
diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx
index bd53eefed693..acb746c2dcdd 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -54,6 +54,7 @@
#include "attrib.hxx"
#include "globstr.hrc"
#include "xestring.hxx"
+#include "conditio.hxx"
#include <oox/token/tokens.hxx>
#include <boost/ptr_container/ptr_vector.hpp>
@@ -1214,6 +1215,17 @@ struct XclExpNumFmtPred
// ----------------------------------------------------------------------------
+void XclExpNumFmt::SaveXml( XclExpXmlStream& rStrm, const String& rFormatCode )
+{
+ sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
+ rStyleSheet->singleElement( XML_numFmt,
+ XML_numFmtId, OString::valueOf( mnXclNumFmt ).getStr(),
+ XML_formatCode, XclXmlUtils::ToOString( rFormatCode ).getStr(),
+ FSEND );
+}
+
+// ----------------------------------------------------------------------------
+
XclExpNumFmtBuffer::XclExpNumFmtBuffer( const XclExpRoot& rRoot ) :
XclExpRoot( rRoot ),
/* Compiler needs a hint, this doesn't work: new NfKeywordTable;
@@ -1278,12 +1290,9 @@ void XclExpNumFmtBuffer::SaveXml( XclExpXmlStream& rStrm )
rStyleSheet->startElement( XML_numFmts,
XML_count, OString::valueOf( (sal_Int32) maFormatMap.size() ).getStr(),
FSEND );
- for( XclExpNumFmtVec::const_iterator aIt = maFormatMap.begin(), aEnd = maFormatMap.end(); aIt != aEnd; ++aIt )
+ for( XclExpNumFmtVec::iterator aIt = maFormatMap.begin(), aEnd = maFormatMap.end(); aIt != aEnd; ++aIt )
{
- rStyleSheet->singleElement( XML_numFmt,
- XML_numFmtId, OString::valueOf( sal_Int32(aIt->mnXclNumFmt) ).getStr(),
- XML_formatCode, XclXmlUtils::ToOString( GetFormatCode( *aIt ) ).getStr(),
- FSEND );
+ aIt->SaveXml( rStrm, GetFormatCode( *aIt ) );
}
rStyleSheet->endElement( XML_numFmts );
}
@@ -2816,11 +2825,142 @@ void XclExpXFBuffer::AddBorderAndFill( const XclExpXF& rXF )
}
}
+
+XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot )
+ : XclExpRoot( rRoot )
+{
+ ScConditionalFormatList* pList = rRoot.GetDoc().GetCondFormList();
+ if (pList)
+ {
+ sal_Int32 nFormatCount = pList->Count();
+ sal_Int32 nIndex = 0;
+ for(sal_Int32 nItem = 0; nItem < nFormatCount; ++nItem)
+ {
+ ScConditionalFormat* pFormat = (*pList)[nItem];
+ sal_Int32 nEntryCount = pFormat->Count();
+ for (sal_Int32 nFormatEntry = 0; nFormatEntry < nEntryCount; ++nFormatEntry)
+ {
+ const ScCondFormatEntry* pEntry = pFormat->GetEntry(nFormatEntry);
+ if (!pEntry)
+ continue;
+
+ rtl::OUString aStyleName = pEntry->GetStyle();
+ if (maStyleNameToDxfId.find(aStyleName) == maStyleNameToDxfId.end())
+ {
+ maStyleNameToDxfId.insert(std::pair<rtl::OUString, sal_Int32>(aStyleName, nIndex));
+
+ SfxItemSet& rSet = rRoot.GetDoc().GetStyleSheetPool()->Find(aStyleName)->GetItemSet();
+
+ XclExpCellBorder* pBorder = new XclExpCellBorder;
+ if (!pBorder->FillFromItemSet( rSet, GetPalette(), GetBiff()) )
+ {
+ delete pBorder;
+ pBorder = NULL;
+ }
+
+ XclExpCellAlign* pAlign = new XclExpCellAlign;
+ if (!pAlign->FillFromItemSet( rSet, false, GetBiff()))
+ {
+ delete pAlign;
+ pAlign = NULL;
+ }
+
+ XclExpCellProt* pCellProt = new XclExpCellProt;
+ if (!pCellProt->FillFromItemSet( rSet ))
+ {
+ delete pCellProt;
+ pCellProt = NULL;
+ }
+
+ XclExpCellArea* pCellArea = new XclExpCellArea;
+ if(!pCellArea->FillFromItemSet( rSet, GetPalette(), GetBiff() ))
+ {
+ delete pCellArea;
+ pCellArea = NULL;
+ }
+ //XclExpFont* pFont = new XclExpFont( GetRoot(), XclFontData( rFont ), EXC_COLOR_CELLTEXT );
+
+ maDxf.push_back(new XclExpDxf( rRoot, pAlign, pBorder, NULL, NULL, pCellProt, pCellArea ));
+ ++nIndex;
+ }
+
+ }
+ }
+ }
+}
+
+void XclExpDxfs::SaveXml( XclExpXmlStream& rStrm )
+{
+ sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
+ rStyleSheet->startElement( XML_dxfs, FSEND,
+ XML_count, rtl::OString::valueOf( static_cast<sal_Int32>(maDxf.size())).getStr() );
+
+ for ( DxfContainer::iterator itr = maDxf.begin(); itr != maDxf.end(); ++itr )
+ {
+ itr->SaveXml( rStrm );
+ }
+
+ rStyleSheet->endElement( XML_dxfs );
+}
+
+// ============================================================================
+
+XclExpDxf::XclExpDxf( const XclExpRoot& rRoot, XclExpCellAlign* pAlign, XclExpCellBorder* pBorder,
+ XclExpFont* pFont, XclExpNumFmt* pNumberFmt, XclExpCellProt* pProt, XclExpCellArea* pCellArea)
+ : XclExpRoot( rRoot ),
+ mpAlign(pAlign),
+ mpBorder(pBorder),
+ mpFont(pFont),
+ mpNumberFmt(pNumberFmt),
+ mpProt(pProt),
+ mpCellArea(pCellArea)
+{
+
+}
+
+XclExpDxf::~XclExpDxf()
+{
+ delete mpAlign;
+ delete mpBorder;
+ delete mpFont;
+ delete mpNumberFmt;
+ delete mpProt;
+ delete mpCellArea;
+}
+
+void XclExpDxf::SaveXml( XclExpXmlStream& rStrm )
+{
+ sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
+ rStyleSheet->startElement( XML_dxf, FSEND );
+
+ if (mpAlign)
+ mpAlign->SaveXml(rStrm);
+ if (mpBorder)
+ mpBorder->SaveXml(rStrm);
+ if (mpFont)
+ mpFont->SaveXml(rStrm);
+ if (mpNumberFmt)
+ mpNumberFmt->SaveXml(rStrm, String());
+ if (mpProt)
+ mpProt->SaveXml(rStrm);
+ if (mpCellArea)
+ mpCellArea->SaveXml(rStrm);
+ rStyleSheet->endElement( XML_dxf );
+}
+
// ============================================================================
XclExpXmlStyleSheet::XclExpXmlStyleSheet( const XclExpRoot& rRoot )
- : XclExpRoot( rRoot )
+ : XclExpRoot( rRoot ),
+ mbDxfs(false)
{
+ if ( ScConditionalFormatList* pList = rRoot.GetDoc().GetCondFormList() )
+ {
+ if ( pList->Count() )
+ {
+ mbDxfs = true;
+ }
+ }
}
void XclExpXmlStyleSheet::SaveXml( XclExpXmlStream& rStrm )
@@ -2841,6 +2981,10 @@ void XclExpXmlStyleSheet::SaveXml( XclExpXmlStream& rStrm )
CreateRecord( EXC_ID_FONTLIST )->SaveXml( rStrm );
CreateRecord( EXC_ID_XFLIST )->SaveXml( rStrm );
CreateRecord( EXC_ID_PALETTE )->SaveXml( rStrm );
+ if(mbDxfs)
+ {
+ CreateRecord( EXC_ID_DXFS )->SaveXml( rStrm );
+ }
aStyleSheet->endElement( XML_styleSheet );
diff --git a/sc/source/filter/inc/xecontent.hxx b/sc/source/filter/inc/xecontent.hxx
index 10b245f61e66..49f375cd6c11 100644
--- a/sc/source/filter/inc/xecontent.hxx
+++ b/sc/source/filter/inc/xecontent.hxx
@@ -179,9 +179,11 @@ class XclExpCFImpl;
class XclExpCF : public XclExpRecord, protected XclExpRoot
{
public:
- explicit XclExpCF( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry );
+ explicit XclExpCF( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry, sal_Int32 nPriority );
virtual ~XclExpCF();
+ virtual void SaveXml( XclExpXmlStream& rStrm );
+
private:
/** Writes the body of the CF record. */
virtual void WriteBody( XclExpStream& rStrm );
diff --git a/sc/source/filter/inc/xeroot.hxx b/sc/source/filter/inc/xeroot.hxx
index f27546eb219e..fb706925758c 100644
--- a/sc/source/filter/inc/xeroot.hxx
+++ b/sc/source/filter/inc/xeroot.hxx
@@ -59,6 +59,7 @@ class XclExpNameManager;
class XclExpObjectManager;
class XclExpFilterManager;
class XclExpPivotTableManager;
+class XclExpDxfs;
/** Stores global buffers and data needed for Excel export filter. */
struct XclExpRootData : public XclRootData
@@ -78,6 +79,7 @@ struct XclExpRootData : public XclRootData
typedef boost::shared_ptr< XclExpObjectManager > XclExpObjectMgrRef;
typedef boost::shared_ptr< XclExpFilterManager > XclExpFilterMgrRef;
typedef boost::shared_ptr< XclExpPivotTableManager > XclExpPTableMgrRef;
+ typedef boost::shared_ptr< XclExpDxfs > XclExpDxfsRef;
XclExpTabInfoRef mxTabInfo; /// Calc->Excel sheet index conversion.
XclExpAddrConvRef mxAddrConv; /// The address converter.
@@ -95,6 +97,7 @@ struct XclExpRootData : public XclRootData
XclExpObjectMgrRef mxObjMgr; /// All drawing objects.
XclExpFilterMgrRef mxFilterMgr; /// Manager for filtered areas in all sheets.
XclExpPTableMgrRef mxPTableMgr; /// All pivot tables and pivot caches.
+ XclExpDxfsRef mxDxfs; /// All delta formatting entries
bool mbRelUrl; /// true = Store URLs relative.
@@ -147,6 +150,8 @@ public:
XclExpFilterManager& GetFilterManager() const;
/** Returns the pivot table manager. */
XclExpPivotTableManager& GetPivotTableManager() const;
+ /** Returns the differential formatting list */
+ XclExpDxfs& GetDxfs() const;
/** Is called when export filter starts to create the Excel document (all BIFF versions). */
void InitializeConvert();
diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx
index c1263b30dba5..18975c436294 100644
--- a/sc/source/filter/inc/xestyle.hxx
+++ b/sc/source/filter/inc/xestyle.hxx
@@ -38,7 +38,9 @@
#include "xerecord.hxx"
#include "xlstyle.hxx"
#include "xeroot.hxx"
+#include "conditio.hxx"
#include <boost/shared_ptr.hpp>
+#include <boost/ptr_container/ptr_vector.hpp>
/* ============================================================================
- Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
@@ -47,6 +49,7 @@
const sal_uInt16 EXC_ID_FONTLIST = 0x8031; /// For internal use only.
const sal_uInt16 EXC_ID_FORMATLIST = 0x801E; /// For internal use only.
const sal_uInt16 EXC_ID_XFLIST = 0x8043; /// For internal use only.
+const sal_uInt16 EXC_ID_DXFS = 0x9999; /// For internal use only. TODO:moggi: find a better/correct value
// PALETTE record - color information =========================================
@@ -276,6 +279,8 @@ struct XclExpNumFmt
inline explicit XclExpNumFmt( sal_uLong nScNumFmt, sal_uInt16 nXclNumFmt ) :
mnScNumFmt( nScNumFmt ), mnXclNumFmt( nXclNumFmt ) {}
+
+ void SaveXml( XclExpXmlStream& rStrm, const String& rFormatCode );
};
// ----------------------------------------------------------------------------
@@ -718,6 +723,42 @@ private:
};
+struct XclDxfStyle
+{
+};
+
+class XclExpDxf : public XclExpRecordBase, protected XclExpRoot
+{
+public:
+ XclExpDxf( const XclExpRoot& rRoot, XclExpCellAlign* pAlign, XclExpCellBorder* pBorder,
+ XclExpFont* pFont, XclExpNumFmt* pNumberFmt, XclExpCellProt* pProt, XclExpCellArea* pCellArea);
+ virtual ~XclExpDxf();
+
+ virtual void SaveXml( XclExpXmlStream& rStrm );
+
+private:
+ XclExpCellAlign* mpAlign;
+ XclExpCellBorder* mpBorder;
+ XclExpFont* mpFont;
+ XclExpNumFmt* mpNumberFmt;
+ XclExpCellProt* mpProt;
+ XclExpCellArea* mpCellArea;
+};
+
+class XclExpDxfs : public XclExpRecordBase, protected XclExpRoot
+{
+public:
+ XclExpDxfs( const XclExpRoot& rRoot );
+
+ sal_Int32 GetDxfId(const rtl::OUString& rName);
+
+ virtual void SaveXml( XclExpXmlStream& rStrm);
+private:
+ typedef boost::ptr_vector<XclExpDxf> DxfContainer;
+ std::map<rtl::OUString, sal_Int32> maStyleNameToDxfId;
+ DxfContainer maDxf;
+};
+
// ============================================================================
class XclExpXmlStyleSheet : public XclExpRecordBase, protected XclExpRoot
@@ -727,6 +768,7 @@ public:
virtual void SaveXml( XclExpXmlStream& rStrm );
private:
+ bool mbDxfs;
};
// ============================================================================