use anyhow::bail;
use quick_xml::events::BytesStart;
use crate::helper::string_to_bool;
#[derive(Debug, Clone, PartialEq)]
pub struct XlsxCellProtection {
pub hidden: Option<bool>,
pub locked: Option<bool>,
}
impl XlsxCellProtection {
pub(crate) fn load(e: &BytesStart) -> anyhow::Result<Self> {
let attributes = e.attributes();
let mut protection = Self {
hidden: None,
locked: None,
};
for a in attributes {
match a {
Ok(a) => {
let string_value = String::from_utf8(a.value.to_vec())?;
match a.key.local_name().as_ref() {
b"hidden" => protection.hidden = string_to_bool(&string_value),
b"locked" => protection.locked = string_to_bool(&string_value),
_ => {}
}
}
Err(error) => {
bail!(error.to_string())
}
}
}
return Ok(protection);
}
}