umya-spreadsheet 3.0.0

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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
// c:ser
use std::io::Cursor;

use quick_xml::{
    Reader,
    Writer,
    events::{
        BytesStart,
        Event,
    },
};

use super::{
    Bubble3D,
    BubbleSize,
    CategoryAxisData,
    DataLabels,
    Explosion,
    Formula,
    Index,
    InvertIfNegative,
    Marker,
    Order,
    ShapeProperties,
    Smooth,
    Values,
    XValues,
    YValues,
};
use crate::{
    drawing::charts::ChartText,
    structs::Workbook,
    writer::driver::{
        write_end_tag,
        write_start_tag,
    },
    xml_read_loop,
};

#[derive(Clone, Default, Debug)]
pub struct AreaChartSeries {
    index:              Index,
    order:              Order,
    chart_text:         Option<ChartText>,
    explosion:          Option<Explosion>,
    invert_if_negative: Option<InvertIfNegative>,
    marker:             Option<Marker>,
    shape_properties:   Option<ShapeProperties>,
    category_axis_data: Option<CategoryAxisData>,
    values:             Option<Values>,
    x_values:           Option<XValues>,
    y_values:           Option<YValues>,
    bubble_size:        Option<BubbleSize>,
    bubble_3d:          Option<Bubble3D>,
    smooth:             Option<Smooth>,
    data_labels:        Option<DataLabels>,
}

