umya_spreadsheet/structs/
cell_style_formats.rs1use super::CellFormat;
3use crate::reader::driver::*;
4use crate::writer::driver::*;
5use quick_xml::events::{BytesStart, Event};
6use quick_xml::Reader;
7use quick_xml::Writer;
8use std::io::Cursor;
9use thin_vec::ThinVec;
10
11#[derive(Clone, Default, Debug)]
12pub(crate) struct CellStyleFormats {
13 cell_format: ThinVec<CellFormat>,
14}
15
16impl CellStyleFormats {
17 #[inline]
18 pub(crate) fn get_cell_format(&self) -> &[CellFormat] {
19 &self.cell_format
20 }
21
22 #[inline]
23 pub(crate) fn _get_cell_format_mut(&mut self) -> &mut ThinVec<CellFormat> {
24 &mut self.cell_format
25 }
26
27 #[inline]
28 pub(crate) fn set_cell_format(&mut self, value: CellFormat) -> &mut Self {
29 self.cell_format.push(value);
30 self
31 }
32
33 pub(crate) fn set_attributes<R: std::io::BufRead>(
34 &mut self,
35 reader: &mut Reader<R>,
36 _e: &BytesStart,
37 ) {
38 xml_read_loop!(
39 reader,
40 Event::Empty(ref e) => {
41 if e.name().into_inner() == b"xf" {
42 let mut obj = CellFormat::default();
43 obj.set_attributes(reader, e, true);
44 self.set_cell_format(obj);
45 }
46 },
47 Event::Start(ref e) => {
48 if e.name().into_inner() == b"xf" {
49 let mut obj = CellFormat::default();
50 obj.set_attributes(reader, e, false);
51 self.set_cell_format(obj);
52 }
53 },
54 Event::End(ref e) => {
55 if e.name().into_inner() == b"cellStyleXfs" {
56 return
57 }
58 },
59 Event::Eof => panic!("Error: Could not find {} end element", "cellStyleXfs")
60 );
61 }
62
63 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
64 if !self.cell_format.is_empty() {
65 write_start_tag(
67 writer,
68 "cellStyleXfs",
69 vec![("count", &self.cell_format.len().to_string())],
70 false,
71 );
72
73 for cell_format in &self.cell_format {
75 cell_format.write_to(writer, false);
76 }
77
78 write_end_tag(writer, "cellStyleXfs");
79 }
80 }
81}