summaryrefslogtreecommitdiff
path: root/sc/source/filter
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-05-20 20:54:00 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-05-20 20:55:02 +0200
commit4f8af4aeacb34e3a99f49aeec66c3ada07d8a027 (patch)
tree73438068af10344952b5f6a032ccbeb551d78e0c /sc/source/filter
parentb930234aade453d8a162f609779756594532d02b (diff)
correctly import data bar information from Excel2010
Change-Id: I7545dfd849f2cc9924a6bb7f6d1ca9d97c3cf079
Diffstat (limited to 'sc/source/filter')
-rw-r--r--sc/source/filter/inc/condformatbuffer.hxx2
-rw-r--r--sc/source/filter/inc/extlstcontext.hxx105
-rw-r--r--sc/source/filter/inc/worksheethelper.hxx3
-rw-r--r--sc/source/filter/oox/condformatcontext.cxx3
-rw-r--r--sc/source/filter/oox/extlstcontext.cxx208
-rw-r--r--sc/source/filter/oox/worksheetfragment.cxx2
-rw-r--r--sc/source/filter/oox/worksheethelper.cxx9
7 files changed, 332 insertions, 0 deletions
diff --git a/sc/source/filter/inc/condformatbuffer.hxx b/sc/source/filter/inc/condformatbuffer.hxx
index de2c906166cc..09b9a83fd8b4 100644
--- a/sc/source/filter/inc/condformatbuffer.hxx
+++ b/sc/source/filter/inc/condformatbuffer.hxx
@@ -123,6 +123,8 @@ public:
void SetData( ScDataBarFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
+ ScDataBarFormatData* getDataBarFormatData() { return mpFormat; }
+
private:
const CondFormat& mrCondFormat;
ScDataBarFormatData* mpFormat;
diff --git a/sc/source/filter/inc/extlstcontext.hxx b/sc/source/filter/inc/extlstcontext.hxx
new file mode 100644
index 000000000000..2ed742dd5d05
--- /dev/null
+++ b/sc/source/filter/inc/extlstcontext.hxx
@@ -0,0 +1,105 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "excelhandlers.hxx"
+#include "worksheetfragment.hxx"
+
+namespace oox {
+namespace xls {
+
+class ExtCfRuleContext : public WorksheetContextBase
+{
+public:
+ explicit ExtCfRuleContext( WorksheetContextBase& rFragment, void* pDataBar );
+
+ virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
+ virtual void onStartElement( const AttributeList& rAttribs );
+
+private:
+ void importDataBar( const AttributeList& rAttribs );
+ void importNegativeFillColor( const AttributeList& rAttribs );
+ void* mpTarget;
+
+};
+
+/**
+ * Handle ExtLst entries in xlsx. These entries are a way to extend the standard
+ * without actually changing it
+ *
+ * Needed right now for data bars
+ *
+ * ExtLstLocalContext is for the entry in the datastructure that needs to be extended
+ */
+class ExtLstLocalContext : public WorksheetContextBase
+{
+public:
+ explicit ExtLstLocalContext( WorksheetContextBase& rFragment, void* pTarget ); // until now a ExtLst always extends an existing entry
+
+protected:
+ virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
+ virtual void onStartElement( const AttributeList& rAttribs );
+ virtual void onCharacters( const ::rtl::OUString& rChars );
+
+private:
+ void* mpTarget;
+};
+
+/**
+ * A single ext entry. Will be skipped until the actual entry with the correct uri is found
+ */
+class ExtGlobalContext : public WorksheetContextBase
+{
+public:
+ explicit ExtGlobalContext( WorksheetContextBase& rFragment );
+
+protected:
+ virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
+ virtual void onStartElement( const AttributeList& rAttribs );
+
+private:
+};
+
+/**
+ * Used for the actual ExtLst containing the new extended definition.
+ * Uses the saved data from the ExtLstLocalContext
+ */
+class ExtLstGlobalContext : public WorksheetContextBase
+{
+public:
+ explicit ExtLstGlobalContext( WorksheetFragment& rFragment );
+
+protected:
+ virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
+ virtual void onStartElement( const AttributeList& rAttribs );
+ virtual void onCharacters( const ::rtl::OUString& rChars );
+};
+
+} //namespace xls
+} //namespace oox
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/inc/worksheethelper.hxx b/sc/source/filter/inc/worksheethelper.hxx
index 93d8089c6b89..3a2de854d422 100644
--- a/sc/source/filter/inc/worksheethelper.hxx
+++ b/sc/source/filter/inc/worksheethelper.hxx
@@ -68,6 +68,7 @@ class SheetViewSettings;
class VmlDrawing;
class WorksheetSettings;
+typedef ::std::map< rtl::OUString, void* > ExtLst;
// ============================================================================
// ============================================================================
@@ -249,6 +250,8 @@ public:
/** Returns the VML drawing page for this sheet (OOXML/BIFF12 only). */
VmlDrawing& getVmlDrawing() const;
+ ExtLst& getExtLst() const;
+
/** Sets a column or row page break described in the passed struct. */
void setPageBreak( const PageBreakModel& rModel, bool bRowBreak );
/** Inserts the hyperlink URL into the spreadsheet. */
diff --git a/sc/source/filter/oox/condformatcontext.cxx b/sc/source/filter/oox/condformatcontext.cxx
index 01ad6a46e245..81d56fbdc134 100644
--- a/sc/source/filter/oox/condformatcontext.cxx
+++ b/sc/source/filter/oox/condformatcontext.cxx
@@ -27,6 +27,7 @@
************************************************************************/
#include "condformatcontext.hxx"
+#include "extlstcontext.hxx"
namespace oox {
namespace xls {
@@ -137,6 +138,8 @@ ContextHandlerRef CondFormatContext::onCreateContext( sal_Int32 nElement, const
return new ColorScaleContext( *this, mxRule );
else if (nElement == XLS_TOKEN( dataBar ) )
return new DataBarContext( *this, mxRule );
+ else if (nElement == XLS_TOKEN( extLst ) )
+ return new ExtLstLocalContext( *this, mxRule->getDataBar()->getDataBarFormatData() );
else
return 0;
}
diff --git a/sc/source/filter/oox/extlstcontext.cxx b/sc/source/filter/oox/extlstcontext.cxx
new file mode 100644
index 000000000000..4b7a79f576ba
--- /dev/null
+++ b/sc/source/filter/oox/extlstcontext.cxx
@@ -0,0 +1,208 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "extlstcontext.hxx"
+#include "worksheethelper.hxx"
+#include <oox/core/contexthandler.hxx>
+#include "colorscale.hxx"
+
+using ::oox::core::ContextHandlerRef;
+
+namespace oox {
+namespace xls {
+
+ExtCfRuleContext::ExtCfRuleContext( WorksheetContextBase& rFragment, void* pTarget ):
+ WorksheetContextBase( rFragment ),
+ mpTarget( pTarget )
+{
+}
+
+ContextHandlerRef ExtCfRuleContext::onCreateContext( sal_Int32 , const AttributeList& )
+{
+ return this;
+}
+
+void ExtCfRuleContext::onStartElement( const AttributeList& rAttribs )
+{
+ switch( getCurrentElement() )
+ {
+ case XLS_EXT_TOKEN( dataBar ):
+ importDataBar( rAttribs );
+ break;
+ case XLS_EXT_TOKEN( negativeFillColor ):
+ importNegativeFillColor( rAttribs );
+
+ default:
+ break;
+ }
+}
+
+void ExtCfRuleContext::importDataBar( const AttributeList& rAttribs )
+{
+ ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
+ pDataBar->mbGradient = rAttribs.getBool( XML_gradient, true );
+
+ if(rAttribs.hasAttribute(XML_axisPosition))
+ {
+ rtl::OUString aAxisPosition = rAttribs.getString( XML_axisPosition, rtl::OUString() );
+ if( aAxisPosition == "none" )
+ {
+ pDataBar->mbSameDirection = true;
+ }
+ }
+}
+
+namespace {
+
+::Color RgbToRgbComponents( sal_Int32& nRgb )
+{
+ sal_Int32 ornR = (nRgb >> 16) & 0xFF;
+ sal_Int32 ornG = (nRgb >> 8) & 0xFF;
+ sal_Int32 ornB = nRgb & 0xFF;
+
+ return ::Color(ornR, ornG, ornB);
+}
+
+}
+
+void ExtCfRuleContext::importNegativeFillColor( const AttributeList& rAttribs )
+{
+ sal_Int32 nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
+ ::Color aColor = RgbToRgbComponents(nColor);
+ ::Color* pColor = new Color(aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue());
+ static_cast<ScDataBarFormatData*>(mpTarget)->mpNegativeColor.reset(pColor);
+}
+
+ExtLstLocalContext::ExtLstLocalContext( WorksheetContextBase& rFragment, void* pTarget ):
+ WorksheetContextBase(rFragment),
+ mpTarget(pTarget)
+{
+}
+
+ContextHandlerRef ExtLstLocalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
+{
+ switch( getCurrentElement() )
+ {
+ case XLS_TOKEN( extLst ):
+ if(nElement == XLS_TOKEN( ext ))
+ return this;
+ else
+ return 0;
+ break;
+ case XLS_TOKEN( ext ):
+ if (nElement == XLS_EXT_TOKEN( id ))
+ return this;
+ else
+ return 0;
+ }
+ return 0;
+}
+
+void ExtLstLocalContext::onStartElement( const AttributeList& )
+{
+ switch( getCurrentElement() )
+ {
+ case XLS_EXT_TOKEN( id ):
+ break;
+ }
+}
+
+void ExtLstLocalContext::onCharacters( const rtl::OUString& rChars )
+{
+ if (getCurrentElement() == XLS_EXT_TOKEN( id ))
+ {
+ getExtLst().insert( std::pair< rtl::OUString, void*>(rChars, mpTarget) );
+ }
+}
+
+ExtGlobalContext::ExtGlobalContext( WorksheetContextBase& rFragment ):
+ WorksheetContextBase(rFragment)
+{
+}
+
+ContextHandlerRef ExtGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
+{
+ if(!rAttribs.hasAttribute( XML_id))
+ return this;
+ else
+ {
+ if(nElement == XLS_EXT_TOKEN( cfRule ))
+ {
+ rtl::OUString aId = rAttribs.getString( XML_id, rtl::OUString() );
+ void* pInfo = getExtLst().find( aId )->second;
+ if (!pInfo)
+ {
+ return NULL;
+ }
+ return new ExtCfRuleContext( *this, pInfo );
+ }
+ else
+ return this;
+ }
+
+ return 0;
+}
+
+void ExtGlobalContext::onStartElement( const AttributeList& rAttribs )
+{
+ if(rAttribs.hasAttribute( XML_id ))
+ {
+ rtl::OUString aId = rAttribs.getString( XML_id, rtl::OUString() );
+ }
+
+ if(rAttribs.hasAttribute( XML_uri ))
+ {
+ rtl::OUString aUri = rAttribs.getString( XML_uri, rtl::OUString() );
+ }
+}
+
+ExtLstGlobalContext::ExtLstGlobalContext( WorksheetFragment& rFragment ):
+ WorksheetContextBase(rFragment)
+{
+}
+
+ContextHandlerRef ExtLstGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
+{
+ if (nElement == XLS_TOKEN( ext ))
+ return new ExtGlobalContext( *this );
+
+ return this;
+}
+
+void ExtLstGlobalContext::onStartElement( const AttributeList& )
+{
+}
+
+void ExtLstGlobalContext::onCharacters( const rtl::OUString&)
+{
+}
+
+} //namespace oox
+} //namespace xls
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/oox/worksheetfragment.cxx b/sc/source/filter/oox/worksheetfragment.cxx
index 0b0c25f92594..be41a16bf0cb 100644
--- a/sc/source/filter/oox/worksheetfragment.cxx
+++ b/sc/source/filter/oox/worksheetfragment.cxx
@@ -48,6 +48,7 @@
#include "sheetdatabuffer.hxx"
#include "sheetdatacontext.hxx"
#include "tablefragment.hxx"
+#include "extlstcontext.hxx"
#include "viewsettings.hxx"
#include "workbooksettings.hxx"
#include "worksheetsettings.hxx"
@@ -253,6 +254,7 @@ ContextHandlerRef WorksheetFragment::onCreateContext( sal_Int32 nElement, const
case XLS_TOKEN( dataValidations ): return new DataValidationsContext( *this );
case XLS_TOKEN( autoFilter ): return new AutoFilterContext( *this, getAutoFilters().createAutoFilter() );
case XLS_TOKEN( scenarios ): return new ScenariosContext( *this );
+ case XLS_TOKEN( extLst ): return new ExtLstGlobalContext( *this );
case XLS_TOKEN( sheetViews ):
case XLS_TOKEN( cols ):
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index 84b167848e1f..43c1b33f2860 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -297,6 +297,9 @@ public:
inline SheetViewSettings& getSheetViewSettings() { return maSheetViewSett; }
/** Returns the VML drawing page for this sheet (OOXML/BIFF12 only). */
inline VmlDrawing& getVmlDrawing() { return *mxVmlDrawing; }
+ /** returns the ExtLst entries that need to be filled */
+ inline ExtLst& getExtLst() { return maExtLst; }
+
/** Returns the BIFF drawing page for this sheet (BIFF2-BIFF8 only). */
inline BiffSheetDrawing& getBiffDrawing() const { return *mxBiffDrawing; }
@@ -408,6 +411,7 @@ private:
PageSettings maPageSett; /// Page/print settings for this sheet.
SheetViewSettings maSheetViewSett; /// View settings for this sheet.
VmlDrawingPtr mxVmlDrawing; /// Collection of all VML shapes.
+ ExtLst maExtLst; /// List of extended elements
BiffSheetDrawingPtr mxBiffDrawing; /// Collection of all BIFF/DFF shapes.
OUString maDrawingPath; /// Path to DrawingML fragment.
OUString maVmlDrawingPath; /// Path to legacy VML drawing fragment.
@@ -1477,6 +1481,11 @@ VmlDrawing& WorksheetHelper::getVmlDrawing() const
return mrSheetGlob.getVmlDrawing();
}
+ExtLst& WorksheetHelper::getExtLst() const
+{
+ return mrSheetGlob.getExtLst();
+}
+
void WorksheetHelper::setPageBreak( const PageBreakModel& rModel, bool bRowBreak )
{
mrSheetGlob.setPageBreak( rModel, bRowBreak );