impl AreaChartSeries {
    #[must_use]
    pub fn index(&self) -> &Index {
        &self.index
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use index()")]
    pub fn get_index(&self) -> &Index {
        self.index()
    }

    pub fn index_mut(&mut self) -> &mut Index {
        &mut self.index
    }

    #[deprecated(since = "3.0.0", note = "Use index_mut()")]
    pub fn get_index_mut(&mut self) -> &mut Index {
        self.index_mut()
    }

    pub fn set_index(&mut self, value: Index) -> &mut Self {
        self.index = value;
        self
    }

    #[must_use]
    pub fn order(&self) -> &Order {
        &self.order
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use order()")]
    pub fn get_order(&self) -> &Order {
        self.order()
    }

    pub fn order_mut(&mut self) -> &mut Order {
        &mut self.order
    }

    #[deprecated(since = "3.0.0", note = "Use order_mut()")]
    pub fn get_order_mut(&mut self) -> &mut Order {
        self.order_mut()
    }

    pub fn set_order(&mut self, value: Order) -> &mut Self {
        self.order = value;
        self
    }

    #[must_use]
    pub fn chart_text(&self) -> Option<&ChartText> {
        self.chart_text.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use chart_text()")]
    pub fn get_chart_text(&self) -> Option<&ChartText> {
        self.chart_text()
    }

    pub fn chart_text_mut(&mut self) -> Option<&mut ChartText> {
        self.chart_text.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use chart_text_mut()")]
    pub fn get_chart_text_mut(&mut self) -> Option<&mut ChartText> {
        self.chart_text_mut()
    }

    pub fn set_chart_text(&mut self, value: ChartText) -> &mut Self {
        self.chart_text = Some(value);
        self
    }

    #[must_use]
    pub fn explosion(&self) -> Option<&Explosion> {
        self.explosion.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use explosion()")]
    pub fn get_explosion(&self) -> Option<&Explosion> {
        self.explosion()
    }

    pub fn explosion_mut(&mut self) -> Option<&mut Explosion> {
        self.explosion.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use explosion_mut()")]
    pub fn get_explosion_mut(&mut self) -> Option<&mut Explosion> {
        self.explosion_mut()
    }

    pub fn set_explosion(&mut self, value: Explosion) -> &mut Self {
        self.explosion = Some(value);
        self
    }

    #[must_use]
    pub fn invert_if_negative(&self) -> Option<&InvertIfNegative> {
        self.invert_if_negative.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use invert_if_negative()")]
    pub fn get_invert_if_negative(&self) -> Option<&InvertIfNegative> {
        self.invert_if_negative()
    }

    pub fn invert_if_negative_mut(&mut self) -> Option<&mut InvertIfNegative> {
        self.invert_if_negative.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use invert_if_negative_mut()")]
    pub fn get_invert_if_negative_mut(&mut self) -> Option<&mut InvertIfNegative> {
        self.invert_if_negative_mut()
    }

    pub fn set_invert_if_negative(&mut self, value: InvertIfNegative) -> &mut Self {
        self.invert_if_negative = Some(value);
        self
    }

    #[must_use]
    pub fn marker(&self) -> Option<&Marker> {
        self.marker.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use marker()")]
    pub fn get_marker(&self) -> Option<&Marker> {
        self.marker()
    }

    pub fn marker_mut(&mut self) -> Option<&mut Marker> {
        self.marker.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use marker_mut()")]
    pub fn get_marker_mut(&mut self) -> Option<&mut Marker> {
        self.marker_mut()
    }

    pub fn set_marker(&mut self, value: Marker) -> &mut Self {
        self.marker = Some(value);
        self
    }

    #[must_use]
    pub fn shape_properties(&self) -> Option<&ShapeProperties> {
        self.shape_properties.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use shape_properties()")]
    pub fn get_shape_properties(&self) -> Option<&ShapeProperties> {
        self.shape_properties()
    }

    pub fn shape_properties_mut(&mut self) -> Option<&mut ShapeProperties> {
        self.shape_properties.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use shape_properties_mut()")]
    pub fn get_shape_properties_mut(&mut self) -> Option<&mut ShapeProperties> {
        self.shape_properties_mut()
    }

    pub fn set_shape_properties(&mut self, value: ShapeProperties) -> &mut Self {
        self.shape_properties = Some(value);
        self
    }

    #[must_use]
    pub fn category_axis_data(&self) -> Option<&CategoryAxisData> {
        self.category_axis_data.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use category_axis_data()")]
    pub fn get_category_axis_data(&self) -> Option<&CategoryAxisData> {
        self.category_axis_data()
    }

    pub fn category_axis_data_mut(&mut self) -> Option<&mut CategoryAxisData> {
        self.category_axis_data.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use category_axis_data_mut()")]
    pub fn get_category_axis_data_mut(&mut self) -> Option<&mut CategoryAxisData> {
        self.category_axis_data_mut()
    }

    pub fn set_category_axis_data(&mut self, value: CategoryAxisData) -> &mut Self {
        self.category_axis_data = Some(value);
        self
    }

    #[must_use]
    pub fn values(&self) -> Option<&Values> {
        self.values.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use values()")]
    pub fn get_values(&self) -> Option<&Values> {
        self.values()
    }

    pub fn values_mut(&mut self) -> Option<&mut Values> {
        self.values.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use values_mut()")]
    pub fn get_values_mut(&mut self) -> Option<&mut Values> {
        self.values_mut()
    }

    pub fn set_values(&mut self, value: Values) -> &mut Self {
        self.values = Some(value);
        self
    }

    #[must_use]
    pub fn x_values(&self) -> Option<&XValues> {
        self.x_values.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use x_values()")]
    pub fn get_x_values(&self) -> Option<&XValues> {
        self.x_values()
    }

    pub fn x_values_mut(&mut self) -> Option<&mut XValues> {
        self.x_values.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use x_values_mut()")]
    pub fn get_x_values_mut(&mut self) -> Option<&mut XValues> {
        self.x_values_mut()
    }

    pub fn set_x_values(&mut self, value: XValues) -> &mut Self {
        self.x_values = Some(value);
        self
    }

    #[must_use]
    pub fn y_values(&self) -> Option<&YValues> {
        self.y_values.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use y_values()")]
    pub fn get_y_values(&self) -> Option<&YValues> {
        self.y_values()
    }

    pub fn y_values_mut(&mut self) -> Option<&mut YValues> {
        self.y_values.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use y_values_mut()")]
    pub fn get_y_values_mut(&mut self) -> Option<&mut YValues> {
        self.y_values_mut()
    }

    pub fn set_y_values(&mut self, value: YValues) -> &mut Self {
        self.y_values = Some(value);
        self
    }

    #[must_use]
    pub fn bubble_size(&self) -> Option<&BubbleSize> {
        self.bubble_size.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use bubble_size()")]
    pub fn get_bubble_size(&self) -> Option<&BubbleSize> {
        self.bubble_size()
    }

    pub fn bubble_size_mut(&mut self) -> Option<&mut BubbleSize> {
        self.bubble_size.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use bubble_size_mut()")]
    pub fn get_bubble_size_mut(&mut self) -> Option<&mut BubbleSize> {
        self.bubble_size_mut()
    }

    pub fn set_bubble_size(&mut self, value: BubbleSize) -> &mut Self {
        self.bubble_size = Some(value);
        self
    }

    #[must_use]
    pub fn bubble_3d(&self) -> Option<&Bubble3D> {
        self.bubble_3d.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use bubble_3d()")]
    pub fn get_bubble_3d(&self) -> Option<&Bubble3D> {
        self.bubble_3d()
    }

    pub fn bubble_3d_mut(&mut self) -> Option<&mut Bubble3D> {
        self.bubble_3d.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use bubble_3d_mut()")]
    pub fn get_bubble_3d_mut(&mut self) -> Option<&mut Bubble3D> {
        self.bubble_3d_mut()
    }

    pub fn set_bubble_3d(&mut self, value: Bubble3D) -> &mut Self {
        self.bubble_3d = Some(value);
        self
    }

    #[must_use]
    pub fn smooth(&self) -> Option<&Smooth> {
        self.smooth.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use smooth()")]
    pub fn get_smooth(&self) -> Option<&Smooth> {
        self.smooth()
    }

    pub fn smooth_mut(&mut self) -> Option<&mut Smooth> {
        self.smooth.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use smooth_mut()")]
    pub fn get_smooth_mut(&mut self) -> Option<&mut Smooth> {
        self.smooth_mut()
    }

    pub fn set_smooth(&mut self, value: Smooth) -> &mut Self {
        self.smooth = Some(value);
        self
    }

    #[must_use]
    pub fn data_labels(&self) -> Option<&DataLabels> {
        self.data_labels.as_ref()
    }

    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use data_labels()")]
    pub fn get_data_labels(&self) -> Option<&DataLabels> {
        self.data_labels()
    }

    pub fn data_labels_mut(&mut self) -> Option<&mut DataLabels> {
        self.data_labels.as_mut()
    }

    #[deprecated(since = "3.0.0", note = "Use data_labels_mut()")]
    pub fn get_data_labels_mut(&mut self) -> Option<&mut DataLabels> {
        self.data_labels_mut()
    }

    pub fn set_data_labels(&mut self, value: DataLabels) -> &mut Self {
        self.data_labels = Some(value);
        self
    }

    pub fn formula_mut(&mut self) -> Vec<&mut Formula> {
        let mut result: Vec<&mut Formula> = Vec::default();

        if let Some(v) = &mut self.category_axis_data {
            if let Some(h) = v.string_reference_mut() {
                result.push(h.formula_mut());
            }
        }
        if let Some(v) = &mut self.values {
            result.push(v.number_reference_mut().formula_mut());
        }
        if let Some(v) = &mut self.x_values {
            result.push(v.number_reference_mut().formula_mut());
        }
        if let Some(v) = &mut self.y_values {
            result.push(v.number_reference_mut().formula_mut());
        }
        if let Some(v) = &mut self.bubble_size {
            result.push(v.number_reference_mut().formula_mut());
        }
        result
    }

    #[deprecated(since = "3.0.0", note = "Use formula_mut()")]
    pub fn get_formula_mut(&mut self) -> Vec<&mut Formula> {
        self.formula_mut()
    }

    pub(crate) fn set_attributes<R: std::io::BufRead>(
        &mut self,
        reader: &mut Reader<R>,
        _e: &BytesStart,
    ) {
        xml_read_loop!(
            reader,
            Event::Start(ref e) => match e.name().into_inner() {
                b"c:tx" => {
                    let mut obj = ChartText::default();
                    obj.set_attributes(reader, e);
                    self.set_chart_text(obj);
                }
                b"c:marker" => {
                    let mut obj = Marker::default();
                    obj.set_attributes(reader, e, false);
                    self.set_marker(obj);
                }
                b"c:spPr" => {
                    let mut obj = ShapeProperties::default();
                    obj.set_attributes(reader, e);
                    self.set_shape_properties(obj);
                }
                b"c:cat" => {
                    let mut obj = CategoryAxisData::default();
                    obj.set_attributes(reader, e);
                    self.set_category_axis_data(obj);
                }
                b"c:val" => {
                    let mut obj = Values::default();
                    obj.set_attributes(reader, e);
                    self.set_values(obj);
                }
                b"c:xVal" => {
                    let mut obj = XValues::default();
                    obj.set_attributes(reader, e);
                    self.set_x_values(obj);
                }
                b"c:yVal" => {
                    let mut obj = YValues::default();
                    obj.set_attributes(reader, e);
                    self.set_y_values(obj);
                }
                b"c:bubbleSize" => {
                    let mut obj = BubbleSize::default();
                    obj.set_attributes(reader, e);
                    self.set_bubble_size(obj);
                }
                b"c:dLbls" => {
                    let mut obj = DataLabels::default();
                    obj.set_attributes(reader, e);
                    self.set_data_labels(obj);
                }
                _ => (),
            },
            Event::Empty(ref e) => match e.name().into_inner() {
                b"c:idx" => {
                    self.index.set_attributes(reader, e);
                }
                b"c:order" => {
                    self.order.set_attributes(reader, e);
                }
                b"c:explosion" => {
                    let mut obj = Explosion::default();
                    obj.set_attributes(reader, e);
                    self.set_explosion(obj);
                }
                b"c:invertIfNegative" => {
                    let mut obj = InvertIfNegative::default();
                    obj.set_attributes(reader, e);
                    self.set_invert_if_negative(obj);
                }
                b"c:bubble3D" => {
                    let mut obj = Bubble3D::default();
                    obj.set_attributes(reader, e);
                    self.set_bubble_3d(obj);
                }
                b"c:smooth" => {
                    let mut obj = Smooth::default();
                    obj.set_attributes(reader, e);
                    self.set_smooth(obj);
                }
                _ => (),
            },
            Event::End(ref e) => {
                if e.name().into_inner() == b"c:ser" {
                    return;
                }
            },
            Event::Eof => panic!("Error: Could not find {} end element", "c:ser"),
        );
    }

    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, wb: &Workbook) {
        // c:ser
        write_start_tag(writer, "c:ser", vec![], false);

        // c:idx
        self.index.write_to(writer);

        // c:order
        self.order.write_to(writer);

        // c:tx
        if let Some(v) = &self.chart_text {
            v.write_to(writer, wb);
        }

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

        // c:invertIfNegative
        if let Some(v) = &self.invert_if_negative {
            v.write_to(writer);
        }

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

        // c:spPr
        if let Some(v) = &self.shape_properties {
            v.write_to(writer);
        }

        // c:dLbls
        if let Some(v) = &self.data_labels {
            v.write_to(writer);
        }

        // c:cat
        if let Some(v) = &self.category_axis_data {
            v.write_to(writer, wb);
        }

        // c:val
        if let Some(v) = &self.values {
            v.write_to(writer, wb);
        }

        // c:xVal
        if let Some(v) = &self.x_values {
            v.write_to(writer, wb);
        }

        // c:yVal
        if let Some(v) = &self.y_values {
            v.write_to(writer, wb);
        }

        // c:bubbleSize
        if let Some(v) = &self.bubble_size {
            v.write_to(writer, wb);
        }

        // c:bubble3D
        if let Some(v) = &self.bubble_3d {
            v.write_to(writer);
        }

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

        write_end_tag(writer, "c:ser");
    }
}