Struct rust_xlsxwriter::ProtectionOptions
source · pub struct ProtectionOptions {Show 15 fields
pub select_locked_cells: bool,
pub select_unlocked_cells: bool,
pub format_cells: bool,
pub format_columns: bool,
pub format_rows: bool,
pub insert_columns: bool,
pub insert_rows: bool,
pub insert_links: bool,
pub delete_columns: bool,
pub delete_rows: bool,
pub sort: bool,
pub use_autofilter: bool,
pub use_pivot_tables: bool,
pub edit_scenarios: bool,
pub edit_objects: bool,
}
Expand description
The ProtectionOptions
struct is use to set protected elements in a worksheet.
You can specify which worksheet elements protection should be on or off via
the ProtectionOptions
members. The corresponding Excel options with
their default states are shown below:
§Examples
The following example demonstrates setting the worksheet properties to be protected in a protected worksheet. In this case we protect the overall worksheet but allow columns and rows to be inserted.
use rust_xlsxwriter::{ProtectionOptions, Workbook, XlsxError};
fn main() -> Result<(), XlsxError> {
let mut workbook = Workbook::new();
// Add a worksheet to the workbook.
let worksheet = workbook.add_worksheet();
// Set some of the options and use the defaults for everything else.
let options = ProtectionOptions {
insert_columns: true,
insert_rows: true,
..ProtectionOptions::default()
};
// Set the protection options.
worksheet.protect_with_options(&options);
worksheet.write_string(0, 0, "Unlock the worksheet to edit the cell")?;
workbook.save("worksheet.xlsx")?;
Ok(())
}
Excel dialog for the output file, compare this with the default image above:
Fields§
§select_locked_cells: bool
When true
(the default) the user can select locked cells in a
protected worksheet.
select_unlocked_cells: bool
When true
(the default) the user can select unlocked cells in a
protected worksheet.
format_cells: bool
When false
(the default) the user cannot format cells in a protected
worksheet.
format_columns: bool
When false
(the default) the user cannot format cells in a protected
worksheet.
format_rows: bool
When false
(the default) the user cannot format rows in a protected
worksheet.
insert_columns: bool
When false
(the default) the user cannot insert new columns in a
protected worksheet.
insert_rows: bool
When false
(the default) the user cannot insert new rows in a
protected worksheet.
insert_links: bool
When false
(the default) the user cannot insert hyperlinks/urls in a
protected worksheet.
delete_columns: bool
When false
(the default) the user cannot delete columns in a protected
worksheet.
delete_rows: bool
When false
(the default) the user cannot delete rows in a protected
worksheet.
sort: bool
When false
(the default) the user cannot sort data in a protected
worksheet.
use_autofilter: bool
When false
(the default) the user cannot use autofilters in a
protected worksheet.
use_pivot_tables: bool
When false
(the default) the user cannot use pivot tables or pivot
charts in a protected worksheet.
edit_scenarios: bool
When false
(the default) the user cannot edit scenarios in a protected
worksheet.
edit_objects: bool
When false
(the default) the user cannot edit objects such as images,
charts or textboxes in a protected worksheet.
Implementations§
source§impl ProtectionOptions
impl ProtectionOptions
sourcepub fn new() -> ProtectionOptions
pub fn new() -> ProtectionOptions
Create a new ProtectionOptions
object to use with the
worksheet.protect_with_options()
method.
Trait Implementations§
source§impl Clone for ProtectionOptions
impl Clone for ProtectionOptions
source§fn clone(&self) -> ProtectionOptions
fn clone(&self) -> ProtectionOptions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more