/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for Additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ namespace HH.WMS.Utils.NPOI.HSSF.Record.Aggregates { using HH.WMS.Utils.NPOI.HSSF.Model; using HH.WMS.Utils.NPOI.HSSF.Record; using HH.WMS.Utils.NPOI.Util; using System; /** * Groups the sheet protection records for a worksheet. *
* * See OOO excelfileformat.pdf sec 4.18.2 'Sheet Protection in a Workbook * (BIFF5-BIFF8)' * * @author Josh Micich */ public class WorksheetProtectionBlock : RecordAggregate { // Every one of these component records is optional // (The whole WorksheetProtectionBlock may not be present) private ProtectRecord _protectRecord; private ObjectProtectRecord _objectProtectRecord; private ScenarioProtectRecord _scenarioProtectRecord; private PasswordRecord _passwordRecord; /** * Creates an empty WorksheetProtectionBlock */ public WorksheetProtectionBlock() { // all fields emptyv } /** * @returnnull
to remove all protection
/// shouldProtectObjects are protected
/// shouldProtectScenarios are protected
public void ProtectSheet(String password, bool shouldProtectObjects,
bool shouldProtectScenarios)
{
if (password == null)
{
_passwordRecord = null;
_protectRecord = null;
_objectProtectRecord = null;
_scenarioProtectRecord = null;
return;
}
ProtectRecord prec = this.Protect;
PasswordRecord pass = this.Password;
prec.Protect = true;
pass.Password = (PasswordRecord.HashPassword(password));
if (_objectProtectRecord == null && shouldProtectObjects)
{
ObjectProtectRecord rec = CreateObjectProtect();
rec.Protect = (true);
_objectProtectRecord = rec;
}
if (_scenarioProtectRecord == null && shouldProtectScenarios)
{
ScenarioProtectRecord srec = CreateScenarioProtect();
srec.Protect = (true);
_scenarioProtectRecord = srec;
}
}
public bool IsSheetProtected
{
get
{
return _protectRecord != null && _protectRecord.Protect;
}
}
public bool IsObjectProtected
{
get{
return _objectProtectRecord != null && _objectProtectRecord.Protect;
}
}
public bool IsScenarioProtected
{
get
{
return _scenarioProtectRecord != null && _scenarioProtectRecord.Protect;
}
}
///