/// <summary>
        /// protect a spreadsheet with a password (not encrypted, just sets protect flags and the password.)
        /// </summary>
        /// <param name="password">password to set;Pass <code>null</code> to remove all protection</param>
        /// <param name="shouldProtectObjects">shouldProtectObjects are protected</param>
        /// <param name="shouldProtectScenarios">shouldProtectScenarios are protected</param>
        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;
            }
        }
 private bool ReadARecord(RecordStream rs)
 {
     
     switch (rs.PeekNextSid())
     {
         case ProtectRecord.sid:
             CheckNotPresent(_protectRecord);
             _protectRecord = rs.GetNext() as ProtectRecord;
             break;
         case ObjectProtectRecord.sid:
             CheckNotPresent(_objectProtectRecord);
             _objectProtectRecord = rs.GetNext() as ObjectProtectRecord;
             break;
         case ScenarioProtectRecord.sid:
             CheckNotPresent(_scenarioProtectRecord);
             _scenarioProtectRecord = rs.GetNext() as ScenarioProtectRecord;
             break;
         case PasswordRecord.sid:
             CheckNotPresent(_passwordRecord);
             _passwordRecord = rs.GetNext() as PasswordRecord;
             break;
         default:
             // all other record types are not part of the PageSettingsBlock
             return false;
     }
     return true;
 }
예제 #3
0
        /**
 * creates a Password record with password set to 00.
 */
        protected static PasswordRecord CreatePassword()
        {
            //if (log.check(POILogger.DEBUG))
            //    log.log(POILogger.DEBUG, "create password record with 00 password");
            PasswordRecord retval = new PasswordRecord((short)00);
            return retval;
        }