umya-spreadsheet 3.1.0

umya-spreadsheet is a library written in pure Rust to read and write xlsx file.
Documentation
use quick_xml::{
    Reader,
    events::Event,
};

use crate::{
    PivotTable,
    structs::{
        PivotCacheDefinition,
        raw::RawFile,
    },
};

pub(crate) fn read(
    raw_file: &RawFile,
    pivot_table: &mut PivotTable,
    raw_cache_records: Option<&RawFile>,
) {
    let data = std::io::Cursor::new(raw_file.file_data());
    let mut reader = Reader::from_reader(data);
    reader.config_mut().trim_text(false);
    let mut buf = Vec::new();
    let mut pivot_cache_def = PivotCacheDefinition::default();

    loop {
        match reader.read_event_into(&mut buf) {
            Ok(Event::Start(ref e)) => {
                if e.name().into_inner() == b"pivotCacheDefinition" {
                    pivot_cache_def.set_attributes(&mut reader, e);
                }
            }
            Ok(Event::End(ref e)) => {
                if e.name().into_inner() == b"pivotCacheDefinition" {
                    break;
                }
            }
            Ok(Event::Eof) => break,
            Err(e) => panic!("Error at position {}: {:?}", reader.buffer_position(), e),
            _ => (),
        }
        buf.clear();
    }

    // Preserve raw cache records if available from the template.
    if let Some(records_file) = raw_cache_records {
        pivot_cache_def.set_raw_cache_records(records_file.file_data().to_vec());
    }

    pivot_table.set_pivot_cache_definition(pivot_cache_def);
}