Search in sources :

Example 1 with ScenarioProtectRecord

use of org.apache.poi.hssf.record.ScenarioProtectRecord in project poi by apache.

the class WorksheetProtectionBlock method protectSheet.

/**
	 * protect a spreadsheet with a password (not encrypted, just sets protect
	 * flags and the password.
	 *
	 * @param password to set. Pass <code>null</code> to remove all protection
	 * @param shouldProtectObjects are protected
	 * @param shouldProtectScenarios are protected
	 */
public void protectSheet(String password, boolean shouldProtectObjects, boolean shouldProtectScenarios) {
    if (password == null) {
        _passwordRecord = null;
        _protectRecord = null;
        _objectProtectRecord = null;
        _scenarioProtectRecord = null;
        return;
    }
    ProtectRecord prec = getProtect();
    PasswordRecord pass = getPassword();
    prec.setProtect(true);
    pass.setPassword((short) CryptoFunctions.createXorVerifier1(password));
    if (_objectProtectRecord == null && shouldProtectObjects) {
        ObjectProtectRecord rec = createObjectProtect();
        rec.setProtect(true);
        _objectProtectRecord = rec;
    }
    if (_scenarioProtectRecord == null && shouldProtectScenarios) {
        ScenarioProtectRecord srec = createScenarioProtect();
        srec.setProtect(true);
        _scenarioProtectRecord = srec;
    }
}
Also used : ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) ObjectProtectRecord(org.apache.poi.hssf.record.ObjectProtectRecord) ScenarioProtectRecord(org.apache.poi.hssf.record.ScenarioProtectRecord) ScenarioProtectRecord(org.apache.poi.hssf.record.ScenarioProtectRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) ObjectProtectRecord(org.apache.poi.hssf.record.ObjectProtectRecord)

Example 2 with ScenarioProtectRecord

use of org.apache.poi.hssf.record.ScenarioProtectRecord in project poi by apache.

the class WorksheetProtectionBlock method createScenarioProtect.

/**
	 * creates a ScenarioProtect record with protect set to false.
	 */
private static ScenarioProtectRecord createScenarioProtect() {
    ScenarioProtectRecord retval = new ScenarioProtectRecord();
    retval.setProtect(false);
    return retval;
}
Also used : ScenarioProtectRecord(org.apache.poi.hssf.record.ScenarioProtectRecord)

Aggregations

ScenarioProtectRecord (org.apache.poi.hssf.record.ScenarioProtectRecord)2 ObjectProtectRecord (org.apache.poi.hssf.record.ObjectProtectRecord)1 PasswordRecord (org.apache.poi.hssf.record.PasswordRecord)1 ProtectRecord (org.apache.poi.hssf.record.ProtectRecord)1