use anyhow::bail;
use quick_xml::events::BytesStart;
use crate::helper::string_to_unsignedint;
#[derive(Debug, Clone, PartialEq)]
pub struct XlsxPhoneticProperties {
pub alignment: Option<String>,
pub font_id: Option<u64>,
pub r#type: Option<String>,
}
impl XlsxPhoneticProperties {
pub(crate) fn load(e: &BytesStart) -> anyhow::Result<Self> {
let attributes = e.attributes();
let mut properties = Self {
alignment: None,
font_id: None,
r#type: 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"alignment" => {
properties.alignment = Some(string_value);
}
b"fontId" => {
properties.font_id = string_to_unsignedint(&string_value);
}
b"type" => {
properties.r#type = Some(string_value);
}
_ => {}
}
}
Err(error) => {
bail!(error.to_string())
}
}
}
Ok(properties)
}
}