umya_spreadsheet/structs/
cell_style.rs

1// cellStyle
2use crate::reader::driver::*;
3use crate::structs::StringValue;
4use crate::structs::UInt32Value;
5use crate::writer::driver::*;
6use quick_xml::events::BytesStart;
7use quick_xml::Reader;
8use quick_xml::Writer;
9use std::io::Cursor;
10
11#[derive(Clone, Default, Debug)]
12pub struct CellStyle {
13    name: StringValue,
14    builtin_id: UInt32Value,
15    format_id: UInt32Value,
16}
17
18impl CellStyle {
19    #[inline]
20    pub fn get_name(&self) -> &str {
21        self.name.get_value_str()
22    }
23
24    #[inline]
25    pub fn set_name<S: Into<String>>(&mut self, value: S) -> &mut Self {
26        self.name.set_value(value);
27        self
28    }
29
30    #[inline]
31    pub fn get_builtin_id(&self) -> &u32 {
32        self.builtin_id.get_value()
33    }
34
35    #[inline]
36    pub fn set_builtin_id(&mut self, value: u32) -> &mut Self {
37        self.builtin_id.set_value(value);
38        self
39    }
40
41    #[inline]
42    pub fn get_format_id(&self) -> &u32 {
43        self.format_id.get_value()
44    }
45
46    #[inline]
47    pub fn set_format_id(&mut self, value: u32) -> &mut Self {
48        self.format_id.set_value(value);
49        self
50    }
51
52    #[inline]
53    pub(crate) fn set_attributes<R: std::io::BufRead>(
54        &mut self,
55        _reader: &mut Reader<R>,
56        e: &BytesStart,
57    ) {
58        set_string_from_xml!(self, e, name, "name");
59        set_string_from_xml!(self, e, builtin_id, "builtinId");
60        set_string_from_xml!(self, e, format_id, "xfId");
61    }
62
63    #[inline]
64    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
65        // cellStyle
66        let mut attributes: Vec<(&str, &str)> = Vec::new();
67        attributes.push(("name", self.name.get_value_str()));
68        let format_id = self.format_id.get_value_string();
69        attributes.push(("xfId", &format_id));
70        let builtin_id = self.builtin_id.get_value_string();
71        attributes.push(("builtinId", &builtin_id));
72        write_start_tag(writer, "cellStyle", attributes, true);
73    }
74}