summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2014-04-08 12:27:15 +0200
committerEike Rathke <erack@redhat.com>2014-04-08 12:39:18 +0200
commit40a61d93ade494fa98c23a9fd8776c8dadf8f30f (patch)
treef2e94cc63603b16a58aeea29a115e4105b77b6ee
parent44569082041d921e8eeb954efac082a02fa7a5a9 (diff)
read protectedRanges and protectedRange elements from OOXML
Change-Id: I3f62deb1ee9adeda5afaf5dd13cbe1cabff0805c
-rw-r--r--sc/source/filter/inc/worksheetsettings.hxx7
-rw-r--r--sc/source/filter/oox/worksheetfragment.cxx8
-rw-r--r--sc/source/filter/oox/worksheetsettings.cxx39
3 files changed, 54 insertions, 0 deletions
diff --git a/sc/source/filter/inc/worksheetsettings.hxx b/sc/source/filter/inc/worksheetsettings.hxx
index 02877c797c8e..274f670263b6 100644
--- a/sc/source/filter/inc/worksheetsettings.hxx
+++ b/sc/source/filter/inc/worksheetsettings.hxx
@@ -22,6 +22,7 @@
#include "richstring.hxx"
#include "worksheethelper.hxx"
+#include "tabprotection.hxx"
namespace oox {
namespace xls {
@@ -60,6 +61,8 @@ struct SheetProtectionModel
bool mbPivotTables; /// True = pivot tables locked.
bool mbSelectUnlocked; /// True = select unlocked cells locked.
+ ::std::vector< ScEnhancedProtection > maEnhancedProtections;
+
explicit SheetProtectionModel();
};
@@ -78,6 +81,10 @@ public:
void importOutlinePr( const AttributeList& rAttribs );
/** Imports protection settings from the sheetProtection element. */
void importSheetProtection( const AttributeList& rAttribs );
+ /** Imports enhanced protection settings from the protectedRanges element. */
+ void importProtectedRanges( const AttributeList& rAttribs );
+ /** Imports enhanced protection settings from the protectedRange element. */
+ void importProtectedRange( const AttributeList& rAttribs );
/** Imports protection settings from the sheetProtection element of a chart sheet. */
void importChartProtection( const AttributeList& rAttribs );
/** Imports phonetic settings from the phoneticPr element. */
diff --git a/sc/source/filter/oox/worksheetfragment.cxx b/sc/source/filter/oox/worksheetfragment.cxx
index 05f8b8cfcb27..6a3753260462 100644
--- a/sc/source/filter/oox/worksheetfragment.cxx
+++ b/sc/source/filter/oox/worksheetfragment.cxx
@@ -245,6 +245,7 @@ ContextHandlerRef WorksheetFragment::onCreateContext( sal_Int32 nElement, const
case XLS_TOKEN( dimension ): importDimension( rAttribs ); break;
case XLS_TOKEN( sheetFormatPr ): importSheetFormatPr( rAttribs ); break;
case XLS_TOKEN( sheetProtection ): getWorksheetSettings().importSheetProtection( rAttribs ); break;
+ case XLS_TOKEN( protectedRanges ): getWorksheetSettings().importProtectedRanges( rAttribs ); return this;
case XLS_TOKEN( phoneticPr ): getWorksheetSettings().importPhoneticPr( rAttribs ); break;
case XLS_TOKEN( printOptions ): getPageSettings().importPrintOptions( rAttribs ); break;
case XLS_TOKEN( pageMargins ): getPageSettings().importPageMargins( rAttribs ); break;
@@ -295,6 +296,13 @@ ContextHandlerRef WorksheetFragment::onCreateContext( sal_Int32 nElement, const
if( nElement == XLS_TOKEN( brk ) ) importBrk( rAttribs, false );
break;
+ case XLS_TOKEN( protectedRanges ):
+ switch( nElement )
+ {
+ case XLS_TOKEN( protectedRange ): getWorksheetSettings().importProtectedRange( rAttribs ); return this;
+ }
+ break;
+
case XLS_TOKEN( headerFooter ):
switch( nElement )
{
diff --git a/sc/source/filter/oox/worksheetsettings.cxx b/sc/source/filter/oox/worksheetsettings.cxx
index e58b41d6d346..a5f863431501 100644
--- a/sc/source/filter/oox/worksheetsettings.cxx
+++ b/sc/source/filter/oox/worksheetsettings.cxx
@@ -28,6 +28,7 @@
#include "workbooksettings.hxx"
#include "tabprotection.hxx"
#include "document.hxx"
+#include "convuno.hxx"
namespace oox {
namespace xls {
@@ -128,6 +129,42 @@ void WorksheetSettings::importSheetProtection( const AttributeList& rAttribs )
maSheetProt.mbSelectUnlocked = rAttribs.getBool( XML_selectUnlockedCells, false );
}
+void WorksheetSettings::importProtectedRanges( const AttributeList& rAttribs )
+{
+ (void)rAttribs; // no attribs known (yet?)
+}
+
+void WorksheetSettings::importProtectedRange( const AttributeList& rAttribs )
+{
+ ScEnhancedProtection aProt;
+ /* XXX ECMA-376/OOXML XMLSchema and ISO/IEC 29500 say 'securityDescriptor'
+ * would be an element, but Excel2013 stores it as attribute. */
+ aProt.maSecurityDescriptorXML = rAttribs.getString( XML_securityDescriptor, OUString());
+ /* XXX ECMA-376/OOXML or ISO/IEC 29500 do not even mention a 'password'
+ * attribute here (or anywhere else), but this is what Excel2013 writes,
+ * similar to BIFF. OOXML XMLschema and ISO/IEC 29500 instead define
+ * 'algorithmName', 'hashValue', 'saltValue' and 'spinCount'. */
+ aProt.mnPasswordVerifier = rAttribs.getIntegerHex( XML_password, 0);
+ aProt.maTitle = rAttribs.getString( XML_name, OUString());
+ OUString aRefs( rAttribs.getString( XML_sqref, OUString()));
+ if (!aRefs.isEmpty())
+ {
+ ApiCellRangeList aRangeList;
+ getAddressConverter().convertToCellRangeList( aRangeList, aRefs, getSheetIndex(), true );
+ if (!aRangeList.empty())
+ {
+ ScRangeList* pRangeList = aProt.maRangeList = new ScRangeList;
+ for (ApiCellRangeList::const_iterator itr( aRangeList.begin()), end( aRangeList.end()); itr != end; ++itr)
+ {
+ ScRange aRange;
+ ScUnoConversion::FillScRange( aRange, *itr);
+ pRangeList->Append( aRange);
+ }
+ }
+ }
+ maSheetProt.maEnhancedProtections.push_back( aProt);
+}
+
void WorksheetSettings::importChartProtection( const AttributeList& rAttribs )
{
maSheetProt.mnPasswordHash = CodecHelper::getPasswordHash( rAttribs, XML_password );
@@ -229,6 +266,8 @@ void WorksheetSettings::finalizeImport()
aProtect.setOption( ScTableProtection::PIVOT_TABLES, !maSheetProt.mbPivotTables );
aProtect.setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, !maSheetProt.mbSelectUnlocked );
+ aProtect.setEnhancedProtection( maSheetProt.maEnhancedProtections);
+
getScDocument().SetTabProtection( getSheetIndex(), &aProtect );
}