pub struct WorkbookProtection {
pub password: Option<String>,
pub lock_structure: bool,
pub lock_windows: bool,
}Expand description
Workbook structure protection (<workbookProtection>, CT_WorkbookProtection). Locks whether
sheets can be added/renamed/hidden/reordered/deleted (lockStructure) and/or whether the
workbook’s window can be moved/resized/closed (lockWindows) — distinct from
SheetProtection, which locks cell editing within one sheet. Uses the same legacy 16-bit
password hash as SheetProtection (see writer.rs::legacy_password_hash’s doc comment for the
algorithm and its caveats) — implemented but not yet verified against a real Excel installation.
Fields§
§password: Option<String>The password, in plain text — hashed on write, never recoverable on read (same one-way
posture as SheetProtection::password).
lock_structure: boolLocks the workbook’s structure (adding/renaming/hiding/reordering/ deleting sheets).
lock_windows: boolLocks the workbook’s window (moving/resizing/closing).
Implementations§
Source§impl WorkbookProtection
impl WorkbookProtection
Sourcepub fn locked() -> WorkbookProtection
pub fn locked() -> WorkbookProtection
Locks the workbook’s structure, no password, windows not locked.
Examples found in repository?
16fn main() -> office_toolkit::Result<()> {
17 let path = output_path("xlsx_protection.xlsx");
18
19 let sheet_protection_sheet = Sheet::new("Sheet protection")
20 .with_row(Row::new().with_text("Locked: this sheet is protected with a password."))
21 .with_protection(SheetProtection::with_password("secret"));
22
23 let protected_range_sheet = Sheet::new("Protected range")
24 .with_row(
25 Row::new()
26 .with_text("A1 is protected; B1 stays editable via a named unprotected range."),
27 )
28 .with_protection(SheetProtection::locked())
29 .with_protected_range(ProtectedRange::new("EditableArea", "B1:B1").with_password("secret"));
30
31 let workbook = Workbook::new()
32 .with_write_protection(
33 WriteProtection::recommended()
34 .with_user_name("Author")
35 .with_password("secret"),
36 )
37 .with_sheet(sheet_protection_sheet)
38 .with_sheet(protected_range_sheet);
39
40 // `Workbook.protection` (structure protection: locking sheet
41 // add/rename/hide/reorder/delete) has no `with_*` builder — it's set
42 // directly, like any other public field.
43 let workbook = Workbook {
44 protection: Some(WorkbookProtection::locked().with_lock_windows(true)),
45 ..workbook
46 };
47
48 workbook.save_to_file(&path)?;
49 println!("Wrote {}", path.display());
50 Ok(())
51}Sourcepub fn with_password(self, password: impl Into<String>) -> WorkbookProtection
pub fn with_password(self, password: impl Into<String>) -> WorkbookProtection
Sets a password and returns the protection for chaining.
Sourcepub fn with_lock_windows(self, lock_windows: bool) -> WorkbookProtection
pub fn with_lock_windows(self, lock_windows: bool) -> WorkbookProtection
Sets whether the workbook’s window is locked and returns the protection for chaining.
Examples found in repository?
16fn main() -> office_toolkit::Result<()> {
17 let path = output_path("xlsx_protection.xlsx");
18
19 let sheet_protection_sheet = Sheet::new("Sheet protection")
20 .with_row(Row::new().with_text("Locked: this sheet is protected with a password."))
21 .with_protection(SheetProtection::with_password("secret"));
22
23 let protected_range_sheet = Sheet::new("Protected range")
24 .with_row(
25 Row::new()
26 .with_text("A1 is protected; B1 stays editable via a named unprotected range."),
27 )
28 .with_protection(SheetProtection::locked())
29 .with_protected_range(ProtectedRange::new("EditableArea", "B1:B1").with_password("secret"));
30
31 let workbook = Workbook::new()
32 .with_write_protection(
33 WriteProtection::recommended()
34 .with_user_name("Author")
35 .with_password("secret"),
36 )
37 .with_sheet(sheet_protection_sheet)
38 .with_sheet(protected_range_sheet);
39
40 // `Workbook.protection` (structure protection: locking sheet
41 // add/rename/hide/reorder/delete) has no `with_*` builder — it's set
42 // directly, like any other public field.
43 let workbook = Workbook {
44 protection: Some(WorkbookProtection::locked().with_lock_windows(true)),
45 ..workbook
46 };
47
48 workbook.save_to_file(&path)?;
49 println!("Wrote {}", path.display());
50 Ok(())
51}Trait Implementations§
Source§impl Clone for WorkbookProtection
impl Clone for WorkbookProtection
Source§fn clone(&self) -> WorkbookProtection
fn clone(&self) -> WorkbookProtection
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more