use anyhow::bail;
use quick_xml::events::BytesStart;
use crate::helper::string_to_bool;
#[derive(Debug, Clone, PartialEq)]
pub struct XlsxTableStyleInfo {
pub name: Option<String>,
pub show_column_stripes: Option<bool>,
pub show_first_column: Option<bool>,
pub show_last_column: Option<bool>,
pub show_row_stripes: Option<bool>,
}
impl XlsxTableStyleInfo {
pub(crate) fn load(e: &BytesStart) -> anyhow::Result<Self> {
let attributes = e.attributes();
let mut info = Self {
name: None,
show_column_stripes: None,
show_first_column: None,
show_last_column: None,
show_row_stripes: 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"name" => info.name = Some(string_value),
b"showColumnStripes" => {
info.show_column_stripes = string_to_bool(&string_value);
}
b"showFirstColumn" => {
info.show_first_column = string_to_bool(&string_value);
}
b"showLastColumn" => {
info.show_last_column = string_to_bool(&string_value);
}
b"showRowStripes" => {
info.show_row_stripes = string_to_bool(&string_value);
}
_ => {}
}
}
Err(error) => {
bail!(error.to_string())
}
}
}
Ok(info)
}
}