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