Top Description Fields Constructors Methods
org.apache.poi.hssf.record.aggregates

public final Class WorksheetProtectionBlock

extends RecordAggregate
Class Inheritance
Imports
org.apache.poi.hssf.model.RecordStream, org.apache.poi.hssf.record.ObjectProtectRecord, .PasswordRecord, .ProtectRecord, .ScenarioProtectRecord, org.apache.poi.poifs.crypt.CryptoFunctions, org.apache.poi.util.RecordFormatException

Groups the sheet protection records for a worksheet.

See OOO excelfileformat.pdf sec 4.18.2 'Sheet Protection in a Workbook (BIFF5-BIFF8)'

Field Summary

Modifier and TypeField and Description
private ObjectProtectRecord
private PasswordRecord
private ProtectRecord
private ScenarioProtectRecord

Constructor Summary

AccessConstructor and Description
public
WorksheetProtectionBlock()

Creates an empty WorksheetProtectionBlock

Method Summary

Modifier and TypeMethod and Description
public void
addRecords(RecordStream rs)

This method reads WorksheetProtectionBlock records from the supplied RecordStream until the first non-WorksheetProtectionBlock record is encountered.

private void
private static ObjectProtectRecord
createObjectProtect()

creates an ObjectProtect record with protect set to false.

private static PasswordRecord
createPassword()

creates a Password record with password set to 0x0000.

private static ScenarioProtectRecord
createScenarioProtect()

creates a ScenarioProtect record with protect set to false.

public ScenarioProtectRecord
private PasswordRecord

Returns:

the PasswordRecord. If one is not contained in the sheet, then one is created.
getPassword
()

public int
public PasswordRecord
private ProtectRecord

Returns:

the ProtectRecord. If one is not contained in the sheet, then one is created.
getProtect
()

public static boolean

Returns:

true if the specified Record sid is one belonging to the 'Page Settings Block'.
isComponentRecord
(int sid)

public boolean
public boolean
public boolean
public void
protectSheet(String
to set. Pass null to remove all protection
password
,
boolean
are protected
shouldProtectObjects
,
boolean
are protected
shouldProtectScenarios
)

protect a spreadsheet with a password (not encrypted, just sets protect flags and the password.

private boolean
public void
visitContainedRecords(RecordAggregate.RecordVisitor
The visitor to use for callbacks while walking this object
rv
)

Implements abstract org.apache.poi.hssf.record.aggregates.RecordAggregate.visitContainedRecords.

Visit each of the atomic BIFF records contained in this RecordAggregate in the order that they should be written to file.

private static void
Inherited from org.apache.poi.hssf.record.aggregates.RecordAggregate:
getRecordSizeserialize

Field Detail

_objectProtectRecordback to summary
private ObjectProtectRecord _objectProtectRecord
_passwordRecordback to summary
private PasswordRecord _passwordRecord
_protectRecordback to summary
private ProtectRecord _protectRecord
_scenarioProtectRecordback to summary
private ScenarioProtectRecord _scenarioProtectRecord

Constructor Detail

WorksheetProtectionBlockback to summary
public WorksheetProtectionBlock()

Creates an empty WorksheetProtectionBlock

Method Detail

addRecordsback to summary
public void addRecords(RecordStream rs)

This method reads WorksheetProtectionBlock records from the supplied RecordStream until the first non-WorksheetProtectionBlock record is encountered. As each record is read, it is incorporated into this WorksheetProtectionBlock.

As per the OOO documentation, the protection block records can be expected to be written together (with no intervening records), but earlier versions of POI (prior to Jun 2009) didn't do this. Workbooks with sheet protection created by those earlier POI versions seemed to be valid (Excel opens them OK). So PO allows continues to support reading of files with non continuous worksheet protection blocks.

Note

- when POI writes out this WorksheetProtectionBlock, the records will always be written in one consolidated block (in the standard ordering) regardless of how scattered the records were when they were originally read.

checkNotPresentback to summary
private void checkNotPresent(Record rec)
createObjectProtectback to summary
private static ObjectProtectRecord createObjectProtect()

creates an ObjectProtect record with protect set to false.

createPasswordback to summary
private static PasswordRecord createPassword()

creates a Password record with password set to 0x0000.

createScenarioProtectback to summary
private static ScenarioProtectRecord createScenarioProtect()

creates a ScenarioProtect record with protect set to false.

getHCenterback to summary
public ScenarioProtectRecord getHCenter()
getPasswordback to summary
private PasswordRecord getPassword()
Returns:PasswordRecord

the PasswordRecord. If one is not contained in the sheet, then one is created.

getPasswordHashback to summary
public int getPasswordHash()
getPasswordRecordback to summary
public PasswordRecord getPasswordRecord()
getProtectback to summary
private ProtectRecord getProtect()
Returns:ProtectRecord

the ProtectRecord. If one is not contained in the sheet, then one is created.

isComponentRecordback to summary
public static boolean isComponentRecord(int sid)
Returns:boolean

true if the specified Record sid is one belonging to the 'Page Settings Block'.

isObjectProtectedback to summary
public boolean isObjectProtected()
isScenarioProtectedback to summary
public boolean isScenarioProtected()
isSheetProtectedback to summary
public boolean isSheetProtected()
protectSheetback to summary
public void protectSheet(String password, boolean shouldProtectObjects, boolean shouldProtectScenarios)

protect a spreadsheet with a password (not encrypted, just sets protect flags and the password.

Parameters
password:String

to set. Pass null to remove all protection

shouldProtectObjects:boolean

are protected

shouldProtectScenarios:boolean

are protected

readARecordback to summary
private boolean readARecord(RecordStream rs)
visitContainedRecordsback to summary
public void visitContainedRecords(RecordAggregate.RecordVisitor rv)

Implements abstract org.apache.poi.hssf.record.aggregates.RecordAggregate.visitContainedRecords.

Doc from org.apache.poi.hssf.record.aggregates.RecordAggregate.visitContainedRecords.

Visit each of the atomic BIFF records contained in this RecordAggregate in the order that they should be written to file. Implementors may or may not return the actual Records being used to manage POI's internal implementation. Callers should not assume either way, and therefore only attempt to modify those Records after cloning

Parameters
rv:RecordAggregate.RecordVisitor

The visitor to use for callbacks while walking this object

Annotations
@Override
visitIfPresentback to summary
private static void visitIfPresent(Record r, RecordAggregate.RecordVisitor rv)