umya-spreadsheet 3.0.0

umya-spreadsheet is a library written in pure Rust to read and write xlsx file.
Documentation
use std::io;

use quick_xml::{
    Writer,
    events::{
        BytesDecl,
        Event,
    },
};

use super::{
    XlsxError,
    driver::write_new_line,
};
use crate::structs::{
    Worksheet,
    WriterManager,
};

pub(crate) fn write<W: io::Seek + io::Write>(
    worksheet: &Worksheet,
    writer_mng: &mut WriterManager<W>,
) -> Result<Vec<String>, XlsxError> {
    let mut pivot_cache_no_list = Vec::<String>::new();
    for pivot_table in worksheet.pivot_tables() {
        let (find, no) = writer_mng
            .get_pivot_cache_no(pivot_table.pivot_cache_definition().hash_code().as_str());
        if find {
            continue;
        }
        let mut writer = Writer::new(io::Cursor::new(Vec::new()));

        // XML header
        writer
            .write_event(Event::Decl(BytesDecl::new(
                "1.0",
                Some("UTF-8"),
                Some("yes"),
            )))
            .unwrap();
        write_new_line(&mut writer);

        // Write pivot cache definition
        pivot_table.pivot_cache_definition().write_to(&mut writer);
        writer_mng.add_file_at_pivot_cache(writer, no)?;
        pivot_cache_no_list.push(no.to_string());
    }
    Ok(pivot_cache_no_list)
}