umya_spreadsheet/structs/
pivot_table_definition.rs

1// pivotTableDefinition
2use crate::helper::const_str::*;
3use crate::reader::driver::*;
4use crate::structs::BooleanValue;
5use crate::structs::ByteValue;
6use crate::structs::ColumnFields;
7use crate::structs::ColumnItems;
8use crate::structs::DataFields;
9use crate::structs::Location;
10use crate::structs::PivotFields;
11use crate::structs::PivotTableStyle;
12use crate::structs::RowItems;
13use crate::structs::StringValue;
14use crate::structs::UInt32Value;
15use crate::writer::driver::*;
16use quick_xml::events::{BytesStart, Event};
17use quick_xml::Reader;
18use quick_xml::Writer;
19use std::io::Cursor;
20
21#[derive(Clone, Default, Debug)]
22pub struct PivotTableDefinition {
23    apply_number_formats: BooleanValue,
24    apply_border_formats: BooleanValue,
25    apply_font_formats: BooleanValue,
26    apply_pattern_formats: BooleanValue,
27    apply_alignment_formats: BooleanValue,
28    apply_width_height_formats: BooleanValue,
29    use_auto_formatting: BooleanValue,
30    item_print_titles: BooleanValue,
31    outline: BooleanValue,
32    outline_data: BooleanValue,
33    multiple_field_filters: BooleanValue,
34    name: StringValue,
35    cache_id: UInt32Value,
36    indent: UInt32Value,
37    local_name: StringValue,
38    data_caption: StringValue,
39    updated_version: ByteValue,
40    min_refreshable_version: ByteValue,
41    created_version: ByteValue,
42    location: Location,
43    pivot_fields: PivotFields,
44    row_items: RowItems,
45    column_fields: ColumnFields,
46    column_items: ColumnItems,
47    data_fields: DataFields,
48    pivot_table_style: PivotTableStyle,
49}
50impl PivotTableDefinition {
51    #[inline]
52    pub fn get_apply_number_formats(&self) -> &bool {
53        self.apply_number_formats.get_value()
54    }
55
56    #[inline]
57    pub fn set_apply_number_formats(&mut self, value: bool) -> &mut Self {
58        self.apply_number_formats.set_value(value);
59        self
60    }
61
62    #[inline]
63    pub fn get_apply_border_formats(&self) -> &bool {
64        self.apply_border_formats.get_value()
65    }
66
67    #[inline]
68    pub fn set_apply_border_formats(&mut self, value: bool) -> &mut Self {
69        self.apply_border_formats.set_value(value);
70        self
71    }
72
73    #[inline]
74    pub fn get_apply_font_formats(&self) -> &bool {
75        self.apply_font_formats.get_value()
76    }
77
78    #[inline]
79    pub fn set_apply_font_formats(&mut self, value: bool) -> &mut Self {
80        self.apply_font_formats.set_value(value);
81        self
82    }
83
84    #[inline]
85    pub fn get_apply_pattern_formats(&self) -> &bool {
86        self.apply_pattern_formats.get_value()
87    }
88
89    #[inline]
90    pub fn set_apply_pattern_formats(&mut self, value: bool) -> &mut Self {
91        self.apply_pattern_formats.set_value(value);
92        self
93    }
94
95    #[inline]
96    pub fn get_apply_alignment_formats(&self) -> &bool {
97        self.apply_alignment_formats.get_value()
98    }
99
100    #[inline]
101    pub fn set_apply_alignment_formats(&mut self, value: bool) -> &mut Self {
102        self.apply_alignment_formats.set_value(value);
103        self
104    }
105
106    #[inline]
107    pub fn get_apply_width_height_formats(&self) -> &bool {
108        self.apply_width_height_formats.get_value()
109    }
110
111    #[inline]
112    pub fn set_apply_width_height_formats(&mut self, value: bool) -> &mut Self {
113        self.apply_width_height_formats.set_value(value);
114        self
115    }
116
117    #[inline]
118    pub fn get_use_auto_formatting(&self) -> &bool {
119        self.use_auto_formatting.get_value()
120    }
121
122    #[inline]
123    pub fn set_use_auto_formatting(&mut self, value: bool) -> &mut Self {
124        self.use_auto_formatting.set_value(value);
125        self
126    }
127
128    #[inline]
129    pub fn get_item_print_titles(&self) -> &bool {
130        self.item_print_titles.get_value()
131    }
132
133    #[inline]
134    pub fn set_item_print_titles(&mut self, value: bool) -> &mut Self {
135        self.item_print_titles.set_value(value);
136        self
137    }
138
139    #[inline]
140    pub fn get_outline(&self) -> &bool {
141        self.outline.get_value()
142    }
143
144    #[inline]
145    pub fn set_outline(&mut self, value: bool) -> &mut Self {
146        self.outline.set_value(value);
147        self
148    }
149
150    #[inline]
151    pub fn get_outline_data(&self) -> &bool {
152        self.outline_data.get_value()
153    }
154
155    #[inline]
156    pub fn set_outline_data(&mut self, value: bool) -> &mut Self {
157        self.outline_data.set_value(value);
158        self
159    }
160
161    #[inline]
162    pub fn get_multiple_field_filters(&self) -> &bool {
163        self.multiple_field_filters.get_value()
164    }
165
166    #[inline]
167    pub fn set_multiple_field_filters(&mut self, value: bool) -> &mut Self {
168        self.multiple_field_filters.set_value(value);
169        self
170    }
171
172    #[inline]
173    pub fn get_name(&self) -> &str {
174        self.name.get_value_str()
175    }
176
177    #[inline]
178    pub fn set_name<S: Into<String>>(&mut self, value: S) -> &mut Self {
179        self.name.set_value(value);
180        self
181    }
182
183    #[inline]
184    pub fn get_cache_id(&self) -> &u32 {
185        self.cache_id.get_value()
186    }
187
188    #[inline]
189    pub fn set_cache_id(&mut self, value: u32) -> &mut Self {
190        self.cache_id.set_value(value);
191        self
192    }
193
194    #[inline]
195    pub fn get_indent(&self) -> &u32 {
196        self.indent.get_value()
197    }
198
199    #[inline]
200    pub fn set_indent(&mut self, value: u32) -> &mut Self {
201        self.indent.set_value(value);
202        self
203    }
204
205    #[inline]
206    pub fn get_local_name(&self) -> &str {
207        self.local_name.get_value_str()
208    }
209
210    #[inline]
211    pub fn set_local_name<S: Into<String>>(&mut self, value: S) -> &mut Self {
212        self.local_name.set_value(value);
213        self
214    }
215
216    #[inline]
217    pub fn get_data_caption(&self) -> &str {
218        self.data_caption.get_value_str()
219    }
220
221    #[inline]
222    pub fn set_data_caption<S: Into<String>>(&mut self, value: S) -> &mut Self {
223        self.data_caption.set_value(value);
224        self
225    }
226
227    #[inline]
228    pub fn get_updated_version(&self) -> &u8 {
229        self.updated_version.get_value()
230    }
231
232    #[inline]
233    pub fn set_updated_version(&mut self, value: u8) -> &mut Self {
234        self.updated_version.set_value(value);
235        self
236    }
237
238    #[inline]
239    pub fn get_min_refreshable_version(&self) -> &u8 {
240        self.min_refreshable_version.get_value()
241    }
242
243    #[inline]
244    pub fn set_min_refreshable_version(&mut self, value: u8) -> &mut Self {
245        self.min_refreshable_version.set_value(value);
246        self
247    }
248
249    #[inline]
250    pub fn get_created_version(&self) -> &u8 {
251        self.created_version.get_value()
252    }
253
254    #[inline]
255    pub fn set_created_version(&mut self, value: u8) -> &mut Self {
256        self.created_version.set_value(value);
257        self
258    }
259
260    #[inline]
261    pub fn get_location(&self) -> &Location {
262        &self.location
263    }
264
265    #[inline]
266    pub fn get_location_mut(&mut self) -> &mut Location {
267        &mut self.location
268    }
269
270    #[inline]
271    pub fn set_location(&mut self, value: Location) -> &mut Self {
272        self.location = value;
273        self
274    }
275
276    #[inline]
277    pub fn get_pivot_fields(&self) -> &PivotFields {
278        &self.pivot_fields
279    }
280
281    #[inline]
282    pub fn get_pivot_fields_mut(&mut self) -> &mut PivotFields {
283        &mut self.pivot_fields
284    }
285
286    #[inline]
287    pub fn set_pivot_fields(&mut self, value: PivotFields) -> &mut Self {
288        self.pivot_fields = value;
289        self
290    }
291
292    #[inline]
293    pub fn get_row_items(&self) -> &RowItems {
294        &self.row_items
295    }
296
297    #[inline]
298    pub fn get_row_items_mut(&mut self) -> &mut RowItems {
299        &mut self.row_items
300    }
301
302    #[inline]
303    pub fn set_row_items(&mut self, value: RowItems) -> &mut Self {
304        self.row_items = value;
305        self
306    }
307
308    #[inline]
309    pub fn get_column_fields(&self) -> &ColumnFields {
310        &self.column_fields
311    }
312
313    #[inline]
314    pub fn get_column_fields_mut(&mut self) -> &mut ColumnFields {
315        &mut self.column_fields
316    }
317
318    #[inline]
319    pub fn set_column_fields(&mut self, value: ColumnFields) -> &mut Self {
320        self.column_fields = value;
321        self
322    }
323
324    #[inline]
325    pub fn get_column_items(&self) -> &ColumnItems {
326        &self.column_items
327    }
328
329    #[inline]
330    pub fn get_column_items_mut(&mut self) -> &mut ColumnItems {
331        &mut self.column_items
332    }
333
334    #[inline]
335    pub fn set_column_items(&mut self, value: ColumnItems) -> &mut Self {
336        self.column_items = value;
337        self
338    }
339
340    #[inline]
341    pub fn get_data_fields(&self) -> &DataFields {
342        &self.data_fields
343    }
344
345    #[inline]
346    pub fn get_data_fields_mut(&mut self) -> &mut DataFields {
347        &mut self.data_fields
348    }
349
350    #[inline]
351    pub fn set_data_fields(&mut self, value: DataFields) -> &mut Self {
352        self.data_fields = value;
353        self
354    }
355
356    #[inline]
357    pub fn get_pivot_table_style(&self) -> &PivotTableStyle {
358        &self.pivot_table_style
359    }
360
361    #[inline]
362    pub fn get_pivot_table_style_mut(&mut self) -> &mut PivotTableStyle {
363        &mut self.pivot_table_style
364    }
365
366    #[inline]
367    pub fn set_pivot_table_style(&mut self, value: PivotTableStyle) -> &mut Self {
368        self.pivot_table_style = value;
369        self
370    }
371
372    #[inline]
373    pub(crate) fn set_attributes<R: std::io::BufRead>(
374        &mut self,
375        reader: &mut Reader<R>,
376        e: &BytesStart,
377    ) {
378        set_string_from_xml!(self, e, name, "name");
379        set_string_from_xml!(self, e, cache_id, "cacheId");
380        set_string_from_xml!(self, e, apply_number_formats, "applyNumberFormats");
381        set_string_from_xml!(self, e, apply_border_formats, "applyBorderFormats");
382        set_string_from_xml!(self, e, apply_font_formats, "applyFontFormats");
383        set_string_from_xml!(self, e, apply_pattern_formats, "applyPatternFormats");
384        set_string_from_xml!(self, e, apply_alignment_formats, "applyAlignmentFormats");
385        set_string_from_xml!(
386            self,
387            e,
388            apply_width_height_formats,
389            "applyWidthHeightFormats"
390        );
391        set_string_from_xml!(self, e, data_caption, "dataCaption");
392        set_string_from_xml!(self, e, updated_version, "updatedVersion");
393        set_string_from_xml!(self, e, min_refreshable_version, "minRefreshableVersion");
394        set_string_from_xml!(self, e, use_auto_formatting, "useAutoFormatting");
395        set_string_from_xml!(self, e, item_print_titles, "itemPrintTitles");
396        set_string_from_xml!(self, e, created_version, "createdVersion");
397        set_string_from_xml!(self, e, indent, "indent");
398        set_string_from_xml!(self, e, outline, "outline");
399        set_string_from_xml!(self, e, outline_data, "outlineData");
400        set_string_from_xml!(self, e, multiple_field_filters, "multipleFieldFilters");
401
402        xml_read_loop!(
403            reader,
404            Event::Empty(ref e) => {
405                if e.name().into_inner() == b"location" {
406                    let mut obj = Location::default();
407                    obj.set_attributes(reader, e);
408                    self.set_location(obj);
409                }
410                if e.name().into_inner() == b"pivotTableStyleInfo" {
411                    let mut obj = PivotTableStyle::default();
412                    obj.set_attributes(reader, e);
413                    self.set_pivot_table_style(obj);
414                }
415            },
416            Event::Start(ref e) => {
417                if e.name().into_inner() == b"pivotFields" {
418                    let mut obj = PivotFields::default();
419                    obj.set_attributes(reader, e);
420                    self.set_pivot_fields(obj);
421                }
422                if e.name().into_inner() == b"rowItems" {
423                    let mut obj = RowItems::default();
424                    obj.set_attributes(reader, e);
425                    self.set_row_items(obj);
426                }
427                if e.name().into_inner() == b"colFields" {
428                    let mut obj = ColumnFields::default();
429                    obj.set_attributes(reader, e);
430                    self.set_column_fields(obj);
431                }
432                if e.name().into_inner() == b"colItems" {
433                    let mut obj = ColumnItems::default();
434                    obj.set_attributes(reader, e);
435                    self.set_column_items(obj);
436                }
437                if e.name().into_inner() == b"dataFields" {
438                    let mut obj = DataFields::default();
439                    obj.set_attributes(reader, e);
440                    self.set_data_fields(obj);
441                }
442            },
443            Event::End(ref e) => {
444                if e.name().into_inner() == b"pivotTableDefinition" {
445                    return
446                }
447            },
448            Event::Eof => panic!("Error: Could not find {} end element", "pivotTableDefinition")
449        );
450    }
451
452    #[inline]
453    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
454        // pivotTableDefinition
455        let mut attributes: Vec<(&str, &str)> = Vec::new();
456        attributes.push(("xmlns", SHEET_MAIN_NS));
457        attributes.push(("xmlns:mc", MC_NS));
458        attributes.push(("mc:Ignorable", "xr"));
459        attributes.push(("xmlns:xr", SHEET_MS_REVISION_NS));
460        if self.name.has_value() {
461            attributes.push(("name", self.name.get_value_str()));
462        }
463        let cache_id_str = self.cache_id.get_value_string();
464        if self.cache_id.has_value() {
465            attributes.push(("cacheId", &cache_id_str));
466        }
467        if self.apply_number_formats.has_value() {
468            attributes.push((
469                "applyNumberFormats",
470                self.apply_number_formats.get_value_string(),
471            ));
472        }
473        if self.apply_border_formats.has_value() {
474            attributes.push((
475                "applyBorderFormats",
476                self.apply_border_formats.get_value_string(),
477            ));
478        }
479        if self.apply_font_formats.has_value() {
480            attributes.push((
481                "applyFontFormats",
482                self.apply_font_formats.get_value_string(),
483            ));
484        }
485        if self.apply_pattern_formats.has_value() {
486            attributes.push((
487                "applyPatternFormats",
488                self.apply_pattern_formats.get_value_string(),
489            ));
490        }
491        if self.apply_alignment_formats.has_value() {
492            attributes.push((
493                "applyAlignmentFormats",
494                self.apply_alignment_formats.get_value_string(),
495            ));
496        }
497        if self.apply_width_height_formats.has_value() {
498            attributes.push((
499                "applyWidthHeightFormats",
500                self.apply_width_height_formats.get_value_string(),
501            ));
502        }
503        if self.data_caption.has_value() {
504            attributes.push(("dataCaption", self.data_caption.get_value_str()));
505        }
506        let updated_version_str = self.updated_version.get_value_string();
507        if self.updated_version.has_value() {
508            attributes.push(("updatedVersion", &updated_version_str));
509        }
510        let min_refreshable_version_str = self.min_refreshable_version.get_value_string();
511        if self.min_refreshable_version.has_value() {
512            attributes.push(("minRefreshableVersion", &min_refreshable_version_str));
513        }
514        if self.use_auto_formatting.has_value() {
515            attributes.push((
516                "useAutoFormatting",
517                self.use_auto_formatting.get_value_string(),
518            ));
519        }
520        if self.item_print_titles.has_value() {
521            attributes.push(("itemPrintTitles", self.item_print_titles.get_value_string()));
522        }
523        let created_version_str = self.created_version.get_value_string();
524        if self.created_version.has_value() {
525            attributes.push(("createdVersion", &created_version_str));
526        }
527        let indent_str = self.indent.get_value_string();
528        if self.indent.has_value() {
529            attributes.push(("indent", &indent_str));
530        }
531        if self.outline.has_value() {
532            attributes.push(("outline", self.outline.get_value_string()));
533        }
534        if self.outline_data.has_value() {
535            attributes.push(("outlineData", self.outline_data.get_value_string()));
536        }
537        if self.multiple_field_filters.has_value() {
538            attributes.push((
539                "multipleFieldFilters",
540                self.multiple_field_filters.get_value_string(),
541            ));
542        }
543        write_start_tag(writer, "pivotTableDefinition", attributes, false);
544
545        // location
546        self.location.write_to(writer);
547
548        // pivotFields
549        self.pivot_fields.write_to(writer);
550
551        // rowItems
552        self.row_items.write_to(writer);
553
554        // colFields
555        self.column_fields.write_to(writer);
556
557        // colItems
558        self.column_items.write_to(writer);
559
560        // dataFields
561        self.data_fields.write_to(writer);
562
563        // pivotTableStyleInfo
564        self.pivot_table_style.write_to(writer);
565
566        write_end_tag(writer, "pivotTableDefinition");
567    }
568}