umya_spreadsheet/structs/
sheet_format_properties.rs1use super::BooleanValue;
3use super::ByteValue;
4use super::DoubleValue;
5use super::UInt32Value;
6use crate::reader::driver::*;
7use crate::writer::driver::*;
8use quick_xml::events::BytesStart;
9use quick_xml::Reader;
10use quick_xml::Writer;
11use std::io::Cursor;
12
13#[derive(Clone, Default, Debug)]
14pub struct SheetFormatProperties {
15 base_column_width: UInt32Value,
16 custom_height: BooleanValue,
17 default_column_width: DoubleValue,
18 default_row_height: DoubleValue,
19 dy_descent: DoubleValue,
20 outline_level_column: ByteValue,
21 outline_level_row: ByteValue,
22 thick_bottom: BooleanValue,
23 thick_top: BooleanValue,
24}
25
26impl SheetFormatProperties {
27 #[inline]
28 pub fn get_base_column_width(&self) -> &u32 {
29 self.base_column_width.get_value()
30 }
31
32 #[inline]
33 pub fn set_base_column_width(&mut self, value: u32) -> &mut Self {
34 self.base_column_width.set_value(value);
35 self
36 }
37
38 #[inline]
39 pub fn get_custom_height(&self) -> &bool {
40 self.custom_height.get_value()
41 }
42
43 #[inline]
44 pub fn set_custom_height(&mut self, value: bool) -> &mut Self {
45 self.custom_height.set_value(value);
46 self
47 }
48
49 #[inline]
50 pub fn get_default_column_width(&self) -> &f64 {
51 self.default_column_width.get_value()
52 }
53
54 #[inline]
55 pub fn set_default_column_width(&mut self, value: f64) -> &mut Self {
56 self.default_column_width.set_value(value);
57 self
58 }
59
60 #[inline]
61 pub fn get_default_row_height(&self) -> &f64 {
62 self.default_row_height.get_value()
63 }
64
65 #[inline]
66 pub fn set_default_row_height(&mut self, value: f64) -> &mut Self {
67 self.default_row_height.set_value(value);
68 self
69 }
70
71 #[inline]
72 pub fn get_dy_descent(&self) -> &f64 {
73 self.dy_descent.get_value()
74 }
75
76 #[inline]
77 pub fn set_dy_descent(&mut self, value: f64) -> &mut Self {
78 self.dy_descent.set_value(value);
79 self
80 }
81
82 #[inline]
83 pub fn get_outline_level_column(&self) -> &u8 {
84 self.outline_level_column.get_value()
85 }
86
87 #[inline]
88 pub fn set_outline_level_column(&mut self, value: u8) -> &mut Self {
89 self.outline_level_column.set_value(value);
90 self
91 }
92
93 #[inline]
94 pub fn get_outline_level_row(&self) -> &u8 {
95 self.outline_level_row.get_value()
96 }
97
98 #[inline]
99 pub fn set_outline_level_row(&mut self, value: u8) -> &mut Self {
100 self.outline_level_row.set_value(value);
101 self
102 }
103
104 #[inline]
105 pub fn get_thick_bottom(&self) -> &bool {
106 self.thick_bottom.get_value()
107 }
108
109 #[inline]
110 pub fn set_thick_bottom(&mut self, value: bool) -> &mut Self {
111 self.thick_bottom.set_value(value);
112 self
113 }
114
115 #[inline]
116 pub fn get_thick_top(&self) -> &bool {
117 self.thick_top.get_value()
118 }
119
120 #[inline]
121 pub fn set_thick_top(&mut self, value: bool) -> &mut Self {
122 self.thick_top.set_value(value);
123 self
124 }
125
126 #[inline]
127 pub(crate) fn set_defalut_value(&mut self) -> &mut Self {
128 self.default_row_height.set_value(13.5);
129 self.dy_descent.set_value(0.15);
130 self
131 }
132
133 pub(crate) fn set_attributes<R: std::io::BufRead>(
134 &mut self,
135 _reader: &mut Reader<R>,
136 e: &BytesStart,
137 ) {
138 set_string_from_xml!(self, e, base_column_width, "baseColWidth");
139 set_string_from_xml!(self, e, custom_height, "customHeight");
140 set_string_from_xml!(self, e, default_column_width, "defaultColWidth");
141 set_string_from_xml!(self, e, default_row_height, "defaultRowHeight");
142 set_string_from_xml!(self, e, dy_descent, "x14ac:dyDescent");
143 set_string_from_xml!(self, e, outline_level_column, "outlineLevelCol");
144 set_string_from_xml!(self, e, outline_level_row, "outlineLevelRow");
145 set_string_from_xml!(self, e, thick_bottom, "thickBottom");
146 set_string_from_xml!(self, e, thick_top, "thickTop");
147 }
148
149 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
150 let mut attributes: Vec<(&str, &str)> = Vec::new();
152 let str_base_column_width = self.base_column_width.get_value_string();
153 if self.base_column_width.has_value() {
154 attributes.push(("baseColWidth", &str_base_column_width));
155 }
156
157 let str_custom_height = self.custom_height.get_value_string();
158 if self.custom_height.has_value() {
159 attributes.push(("customHeight", &str_custom_height));
160 }
161
162 let str_default_column_width = self.default_column_width.get_value_string();
163 if self.default_column_width.has_value() {
164 attributes.push(("defaultColWidth", &str_default_column_width));
165 }
166
167 let str_default_row_height = self.default_row_height.get_value_string();
168 if self.default_row_height.has_value() {
169 attributes.push(("defaultRowHeight", &str_default_row_height));
170 }
171
172 let str_dy_descent = self.dy_descent.get_value_string();
173 if self.dy_descent.has_value() {
174 attributes.push(("x14ac:dyDescent", &str_dy_descent));
175 }
176
177 let str_outline_level_column = self.outline_level_column.get_value_string();
178 if self.outline_level_column.has_value() {
179 attributes.push(("outlineLevelCol", &str_outline_level_column));
180 }
181
182 let str_outline_level_row = self.outline_level_row.get_value_string();
183 if self.outline_level_row.has_value() {
184 attributes.push(("outlineLevelRow", &str_outline_level_row));
185 }
186
187 let str_thick_bottom = self.thick_bottom.get_value_string();
188 if self.thick_bottom.has_value() {
189 attributes.push(("thickBottom", &str_thick_bottom));
190 }
191
192 let str_thick_top = self.thick_top.get_value_string();
193 if self.thick_top.has_value() {
194 attributes.push(("thickTop", &str_thick_top));
195 }
196
197 write_start_tag(writer, "sheetFormatPr", attributes, true);
198 }
199}