read protectedRanges and protectedRange elements from OOXML

Change-Id: I3f62deb1ee9adeda5afaf5dd13cbe1cabff0805c
This commit is contained in:
Eike Rathke 2014-04-08 12:27:15 +02:00
parent 4456908204
commit 40a61d93ad
3 changed files with 54 additions and 0 deletions

View File

@ -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. */

View File

@ -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 )
{

View File

@ -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 );
}