protect
protect
Password protects the contents of an Excel spreadsheet.
This method allows to password protect an XLSX file. One may protect worksheet or sheet scopes.
Notice that this method does not encrypt the contents of the Excel spreadsheet, only protects them from unauthorized modifications. This method is not secure and can be easily overriden by an experienced user. The encrypt method can be used to encrypt XLSX files.
source
Path to the Excel spreadsheet you want to protect.
target
Path to the resulting protected spreadsheet.
options
The possible keys and values are:
Key | Type | Description |
---|---|---|
replace | bool | True or false. If true (default value) replaces the existing protection if it exists. |
password | string | The password should be a string of 15 or less characters. If you introduce a password with more than 15 characters it will be automatically truncated. |
scope | string | 'worksheet' or 'sheets'. |
sheetProtections | array | Available sheet protection types:
Boolean values. Default as true: objects, scenarios, sheet. |
sheetsSelection | array | Sheets to protect: 'names' or 'positions'. If not set, all sheets are protected. |
The source file doesn't exist.
A password is not set.
Example #1
Example #2
- phpxlsx 1.0: new method.