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; }
/// <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; } }
/** * creates a Protect record with protect set to false. */ protected ProtectRecord CreateProtect() { /*if (log.check(POILogger.DEBUG)) { log.log(POILogger.DEBUG, "create protect record with protection disabled"); }*/ ProtectRecord retval = new ProtectRecord(false); return retval; }