1use crate::helper::const_str::*;
2use crate::helper::coordinate::*;
3use crate::helper::range::*;
4use crate::office2019::threaded_comment::ThreadedComment;
5use crate::reader::xlsx::worksheet::*;
6use crate::structs::drawing::spreadsheet::WorksheetDrawing;
7use crate::structs::office2010::excel::DataValidations as DataValidations2010;
8use crate::structs::raw::RawWorksheet;
9use crate::structs::AutoFilter;
10use crate::structs::Cell;
11use crate::structs::CellValue;
12use crate::structs::Cells;
13use crate::structs::Chart;
14use crate::structs::Color;
15use crate::structs::Column;
16use crate::structs::ColumnBreaks;
17use crate::structs::Columns;
18use crate::structs::Comment;
19use crate::structs::ConditionalFormatting;
20use crate::structs::DataValidations;
21use crate::structs::DefinedName;
22use crate::structs::EnumValue;
23use crate::structs::HeaderFooter;
24use crate::structs::Hyperlink;
25use crate::structs::Image;
26use crate::structs::MediaObject;
27use crate::structs::MergeCells;
28use crate::structs::OleObjects;
29use crate::structs::PageMargins;
30use crate::structs::PageSetup;
31use crate::structs::PivotTable;
32use crate::structs::PrintOptions;
33use crate::structs::Range;
34use crate::structs::Row;
35use crate::structs::RowBreaks;
36use crate::structs::Rows;
37use crate::structs::SharedStringTable;
38use crate::structs::SheetFormatProperties;
39use crate::structs::SheetProtection;
40use crate::structs::SheetStateValues;
41use crate::structs::SheetViews;
42use crate::structs::Style;
43use crate::structs::Stylesheet;
44use crate::structs::Table;
45use crate::traits;
46use crate::traits::AdjustmentCoordinate;
47use crate::traits::AdjustmentCoordinateWith2Sheet;
48use crate::traits::AdjustmentCoordinateWithSheet;
49use crate::traits::AdjustmentValue;
50use crate::StringValue;
51use std::collections::HashMap;
52use thin_vec::ThinVec;
53
54use super::EnumTrait;
55
56#[derive(Clone, Debug, Default)]
58pub struct Worksheet {
59 raw_data_of_worksheet: Option<RawWorksheet>,
60 r_id: Box<str>,
61 sheet_id: Box<str>,
62 title: Box<str>,
63 state: EnumValue<SheetStateValues>,
64 cell_collection: Cells,
65 row_dimensions: Rows,
66 column_dimensions: Columns,
67 worksheet_drawing: WorksheetDrawing,
68 sheet_state: Box<str>,
69 page_setup: PageSetup,
70 page_margins: PageMargins,
71 header_footer: HeaderFooter,
72 sheet_views: SheetViews,
73 conditional_formatting_collection: ThinVec<ConditionalFormatting>,
74 merge_cells: MergeCells,
75 auto_filter: Option<AutoFilter>,
76 comments: ThinVec<Comment>,
77 threaded_comments: ThinVec<ThreadedComment>,
78 active_cell: Box<str>,
79 tab_color: Option<Color>,
80 code_name: StringValue,
81 ole_objects: OleObjects,
82 defined_names: ThinVec<DefinedName>,
83 print_options: PrintOptions,
84 column_breaks: ColumnBreaks,
85 row_breaks: RowBreaks,
86 tables: ThinVec<Table>,
87 pivot_tables: ThinVec<PivotTable>,
88 data_validations: Option<DataValidations>,
89 data_validations_2010: Option<DataValidations2010>,
90 sheet_format_properties: SheetFormatProperties,
91 sheet_protection: Option<SheetProtection>,
92}
93
94impl Worksheet {
95 #[inline]
113 pub fn get_value<T>(&self, coordinate: T) -> String
114 where
115 T: Into<CellCoordinates>,
116 {
117 let CellCoordinates { col, row } = coordinate.into();
118 self.get_cell((col, row))
119 .map(|v| v.get_value().into())
120 .unwrap_or_default()
121 }
122
123 #[inline]
137 pub fn get_value_number<T>(&self, coordinate: T) -> Option<f64>
138 where
139 T: Into<CellCoordinates>,
140 {
141 let CellCoordinates { col, row } = coordinate.into();
142 self.get_cell((col, row)).and_then(|v| v.get_value_number())
143 }
144
145 #[inline]
159 pub fn get_formatted_value<T>(&self, coordinate: T) -> String
160 where
161 T: Into<CellCoordinates>,
162 {
163 let CellCoordinates { col, row } = coordinate.into();
164 self.cell_collection
165 .get_formatted_value_by_column_and_row(&col, &row)
166 }
167
168 #[inline]
173 pub fn get_cell_collection(&self) -> Vec<&Cell> {
174 self.cell_collection.iter_collection().collect()
175 }
176
177 #[inline]
178 pub fn get_cell_collection_sorted(&self) -> Vec<&Cell> {
179 self.cell_collection
180 .iter_cells_sorted_by_row_column()
181 .collect()
182 }
183
184 #[inline]
186 pub fn get_cell_collection_mut(&mut self) -> Vec<&mut Cell> {
187 self.cell_collection.get_collection_mut()
188 }
189
190 #[inline]
191 pub fn get_collection_to_hashmap(&self) -> &HashMap<(u32, u32), Box<Cell>> {
192 self.cell_collection.get_collection_to_hashmap()
193 }
194
195 #[inline]
196 pub fn get_collection_to_hashmap_mut(&mut self) -> &mut HashMap<(u32, u32), Box<Cell>> {
197 self.cell_collection.get_collection_to_hashmap_mut()
198 }
199
200 pub(crate) fn get_cell_collection_stream(
201 &self,
202 shared_string_table: &SharedStringTable,
203 stylesheet: &Stylesheet,
204 ) -> Cells {
205 assert!(!self.is_deserialized(), "This Worksheet is Deserialized.");
206
207 read_lite(
208 self.raw_data_of_worksheet.as_ref().unwrap(),
209 shared_string_table,
210 stylesheet,
211 )
212 .unwrap()
213 }
214
215 #[inline]
218 pub(crate) fn get_cell_collection_crate(&self) -> &Cells {
219 &self.cell_collection
220 }
221
222 #[inline]
225 pub(crate) fn get_cell_collection_crate_mut(&mut self) -> &mut Cells {
226 &mut self.cell_collection
227 }
228
229 #[inline]
245 pub fn get_cell<T>(&self, coordinate: T) -> Option<&Cell>
246 where
247 T: Into<CellCoordinates>,
248 {
249 self.cell_collection.get(coordinate)
250 }
251
252 pub fn get_cell_mut<T>(&mut self, coordinate: T) -> &mut Cell
266 where
267 T: Into<CellCoordinates>,
268 {
269 let CellCoordinates { col, row } = coordinate.into();
270 self.get_row_dimension_mut(&row);
271 let row_dimenshon = self.get_row_dimension_mut(&row).clone();
272 let col_dimenshon = self.get_column_dimension_by_number_mut(&col).clone();
273 self.cell_collection
274 .get_mut((col, row), &row_dimenshon, &col_dimenshon)
275 }
276
277 #[inline]
278 pub fn get_collection_by_column(&self, column_num: &u32) -> Vec<&Cell> {
279 self.cell_collection
280 .iter_cells_by_column(*column_num)
281 .collect()
282 }
283
284 #[inline]
285 pub fn get_collection_by_row(&self, row_num: &u32) -> Vec<&Cell> {
286 self.cell_collection.iter_cells_by_row(*row_num).collect()
287 }
288
289 #[inline]
290 pub fn get_collection_by_column_to_hashmap(&self, column_num: &u32) -> HashMap<u32, &Cell> {
291 self.cell_collection
292 .get_collection_by_column_to_hashmap(column_num)
293 }
294
295 #[inline]
296 pub fn get_collection_by_row_to_hashmap(&self, row_num: &u32) -> HashMap<u32, &Cell> {
297 self.cell_collection
298 .get_collection_by_row_to_hashmap(row_num)
299 }
300
301 pub fn set_cell(&mut self, cell: Cell) -> &mut Self {
305 let row_dimenshon = self
306 .get_row_dimension_mut(cell.get_coordinate().get_row_num())
307 .clone();
308 let col_dimenshon = self
309 .get_column_dimension_by_number_mut(cell.get_coordinate().get_col_num())
310 .clone();
311 self.cell_collection
312 .set(cell, &row_dimenshon, &col_dimenshon);
313 self
314 }
315
316 #[inline]
326 pub fn remove_cell<T>(&mut self, coordinate: T) -> bool
327 where
328 T: Into<CellCoordinates>,
329 {
330 let CellCoordinates { col, row } = coordinate.into();
331 self.cell_collection.remove(&col, &row)
332 }
333
334 #[inline]
348 pub fn get_cell_value<T>(&self, coordinate: T) -> &CellValue
349 where
350 T: Into<CellCoordinates>,
351 {
352 self.cell_collection.get_cell_value(coordinate)
353 }
354
355 #[inline]
369 pub fn get_cell_value_mut<T>(&mut self, coordinate: T) -> &mut CellValue
370 where
371 T: Into<CellCoordinates>,
372 {
373 self.get_cell_mut(coordinate).get_cell_value_mut()
374 }
375
376 #[inline]
388 pub fn get_cell_value_by_range(&self, range: &str) -> Vec<&CellValue> {
389 self.cell_collection
390 .iter_all_cell_values_by_range_sorted_by_row(range)
391 .collect()
392 }
393
394 #[inline]
408 pub fn get_style<T>(&self, coordinate: T) -> &Style
409 where
410 T: Into<CellCoordinates>,
411 {
412 self.cell_collection.get_style(coordinate)
413 }
414
415 #[inline]
429 pub fn get_style_mut<T>(&mut self, coordinate: T) -> &mut Style
430 where
431 T: Into<CellCoordinates>,
432 {
433 self.get_cell_mut(coordinate).get_style_mut()
434 }
435
436 #[inline]
437 pub fn set_style<T>(&mut self, coordinate: T, style: Style) -> &mut Self
438 where
439 T: Into<CellCoordinates>,
440 {
441 self.get_cell_mut(coordinate).set_style(style);
442 self
443 }
444
445 pub fn set_style_by_range(&mut self, range: &str, style: Style) -> &mut Self {
460 let coordinate_list = get_coordinate_list(&range);
461
462 let (col_num_start, row_num_start) = coordinate_list[0];
463 if col_num_start == 0 {
464 let (_, row_num_end) = coordinate_list[1];
465 for row_num in row_num_start..=row_num_end {
466 self.get_row_dimension_mut(&row_num)
467 .set_style(style.clone());
468 }
469 return self;
470 }
471 if row_num_start == 0 {
472 let (col_num_end, _) = coordinate_list[1];
473 for col_num in col_num_start..=col_num_end {
474 self.get_column_dimension_by_number_mut(&col_num)
475 .set_style(style.clone());
476 }
477 return self;
478 }
479
480 for (col_num, row_num) in coordinate_list {
481 self.set_style((col_num, row_num), style.clone());
482 }
483 self
484 }
485
486 pub fn map_merged_cell<T>(&self, coordinate: T) -> (u32, u32)
488 where
489 T: Into<CellCoordinates>,
490 {
491 let CellCoordinates { col, row } = coordinate.into();
492 self.merge_cells
493 .get_range_collection()
494 .into_iter()
495 .find_map(|range| {
496 let Some(start_col) = range.get_coordinate_start_col() else {
497 return None;
498 };
499 let Some(start_row) = range.get_coordinate_start_row() else {
500 return None;
501 };
502 let Some(end_col) = range.get_coordinate_end_col() else {
503 return None;
504 };
505 let Some(end_row) = range.get_coordinate_end_row() else {
506 return None;
507 };
508 if col >= *start_col.get_num()
509 && col <= *end_col.get_num()
510 && row >= *start_row.get_num()
511 && row <= *end_row.get_num()
512 {
513 Some((*start_col.get_num(), *start_row.get_num()))
514 } else {
515 None
516 }
517 })
518 .unwrap_or((col, row))
519 }
520
521 #[inline]
526 pub fn get_comments(&self) -> &[Comment] {
527 &self.comments
528 }
529
530 #[inline]
532 pub fn get_comments_mut(&mut self) -> &mut ThinVec<Comment> {
533 &mut self.comments
534 }
535
536 #[inline]
538 pub fn get_comments_to_hashmap(&self) -> HashMap<String, &Comment> {
539 let mut result = HashMap::default();
540 for comment in &self.comments {
541 result.insert(comment.get_coordinate().to_string(), comment);
542 }
543 result
544 }
545
546 #[inline]
550 pub fn set_comments(&mut self, value: impl Into<ThinVec<Comment>>) {
551 self.comments = value.into();
552 }
553
554 #[inline]
558 pub fn add_comments(&mut self, value: Comment) {
559 self.comments.push(value);
560 }
561
562 #[inline]
564 pub fn has_comments(&self) -> bool {
565 !self.comments.is_empty()
566 }
567
568 #[inline]
573 pub fn get_threaded_comments(&self) -> &[ThreadedComment] {
574 &self.threaded_comments
575 }
576
577 #[inline]
579 pub fn get_threaded_comments_mut(&mut self) -> &mut ThinVec<ThreadedComment> {
580 &mut self.threaded_comments
581 }
582
583 #[inline]
585 pub fn get_threaded_comments_to_hashmap(&self) -> HashMap<String, &ThreadedComment> {
586 let mut result = HashMap::default();
587 for threaded_comment in &self.threaded_comments {
588 result.insert(
589 threaded_comment.get_coordinate().to_string(),
590 threaded_comment,
591 );
592 }
593 result
594 }
595
596 #[inline]
600 pub fn set_threaded_comments(&mut self, value: impl Into<ThinVec<ThreadedComment>>) {
601 self.threaded_comments = value.into();
602 }
603
604 #[inline]
608 pub fn add_threaded_comments(&mut self, value: ThreadedComment) {
609 self.threaded_comments.push(value);
610 }
611
612 #[inline]
614 pub fn has_threaded_comments(&self) -> bool {
615 !self.threaded_comments.is_empty()
616 }
617
618 #[inline]
623 pub fn get_conditional_formatting_collection(&self) -> &[ConditionalFormatting] {
624 &self.conditional_formatting_collection
625 }
626
627 #[inline]
631 pub fn set_conditional_formatting_collection(
632 &mut self,
633 value: impl Into<ThinVec<ConditionalFormatting>>,
634 ) {
635 self.conditional_formatting_collection = value.into();
636 }
637
638 #[inline]
642 pub fn add_conditional_formatting_collection(&mut self, value: ConditionalFormatting) {
643 self.conditional_formatting_collection.push(value);
644 }
645
646 pub(crate) fn get_hyperlink_collection(&self) -> ThinVec<(String, &Hyperlink)> {
652 let mut result: ThinVec<(String, &Hyperlink)> = ThinVec::new();
653 for cell in self.cell_collection.get_collection_sorted() {
654 if let Some(hyperlink) = cell.get_hyperlink() {
655 let coordition = coordinate_from_index(
656 cell.get_coordinate().get_col_num(),
657 cell.get_coordinate().get_row_num(),
658 );
659 result.push((coordition, hyperlink));
660 }
661 }
662 result
663 }
664
665 #[inline]
668 pub(crate) fn has_hyperlink(&self) -> bool {
669 self.cell_collection.has_hyperlink()
670 }
671
672 #[inline]
677 pub fn get_merge_cells(&self) -> &[Range] {
678 self.merge_cells.get_range_collection()
679 }
680
681 #[inline]
683 pub fn get_merge_cells_mut(&mut self) -> &mut ThinVec<Range> {
684 self.merge_cells.get_range_collection_mut()
685 }
686
687 #[inline]
697 pub fn add_merge_cells<S: Into<String>>(&mut self, range: S) -> &mut Self {
698 self.merge_cells.add_range(range);
699 self
700 }
701
702 #[inline]
705 pub(crate) fn get_merge_cells_crate(&self) -> &MergeCells {
706 &self.merge_cells
707 }
708
709 #[inline]
712 pub(crate) fn get_merge_cells_crate_mut(&mut self) -> &mut MergeCells {
713 &mut self.merge_cells
714 }
715
716 #[inline]
721 pub fn get_auto_filter(&self) -> Option<&AutoFilter> {
722 self.auto_filter.as_ref()
723 }
724
725 #[inline]
727 pub fn get_auto_filter_mut(&mut self) -> Option<&mut AutoFilter> {
728 self.auto_filter.as_mut()
729 }
730
731 #[inline]
741 pub fn set_auto_filter<S: Into<String>>(&mut self, range: S) {
742 let mut auto_filter = AutoFilter::default();
743 auto_filter.set_range(range);
744 self.auto_filter = Some(auto_filter);
745 }
746
747 #[inline]
749 pub fn remove_auto_filter(&mut self) {
750 self.auto_filter = None;
751 }
752
753 #[inline]
758 pub fn get_column_dimensions(&self) -> &[Column] {
759 self.column_dimensions.get_column_collection()
760 }
761
762 #[inline]
764 pub fn get_column_dimensions_mut(&mut self) -> &mut ThinVec<Column> {
765 self.column_dimensions.get_column_collection_mut()
766 }
767
768 #[inline]
770 pub fn calculation_auto_width(&mut self) -> &mut Self {
771 let cells = self.get_cell_collection_crate().clone();
772 let merge_cells = self.get_merge_cells_crate().clone();
773 self.get_column_dimensions_crate_mut()
774 .calculation_auto_width(&cells, &merge_cells);
775 self
776 }
777
778 #[inline]
782 pub fn get_column_dimension(&self, column: &str) -> Option<&Column> {
783 self.get_column_dimension_by_number(&column_index_from_string(column))
784 }
785
786 #[inline]
790 pub fn get_column_dimension_mut(&mut self, column: &str) -> &mut Column {
791 self.get_column_dimension_by_number_mut(&column_index_from_string(column))
792 }
793
794 #[inline]
798 pub fn get_column_dimension_by_number(&self, col: &u32) -> Option<&Column> {
799 self.get_column_dimensions_crate().get_column(col)
800 }
801
802 #[inline]
806 pub fn get_column_dimension_by_number_mut(&mut self, col: &u32) -> &mut Column {
807 self.get_column_dimensions_crate_mut().get_column_mut(col)
808 }
809
810 #[inline]
813 pub(crate) fn get_column_dimensions_crate(&self) -> &Columns {
814 &self.column_dimensions
815 }
816
817 #[inline]
820 pub(crate) fn get_column_dimensions_crate_mut(&mut self) -> &mut Columns {
821 &mut self.column_dimensions
822 }
823
824 #[inline]
827 pub(crate) fn set_column_dimensions_crate(&mut self, value: Columns) -> &mut Self {
828 self.column_dimensions = value;
829 self
830 }
831
832 #[inline]
836 pub fn has_sheet_data(&self) -> bool {
837 self.row_dimensions.has_sheet_data()
838 }
839
840 #[inline]
842 pub fn get_row_dimensions(&self) -> Vec<&Row> {
843 self.row_dimensions.get_row_dimensions()
844 }
845
846 #[inline]
848 pub fn get_row_dimensions_mut(&mut self) -> Vec<&mut Row> {
849 self.row_dimensions.get_row_dimensions_mut()
850 }
851
852 #[inline]
854 pub fn get_row_dimensions_to_hashmap(&self) -> &HashMap<u32, Box<Row>> {
855 self.row_dimensions.get_row_dimensions_to_hashmap()
856 }
857
858 #[inline]
859 pub fn get_row_dimensions_to_hashmap_mut(&mut self) -> &mut HashMap<u32, Box<Row>> {
860 self.row_dimensions.get_row_dimensions_to_hashmap_mut()
861 }
862
863 #[inline]
865 pub fn get_row_dimension(&self, row: &u32) -> Option<&Row> {
866 self.row_dimensions.get_row_dimension(row)
867 }
868
869 #[inline]
871 pub fn get_row_dimension_mut(&mut self, row: &u32) -> &mut Row {
872 self.row_dimensions.get_row_dimension_mut(row)
873 }
874
875 #[inline]
878 pub(crate) fn set_row_dimension(&mut self, value: Row) -> &mut Self {
879 self.row_dimensions.set_row_dimension(value);
880 self
881 }
882
883 #[inline]
886 pub(crate) fn get_row_dimensions_crate_mut(&mut self) -> &mut Rows {
887 &mut self.row_dimensions
888 }
889
890 #[inline]
893 pub(crate) fn _get_row_dimensions_crate(&self) -> &Rows {
894 &self.row_dimensions
895 }
896
897 #[inline]
902 pub fn get_worksheet_drawing(&self) -> &WorksheetDrawing {
903 &self.worksheet_drawing
904 }
905
906 #[inline]
908 pub fn get_worksheet_drawing_mut(&mut self) -> &mut WorksheetDrawing {
909 &mut self.worksheet_drawing
910 }
911
912 #[inline]
916 pub fn set_worksheet_drawing(&mut self, value: WorksheetDrawing) {
917 self.worksheet_drawing = value;
918 }
919
920 #[inline]
922 pub fn has_drawing_object(&self) -> bool {
923 self.worksheet_drawing.has_drawing_object()
924 }
925
926 #[inline]
940 pub fn insert_new_row(&mut self, row_index: &u32, num_rows: &u32) {
941 let title = self.title.clone();
942 self.adjustment_insert_coordinate(&0, &0, row_index, num_rows);
943 self.adjustment_insert_coordinate_with_sheet(&title, &0, &0, row_index, num_rows);
944 }
945
946 #[inline]
948 pub fn insert_new_row_from_other_sheet(
949 &mut self,
950 sheet_name: &str,
951 row_index: &u32,
952 num_rows: &u32,
953 ) {
954 self.adjustment_insert_coordinate(&0, &0, row_index, num_rows);
955 self.adjustment_insert_coordinate_with_sheet(sheet_name, &0, &0, row_index, num_rows);
956 }
957
958 #[inline]
969 pub fn insert_new_column(&mut self, column: &str, num_columns: &u32) {
970 self.insert_new_column_by_index(&column_index_from_string(column), num_columns);
971 }
972
973 #[inline]
975 pub fn insert_new_column_from_other_sheet(
976 &mut self,
977 sheet_name: &str,
978 column: &str,
979 num_columns: &u32,
980 ) {
981 self.insert_new_column_by_index_from_other_sheet(
982 sheet_name,
983 &column_index_from_string(column),
984 num_columns,
985 );
986 }
987
988 #[inline]
999 pub fn insert_new_column_by_index(&mut self, column_index: &u32, num_columns: &u32) {
1000 let title = self.title.clone();
1001 self.adjustment_insert_coordinate(column_index, num_columns, &0, &0);
1002 self.adjustment_insert_coordinate_with_sheet(&title, column_index, num_columns, &0, &0);
1003 }
1004
1005 #[inline]
1007 pub fn insert_new_column_by_index_from_other_sheet(
1008 &mut self,
1009 sheet_name: &str,
1010 column_index: &u32,
1011 num_columns: &u32,
1012 ) {
1013 self.adjustment_insert_coordinate(column_index, num_columns, &0, &0);
1014 self.adjustment_insert_coordinate_with_sheet(sheet_name, column_index, num_columns, &0, &0);
1015 }
1016
1017 #[inline]
1028 pub fn remove_row(&mut self, row_index: &u32, num_rows: &u32) {
1029 let title = self.title.clone();
1030 self.adjustment_remove_coordinate(&0, &0, row_index, num_rows);
1031 self.adjustment_remove_coordinate_with_sheet(&title, &0, &0, row_index, num_rows);
1032 }
1033
1034 #[inline]
1036 pub fn remove_row_from_other_sheet(
1037 &mut self,
1038 sheet_name: &str,
1039 row_index: &u32,
1040 num_rows: &u32,
1041 ) {
1042 self.adjustment_remove_coordinate(&0, &0, row_index, num_rows);
1043 self.adjustment_remove_coordinate_with_sheet(sheet_name, &0, &0, row_index, num_rows);
1044 }
1045
1046 #[inline]
1058 pub fn remove_column(&mut self, column: &str, num_columns: &u32) {
1059 self.remove_column_by_index(&column_index_from_string(column), num_columns);
1060 }
1061
1062 #[inline]
1064 pub fn remove_column_from_other_sheet(
1065 &mut self,
1066 sheet_name: &str,
1067 column: &str,
1068 num_columns: &u32,
1069 ) {
1070 self.remove_column_by_index_from_other_sheet(
1071 sheet_name,
1072 &column_index_from_string(column),
1073 num_columns,
1074 );
1075 }
1076
1077 #[inline]
1088 pub fn remove_column_by_index(&mut self, column_index: &u32, num_columns: &u32) {
1089 let title = self.title.clone();
1090 self.adjustment_remove_coordinate(column_index, num_columns, &0, &0);
1091 self.adjustment_remove_coordinate_with_sheet(&title, column_index, num_columns, &0, &0);
1092 }
1093
1094 #[inline]
1096 pub fn remove_column_by_index_from_other_sheet(
1097 &mut self,
1098 sheet_name: &str,
1099 column_index: &u32,
1100 num_columns: &u32,
1101 ) {
1102 self.adjustment_remove_coordinate(column_index, num_columns, &0, &0);
1103 self.adjustment_remove_coordinate_with_sheet(sheet_name, column_index, num_columns, &0, &0);
1104 }
1105
1106 #[inline]
1108 pub fn get_code_name(&self) -> Option<&str> {
1109 self.code_name.get_value()
1110 }
1111
1112 #[inline]
1116 pub fn set_code_name<S: Into<String>>(&mut self, value: S) {
1117 self.code_name.set_value(value);
1118 }
1119
1120 #[inline]
1122 pub fn get_header_footer(&self) -> &HeaderFooter {
1123 &self.header_footer
1124 }
1125
1126 #[inline]
1128 pub fn get_header_footer_mut(&mut self) -> &mut HeaderFooter {
1129 &mut self.header_footer
1130 }
1131
1132 #[inline]
1136 pub fn set_header_footer(&mut self, value: HeaderFooter) -> &mut Self {
1137 self.header_footer = value;
1138 self
1139 }
1140
1141 #[inline]
1143 pub fn get_active_cell(&self) -> &str {
1144 &self.active_cell
1145 }
1146
1147 #[inline]
1151 pub fn set_active_cell<S: Into<String>>(&mut self, cell: S) {
1152 self.active_cell = cell.into().into_boxed_str();
1153 }
1154
1155 #[inline]
1157 pub(crate) fn get_r_id(&self) -> &str {
1158 &self.r_id
1159 }
1160
1161 #[inline]
1164 pub(crate) fn set_r_id<S: Into<String>>(&mut self, value: S) {
1165 self.r_id = value.into().into_boxed_str();
1166 }
1167
1168 #[inline]
1170 pub fn get_sheet_id(&self) -> &str {
1171 &self.sheet_id
1172 }
1173
1174 #[inline]
1177 pub(crate) fn set_sheet_id<S: Into<String>>(&mut self, value: S) {
1178 self.sheet_id = value.into().into_boxed_str();
1179 }
1180
1181 #[inline]
1183 pub fn has_code_name(&self) -> bool {
1184 self.code_name.has_value()
1185 }
1186
1187 #[inline]
1189 pub fn get_tab_color(&self) -> Option<&Color> {
1190 self.tab_color.as_ref()
1191 }
1192
1193 #[inline]
1195 pub fn get_tab_color_mut(&mut self) -> &mut Color {
1196 if self.tab_color.is_some() {
1197 return self.tab_color.as_mut().unwrap();
1198 }
1199 self.set_tab_color(Color::default());
1200 self.tab_color.as_mut().unwrap()
1201 }
1202
1203 #[inline]
1207 pub fn set_tab_color(&mut self, value: Color) -> &mut Self {
1208 self.tab_color = Some(value);
1209 self
1210 }
1211
1212 #[inline]
1214 pub fn remove_tab_color(&mut self) -> &mut Self {
1215 self.tab_color = None;
1216 self
1217 }
1218
1219 pub fn calculate_worksheet_dimension(&self) -> String {
1221 let (column, row) = self.cell_collection.get_highest_column_and_row();
1222 if row == 0 {
1223 return "A1".to_string();
1224 }
1225 let column_str = string_from_column_index(&column);
1226 format!("A1:{}{}", column_str, row)
1227 }
1228
1229 #[inline]
1233 pub fn get_highest_column_and_row(&self) -> (u32, u32) {
1234 self.cell_collection.get_highest_column_and_row()
1235 }
1236
1237 #[inline]
1239 pub fn get_highest_column(&self) -> u32 {
1240 let (column, _row) = self.cell_collection.get_highest_column_and_row();
1241 column
1242 }
1243
1244 #[inline]
1246 pub fn get_highest_row(&self) -> u32 {
1247 let (_column, row) = self.cell_collection.get_highest_column_and_row();
1248 row
1249 }
1250
1251 #[inline]
1253 pub fn get_name(&self) -> &str {
1254 &self.title
1255 }
1256
1257 pub fn set_name<S: Into<String>>(&mut self, sheet_name: S) -> &mut Self {
1261 self.title = sheet_name.into().into_boxed_str();
1262 let title = self.get_name().to_string();
1263 for defined_name in self.get_defined_names_mut() {
1264 defined_name.set_sheet_name(&title);
1265 }
1266 self
1267 }
1268
1269 #[inline]
1270 pub(crate) fn has_state(&self) -> bool {
1271 self.state.has_value()
1272 }
1273
1274 #[inline]
1275 pub fn get_state(&self) -> &SheetStateValues {
1276 self.state.get_value()
1277 }
1278
1279 #[inline]
1280 pub(crate) fn get_state_str(&self) -> &str {
1281 self.state.get_value_string()
1282 }
1283
1284 pub fn set_state(&mut self, value: SheetStateValues) -> &mut Self {
1285 self.state.set_value(value);
1286 self
1287 }
1288
1289 #[inline]
1290 pub(crate) fn set_state_str(&mut self, value: &str) -> &mut Self {
1291 self.state.set_value_string(value);
1292 self
1293 }
1294
1295 #[inline]
1297 pub fn get_sheet_state(&self) -> &str {
1298 &self.sheet_state
1299 }
1300
1301 #[inline]
1305 pub fn set_sheet_state(&mut self, value: String) -> &mut Self {
1306 self.sheet_state = value.into_boxed_str();
1307 self
1308 }
1309
1310 #[inline]
1312 pub fn get_page_setup(&self) -> &PageSetup {
1313 &self.page_setup
1314 }
1315
1316 #[inline]
1318 pub fn get_page_setup_mut(&mut self) -> &mut PageSetup {
1319 &mut self.page_setup
1320 }
1321
1322 #[inline]
1326 pub fn set_page_setup(&mut self, value: PageSetup) -> &mut Self {
1327 self.page_setup = value;
1328 self
1329 }
1330
1331 #[inline]
1333 pub fn get_page_margins(&self) -> &PageMargins {
1334 &self.page_margins
1335 }
1336
1337 #[inline]
1339 pub fn get_page_margins_mut(&mut self) -> &mut PageMargins {
1340 &mut self.page_margins
1341 }
1342
1343 #[inline]
1347 pub fn set_page_margins(&mut self, value: PageMargins) -> &mut Self {
1348 self.page_margins = value;
1349 self
1350 }
1351
1352 #[inline]
1354 pub fn get_sheets_views(&self) -> &SheetViews {
1355 &self.sheet_views
1356 }
1357
1358 #[inline]
1360 pub fn get_sheet_views_mut(&mut self) -> &mut SheetViews {
1361 &mut self.sheet_views
1362 }
1363
1364 #[inline]
1368 pub fn set_sheets_views(&mut self, value: SheetViews) -> &mut Self {
1369 self.sheet_views = value;
1370 self
1371 }
1372
1373 #[inline]
1375 pub fn get_ole_objects(&self) -> &OleObjects {
1376 &self.ole_objects
1377 }
1378
1379 #[inline]
1381 pub fn get_ole_objects_mut(&mut self) -> &mut OleObjects {
1382 &mut self.ole_objects
1383 }
1384
1385 #[inline]
1389 pub fn set_ole_objects(&mut self, value: OleObjects) -> &mut Self {
1390 self.ole_objects = value;
1391 self
1392 }
1393
1394 #[inline]
1396 pub fn get_defined_names(&self) -> &[DefinedName] {
1397 &self.defined_names
1398 }
1399
1400 #[inline]
1402 pub fn get_defined_names_mut(&mut self) -> &mut ThinVec<DefinedName> {
1403 &mut self.defined_names
1404 }
1405
1406 #[inline]
1410 pub fn set_defined_names(&mut self, value: impl Into<ThinVec<DefinedName>>) {
1411 self.defined_names = value.into();
1412 }
1413
1414 #[inline]
1418 pub fn add_defined_names(&mut self, value: DefinedName) {
1419 self.defined_names.push(value);
1420 }
1421
1422 #[inline]
1427 pub fn add_defined_name<S: Into<String>>(&mut self, name: S, address: S) -> Result<(), &str> {
1428 let mut defined_name = DefinedName::default();
1429 defined_name.set_name(name.into());
1430 defined_name.set_address(address.into());
1431 self.add_defined_names(defined_name);
1432 Ok(())
1433 }
1434
1435 #[inline]
1437 pub fn get_print_options(&self) -> &PrintOptions {
1438 &self.print_options
1439 }
1440
1441 #[inline]
1443 pub fn get_print_options_mut(&mut self) -> &mut PrintOptions {
1444 &mut self.print_options
1445 }
1446
1447 #[inline]
1451 pub fn set_print_options(&mut self, value: PrintOptions) -> &mut Self {
1452 self.print_options = value;
1453 self
1454 }
1455
1456 #[inline]
1458 pub fn get_column_breaks(&self) -> &ColumnBreaks {
1459 &self.column_breaks
1460 }
1461
1462 #[inline]
1464 pub fn get_column_breaks_mut(&mut self) -> &mut ColumnBreaks {
1465 &mut self.column_breaks
1466 }
1467
1468 #[inline]
1472 pub fn set_column_breaks(&mut self, value: ColumnBreaks) -> &mut Self {
1473 self.column_breaks = value;
1474 self
1475 }
1476
1477 #[inline]
1479 pub fn get_row_breaks(&self) -> &RowBreaks {
1480 &self.row_breaks
1481 }
1482
1483 #[inline]
1485 pub fn get_row_breaks_mut(&mut self) -> &mut RowBreaks {
1486 &mut self.row_breaks
1487 }
1488
1489 #[inline]
1493 pub fn set_row_breaks(&mut self, value: RowBreaks) -> &mut Self {
1494 self.row_breaks = value;
1495 self
1496 }
1497
1498 #[inline]
1499 pub fn has_table(&self) -> bool {
1500 !self.tables.is_empty()
1501 }
1502
1503 #[inline]
1504 pub fn add_table(&mut self, table: Table) {
1505 self.tables.push(table);
1506 }
1507
1508 #[inline]
1509 pub fn get_tables(&self) -> &[Table] {
1510 &self.tables
1511 }
1512
1513 #[inline]
1514 pub fn get_tables_mut(&mut self) -> &mut ThinVec<Table> {
1515 &mut self.tables
1516 }
1517
1518 #[inline]
1519 pub(crate) fn has_pivot_table(&self) -> bool {
1520 !self.pivot_tables.is_empty()
1521 }
1522
1523 #[inline]
1524 pub(crate) fn add_pivot_table(&mut self, pivot_table: PivotTable) {
1525 self.pivot_tables.push(pivot_table);
1526 }
1527
1528 #[inline]
1529 pub(crate) fn get_pivot_tables(&self) -> &[PivotTable] {
1530 &self.pivot_tables
1531 }
1532
1533 #[inline]
1534 pub(crate) fn get_pivot_tables_mut(&mut self) -> &mut ThinVec<PivotTable> {
1535 &mut self.pivot_tables
1536 }
1537
1538 #[inline]
1539 pub fn get_data_validations(&self) -> Option<&DataValidations> {
1540 self.data_validations.as_ref()
1541 }
1542
1543 #[inline]
1544 pub fn get_data_validations_mut(&mut self) -> Option<&mut DataValidations> {
1545 self.data_validations.as_mut()
1546 }
1547
1548 #[inline]
1549 pub fn set_data_validations(&mut self, value: DataValidations) -> &mut Self {
1550 self.data_validations = Some(value);
1551 self
1552 }
1553
1554 #[inline]
1555 pub fn remove_data_validations(&mut self) -> &mut Self {
1556 self.data_validations = None;
1557 self
1558 }
1559
1560 #[inline]
1561 pub fn get_data_validations_2010(&self) -> Option<&DataValidations2010> {
1562 self.data_validations_2010.as_ref()
1563 }
1564
1565 #[inline]
1566 pub fn get_data_validations_2010_mut(&mut self) -> Option<&mut DataValidations2010> {
1567 self.data_validations_2010.as_mut()
1568 }
1569
1570 #[inline]
1571 pub fn set_data_validations_2010(&mut self, value: DataValidations2010) -> &mut Self {
1572 self.data_validations_2010 = Some(value);
1573 self
1574 }
1575
1576 #[inline]
1577 pub fn remove_data_validations_2010(&mut self) -> &mut Self {
1578 self.data_validations_2010 = None;
1579 self
1580 }
1581
1582 #[inline]
1583 pub fn get_sheet_format_properties(&self) -> &SheetFormatProperties {
1584 &self.sheet_format_properties
1585 }
1586
1587 #[inline]
1588 pub fn get_sheet_format_properties_mut(&mut self) -> &mut SheetFormatProperties {
1589 &mut self.sheet_format_properties
1590 }
1591
1592 #[inline]
1593 pub fn set_sheet_format_properties(&mut self, value: SheetFormatProperties) -> &mut Self {
1594 self.sheet_format_properties = value;
1595 self
1596 }
1597
1598 #[inline]
1602 pub fn get_image_collection(&self) -> &[Image] {
1603 self.get_worksheet_drawing().get_image_collection()
1604 }
1605
1606 #[inline]
1610 pub fn get_image_collection_mut(&mut self) -> &mut ThinVec<Image> {
1611 self.get_worksheet_drawing_mut().get_image_collection_mut()
1612 }
1613
1614 #[inline]
1615 pub fn add_image(&mut self, value: Image) -> &mut Self {
1616 self.get_worksheet_drawing_mut().add_image(value);
1617 self
1618 }
1619
1620 #[inline]
1621 pub fn get_image<T>(&self, coordinate: T) -> Option<&Image>
1622 where
1623 T: Into<CellCoordinates>,
1624 {
1625 let CellCoordinates { col, row } = coordinate.into();
1626 self.get_worksheet_drawing().get_image(&col, &row)
1627 }
1628
1629 #[inline]
1630 pub fn get_image_mut<T>(&mut self, coordinate: T) -> Option<&mut Image>
1631 where
1632 T: Into<CellCoordinates>,
1633 {
1634 let CellCoordinates { col, row } = coordinate.into();
1635 self.get_worksheet_drawing_mut().get_image_mut(&col, &row)
1636 }
1637
1638 #[inline]
1639 pub fn get_image_by_column_and_row_mut(&mut self, col: &u32, row: &u32) -> Option<&mut Image> {
1640 self.get_worksheet_drawing_mut().get_image_mut(col, row)
1641 }
1642
1643 #[inline]
1644 pub fn get_images<T>(&self, coordinate: T) -> Vec<&Image>
1645 where
1646 T: Into<CellCoordinates>,
1647 {
1648 let CellCoordinates { col, row } = coordinate.into();
1649 self.get_worksheet_drawing().get_images(&col, &row)
1650 }
1651
1652 #[inline]
1653 pub fn get_images_mut<T>(&mut self, coordinate: T) -> Vec<&mut Image>
1654 where
1655 T: Into<CellCoordinates>,
1656 {
1657 let CellCoordinates { col, row } = coordinate.into();
1658 self.get_worksheet_drawing_mut().get_images_mut(&col, &row)
1659 }
1660
1661 #[inline]
1665 pub fn get_chart_collection(&self) -> &[Chart] {
1666 self.get_worksheet_drawing().get_chart_collection()
1667 }
1668
1669 #[inline]
1673 pub fn get_chart_collection_mut(&mut self) -> &mut ThinVec<Chart> {
1674 self.get_worksheet_drawing_mut().get_chart_collection_mut()
1675 }
1676
1677 #[inline]
1678 pub fn add_chart(&mut self, value: Chart) -> &mut Self {
1679 self.get_worksheet_drawing_mut().add_chart_collection(value);
1680 self
1681 }
1682
1683 #[inline]
1684 pub fn get_chart<T>(&self, coordinate: T) -> Option<&Chart>
1685 where
1686 T: Into<CellCoordinates>,
1687 {
1688 let CellCoordinates { col, row } = coordinate.into();
1689 self.get_worksheet_drawing().get_chart(&col, &row)
1690 }
1691
1692 #[inline]
1693 pub fn get_chart_mut<T>(&mut self, coordinate: T) -> Option<&mut Chart>
1694 where
1695 T: Into<CellCoordinates>,
1696 {
1697 let CellCoordinates { col, row } = coordinate.into();
1698 self.get_worksheet_drawing_mut().get_chart_mut(&col, &row)
1699 }
1700
1701 #[inline]
1702 pub fn get_charts<T>(&self, coordinate: T) -> Vec<&Chart>
1703 where
1704 T: Into<CellCoordinates>,
1705 {
1706 let CellCoordinates { col, row } = coordinate.into();
1707 self.get_worksheet_drawing().get_charts(&col, &row)
1708 }
1709
1710 #[inline]
1711 pub fn get_charts_mut<T>(&mut self, coordinate: T) -> Vec<&mut Chart>
1712 where
1713 T: Into<CellCoordinates>,
1714 {
1715 let CellCoordinates { col, row } = coordinate.into();
1716 self.get_worksheet_drawing_mut().get_charts_mut(&col, &row)
1717 }
1718
1719 pub(crate) fn get_media_object_collection(&self) -> Vec<&MediaObject> {
1723 let mut list: Vec<&MediaObject> = Vec::new();
1724 for image in self.get_worksheet_drawing().get_image_collection() {
1725 for media_object in image.get_media_object() {
1726 let is_new = !list
1727 .iter()
1728 .any(|v| v.get_image_name() == media_object.get_image_name());
1729 if is_new {
1730 list.push(media_object);
1731 }
1732 }
1733 }
1734 for ole_objects in self.get_ole_objects().get_ole_object() {
1735 let media_object = ole_objects.get_embedded_object_properties().get_image();
1736 let is_new = !list
1737 .iter()
1738 .any(|v| v.get_image_name() == media_object.get_image_name());
1739 if is_new {
1740 list.push(media_object);
1741 }
1742 }
1743 for ole_objects in self.get_ole_objects().get_ole_object() {
1744 if let Some(fill) = ole_objects.get_shape().get_fill() {
1745 if let Some(media_object) = fill.get_image() {
1746 let is_new = !list
1747 .iter()
1748 .any(|v| v.get_image_name() == media_object.get_image_name());
1749 if is_new {
1750 list.push(media_object);
1751 }
1752 }
1753 }
1754 }
1755 for comment in self.get_comments() {
1756 if let Some(fill) = comment.get_shape().get_fill() {
1757 if let Some(media_object) = fill.get_image() {
1758 let is_new = !list
1759 .iter()
1760 .any(|v| v.get_image_name() == media_object.get_image_name());
1761 if is_new {
1762 list.push(media_object);
1763 }
1764 }
1765 }
1766 }
1767
1768 list
1769 }
1770
1771 pub(crate) fn get_pivot_cache_definition_collection(&self) -> Vec<&str> {
1772 let mut result: Vec<&str> = Vec::new();
1773 if let Some(raw_data) = &self.raw_data_of_worksheet {
1774 for relationships in raw_data.get_relationships_list() {
1775 for row in relationships.get_relationship_list() {
1776 if row.get_type() == PIVOT_CACHE_DEF_NS {
1777 result.push(row.get_raw_file().get_file_target());
1778 }
1779 }
1780 }
1781 }
1782 result
1783 }
1784
1785 #[inline]
1788 pub(crate) fn has_defined_names(&self) -> bool {
1789 !self.get_defined_names().is_empty()
1790 }
1791
1792 #[inline]
1793 pub(crate) fn is_deserialized(&self) -> bool {
1794 self.raw_data_of_worksheet.is_none()
1795 }
1796
1797 #[inline]
1798 pub(crate) fn get_raw_data_of_worksheet(&self) -> &RawWorksheet {
1799 self.raw_data_of_worksheet
1800 .as_ref()
1801 .expect("Not found at raw data of worksheet.")
1802 }
1803
1804 #[inline]
1805 pub(crate) fn set_raw_data_of_worksheet(&mut self, value: RawWorksheet) -> &mut Self {
1806 self.raw_data_of_worksheet = Some(value);
1807 self
1808 }
1809
1810 #[inline]
1811 pub(crate) fn remove_raw_data_of_worksheet(&mut self) -> &mut Self {
1812 self.raw_data_of_worksheet = None;
1813 self
1814 }
1815
1816 #[inline]
1817 pub fn get_sheet_protection(&self) -> Option<&SheetProtection> {
1818 self.sheet_protection.as_ref()
1819 }
1820
1821 #[inline]
1822 pub fn get_sheet_protection_mut(&mut self) -> &mut SheetProtection {
1823 self.sheet_protection
1824 .get_or_insert(SheetProtection::default())
1825 }
1826
1827 #[inline]
1828 pub fn set_sheet_protection(&mut self, value: SheetProtection) -> &mut Self {
1829 self.sheet_protection = Some(value);
1830 self
1831 }
1832
1833 #[inline]
1834 pub fn remove_sheet_protection(&mut self) -> &mut Self {
1835 self.sheet_protection = None;
1836 self
1837 }
1838
1839 #[inline]
1842 pub(crate) fn has_ole_objects(&self) -> bool {
1843 !self.ole_objects.get_ole_object().is_empty()
1844 }
1845
1846 #[inline]
1849 pub(crate) fn has_legacy_drawing(&self) -> bool {
1850 self.has_comments() || self.has_ole_objects()
1851 }
1852
1853 #[inline]
1859 pub fn move_range(&mut self, range: &str, row: &i32, column: &i32) -> &mut Self {
1860 self.move_or_copy_range(&range, &row, &column, true)
1861 }
1862
1863 #[inline]
1869 pub fn copy_range(&mut self, range: &str, row: &i32, column: &i32) -> &mut Self {
1870 self.move_or_copy_range(&range, &row, &column, false)
1871 }
1872
1873 #[inline]
1875 fn move_or_copy_range(
1876 &mut self,
1877 range: &str,
1878 row: &i32,
1879 column: &i32,
1880 is_move: bool,
1881 ) -> &mut Self {
1882 let (row_start, row_end, col_start, col_end) = get_start_and_end_point(&range);
1886 if (col_start as i32 + column) < 1
1887 || (row_start as i32 + row) < 1
1888 || (col_end as i32 + column) > 16384
1889 || (row_end as i32 + row) > 1048576
1890 {
1891 panic!("Out of Range.");
1892 }
1893
1894 let mut copy_cells: Vec<Cell> = self
1896 .cell_collection
1897 .iter_all_cells_by_range_sorted_by_row(range)
1898 .flatten()
1899 .map(|cell| cell.clone())
1900 .collect();
1901
1902 if is_move {
1904 get_coordinate_list(&range)
1905 .iter()
1906 .for_each(|(col_num, row_num)| {
1907 self.cell_collection.remove(col_num, row_num);
1908 self.cell_collection.remove(
1909 &((*col_num as i32 + column) as u32),
1910 &((*row_num as i32 + row) as u32),
1911 );
1912 });
1913 }
1914
1915 for cell in &mut copy_cells {
1917 cell.get_coordinate_mut().offset_col_num(*column);
1918 cell.get_coordinate_mut().offset_row_num(*row);
1919 self.set_cell(cell.clone());
1920 }
1921
1922 self
1923 }
1924
1925 #[inline]
1929 pub fn cleanup(&mut self) {
1930 let (_, max_row) = self.get_highest_column_and_row();
1931 for row in (1..(max_row + 1)).rev() {
1932 if self.row_dimensions.get_row_dimension(&row).is_some() {
1933 let mut indexes: Vec<(u32, u32)> = Vec::new();
1934 {
1935 let cells: Vec<&Cell> = self.cell_collection.iter_cells_by_row(row).collect();
1936 for cell in cells {
1937 if !cell.is_visually_empty() {
1938 return;
1939 }
1940 indexes.push((
1941 *cell.get_coordinate().get_row_num(),
1942 *cell.get_coordinate().get_col_num(),
1943 ));
1944 }
1945 }
1946
1947 self.row_dimensions
1948 .get_row_dimensions_to_hashmap_mut()
1949 .remove(&row);
1950 for (i_row, i_col) in indexes {
1951 self.cell_collection.remove(&i_col, &i_row);
1952 }
1953 }
1954 }
1955 }
1956
1957 #[inline]
1958 pub fn copy_cell_styling<T>(&mut self, source: T, target: T)
1959 where
1960 T: Into<CellCoordinates>,
1961 {
1962 let style = self.cell_collection.get_style(source).clone();
1963 self.get_cell_mut(target).set_style(style);
1964 }
1965
1966 #[inline]
1973 pub fn copy_row_styling(
1974 &mut self,
1975 source_row_no: &u32,
1976 target_row_no: &u32,
1977 start_col: Option<&u32>,
1978 end_col: Option<&u32>,
1979 ) {
1980 let mut start_no = *start_col.unwrap_or(&1);
1981 let mut end_no = *end_col.unwrap_or(&self.get_highest_column());
1982
1983 if let Some(row_style) = self
1984 ._get_row_dimensions_crate()
1985 .get_row_dimension(source_row_no)
1986 .map(Row::get_style)
1987 .cloned()
1988 {
1989 self.get_row_dimensions_crate_mut()
1990 .get_row_dimension_mut(target_row_no)
1991 .set_style(row_style);
1992 }
1993
1994 for col_no in start_no..=end_no {
1995 self.copy_cell_styling((&col_no, source_row_no), (&col_no, target_row_no));
1996 }
1997 }
1998
1999 #[inline]
2006 pub fn copy_col_styling(
2007 &mut self,
2008 source_col_no: &u32,
2009 target_col_no: &u32,
2010 start_row: Option<&u32>,
2011 end_row: Option<&u32>,
2012 ) {
2013 let mut start_no = *start_row.unwrap_or(&1);
2014 let mut end_no = *end_row.unwrap_or(&self.get_highest_row());
2015
2016 if let Some(col_style) = self
2017 .get_column_dimensions_crate()
2018 .get_column(source_col_no)
2019 .map(Column::get_style)
2020 .cloned()
2021 {
2022 self.get_column_dimensions_crate_mut()
2023 .get_column_mut(target_col_no)
2024 .set_style(col_style);
2025 }
2026
2027 for row_no in start_no..=end_no {
2028 self.copy_cell_styling((source_col_no, &row_no), (target_col_no, &row_no));
2029 }
2030 }
2031}
2032impl AdjustmentCoordinate for Worksheet {
2033 fn adjustment_insert_coordinate(
2034 &mut self,
2035 root_col_num: &u32,
2036 offset_col_num: &u32,
2037 root_row_num: &u32,
2038 offset_row_num: &u32,
2039 ) {
2040 if offset_col_num != &0 {
2041 self.column_dimensions
2043 .adjustment_insert_value(root_col_num, offset_col_num);
2044 }
2045 if offset_row_num != &0 {
2046 self.get_row_dimensions_crate_mut()
2048 .adjustment_insert_value(root_row_num, offset_row_num);
2049 }
2050 if (offset_col_num == &0 && offset_row_num == &0) {
2051 return;
2052 }
2053
2054 for defined_name in &mut self.defined_names {
2056 defined_name.adjustment_insert_coordinate_with_sheet(
2057 &self.title,
2058 root_col_num,
2059 offset_col_num,
2060 root_row_num,
2061 offset_row_num,
2062 );
2063 }
2064
2065 self.cell_collection.adjustment_insert_coordinate(
2067 root_col_num,
2068 offset_col_num,
2069 root_row_num,
2070 offset_row_num,
2071 );
2072
2073 self.worksheet_drawing.adjustment_insert_coordinate(
2075 root_col_num,
2076 offset_col_num,
2077 root_row_num,
2078 offset_row_num,
2079 );
2080
2081 for comment in &mut self.comments {
2083 comment.adjustment_insert_coordinate(
2084 root_col_num,
2085 offset_col_num,
2086 root_row_num,
2087 offset_row_num,
2088 );
2089 }
2090
2091 for conditional_styles in &mut self.conditional_formatting_collection {
2093 conditional_styles.adjustment_insert_coordinate(
2094 root_col_num,
2095 offset_col_num,
2096 root_row_num,
2097 offset_row_num,
2098 );
2099 }
2100
2101 for merge_cell in self.get_merge_cells_mut() {
2103 merge_cell.adjustment_insert_coordinate(
2104 root_col_num,
2105 offset_col_num,
2106 root_row_num,
2107 offset_row_num,
2108 );
2109 }
2110
2111 if let Some(v) = self.get_auto_filter_mut() {
2113 v.adjustment_insert_coordinate(
2114 root_col_num,
2115 offset_col_num,
2116 root_row_num,
2117 offset_row_num,
2118 );
2119 };
2120 }
2121
2122 fn adjustment_remove_coordinate(
2123 &mut self,
2124 root_col_num: &u32,
2125 offset_col_num: &u32,
2126 root_row_num: &u32,
2127 offset_row_num: &u32,
2128 ) {
2129 if offset_col_num != &0 {
2130 self.column_dimensions
2132 .adjustment_remove_value(root_col_num, offset_col_num);
2133 }
2134 if offset_row_num != &0 {
2135 self.row_dimensions
2137 .adjustment_remove_value(root_row_num, offset_row_num);
2138 }
2139 if (offset_col_num == &0 && offset_row_num == &0) {
2140 return;
2141 }
2142
2143 let title = &self.title;
2145 self.defined_names.retain(|defined_name| {
2146 !defined_name.is_remove_coordinate_with_sheet(
2147 &title,
2148 root_col_num,
2149 offset_col_num,
2150 root_row_num,
2151 offset_row_num,
2152 )
2153 });
2154
2155 for defined_name in &mut self.defined_names {
2156 defined_name.adjustment_remove_coordinate_with_sheet(
2157 &self.title,
2158 root_col_num,
2159 offset_col_num,
2160 root_row_num,
2161 offset_row_num,
2162 );
2163 }
2164
2165 self.cell_collection.adjustment_remove_coordinate(
2167 root_col_num,
2168 offset_col_num,
2169 root_row_num,
2170 offset_row_num,
2171 );
2172
2173 self.get_worksheet_drawing_mut()
2175 .adjustment_remove_coordinate(
2176 root_col_num,
2177 offset_col_num,
2178 root_row_num,
2179 offset_row_num,
2180 );
2181
2182 self.comments.retain(|x| {
2184 !(x.is_remove_coordinate(root_col_num, offset_col_num, root_row_num, offset_row_num))
2185 });
2186 for comment in &mut self.comments {
2187 comment.adjustment_remove_coordinate(
2188 root_col_num,
2189 offset_col_num,
2190 root_row_num,
2191 offset_row_num,
2192 );
2193 }
2194
2195 self.conditional_formatting_collection.retain(|x| {
2197 !x.is_remove_coordinate(root_col_num, offset_col_num, root_row_num, offset_row_num)
2198 });
2199 for conditional_styles in &mut self.conditional_formatting_collection {
2200 conditional_styles.adjustment_remove_coordinate(
2201 root_col_num,
2202 offset_col_num,
2203 root_row_num,
2204 offset_row_num,
2205 );
2206 }
2207
2208 self.get_merge_cells_mut().retain(|x| {
2210 !(x.is_remove_coordinate(root_col_num, offset_col_num, root_row_num, offset_row_num))
2211 });
2212 for merge_cell in self.get_merge_cells_mut() {
2213 merge_cell.adjustment_remove_coordinate(
2214 root_col_num,
2215 offset_col_num,
2216 root_row_num,
2217 offset_row_num,
2218 );
2219 }
2220
2221 let is_remove = match self.get_auto_filter() {
2223 Some(v) => v.get_range().is_remove_coordinate(
2224 root_col_num,
2225 offset_col_num,
2226 root_row_num,
2227 offset_row_num,
2228 ),
2229 None => false,
2230 };
2231 if is_remove {
2232 self.remove_auto_filter();
2233 }
2234 if let Some(v) = self.get_auto_filter_mut() {
2235 v.adjustment_remove_coordinate(
2236 root_col_num,
2237 offset_col_num,
2238 root_row_num,
2239 offset_row_num,
2240 );
2241 };
2242 }
2243}
2244impl AdjustmentCoordinateWithSheet for Worksheet {
2245 fn adjustment_insert_coordinate_with_sheet(
2246 &mut self,
2247 sheet_name: &str,
2248 root_col_num: &u32,
2249 offset_col_num: &u32,
2250 root_row_num: &u32,
2251 offset_row_num: &u32,
2252 ) {
2253 if (offset_col_num == &0 && offset_row_num == &0) {
2254 return;
2255 }
2256
2257 let title = self.title.clone();
2259 self.get_cell_collection_crate_mut()
2260 .adjustment_insert_coordinate_with_2sheet(
2261 &title,
2262 sheet_name,
2263 root_col_num,
2264 offset_col_num,
2265 root_row_num,
2266 offset_row_num,
2267 );
2268
2269 self.worksheet_drawing
2271 .adjustment_insert_coordinate_with_sheet(
2272 sheet_name,
2273 root_col_num,
2274 offset_col_num,
2275 root_row_num,
2276 offset_row_num,
2277 );
2278 }
2279
2280 fn adjustment_remove_coordinate_with_sheet(
2281 &mut self,
2282 sheet_name: &str,
2283 root_col_num: &u32,
2284 offset_col_num: &u32,
2285 root_row_num: &u32,
2286 offset_row_num: &u32,
2287 ) {
2288 if (offset_col_num == &0 && offset_row_num == &0) {
2289 return;
2290 }
2291
2292 let title = self.title.clone();
2294 self.get_cell_collection_crate_mut()
2295 .adjustment_remove_coordinate_with_2sheet(
2296 &title,
2297 sheet_name,
2298 root_col_num,
2299 offset_col_num,
2300 root_row_num,
2301 offset_row_num,
2302 );
2303
2304 self.worksheet_drawing
2306 .adjustment_remove_coordinate_with_sheet(
2307 sheet_name,
2308 root_col_num,
2309 offset_col_num,
2310 root_row_num,
2311 offset_row_num,
2312 );
2313 }
2314}