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§

Trait Implementations§

source§

impl Clone for ProtectionOptions

source§

fn clone(&self) -> ProtectionOptions

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for ProtectionOptions

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.