1use get_size::GetSize;
6use get_size_derive::GetSize;
7use std::borrow::Borrow;
8use std::fmt;
9use std::fmt::Formatter;
10use std::hash::Hash;
11
12use icu_locid::{locale, Locale};
13
14use crate::config::Config;
15use crate::defaultstyles::{DefaultFormat, DefaultStyle};
16use crate::ds::detach::{Detach, Detached};
17use crate::format::ValueFormatTrait;
18use crate::io::read::default_settings;
19use crate::io::NamespaceMap;
20use crate::manifest::Manifest;
21use crate::metadata::Metadata;
22use crate::sheet_::Sheet;
23use crate::style::{
24 ColStyle, ColStyleRef, FontFaceDecl, GraphicStyle, GraphicStyleRef, MasterPage, MasterPageRef,
25 PageStyle, PageStyleRef, ParagraphStyle, ParagraphStyleRef, RowStyle, RowStyleRef, RubyStyle,
26 RubyStyleRef, TableStyle, TableStyleRef, TextStyle, TextStyleRef,
27};
28use crate::validation::{Validation, ValidationRef};
29use crate::value_::ValueType;
30use crate::xlink::{XLinkActuate, XLinkType};
31use crate::xmltree::{XmlContent, XmlTag};
32use crate::{
33 locale, CellStyle, CellStyleRef, HashMap, ValueFormatBoolean, ValueFormatCurrency,
34 ValueFormatDateTime, ValueFormatNumber, ValueFormatPercentage, ValueFormatRef, ValueFormatText,
35 ValueFormatTimeDuration,
36};
37
38#[derive(Clone, GetSize)]
40pub struct WorkBook {
41 pub(crate) sheets: Vec<Detach<Sheet>>,
43
44 pub(crate) version: String,
46
47 pub(crate) fonts: HashMap<String, FontFaceDecl>,
49
50 pub(crate) autonum: HashMap<String, u32>,
52
53 pub(crate) scripts: Vec<Script>,
55 pub(crate) event_listener: HashMap<String, EventListener>,
56
57 pub(crate) tablestyles: HashMap<TableStyleRef, TableStyle>,
59 pub(crate) rowstyles: HashMap<RowStyleRef, RowStyle>,
60 pub(crate) colstyles: HashMap<ColStyleRef, ColStyle>,
61 pub(crate) cellstyles: HashMap<CellStyleRef, CellStyle>,
62 pub(crate) paragraphstyles: HashMap<ParagraphStyleRef, ParagraphStyle>,
63 pub(crate) textstyles: HashMap<TextStyleRef, TextStyle>,
64 pub(crate) rubystyles: HashMap<RubyStyleRef, RubyStyle>,
65 pub(crate) graphicstyles: HashMap<GraphicStyleRef, GraphicStyle>,
66
67 pub(crate) formats_boolean: HashMap<String, ValueFormatBoolean>,
70 pub(crate) formats_number: HashMap<String, ValueFormatNumber>,
71 pub(crate) formats_percentage: HashMap<String, ValueFormatPercentage>,
72 pub(crate) formats_currency: HashMap<String, ValueFormatCurrency>,
73 pub(crate) formats_text: HashMap<String, ValueFormatText>,
74 pub(crate) formats_datetime: HashMap<String, ValueFormatDateTime>,
75 pub(crate) formats_timeduration: HashMap<String, ValueFormatTimeDuration>,
76
77 pub(crate) def_styles: HashMap<ValueType, CellStyleRef>,
80
81 pub(crate) pagestyles: HashMap<PageStyleRef, PageStyle>,
83 pub(crate) masterpages: HashMap<MasterPageRef, MasterPage>,
84
85 pub(crate) validations: HashMap<ValidationRef, Validation>,
87
88 pub(crate) config: Detach<Config>,
91 pub(crate) workbook_config: WorkBookConfig,
93 pub(crate) xmlns: HashMap<String, NamespaceMap>,
95
96 pub(crate) manifest: HashMap<String, Manifest>,
98
99 pub(crate) metadata: Metadata,
101
102 pub(crate) extra: Vec<XmlTag>,
104}
105
106impl fmt::Debug for WorkBook {
107 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
108 writeln!(f, "{:?}", self.version)?;
109 for s in self.sheets.iter() {
110 writeln!(f, "{:?}", s)?;
111 }
112 for s in self.fonts.values() {
113 writeln!(f, "{:?}", s)?;
114 }
115 for s in self.tablestyles.values() {
116 writeln!(f, "{:?}", s)?;
117 }
118 for s in self.rowstyles.values() {
119 writeln!(f, "{:?}", s)?;
120 }
121 for s in self.colstyles.values() {
122 writeln!(f, "{:?}", s)?;
123 }
124 for s in self.cellstyles.values() {
125 writeln!(f, "{:?}", s)?;
126 }
127 for s in self.paragraphstyles.values() {
128 writeln!(f, "{:?}", s)?;
129 }
130 for s in self.textstyles.values() {
131 writeln!(f, "{:?}", s)?;
132 }
133 for s in self.rubystyles.values() {
134 writeln!(f, "{:?}", s)?;
135 }
136 for s in self.graphicstyles.values() {
137 writeln!(f, "{:?}", s)?;
138 }
139 for s in self.formats_boolean.values() {
140 writeln!(f, "{:?}", s)?;
141 }
142 for s in self.formats_number.values() {
143 writeln!(f, "{:?}", s)?;
144 }
145 for s in self.formats_percentage.values() {
146 writeln!(f, "{:?}", s)?;
147 }
148 for s in self.formats_currency.values() {
149 writeln!(f, "{:?}", s)?;
150 }
151 for s in self.formats_text.values() {
152 writeln!(f, "{:?}", s)?;
153 }
154 for s in self.formats_datetime.values() {
155 writeln!(f, "{:?}", s)?;
156 }
157 for s in self.formats_timeduration.values() {
158 writeln!(f, "{:?}", s)?;
159 }
160 for (t, s) in &self.def_styles {
161 writeln!(f, "{:?} -> {:?}", t, s)?;
162 }
163 for s in self.pagestyles.values() {
164 writeln!(f, "{:?}", s)?;
165 }
166 for s in self.masterpages.values() {
167 writeln!(f, "{:?}", s)?;
168 }
169 for s in self.validations.values() {
170 writeln!(f, "{:?}", s)?;
171 }
172 writeln!(f, "{:?}", &self.workbook_config)?;
173 for v in self.manifest.values() {
174 writeln!(f, "extras {:?}", v)?;
175 }
176 writeln!(f, "{:?}", &self.metadata)?;
177 for xtr in &self.extra {
178 writeln!(f, "extras {:?}", xtr)?;
179 }
180 Ok(())
181 }
182}
183
184fn auto_style_name2<K, V>(
187 autonum: &mut HashMap<String, u32>,
188 prefix: &str,
189 styles: &HashMap<K, V>,
190) -> String
191where
192 K: Borrow<str> + Hash + Eq,
193{
194 let mut cnt = if let Some(n) = autonum.get(prefix) {
195 n + 1
196 } else {
197 0
198 };
199
200 let style_name = loop {
201 let style_name = format!("{}{}", prefix, cnt);
202 if !styles.contains_key(&style_name) {
203 break style_name;
204 }
205 cnt += 1;
206 };
207
208 autonum.insert(prefix.to_string(), cnt);
209
210 style_name
211}
212
213fn auto_style_name<T>(
216 autonum: &mut HashMap<String, u32>,
217 prefix: &str,
218 styles: &HashMap<String, T>,
219) -> String {
220 let mut cnt = if let Some(n) = autonum.get(prefix) {
221 n + 1
222 } else {
223 0
224 };
225
226 let style_name = loop {
227 let style_name = format!("{}{}", prefix, cnt);
228 if !styles.contains_key(&style_name) {
229 break style_name;
230 }
231 cnt += 1;
232 };
233
234 autonum.insert(prefix.to_string(), cnt);
235
236 style_name
237}
238
239impl Default for WorkBook {
240 fn default() -> Self {
241 WorkBook::new(locale!("en"))
242 }
243}
244
245impl WorkBook {
246 pub fn new_empty() -> Self {
250 WorkBook {
251 sheets: Default::default(),
252 version: "1.3".to_string(),
253 fonts: Default::default(),
254 autonum: Default::default(),
255 scripts: Default::default(),
256 event_listener: Default::default(),
257 tablestyles: Default::default(),
258 rowstyles: Default::default(),
259 colstyles: Default::default(),
260 cellstyles: Default::default(),
261 paragraphstyles: Default::default(),
262 textstyles: Default::default(),
263 rubystyles: Default::default(),
264 graphicstyles: Default::default(),
265 formats_boolean: Default::default(),
266 formats_number: Default::default(),
267 formats_percentage: Default::default(),
268 formats_currency: Default::default(),
269 formats_text: Default::default(),
270 formats_datetime: Default::default(),
271 formats_timeduration: Default::default(),
272 def_styles: Default::default(),
273 pagestyles: Default::default(),
274 masterpages: Default::default(),
275 validations: Default::default(),
276 config: default_settings(),
277 workbook_config: Default::default(),
278 extra: vec![],
279 manifest: Default::default(),
280 metadata: Default::default(),
281 xmlns: Default::default(),
282 }
283 }
284
285 pub fn new(locale: Locale) -> Self {
293 let mut wb = WorkBook::new_empty();
294 wb.locale_settings(locale);
295 wb
296 }
297
298 pub fn locale_settings(&mut self, locale: Locale) {
305 if let Some(lf) = locale::localized_format(locale) {
306 self.add_boolean_format(lf.boolean_format());
307 self.add_number_format(lf.number_format());
308 self.add_percentage_format(lf.percentage_format());
309 self.add_currency_format(lf.currency_format());
310 self.add_datetime_format(lf.date_format());
311 self.add_datetime_format(lf.datetime_format());
312 self.add_datetime_format(lf.time_of_day_format());
313 self.add_timeduration_format(lf.time_interval_format());
314 }
315
316 self.add_cellstyle(CellStyle::new(DefaultStyle::bool(), &DefaultFormat::bool()));
317 self.add_cellstyle(CellStyle::new(
318 DefaultStyle::number(),
319 &DefaultFormat::number(),
320 ));
321 self.add_cellstyle(CellStyle::new(
322 DefaultStyle::percent(),
323 &DefaultFormat::percent(),
324 ));
325 self.add_cellstyle(CellStyle::new(
326 DefaultStyle::currency(),
327 &DefaultFormat::currency(),
328 ));
329 self.add_cellstyle(CellStyle::new(DefaultStyle::date(), &DefaultFormat::date()));
330 self.add_cellstyle(CellStyle::new(
331 DefaultStyle::datetime(),
332 &DefaultFormat::datetime(),
333 ));
334 self.add_cellstyle(CellStyle::new(
335 DefaultStyle::time_of_day(),
336 &DefaultFormat::time_of_day(),
337 ));
338 self.add_cellstyle(CellStyle::new(
339 DefaultStyle::time_interval(),
340 &DefaultFormat::time_interval(),
341 ));
342
343 self.add_def_style(ValueType::Boolean, DefaultStyle::bool());
344 self.add_def_style(ValueType::Number, DefaultStyle::number());
345 self.add_def_style(ValueType::Percentage, DefaultStyle::percent());
346 self.add_def_style(ValueType::Currency, DefaultStyle::currency());
347 self.add_def_style(ValueType::DateTime, DefaultStyle::date());
348 self.add_def_style(ValueType::TimeDuration, DefaultStyle::time_interval());
349 }
350
351 pub fn version(&self) -> &String {
353 &self.version
354 }
355
356 pub fn set_version(&mut self, version: String) {
359 self.version = version;
360 }
361
362 pub fn config(&self) -> &WorkBookConfig {
364 &self.workbook_config
365 }
366
367 pub fn config_mut(&mut self) -> &mut WorkBookConfig {
369 &mut self.workbook_config
370 }
371
372 pub fn num_sheets(&self) -> usize {
374 self.sheets.len()
375 }
376
377 pub fn sheet_idx<S: AsRef<str>>(&self, name: S) -> Option<usize> {
379 for (idx, sheet) in self.sheets.iter().enumerate() {
380 if sheet.name() == name.as_ref() {
381 return Some(idx);
382 }
383 }
384 None
385 }
386
387 pub fn detach_sheet(&mut self, n: usize) -> Detached<usize, Sheet> {
400 self.sheets[n].detach(n)
401 }
402
403 pub fn attach_sheet(&mut self, sheet: Detached<usize, Sheet>) {
409 self.sheets[Detached::key(&sheet)].attach(sheet)
410 }
411
412 pub fn sheet(&self, n: usize) -> &Sheet {
418 self.sheets[n].as_ref()
419 }
420
421 pub fn sheet_mut(&mut self, n: usize) -> &mut Sheet {
427 self.sheets[n].as_mut()
428 }
429
430 pub fn iter_sheets(&self) -> impl Iterator<Item = &Sheet> {
432 self.sheets.iter().map(|sheet| &**sheet)
433 }
434
435 pub fn insert_sheet(&mut self, i: usize, sheet: Sheet) {
437 self.sheets.insert(i, sheet.into());
438 }
439
440 pub fn push_sheet(&mut self, sheet: Sheet) {
442 self.sheets.push(sheet.into());
443 }
444
445 pub fn remove_sheet(&mut self, n: usize) -> Sheet {
451 self.sheets.remove(n).take()
452 }
453
454 pub fn add_script(&mut self, v: Script) {
456 self.scripts.push(v);
457 }
458
459 pub fn iter_scripts(&self) -> impl Iterator<Item = &Script> {
461 self.scripts.iter()
462 }
463
464 pub fn scripts(&self) -> &Vec<Script> {
466 &self.scripts
467 }
468
469 pub fn scripts_mut(&mut self) -> &mut Vec<Script> {
471 &mut self.scripts
472 }
473
474 pub fn add_event_listener(&mut self, e: EventListener) {
476 self.event_listener.insert(e.event_name.clone(), e);
477 }
478
479 pub fn remove_event_listener(&mut self, event_name: &str) -> Option<EventListener> {
481 self.event_listener.remove(event_name)
482 }
483
484 pub fn iter_event_listeners(&self) -> impl Iterator<Item = &EventListener> {
486 self.event_listener.values()
487 }
488
489 pub fn event_listener(&self, event_name: &str) -> Option<&EventListener> {
491 self.event_listener.get(event_name)
492 }
493
494 pub fn event_listener_mut(&mut self, event_name: &str) -> Option<&mut EventListener> {
496 self.event_listener.get_mut(event_name)
497 }
498
499 pub fn add_def_style(&mut self, value_type: ValueType, style: CellStyleRef) {
502 self.def_styles.insert(value_type, style);
503 }
504
505 pub fn def_style(&self, value_type: ValueType) -> Option<&CellStyleRef> {
507 self.def_styles.get(&value_type)
508 }
509
510 pub fn add_font(&mut self, font: FontFaceDecl) {
512 self.fonts.insert(font.name().to_string(), font);
513 }
514
515 pub fn remove_font(&mut self, name: &str) -> Option<FontFaceDecl> {
517 self.fonts.remove(name)
518 }
519
520 pub fn iter_fonts(&self) -> impl Iterator<Item = &FontFaceDecl> {
522 self.fonts.values()
523 }
524
525 pub fn font(&self, name: &str) -> Option<&FontFaceDecl> {
527 self.fonts.get(name)
528 }
529
530 pub fn font_mut(&mut self, name: &str) -> Option<&mut FontFaceDecl> {
532 self.fonts.get_mut(name)
533 }
534
535 pub fn add_tablestyle(&mut self, mut style: TableStyle) -> TableStyleRef {
538 if style.name().is_empty() {
539 style.set_name(auto_style_name2(&mut self.autonum, "ta", &self.tablestyles));
540 }
541 let sref = style.style_ref();
542 self.tablestyles.insert(style.style_ref(), style);
543 sref
544 }
545
546 pub fn remove_tablestyle<S: AsRef<str>>(&mut self, name: S) -> Option<TableStyle> {
548 self.tablestyles.remove(name.as_ref())
549 }
550
551 pub fn iter_table_styles(&self) -> impl Iterator<Item = &TableStyle> {
553 self.tablestyles.values()
554 }
555
556 pub fn tablestyle<S: AsRef<str>>(&self, name: S) -> Option<&TableStyle> {
558 self.tablestyles.get(name.as_ref())
559 }
560
561 pub fn tablestyle_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut TableStyle> {
563 self.tablestyles.get_mut(name.as_ref())
564 }
565
566 pub fn add_rowstyle(&mut self, mut style: RowStyle) -> RowStyleRef {
569 if style.name().is_empty() {
570 style.set_name(auto_style_name2(&mut self.autonum, "ro", &self.rowstyles));
571 }
572 let sref = style.style_ref();
573 self.rowstyles.insert(style.style_ref(), style);
574 sref
575 }
576
577 pub fn remove_rowstyle<S: AsRef<str>>(&mut self, name: S) -> Option<RowStyle> {
579 self.rowstyles.remove(name.as_ref())
580 }
581
582 pub fn rowstyle<S: AsRef<str>>(&self, name: S) -> Option<&RowStyle> {
584 self.rowstyles.get(name.as_ref())
585 }
586
587 pub fn rowstyle_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut RowStyle> {
589 self.rowstyles.get_mut(name.as_ref())
590 }
591
592 pub fn iter_rowstyles(&self) -> impl Iterator<Item = &RowStyle> {
594 self.rowstyles.values()
595 }
596
597 pub fn add_colstyle(&mut self, mut style: ColStyle) -> ColStyleRef {
600 if style.name().is_empty() {
601 style.set_name(auto_style_name2(&mut self.autonum, "co", &self.colstyles));
602 }
603 let sref = style.style_ref();
604 self.colstyles.insert(style.style_ref(), style);
605 sref
606 }
607
608 pub fn remove_colstyle<S: AsRef<str>>(&mut self, name: S) -> Option<ColStyle> {
610 self.colstyles.remove(name.as_ref())
611 }
612
613 pub fn colstyle<S: AsRef<str>>(&self, name: S) -> Option<&ColStyle> {
615 self.colstyles.get(name.as_ref())
616 }
617
618 pub fn colstyle_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut ColStyle> {
620 self.colstyles.get_mut(name.as_ref())
621 }
622
623 pub fn iter_colstyles(&self) -> impl Iterator<Item = &ColStyle> {
625 self.colstyles.values()
626 }
627
628 pub fn add_cellstyle(&mut self, mut style: CellStyle) -> CellStyleRef {
631 if style.name().is_empty() {
632 style.set_name(auto_style_name2(&mut self.autonum, "ce", &self.cellstyles));
633 }
634 let sref = style.style_ref();
635 self.cellstyles.insert(style.style_ref(), style);
636 sref
637 }
638
639 pub fn remove_cellstyle<S: AsRef<str>>(&mut self, name: S) -> Option<CellStyle> {
641 self.cellstyles.remove(name.as_ref())
642 }
643
644 pub fn iter_cellstyles(&self) -> impl Iterator<Item = &CellStyle> {
646 self.cellstyles.values()
647 }
648
649 pub fn cellstyle<S: AsRef<str>>(&self, name: S) -> Option<&CellStyle> {
651 self.cellstyles.get(name.as_ref())
652 }
653
654 pub fn cellstyle_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut CellStyle> {
656 self.cellstyles.get_mut(name.as_ref())
657 }
658
659 pub fn add_paragraphstyle(&mut self, mut style: ParagraphStyle) -> ParagraphStyleRef {
662 if style.name().is_empty() {
663 style.set_name(auto_style_name2(
664 &mut self.autonum,
665 "para",
666 &self.paragraphstyles,
667 ));
668 }
669 let sref = style.style_ref();
670 self.paragraphstyles.insert(style.style_ref(), style);
671 sref
672 }
673
674 pub fn remove_paragraphstyle<S: AsRef<str>>(&mut self, name: S) -> Option<ParagraphStyle> {
676 self.paragraphstyles.remove(name.as_ref())
677 }
678
679 pub fn iter_paragraphstyles(&self) -> impl Iterator<Item = &ParagraphStyle> {
681 self.paragraphstyles.values()
682 }
683
684 pub fn paragraphstyle<S: AsRef<str>>(&self, name: S) -> Option<&ParagraphStyle> {
686 self.paragraphstyles.get(name.as_ref())
687 }
688
689 pub fn paragraphstyle_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut ParagraphStyle> {
691 self.paragraphstyles.get_mut(name.as_ref())
692 }
693
694 pub fn add_textstyle(&mut self, mut style: TextStyle) -> TextStyleRef {
697 if style.name().is_empty() {
698 style.set_name(auto_style_name2(&mut self.autonum, "txt", &self.textstyles));
699 }
700 let sref = style.style_ref();
701 self.textstyles.insert(style.style_ref(), style);
702 sref
703 }
704
705 pub fn remove_textstyle<S: AsRef<str>>(&mut self, name: S) -> Option<TextStyle> {
707 self.textstyles.remove(name.as_ref())
708 }
709
710 pub fn iter_textstyles(&self) -> impl Iterator<Item = &TextStyle> {
712 self.textstyles.values()
713 }
714
715 pub fn textstyle<S: AsRef<str>>(&self, name: S) -> Option<&TextStyle> {
717 self.textstyles.get(name.as_ref())
718 }
719
720 pub fn textstyle_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut TextStyle> {
722 self.textstyles.get_mut(name.as_ref())
723 }
724
725 pub fn add_rubystyle(&mut self, mut style: RubyStyle) -> RubyStyleRef {
728 if style.name().is_empty() {
729 style.set_name(auto_style_name2(
730 &mut self.autonum,
731 "ruby",
732 &self.rubystyles,
733 ));
734 }
735 let sref = style.style_ref();
736 self.rubystyles.insert(style.style_ref(), style);
737 sref
738 }
739
740 pub fn remove_rubystyle<S: AsRef<str>>(&mut self, name: S) -> Option<RubyStyle> {
742 self.rubystyles.remove(name.as_ref())
743 }
744
745 pub fn iter_rubystyles(&self) -> impl Iterator<Item = &RubyStyle> {
747 self.rubystyles.values()
748 }
749
750 pub fn rubystyle<S: AsRef<str>>(&self, name: S) -> Option<&RubyStyle> {
752 self.rubystyles.get(name.as_ref())
753 }
754
755 pub fn rubystyle_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut RubyStyle> {
757 self.rubystyles.get_mut(name.as_ref())
758 }
759
760 pub fn add_graphicstyle(&mut self, mut style: GraphicStyle) -> GraphicStyleRef {
763 if style.name().is_empty() {
764 style.set_name(auto_style_name2(
765 &mut self.autonum,
766 "gr",
767 &self.graphicstyles,
768 ));
769 }
770 let sref = style.style_ref();
771 self.graphicstyles.insert(style.style_ref(), style);
772 sref
773 }
774
775 pub fn remove_graphicstyle<S: AsRef<str>>(&mut self, name: S) -> Option<GraphicStyle> {
777 self.graphicstyles.remove(name.as_ref())
778 }
779
780 pub fn iter_graphicstyles(&self) -> impl Iterator<Item = &GraphicStyle> {
782 self.graphicstyles.values()
783 }
784
785 pub fn graphicstyle<S: AsRef<str>>(&self, name: S) -> Option<&GraphicStyle> {
787 self.graphicstyles.get(name.as_ref())
788 }
789
790 pub fn graphicstyle_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut GraphicStyle> {
792 self.graphicstyles.get_mut(name.as_ref())
793 }
794
795 pub fn add_boolean_format(&mut self, mut vstyle: ValueFormatBoolean) -> ValueFormatRef {
798 if vstyle.name().is_empty() {
799 vstyle.set_name(
800 auto_style_name(&mut self.autonum, "val_boolean", &self.formats_boolean).as_str(),
801 );
802 }
803 let sref = vstyle.format_ref();
804 self.formats_boolean
805 .insert(vstyle.name().to_string(), vstyle);
806 sref
807 }
808
809 pub fn remove_boolean_format(&mut self, name: &str) -> Option<ValueFormatBoolean> {
811 self.formats_boolean.remove(name)
812 }
813
814 pub fn iter_boolean_formats(&self) -> impl Iterator<Item = &ValueFormatBoolean> {
816 self.formats_boolean.values()
817 }
818
819 pub fn boolean_format(&self, name: &str) -> Option<&ValueFormatBoolean> {
821 self.formats_boolean.get(name)
822 }
823
824 pub fn boolean_format_mut(&mut self, name: &str) -> Option<&mut ValueFormatBoolean> {
826 self.formats_boolean.get_mut(name)
827 }
828
829 pub fn add_number_format(&mut self, mut vstyle: ValueFormatNumber) -> ValueFormatRef {
832 if vstyle.name().is_empty() {
833 vstyle.set_name(
834 auto_style_name(&mut self.autonum, "val_number", &self.formats_number).as_str(),
835 );
836 }
837 let sref = vstyle.format_ref();
838 self.formats_number
839 .insert(vstyle.name().to_string(), vstyle);
840 sref
841 }
842
843 pub fn remove_number_format(&mut self, name: &str) -> Option<ValueFormatNumber> {
845 self.formats_number.remove(name)
846 }
847
848 pub fn iter_number_formats(&self) -> impl Iterator<Item = &ValueFormatNumber> {
850 self.formats_number.values()
851 }
852
853 pub fn number_format(&self, name: &str) -> Option<&ValueFormatBoolean> {
855 self.formats_boolean.get(name)
856 }
857
858 pub fn number_format_mut(&mut self, name: &str) -> Option<&mut ValueFormatBoolean> {
860 self.formats_boolean.get_mut(name)
861 }
862
863 pub fn add_percentage_format(&mut self, mut vstyle: ValueFormatPercentage) -> ValueFormatRef {
866 if vstyle.name().is_empty() {
867 vstyle.set_name(
868 auto_style_name(
869 &mut self.autonum,
870 "val_percentage",
871 &self.formats_percentage,
872 )
873 .as_str(),
874 );
875 }
876 let sref = vstyle.format_ref();
877 self.formats_percentage
878 .insert(vstyle.name().to_string(), vstyle);
879 sref
880 }
881
882 pub fn remove_percentage_format(&mut self, name: &str) -> Option<ValueFormatPercentage> {
884 self.formats_percentage.remove(name)
885 }
886
887 pub fn iter_percentage_formats(&self) -> impl Iterator<Item = &ValueFormatPercentage> {
889 self.formats_percentage.values()
890 }
891
892 pub fn percentage_format(&self, name: &str) -> Option<&ValueFormatPercentage> {
894 self.formats_percentage.get(name)
895 }
896
897 pub fn percentage_format_mut(&mut self, name: &str) -> Option<&mut ValueFormatPercentage> {
899 self.formats_percentage.get_mut(name)
900 }
901
902 pub fn add_currency_format(&mut self, mut vstyle: ValueFormatCurrency) -> ValueFormatRef {
905 if vstyle.name().is_empty() {
906 vstyle.set_name(
907 auto_style_name(&mut self.autonum, "val_currency", &self.formats_currency).as_str(),
908 );
909 }
910 let sref = vstyle.format_ref();
911 self.formats_currency
912 .insert(vstyle.name().to_string(), vstyle);
913 sref
914 }
915
916 pub fn remove_currency_format(&mut self, name: &str) -> Option<ValueFormatCurrency> {
918 self.formats_currency.remove(name)
919 }
920
921 pub fn iter_currency_formats(&self) -> impl Iterator<Item = &ValueFormatCurrency> {
923 self.formats_currency.values()
924 }
925
926 pub fn currency_format(&self, name: &str) -> Option<&ValueFormatCurrency> {
928 self.formats_currency.get(name)
929 }
930
931 pub fn currency_format_mut(&mut self, name: &str) -> Option<&mut ValueFormatCurrency> {
933 self.formats_currency.get_mut(name)
934 }
935
936 pub fn add_text_format(&mut self, mut vstyle: ValueFormatText) -> ValueFormatRef {
939 if vstyle.name().is_empty() {
940 vstyle.set_name(
941 auto_style_name(&mut self.autonum, "val_text", &self.formats_text).as_str(),
942 );
943 }
944 let sref = vstyle.format_ref();
945 self.formats_text.insert(vstyle.name().to_string(), vstyle);
946 sref
947 }
948
949 pub fn remove_text_format(&mut self, name: &str) -> Option<ValueFormatText> {
951 self.formats_text.remove(name)
952 }
953
954 pub fn iter_text_formats(&self) -> impl Iterator<Item = &ValueFormatText> {
956 self.formats_text.values()
957 }
958
959 pub fn text_format(&self, name: &str) -> Option<&ValueFormatText> {
961 self.formats_text.get(name)
962 }
963
964 pub fn text_format_mut(&mut self, name: &str) -> Option<&mut ValueFormatText> {
966 self.formats_text.get_mut(name)
967 }
968
969 pub fn add_datetime_format(&mut self, mut vstyle: ValueFormatDateTime) -> ValueFormatRef {
972 if vstyle.name().is_empty() {
973 vstyle.set_name(
974 auto_style_name(&mut self.autonum, "val_datetime", &self.formats_datetime).as_str(),
975 );
976 }
977 let sref = vstyle.format_ref();
978 self.formats_datetime
979 .insert(vstyle.name().to_string(), vstyle);
980 sref
981 }
982
983 pub fn remove_datetime_format(&mut self, name: &str) -> Option<ValueFormatDateTime> {
985 self.formats_datetime.remove(name)
986 }
987
988 pub fn iter_datetime_formats(&self) -> impl Iterator<Item = &ValueFormatDateTime> {
990 self.formats_datetime.values()
991 }
992
993 pub fn datetime_format(&self, name: &str) -> Option<&ValueFormatDateTime> {
995 self.formats_datetime.get(name)
996 }
997
998 pub fn datetime_format_mut(&mut self, name: &str) -> Option<&mut ValueFormatDateTime> {
1000 self.formats_datetime.get_mut(name)
1001 }
1002
1003 pub fn add_timeduration_format(
1006 &mut self,
1007 mut vstyle: ValueFormatTimeDuration,
1008 ) -> ValueFormatRef {
1009 if vstyle.name().is_empty() {
1010 vstyle.set_name(
1011 auto_style_name(
1012 &mut self.autonum,
1013 "val_timeduration",
1014 &self.formats_timeduration,
1015 )
1016 .as_str(),
1017 );
1018 }
1019 let sref = vstyle.format_ref();
1020 self.formats_timeduration
1021 .insert(vstyle.name().to_string(), vstyle);
1022 sref
1023 }
1024
1025 pub fn remove_timeduration_format(&mut self, name: &str) -> Option<ValueFormatTimeDuration> {
1027 self.formats_timeduration.remove(name)
1028 }
1029
1030 pub fn iter_timeduration_formats(&self) -> impl Iterator<Item = &ValueFormatTimeDuration> {
1032 self.formats_timeduration.values()
1033 }
1034
1035 pub fn timeduration_format(&self, name: &str) -> Option<&ValueFormatTimeDuration> {
1037 self.formats_timeduration.get(name)
1038 }
1039
1040 pub fn timeduration_format_mut(&mut self, name: &str) -> Option<&mut ValueFormatTimeDuration> {
1042 self.formats_timeduration.get_mut(name)
1043 }
1044
1045 pub fn add_pagestyle(&mut self, mut pstyle: PageStyle) -> PageStyleRef {
1048 if pstyle.name().is_empty() {
1049 pstyle.set_name(auto_style_name2(
1050 &mut self.autonum,
1051 "page",
1052 &self.pagestyles,
1053 ));
1054 }
1055 let sref = pstyle.style_ref();
1056 self.pagestyles.insert(pstyle.style_ref(), pstyle);
1057 sref
1058 }
1059
1060 pub fn remove_pagestyle<S: AsRef<str>>(&mut self, name: S) -> Option<PageStyle> {
1062 self.pagestyles.remove(name.as_ref())
1063 }
1064
1065 pub fn iter_pagestyles(&self) -> impl Iterator<Item = &PageStyle> {
1067 self.pagestyles.values()
1068 }
1069
1070 pub fn pagestyle<S: AsRef<str>>(&self, name: S) -> Option<&PageStyle> {
1072 self.pagestyles.get(name.as_ref())
1073 }
1074
1075 pub fn pagestyle_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut PageStyle> {
1077 self.pagestyles.get_mut(name.as_ref())
1078 }
1079
1080 pub fn add_masterpage(&mut self, mut mpage: MasterPage) -> MasterPageRef {
1083 if mpage.name().is_empty() {
1084 mpage.set_name(auto_style_name2(&mut self.autonum, "mp", &self.masterpages));
1085 }
1086 let sref = mpage.masterpage_ref();
1087 self.masterpages.insert(mpage.masterpage_ref(), mpage);
1088 sref
1089 }
1090
1091 pub fn remove_masterpage<S: AsRef<str>>(&mut self, name: S) -> Option<MasterPage> {
1093 self.masterpages.remove(name.as_ref())
1094 }
1095
1096 pub fn iter_masterpages(&self) -> impl Iterator<Item = &MasterPage> {
1098 self.masterpages.values()
1099 }
1100
1101 pub fn masterpage<S: AsRef<str>>(&self, name: S) -> Option<&MasterPage> {
1103 self.masterpages.get(name.as_ref())
1104 }
1105
1106 pub fn masterpage_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut MasterPage> {
1108 self.masterpages.get_mut(name.as_ref())
1109 }
1110
1111 pub fn add_validation(&mut self, mut valid: Validation) -> ValidationRef {
1114 if valid.name().is_empty() {
1115 valid.set_name(auto_style_name2(
1116 &mut self.autonum,
1117 "val",
1118 &self.validations,
1119 ));
1120 }
1121 let vref = valid.validation_ref();
1122 self.validations.insert(valid.validation_ref(), valid);
1123 vref
1124 }
1125
1126 pub fn remove_validation<S: AsRef<str>>(&mut self, name: S) -> Option<Validation> {
1128 self.validations.remove(name.as_ref())
1129 }
1130
1131 pub fn iter_validations(&self) -> impl Iterator<Item = &Validation> {
1133 self.validations.values()
1134 }
1135
1136 pub fn validation<S: AsRef<str>>(&self, name: S) -> Option<&Validation> {
1138 self.validations.get(name.as_ref())
1139 }
1140
1141 pub fn validation_mut<S: AsRef<str>>(&mut self, name: S) -> Option<&mut Validation> {
1143 self.validations.get_mut(name.as_ref())
1144 }
1145
1146 pub fn add_manifest(&mut self, manifest: Manifest) {
1148 self.manifest.insert(manifest.full_path.clone(), manifest);
1149 }
1150
1151 pub fn remove_manifest(&mut self, path: &str) -> Option<Manifest> {
1153 self.manifest.remove(path)
1154 }
1155
1156 pub fn iter_manifest(&self) -> impl Iterator<Item = &Manifest> {
1158 self.manifest.values()
1159 }
1160
1161 pub fn manifest(&self, path: &str) -> Option<&Manifest> {
1163 self.manifest.get(path)
1164 }
1165
1166 pub fn manifest_mut(&mut self, path: &str) -> Option<&mut Manifest> {
1168 self.manifest.get_mut(path)
1169 }
1170
1171 pub fn metadata(&self) -> &Metadata {
1173 &self.metadata
1174 }
1175
1176 pub fn metadata_mut(&mut self) -> &mut Metadata {
1178 &mut self.metadata
1179 }
1180}
1181
1182#[derive(Clone, Debug, GetSize)]
1184pub struct WorkBookConfig {
1185 pub active_table: String,
1187 pub show_grid: bool,
1189 pub show_page_breaks: bool,
1191 pub has_sheet_tabs: bool,
1193}
1194
1195impl Default for WorkBookConfig {
1196 fn default() -> Self {
1197 Self {
1198 active_table: "".to_string(),
1199 show_grid: true,
1200 show_page_breaks: false,
1201 has_sheet_tabs: true,
1202 }
1203 }
1204}
1205
1206#[derive(Debug, Default, Clone, GetSize)]
1208pub struct Script {
1209 pub(crate) script_lang: String,
1210 pub(crate) script: Vec<XmlContent>,
1211}
1212
1213impl Script {
1214 pub fn new() -> Self {
1216 Self {
1217 script_lang: "".to_string(),
1218 script: Default::default(),
1219 }
1220 }
1221
1222 pub fn script_lang(&self) -> &str {
1224 &self.script_lang
1225 }
1226
1227 pub fn set_script_lang(&mut self, script_lang: String) {
1229 self.script_lang = script_lang
1230 }
1231
1232 pub fn script(&self) -> &Vec<XmlContent> {
1234 &self.script
1235 }
1236
1237 pub fn set_script(&mut self, script: Vec<XmlContent>) {
1239 self.script = script
1240 }
1241}
1242
1243#[derive(Debug, Clone, GetSize)]
1245pub struct EventListener {
1246 pub(crate) event_name: String,
1247 pub(crate) script_lang: String,
1248 pub(crate) macro_name: String,
1249 pub(crate) actuate: XLinkActuate,
1250 pub(crate) href: String,
1251 pub(crate) link_type: XLinkType,
1252}
1253
1254impl EventListener {
1255 pub fn new() -> Self {
1257 Self {
1258 event_name: Default::default(),
1259 script_lang: Default::default(),
1260 macro_name: Default::default(),
1261 actuate: XLinkActuate::OnLoad,
1262 href: Default::default(),
1263 link_type: Default::default(),
1264 }
1265 }
1266
1267 pub fn event_name(&self) -> &str {
1269 &self.event_name
1270 }
1271
1272 pub fn set_event_name(&mut self, name: String) {
1274 self.event_name = name;
1275 }
1276
1277 pub fn script_lang(&self) -> &str {
1279 &self.script_lang
1280 }
1281
1282 pub fn set_script_lang(&mut self, lang: String) {
1284 self.script_lang = lang
1285 }
1286
1287 pub fn macro_name(&self) -> &str {
1289 &self.macro_name
1290 }
1291
1292 pub fn set_macro_name(&mut self, name: String) {
1294 self.macro_name = name
1295 }
1296
1297 pub fn actuate(&self) -> XLinkActuate {
1299 self.actuate
1300 }
1301
1302 pub fn set_actuate(&mut self, actuate: XLinkActuate) {
1304 self.actuate = actuate;
1305 }
1306
1307 pub fn href(&self) -> &str {
1309 &self.href
1310 }
1311
1312 pub fn set_href(&mut self, href: String) {
1314 self.href = href;
1315 }
1316
1317 pub fn link_type(&self) -> XLinkType {
1319 self.link_type
1320 }
1321
1322 pub fn set_link_type(&mut self, link_type: XLinkType) {
1324 self.link_type = link_type
1325 }
1326}
1327
1328impl Default for EventListener {
1329 fn default() -> Self {
1330 Self {
1331 event_name: Default::default(),
1332 script_lang: Default::default(),
1333 macro_name: Default::default(),
1334 actuate: XLinkActuate::OnRequest,
1335 href: Default::default(),
1336 link_type: Default::default(),
1337 }
1338 }
1339}