umya-spreadsheet 2.3.3

umya-spreadsheet is a library written in pure Rust to read and write xlsx file.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
// a:ln
use super::Bevel;
use super::GradientFill;
use super::Miter;
use super::NoFill;
use super::PenAlignmentValues;
use super::PresetDash;
use super::Round;
use super::SolidFill;
use super::SystemColor;
use super::TailEnd;
use crate::reader::driver::*;
use crate::structs::EnumValue;
use crate::structs::UInt32Value;
use crate::writer::driver::*;
use crate::StringValue;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use std::io::Cursor;

#[derive(Clone, Default, Debug)]
pub struct Outline {
    width: UInt32Value,
    cap_type: StringValue,
    compound_line_type: StringValue,
    solid_fill: Option<Box<SolidFill>>,
    gradient_fill: Option<Box<GradientFill>>,
    tail_end: Option<Box<TailEnd>>,
    no_fill: Option<NoFill>,
    bevel: Option<Box<Bevel>>,
    preset_dash: Option<PresetDash>,
    miter: Option<Miter>,
    round: Option<Round>,
    alignment: EnumValue<PenAlignmentValues>,
    system_color: Option<Box<SystemColor>>,
}

impl Outline {
    #[inline]
    pub fn get_width(&self) -> &u32 {
        self.width.get_value()
    }

    #[inline]
    pub fn set_width(&mut self, value: u32) -> &mut Self {
        self.width.set_value(value);
        self
    }

    #[inline]
    pub fn get_cap_type(&self) -> Option<&str> {
        self.cap_type.get_value()
    }

    #[inline]
    pub fn set_cap_type<S: Into<String>>(&mut self, value: S) -> &mut Self {
        self.cap_type.set_value(value);
        self
    }

    #[inline]
    pub fn get_compound_line_type(&self) -> Option<&str> {
        self.compound_line_type.get_value()
    }

    #[inline]
    pub fn set_compound_line_type<S: Into<String>>(&mut self, value: S) -> &mut Self {
        self.compound_line_type.set_value(value);
        self
    }

    #[inline]
    pub fn get_solid_fill(&self) -> Option<&SolidFill> {
        self.solid_fill.as_deref()
    }

    #[inline]
    pub fn get_solid_fill_mut(&mut self) -> Option<&mut SolidFill> {
        self.solid_fill.as_deref_mut()
    }

    #[inline]
    pub fn set_solid_fill(&mut self, value: SolidFill) -> &mut Self {
        self.solid_fill = Some(Box::new(value));
        self
    }

    #[inline]
    pub fn get_gradient_fill(&self) -> Option<&GradientFill> {
        self.gradient_fill.as_deref()
    }

    #[inline]
    pub fn get_gradient_fill_mut(&mut self) -> Option<&mut GradientFill> {
        self.gradient_fill.as_deref_mut()
    }

    #[inline]
    pub fn set_gradient_fill(&mut self, value: GradientFill) -> &mut Self {
        self.gradient_fill = Some(Box::new(value));
        self
    }

    #[inline]
    pub fn get_tail_end(&self) -> Option<&TailEnd> {
        self.tail_end.as_deref()
    }

    #[inline]
    pub fn get_tail_end_mut(&mut self) -> Option<&mut TailEnd> {
        self.tail_end.as_deref_mut()
    }

    #[inline]
    pub fn set_tail_end(&mut self, value: TailEnd) -> &mut Self {
        self.tail_end = Some(Box::new(value));
        self
    }

    #[inline]
    pub fn get_no_fill(&self) -> Option<&NoFill> {
        self.no_fill.as_ref()
    }

    #[inline]
    pub fn get_no_fill_mut(&mut self) -> Option<&mut NoFill> {
        self.no_fill.as_mut()
    }

    #[inline]
    pub fn set_no_fill(&mut self, value: NoFill) -> &mut Self {
        self.no_fill = Some(value);
        self
    }

    #[inline]
    pub fn get_bevel(&self) -> Option<&Bevel> {
        self.bevel.as_deref()
    }

    #[inline]
    pub fn get_bevel_mut(&mut self) -> Option<&mut Bevel> {
        self.bevel.as_deref_mut()
    }

    #[inline]
    pub fn set_bevel(&mut self, value: Bevel) -> &mut Self {
        self.bevel = Some(Box::new(value));
        self
    }

    #[inline]
    pub fn get_preset_dash(&self) -> Option<&PresetDash> {
        self.preset_dash.as_ref()
    }

    #[inline]
    pub fn get_preset_dash_mut(&mut self) -> Option<&mut PresetDash> {
        self.preset_dash.as_mut()
    }

    #[inline]
    pub fn set_preset_dash(&mut self, value: PresetDash) -> &mut Self {
        self.preset_dash = Some(value);
        self
    }

    #[inline]
    pub fn get_miter(&self) -> Option<&Miter> {
        self.miter.as_ref()
    }

    #[inline]
    pub fn get_miter_mut(&mut self) -> Option<&mut Miter> {
        self.miter.as_mut()
    }

    #[inline]
    pub fn set_miter(&mut self, value: Miter) -> &mut Self {
        self.miter = Some(value);
        self
    }

    #[inline]
    pub fn get_round(&self) -> Option<&Round> {
        self.round.as_ref()
    }

    #[inline]
    pub fn get_round_mut(&mut self) -> Option<&mut Round> {
        self.round.as_mut()
    }

    #[inline]
    pub fn set_round(&mut self, value: Round) -> &mut Self {
        self.round = Some(value);
        self
    }

    #[inline]
    pub fn get_alignment(&self) -> &PenAlignmentValues {
        self.alignment.get_value()
    }

