use anyhow::bail;
use quick_xml::events::Event;
use std::io::Read;
use crate::excel::XmlReader;
use super::cell_format::XlsxCellFormat;
pub type XlsxCellStyleFormats = Vec<XlsxCellFormat>;
pub(crate) fn load_cell_styles_xfs(
reader: &mut XmlReader<impl Read>,
) -> anyhow::Result<Vec<XlsxCellFormat>> {
let mut buf: Vec<u8> = Vec::new();
let mut formats: Vec<XlsxCellFormat> = vec![];
loop {
buf.clear();
match reader.read_event_into(&mut buf) {
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"xf" => {
let format = XlsxCellFormat::load(reader, e)?;
formats.push(format);
}
Ok(Event::End(ref e)) if e.local_name().as_ref() == b"cellStyleXfs" => break,
Ok(Event::Eof) => bail!("unexpected end of file."),
Err(e) => bail!(e.to_string()),
_ => (),
}
}
Ok(formats)
}