use std::io::Read;
use anyhow::bail;
use quick_xml::events::Event;
use crate::excel::XmlReader;
use super::row::XlsxRow;
#[derive(Debug, Clone, PartialEq)]
pub struct XlsxSheetData {
pub rows: Option<Vec<XlsxRow>>,
}
impl XlsxSheetData {
pub(crate) fn load(reader: &mut XmlReader<impl Read>) -> anyhow::Result<Self> {
let mut rows: Vec<XlsxRow> = vec![];
let mut buf: Vec<u8> = Vec::new();
loop {
buf.clear();
match reader.read_event_into(&mut buf) {
Ok(Event::Start(ref e)) if e.local_name().as_ref() == b"row" => {
rows.push(XlsxRow::load(reader, e)?);
}
Ok(Event::End(ref e)) if e.local_name().as_ref() == b"sheetData" => break,
Ok(Event::Eof) => bail!("unexpected end of file at `row`."),
Err(e) => bail!(e.to_string()),
_ => (),
}
}
return Ok(Self { rows: Some(rows) });
}
}