    #[inline]
    pub fn set_alignment(&mut self, value: PenAlignmentValues) {
        self.alignment.set_value(value);
    }

    #[inline]
    pub fn set_system_color(&mut self, value: SystemColor) {
        self.system_color = Some(Box::new(value));
    }

    #[inline]
    pub fn get_system_color(&self) -> Option<&SystemColor> {
        self.system_color.as_deref()
    }

    #[inline]
    pub fn get_system_color_mut(&mut self) -> Option<&mut SystemColor> {
        self.system_color.as_deref_mut()
    }

    pub(crate) fn set_attributes<R: std::io::BufRead>(
        &mut self,
        reader: &mut Reader<R>,
        e: &BytesStart,
    ) {
        if let Some(v) = get_attribute(e, b"w") {
            self.set_width(v.parse::<u32>().unwrap());
        }

        if let Some(v) = get_attribute(e, b"cap") {
            self.set_cap_type(v);
        }

        if let Some(v) = get_attribute(e, b"cmpd") {
            self.set_compound_line_type(v);
        }

        set_string_from_xml!(self, e, alignment, "algn");

        xml_read_loop!(
            reader,
            Event::Start(ref e) => {
                match e.name().into_inner() {
                    b"a:solidFill" => {
                        let mut solid_fill = SolidFill::default();
                        solid_fill.set_attributes(reader, e);
                        self.set_solid_fill(solid_fill);
                    }
                    b"a:gradFill" => {
                        let mut obj = GradientFill::default();
                        obj.set_attributes(reader, e);
                        self.set_gradient_fill(obj);
                    }
                    b"a:tailEnd" => {
                        let mut obj = TailEnd::default();
                        obj.set_attributes(reader, e, false);
                        self.set_tail_end(obj);
                    }
                    b"a:noFill" => {
                        let mut obj = NoFill::default();
                        obj.set_attributes(reader, e, false);
                        self.set_no_fill(obj);
                    }
                    b"a:bevel" => {
                        let mut obj = Bevel::default();
                        obj.set_attributes(reader, e, false);
                        self.set_bevel(obj);
                    }
                    b"a:miter" => {
                        let mut obj = Miter::default();
                        obj.set_attributes(reader, e, false);
                        self.set_miter(obj);
                    }
                    b"a:prstDash" => {
                        let mut obj = PresetDash::default();
                        obj.set_attributes(reader, e, false);
                        self.set_preset_dash(obj);
                    }
                    b"a:round" => {
                        let mut obj = Round::default();
                        obj.set_attributes(reader, e, false);
                        self.set_round(obj);
                    }
                    b"a:sysClr" => {
                        let mut obj = SystemColor::default();
                        obj.set_attributes(reader, e, false);
                        self.set_system_color(obj);
                    }
                    _ => (),
                }
            },
            Event::Empty(ref e) => {
                match e.name().into_inner() {
                    b"a:tailEnd" => {
                        let mut obj = TailEnd::default();
                        obj.set_attributes(reader, e, true);
                        self.set_tail_end(obj);
                    }
                    b"a:noFill" => {
                        let mut obj = NoFill::default();
                        obj.set_attributes(reader, e, true);
                        self.set_no_fill(obj);
                    }
                    b"a:bevel" => {
                        let mut obj = Bevel::default();
                        obj.set_attributes(reader, e, true);
                        self.set_bevel(obj);
                    }
                    b"a:miter" => {
                        let mut obj = Miter::default();
                        obj.set_attributes(reader, e, true);
                        self.set_miter(obj);
                    }
                    b"a:prstDash" => {
                        let mut obj = PresetDash::default();
                        obj.set_attributes(reader, e, true);
                        self.set_preset_dash(obj);
                    }
                    b"a:round" => {
                        let mut obj = Round::default();
                        obj.set_attributes(reader, e, true);
                        self.set_round(obj);
                    }
                    b"a:sysClr" => {
                        let mut obj = SystemColor::default();
                        obj.set_attributes(reader, e, true);
                        self.set_system_color(obj);
                    }
                    _ => (),
                }
            },
            Event::End(ref e) => {
                if  e.name().into_inner() == b"a:ln" {
                    return;
                }
            },
            Event::Eof => panic!("Error: Could not find {} end element", "a:ln")
        );
    }

    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
        // a:ln
        let mut attributes: Vec<(&str, &str)> = Vec::new();
        let width = self.width.get_value_string();
        if self.width.has_value() {
            attributes.push(("w", &width));
        }
        if let Some(v) = self.cap_type.get_value() {
            attributes.push(("cap", v));
        }
        if let Some(v) = self.compound_line_type.get_value() {
            attributes.push(("cmpd", v));
        }
        if self.alignment.has_value() {
            attributes.push(("algn", (self.alignment.get_value_string())));
        }
        write_start_tag(writer, "a:ln", attributes, false);

        // a:solidFill
        if let Some(v) = &self.solid_fill {
            v.write_to(writer);
        }

        // a:gradFill
        if let Some(v) = &self.gradient_fill {
            v.write_to(writer);
        }

        // a:round
        if let Some(v) = &self.round {
            v.write_to(writer);
        }

        // a:tailEnd
        if let Some(v) = &self.tail_end {
            v.write_to(writer);
        }

        // a:noFill
        if let Some(v) = &self.no_fill {
            v.write_to(writer);
        }

        // a:bevel
        if let Some(v) = &self.bevel {
            v.write_to(writer);
        }

        // a:prstDash
        if let Some(v) = &self.preset_dash {
            v.write_to(writer);
        }

        // a:miter
        if let Some(v) = &self.miter {
            v.write_to(writer);
        }

        write_end_tag(writer, "a:ln");
    }
}