summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2013-08-01 10:04:42 +0100
committerEike Rathke <erack@redhat.com>2013-08-03 12:34:02 +0000
commit9d07f380bb0d5053571a9f3866b0415fe8339c5b (patch)
tree51003673f803c5e12d5976918229fccc36fb9dd5
parentc549ac677ba6279387aca33c5117b8ee1461bd9e (diff)
1st step fix for exporting SheetProtection fdo#64753 is to import correctly
(cherry picked from commit 016e18680e471d9f0cea8ee35f9716ae0f9baa11) 2nd step to export SheetProtection fdo#64753, actually export the data (cherry picked from commit 8ce1124359783df750d176b8390b4eb0f54fb6ba) unit test for fdo#64753 ( import/export of sheetprotection ) Conflicts: sc/qa/unit/subsequent_export-test.cxx Change-Id: If420b386543c15c7b550a720b6e2db69bf372d7f Reviewed-on: https://gerrit.libreoffice.org/5229 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
-rwxr-xr-xsc/qa/unit/data/xlsx/ProtecteSheet1234Pass.xlsxbin0 -> 7768 bytes
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx31
-rw-r--r--sc/source/filter/excel/excdoc.cxx5
-rw-r--r--sc/source/filter/excel/excrecds.cxx44
-rw-r--r--sc/source/filter/inc/excrecds.hxx8
-rw-r--r--sc/source/filter/oox/worksheetsettings.cxx35
6 files changed, 117 insertions, 6 deletions
diff --git a/sc/qa/unit/data/xlsx/ProtecteSheet1234Pass.xlsx b/sc/qa/unit/data/xlsx/ProtecteSheet1234Pass.xlsx
new file mode 100755
index 000000000000..509ebe2322f2
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/ProtecteSheet1234Pass.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index ed23eeedb566..9a06e9afd081 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -29,6 +29,7 @@
#include "scitems.hxx"
#include "document.hxx"
#include "cellform.hxx"
+#include "tabprotection.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -53,6 +54,7 @@ public:
void testDataBarExportXLSX();
void testMiscRowHeightExport();
void testNamedRangeBugfdo62729();
+ void testSheetProtectionXLSX();
CPPUNIT_TEST_SUITE(ScExportTest);
CPPUNIT_TEST(test);
@@ -65,6 +67,7 @@ public:
CPPUNIT_TEST(testColorScaleExportXLSX);
CPPUNIT_TEST(testMiscRowHeightExport);
CPPUNIT_TEST(testNamedRangeBugfdo62729);
+ CPPUNIT_TEST(testSheetProtectionXLSX);
CPPUNIT_TEST_SUITE_END();
private:
@@ -322,6 +325,34 @@ void ScExportTest::testNamedRangeBugfdo62729()
xDocSh->DoClose();
}
+void ScExportTest::testSheetProtectionXLSX()
+{
+ ScDocShellRef xShell = loadDoc("ProtecteSheet1234Pass.", XLSX);
+ CPPUNIT_ASSERT(xShell.Is());
+
+ ScDocShellRef xDocSh = saveAndReload(xShell, XLSX);
+ CPPUNIT_ASSERT(xDocSh.Is());
+
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ const ScTableProtection* pTabProtect = pDoc->GetTabProtection(0);
+ CPPUNIT_ASSERT(pTabProtect);
+ if ( pTabProtect )
+ {
+ Sequence<sal_Int8> aHash = pTabProtect->getPasswordHash(PASSHASH_XL);
+ // check has
+ if (aHash.getLength() >= 2)
+ {
+ CPPUNIT_ASSERT( (sal_uInt8)aHash[0] == 204 );
+ CPPUNIT_ASSERT( (sal_uInt8)aHash[1] == 61 );
+ }
+ // we could flesh out this check I guess
+ CPPUNIT_ASSERT ( pTabProtect->isOptionEnabled( ScTableProtection::OBJECTS ) );
+ CPPUNIT_ASSERT ( pTabProtect->isOptionEnabled( ScTableProtection::SCENARIOS ) );
+ }
+ xDocSh->DoClose();
+}
+
ScExportTest::ScExportTest()
: ScBootstrapFixture("/sc/qa/unit/data")
{
diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx
index b95b66035a8f..7c64d474746e 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -593,6 +593,11 @@ void ExcTable::FillAsXmlTable( SCTAB nCodeNameIdx )
// conditional formats
Add( new XclExpCondFormatBuffer( GetRoot(), xExtLst ) );
+ ScDocument& rDoc = GetDoc();
+ const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
+ if (pTabProtect && pTabProtect->isProtected())
+ Add( new XclExpSheetProtection(true, mnScTab) );
+
if( HasVbaStorage() )
if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx
index fc8be48a3e57..39e422215a51 100644
--- a/sc/source/filter/excel/excrecds.cxx
+++ b/sc/source/filter/excel/excrecds.cxx
@@ -79,6 +79,7 @@
#include "xecontent.hxx"
#include "xcl97rec.hxx"
+#include "tabprotection.hxx"
using namespace ::oox;
@@ -494,6 +495,49 @@ XclExpProtection::XclExpProtection(bool bValue) :
{
}
+XclExpSheetProtection::XclExpSheetProtection(bool bValue, SCTAB nTab ) :
+ XclExpProtection( bValue),
+ mnTab(nTab)
+{
+}
+
+void XclExpSheetProtection::SaveXml( XclExpXmlStream& rStrm )
+{
+ ScDocument& rDoc = rStrm.GetRoot().GetDoc();
+ const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnTab);
+ if ( pTabProtect )
+ {
+ Sequence<sal_Int8> aHash = pTabProtect->getPasswordHash(PASSHASH_XL);
+ sal_uInt16 nHash(0x0000);
+ OString sHash;
+ if (aHash.getLength() >= 2)
+ {
+ nHash = ((aHash[0] << 8) & 0xFFFF);
+ nHash |= (aHash[1] & 0xFF);
+ sHash = OString::valueOf( static_cast<sal_Int32>(nHash), 16 );
+ }
+ sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
+ rWorksheet->singleElement( XML_sheetProtection,
+ XML_sheet, XclXmlUtils::ToPsz( true ),
+ XML_password, sHash.getStr(),
+ XML_objects, pTabProtect->isOptionEnabled( ScTableProtection::OBJECTS ) ? XclXmlUtils::ToPsz( true ) : NULL,
+ XML_scenarios, pTabProtect->isOptionEnabled( ScTableProtection::SCENARIOS ) ? XclXmlUtils::ToPsz( true ) : NULL,
+ XML_formatCells, pTabProtect->isOptionEnabled( ScTableProtection::FORMAT_CELLS ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_formatColumns, pTabProtect->isOptionEnabled( ScTableProtection::FORMAT_COLUMNS ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_formatRows, pTabProtect->isOptionEnabled( ScTableProtection::FORMAT_ROWS ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_insertColumns, pTabProtect->isOptionEnabled( ScTableProtection::INSERT_COLUMNS ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_insertRows, pTabProtect->isOptionEnabled( ScTableProtection::INSERT_ROWS ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_insertHyperlinks, pTabProtect->isOptionEnabled( ScTableProtection::INSERT_HYPERLINKS ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_deleteColumns, pTabProtect->isOptionEnabled( ScTableProtection::DELETE_COLUMNS ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_deleteRows, pTabProtect->isOptionEnabled( ScTableProtection::DELETE_ROWS ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_selectLockedCells, pTabProtect->isOptionEnabled( ScTableProtection::SELECT_LOCKED_CELLS ) ? XclXmlUtils::ToPsz( true ) : NULL,
+ XML_sort, pTabProtect->isOptionEnabled( ScTableProtection::SORT ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_autoFilter, pTabProtect->isOptionEnabled( ScTableProtection::AUTOFILTER ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_pivotTables, pTabProtect->isOptionEnabled( ScTableProtection::PIVOT_TABLES ) ? NULL : XclXmlUtils::ToPsz( true ),
+ XML_selectUnlockedCells, pTabProtect->isOptionEnabled( ScTableProtection::SELECT_UNLOCKED_CELLS ) ? XclXmlUtils::ToPsz( true ) : NULL,
+ FSEND );
+ }
+}
// ============================================================================
XclExpPassHash::XclExpPassHash(const Sequence<sal_Int8>& aHash) :
diff --git a/sc/source/filter/inc/excrecds.hxx b/sc/source/filter/inc/excrecds.hxx
index fe70907bd330..a46d57d15f1c 100644
--- a/sc/source/filter/inc/excrecds.hxx
+++ b/sc/source/filter/inc/excrecds.hxx
@@ -191,6 +191,14 @@ class XclExpProtection : public XclExpBoolRecord
XclExpProtection(bool bValue);
};
+class XclExpSheetProtection : public XclExpProtection
+{
+ SCTAB mnTab;
+ public:
+ XclExpSheetProtection(bool bValue, SCTAB nTab);
+ virtual void SaveXml( XclExpXmlStream& rStrm );
+};
+
class XclExpPassHash : public XclExpRecord
{
public:
diff --git a/sc/source/filter/oox/worksheetsettings.cxx b/sc/source/filter/oox/worksheetsettings.cxx
index 1980283e4820..96ca193a30a5 100644
--- a/sc/source/filter/oox/worksheetsettings.cxx
+++ b/sc/source/filter/oox/worksheetsettings.cxx
@@ -26,6 +26,8 @@
#include "biffinputstream.hxx"
#include "pagesettings.hxx"
#include "workbooksettings.hxx"
+#include "tabprotection.hxx"
+#include "document.hxx"
namespace oox {
namespace xls {
@@ -231,13 +233,34 @@ void WorksheetSettings::importPhoneticPr( SequenceInputStream& rStrm )
void WorksheetSettings::finalizeImport()
{
// sheet protection
- if( maSheetProt.mbSheet ) try
- {
- Reference< XProtectable > xProtectable( getSheet(), UNO_QUERY_THROW );
- xProtectable->protect( OUString() );
- }
- catch( Exception& )
+ if( maSheetProt.mbSheet )
{
+ ScTableProtection aProtect;
+ aProtect.setProtected(true);
+ if (maSheetProt.mnPasswordHash)
+ {
+ Sequence<sal_Int8> aPass(2);
+ aPass[0] = ( maSheetProt.mnPasswordHash>> 8) & 0xFF;
+ aPass[1] = maSheetProt.mnPasswordHash & 0xFF;
+ aProtect.setPasswordHash(aPass, PASSHASH_XL);
+ }
+ aProtect.setOption( ScTableProtection::OBJECTS, maSheetProt.mbObjects);
+ aProtect.setOption( ScTableProtection::SCENARIOS, maSheetProt.mbScenarios );
+ aProtect.setOption( ScTableProtection::FORMAT_CELLS, maSheetProt.mbFormatCells );
+ aProtect.setOption( ScTableProtection::FORMAT_COLUMNS, maSheetProt.mbFormatColumns );
+ aProtect.setOption( ScTableProtection::FORMAT_ROWS, maSheetProt.mbFormatRows );
+ aProtect.setOption( ScTableProtection::INSERT_COLUMNS, maSheetProt.mbInsertColumns );
+ aProtect.setOption( ScTableProtection::INSERT_ROWS, maSheetProt.mbInsertRows );
+ aProtect.setOption( ScTableProtection::INSERT_HYPERLINKS, maSheetProt.mbInsertHyperlinks );
+ aProtect.setOption( ScTableProtection::DELETE_COLUMNS, maSheetProt.mbDeleteColumns );
+ aProtect.setOption( ScTableProtection::DELETE_ROWS,maSheetProt.mbDeleteRows );
+ aProtect.setOption( ScTableProtection::SELECT_LOCKED_CELLS, maSheetProt.mbSelectLocked );
+ aProtect.setOption( ScTableProtection::SORT, maSheetProt.mbSort );
+ aProtect.setOption( ScTableProtection::AUTOFILTER, maSheetProt.mbAutoFilter );
+ aProtect.setOption( ScTableProtection::PIVOT_TABLES, maSheetProt.mbPivotTables );
+ aProtect.setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, maSheetProt.mbSelectUnlocked );
+
+ getScDocument().SetTabProtection( getSheetIndex(), &aProtect );
}
// VBA code name