@brief Protect elements of a worksheet from modification.
@param worksheet Pointer to a lxw_worksheet instance to be updated.
@param password A worksheet password.
@param options Worksheet elements to protect.
The %worksheet_protect() function protects worksheet elements from modification:
Passing a NULL password is the same as turning on protection without a
password. Passing a NULL password and NULL options, or any other
combination has the effect of enabling a cell's locked and hidden
properties if they have been set.
A *locked* cell cannot be edited and this property is on by default for all
cells. A *hidden* cell will display the results of a formula but not the
formula itself. These properties can be set using the format_set_unlocked()
and format_set_hidden() format functions.
You can specify which worksheet elements you wish to protect by passing a
lxw_protection pointer in the options argument with any or all of the
following members set:
See also the format_set_unlocked() and format_set_hidden() format functions.
**Note:** Worksheet level passwords in Excel offer **very** weak
protection. They don't encrypt your data and are very easy to
deactivate. Full workbook encryption is not supported by libxlsxwriter
since it requires a completely different file format and would take several
man months to implement.
@brief Protect elements of a worksheet from modification.
@param worksheet Pointer to a lxw_worksheet instance to be updated. @param password A worksheet password. @param options Worksheet elements to protect.
The %worksheet_protect() function protects worksheet elements from modification:
@code worksheet_protect(worksheet, "Some Password", options); @endcode
The password and lxw_protection pointer are both optional:
@code worksheet_protect(worksheet1, NULL, NULL); worksheet_protect(worksheet2, NULL, my_options); worksheet_protect(worksheet3, "password", NULL); worksheet_protect(worksheet4, "password", my_options); @endcode
Passing a NULL password is the same as turning on protection without a password. Passing a NULL password and NULL options, or any other combination has the effect of enabling a cell's locked and hidden properties if they have been set.
A *locked* cell cannot be edited and this property is on by default for all cells. A *hidden* cell will display the results of a formula but not the formula itself. These properties can be set using the format_set_unlocked() and format_set_hidden() format functions.
You can specify which worksheet elements you wish to protect by passing a lxw_protection pointer in the options argument with any or all of the following members set:
no_select_locked_cells no_select_unlocked_cells format_cells format_columns format_rows insert_columns insert_rows insert_hyperlinks delete_columns delete_rows sort autofilter pivot_tables scenarios objects
All parameters are off by default. Individual elements can be protected as follows:
@code lxw_protection options = { .format_cells = 1, .insert_hyperlinks = 1, .insert_rows = 1, .delete_rows = 1, .insert_columns = 1, .delete_columns = 1, };
worksheet_protect(worksheet, NULL, &options);
@endcode
See also the format_set_unlocked() and format_set_hidden() format functions.
**Note:** Worksheet level passwords in Excel offer **very** weak protection. They don't encrypt your data and are very easy to deactivate. Full workbook encryption is not supported by libxlsxwriter since it requires a completely different file format and would take several man months to implement.