openprxl 0.1.0

A Rust spreadsheet library inspired by Python's openpyxl
Documentation
//! Serialization of `xl/sharedStrings.xml`.

use crate::error::Result;
use crate::shared_strings::SharedStrings;
use crate::xml;
use quick_xml::events::{BytesEnd, BytesStart, Event};

pub fn write<W: std::io::Write>(sink: W, strings: &SharedStrings) -> Result<()> {
    let mut writer = xml::writer(sink);

    let mut root = BytesStart::new("sst");
    root.push_attribute(("xmlns", xml::NS_MAIN));
    root.push_attribute(("count", strings.len().to_string().as_str()));
    root.push_attribute(("uniqueCount", strings.len().to_string().as_str()));
    writer.write_event(Event::Start(root))?;

    for (_, s) in strings.iter() {
        writer.write_event(Event::Start(BytesStart::new("si")))?;
        writer.write_event(Event::Start(BytesStart::new("t")))?;
        xml::write_text(&mut writer, s)?;
        writer.write_event(Event::End(BytesEnd::new("t")))?;
        writer.write_event(Event::End(BytesEnd::new("si")))?;
    }

    writer.write_event(Event::End(BytesEnd::new("sst")))?;
    Ok(())
}