umya_spreadsheet/structs/
worksheet.rs

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/// A Worksheet Object.
57#[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    // ************************
96    // Value
97    // ************************
98
99    /// Get value.
100    /// # Arguments
101    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)` or `(&1, &1)`
102    /// # Return value
103    /// * `String` - Value of the specified cell.
104    /// # Examples
105    /// ```
106    /// let book = umya_spreadsheet::new_file();
107    /// let worksheet = book.get_sheet(&0).unwrap();
108    /// let value = worksheet.get_value("A1");
109    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
110    /// let value = worksheet.get_value((1, 1));
111    /// ```
112    #[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    /// Get value number.
124    /// # Arguments
125    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)`
126    /// # Return value
127    /// * `Option<f64>` - Value of the specified cell.
128    /// # Examples
129    /// ```
130    /// let book = umya_spreadsheet::new_file();
131    /// let worksheet = book.get_sheet(&0).unwrap();
132    /// let value = worksheet.get_value_number("A1");
133    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
134    /// let value = worksheet.get_value_number((1, 1));
135    /// ```
136    #[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    /// Get formatted value.
146    /// # Arguments
147    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)` or `(&1, &1)`
148    /// # Return value
149    /// * `String` - Formatted value of the specified cell.
150    /// # Examples
151    /// ```
152    /// let book = umya_spreadsheet::new_file();
153    /// let worksheet = book.get_sheet(&0).unwrap();
154    /// let value = worksheet.get_formatted_value("A1");
155    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
156    /// let value = worksheet.get_formatted_value((1, 1));
157    /// ```
158    #[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    // ************************
169    // Cell
170    // ************************
171    /// Get Cell List.
172    #[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    /// Get Cell List in mutable.
185    #[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    /// (This method is crate only.)
216    /// Get Cells.
217    #[inline]
218    pub(crate) fn get_cell_collection_crate(&self) -> &Cells {
219        &self.cell_collection
220    }
221
222    /// (This method is crate only.)
223    /// Get Cells in mutable.
224    #[inline]
225    pub(crate) fn get_cell_collection_crate_mut(&mut self) -> &mut Cells {
226        &mut self.cell_collection
227    }
228
229    /// Get cell.
230    /// # Note
231    /// Cells with unset Value and Style will return None.
232    /// # Arguments
233    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)` or `(&1, &1)`
234    /// # Return value
235    /// * `Option` - Cell in the Some.
236    /// # Examples
237    /// ```
238    /// let book = umya_spreadsheet::new_file();
239    /// let worksheet = book.get_sheet(&0).unwrap();
240    /// let cell = worksheet.get_cell("A1");
241    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
242    /// let cell = worksheet.get_cell((1, 1));
243    /// ```
244    #[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    /// Get cell with mutable.
253    /// # Arguments
254    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)` or `(&1, &1)`
255    /// # Return value
256    /// * `&mut Cell` - Cell with mutable.
257    /// # Examples
258    /// ```
259    /// let mut book = umya_spreadsheet::new_file();
260    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
261    /// let cell = worksheet.get_cell_mut("A1");
262    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
263    /// let cell = worksheet.get_cell_mut((1, 1));
264    /// ```
265    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    /// Set Cell
302    /// # Arguments
303    /// * `cell` - Cell
304    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    /// Remove Cell
317    /// # Arguments
318    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)` or `(&1, &1)`
319    /// # Examples
320    /// ```
321    /// worksheet.remove_cell("A1");
322    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
323    /// worksheet.remove_cell((1, 1));
324    /// ```
325    #[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    /// Get cell value.
335    /// # Arguments
336    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)` or `(&1, &1)`
337    /// # Return value
338    /// * `&CellValue` - CellValue.
339    /// # Examples
340    /// ```
341    /// let book = umya_spreadsheet::new_file();
342    /// let worksheet = book.get_sheet(&0).unwrap();
343    /// let cell_value = worksheet.get_cell_value("A1");
344    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
345    /// let cell_value = worksheet.get_cell_value((1, 1));
346    /// ```
347    #[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    /// Get cell value with mutable.
356    /// # Arguments
357    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)` or `(&1, &1)`
358    /// # Return value
359    /// * `&mut CellValue` - CellValue with mutable.
360    /// # Examples
361    /// ```
362    /// let mut book = umya_spreadsheet::new_file();
363    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
364    /// let cell_value = worksheet.get_cell_value_mut("A1");
365    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
366    /// let cell_value = worksheet.get_cell_value_mut((1, 1));
367    /// ```
368    #[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    /// Gets the cell value by specifying an range.
377    /// # Arguments
378    /// * `range` - range. ex) "A1:C5"
379    /// # Return value
380    /// *`Vec<&CellValue>` - CellValue List.
381    /// # Examples
382    /// ```
383    /// let mut book = umya_spreadsheet::new_file();
384    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
385    /// let mut cell_value_List = worksheet.get_cell_value_by_range("A1:C5");
386    /// ```
387    #[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    /// Get style.
395    /// # Arguments
396    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)` or `(&1, &1)`
397    /// # Return value
398    /// * `&Style` - Style.
399    /// # Examples
400    /// ```
401    /// let book = umya_spreadsheet::new_file();
402    /// let worksheet = book.get_sheet(&0).unwrap();
403    /// let style = worksheet.get_style("A1");
404    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
405    /// let style = worksheet.get_style((1, 1));
406    /// ```
407    #[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    /// Get style with mutable.
416    /// # Arguments
417    /// * `coordinate` - Specify the coordinates. ex) `"A1"` or `(1, 1)` or `(&1, &1)`
418    /// # Return value
419    /// * `&mut Style` - Style with mutable.
420    /// # Examples
421    /// ```
422    /// let mut book = umya_spreadsheet::new_file();
423    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
424    /// let style = worksheet.get_style_mut("A1");
425    /// // or pass in a tuple `(col, row)`, both col and row starting at `1`
426    /// let style = worksheet.get_style_mut((1, 1));
427    /// ```
428    #[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    /// Set style by range.
446    /// # Arguments
447    /// * `range` - Specify the range. ex) "A1:B2"
448    /// * `style` - Style
449    /// # Return value
450    /// * `&mut Self` - Self.
451    /// # Examples
452    /// ```
453    /// let mut book = umya_spreadsheet::new_file();
454    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
455    /// let mut style = umya_spreadsheet::Style::default();
456    /// style.get_borders_mut().get_bottom_mut().set_border_style(umya_spreadsheet::Border::BORDER_MEDIUM);
457    /// worksheet.set_style_by_range("A1:A3", style);
458    /// ```
459    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    /// Get the upper-left corner cell of a cell inside a merged cell range (if any).
487    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    // ************************
522    // Comment
523    // ************************
524    /// Get Comments
525    #[inline]
526    pub fn get_comments(&self) -> &[Comment] {
527        &self.comments
528    }
529
530    /// Get Comments in mutable.
531    #[inline]
532    pub fn get_comments_mut(&mut self) -> &mut ThinVec<Comment> {
533        &mut self.comments
534    }
535
536    /// Get Comments convert to hashmap.
537    #[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    /// Set Comments.
547    /// # Arguments
548    /// * `value` - Comment List (Vec)
549    #[inline]
550    pub fn set_comments(&mut self, value: impl Into<ThinVec<Comment>>) {
551        self.comments = value.into();
552    }
553
554    /// Add Comments.
555    /// # Arguments
556    /// * `value` - Comment
557    #[inline]
558    pub fn add_comments(&mut self, value: Comment) {
559        self.comments.push(value);
560    }
561
562    /// Has Comments.
563    #[inline]
564    pub fn has_comments(&self) -> bool {
565        !self.comments.is_empty()
566    }
567
568    // ************************
569    // ThreadedComment
570    // ************************
571    /// Get ThreadedComments
572    #[inline]
573    pub fn get_threaded_comments(&self) -> &[ThreadedComment] {
574        &self.threaded_comments
575    }
576
577    /// Get ThreadedComments in mutable.
578    #[inline]
579    pub fn get_threaded_comments_mut(&mut self) -> &mut ThinVec<ThreadedComment> {
580        &mut self.threaded_comments
581    }
582
583    /// Get ThreadedComments convert to hashmap.
584    #[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    /// Set ThreadedComment.
597    /// # Arguments
598    /// * `value` - ThreadedComment List (Vec)
599    #[inline]
600    pub fn set_threaded_comments(&mut self, value: impl Into<ThinVec<ThreadedComment>>) {
601        self.threaded_comments = value.into();
602    }
603
604    /// Add ThreadedComment.
605    /// # Arguments
606    /// * `value` - ThreadedComment
607    #[inline]
608    pub fn add_threaded_comments(&mut self, value: ThreadedComment) {
609        self.threaded_comments.push(value);
610    }
611
612    /// Has ThreadedComments.
613    #[inline]
614    pub fn has_threaded_comments(&self) -> bool {
615        !self.threaded_comments.is_empty()
616    }
617
618    // ************************
619    // Conditional
620    // ************************
621    /// Get ConditionalFormatting list.
622    #[inline]
623    pub fn get_conditional_formatting_collection(&self) -> &[ConditionalFormatting] {
624        &self.conditional_formatting_collection
625    }
626
627    /// Set ConditionalFormatting.
628    /// # Arguments
629    /// * `value` - ConditionalSet List (Vec)
630    #[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    /// Add ConditionalFormatting.
639    /// # Arguments
640    /// * `value` - ConditionalFormatting
641    #[inline]
642    pub fn add_conditional_formatting_collection(&mut self, value: ConditionalFormatting) {
643        self.conditional_formatting_collection.push(value);
644    }
645
646    // ************************
647    // Hyperlink
648    // ************************
649    /// (This method is crate only.)
650    /// Get Hyperlink convert to vec.
651    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    /// (This method is crate only.)
666    /// Has Hyperlink
667    #[inline]
668    pub(crate) fn has_hyperlink(&self) -> bool {
669        self.cell_collection.has_hyperlink()
670    }
671
672    // ************************
673    // Merge Cells
674    // ************************
675    // Get Merge Cells
676    #[inline]
677    pub fn get_merge_cells(&self) -> &[Range] {
678        self.merge_cells.get_range_collection()
679    }
680
681    // Get Merge Cells in mutable.
682    #[inline]
683    pub fn get_merge_cells_mut(&mut self) -> &mut ThinVec<Range> {
684        self.merge_cells.get_range_collection_mut()
685    }
686
687    // Add Merge Cells.
688    /// # Arguments
689    /// * `range` - Range. ex) "A1:C5"
690    /// # Examples
691    /// ```
692    /// let mut book = umya_spreadsheet::new_file();
693    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
694    /// worksheet.add_merge_cells("A1:C5");
695    /// ```
696    #[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    /// (This method is crate only.)
703    // Get Merge Cells Object
704    #[inline]
705    pub(crate) fn get_merge_cells_crate(&self) -> &MergeCells {
706        &self.merge_cells
707    }
708
709    /// (This method is crate only.)
710    // Get Merge Cells Object in mutable.
711    #[inline]
712    pub(crate) fn get_merge_cells_crate_mut(&mut self) -> &mut MergeCells {
713        &mut self.merge_cells
714    }
715
716    // ************************
717    // Auto Filter
718    // ************************
719    // Get Auto Filter (Option).
720    #[inline]
721    pub fn get_auto_filter(&self) -> Option<&AutoFilter> {
722        self.auto_filter.as_ref()
723    }
724
725    // Get Auto Filter (Option) in mutable.
726    #[inline]
727    pub fn get_auto_filter_mut(&mut self) -> Option<&mut AutoFilter> {
728        self.auto_filter.as_mut()
729    }
730
731    // Set Auto Filter.
732    /// # Arguments
733    /// * `range` - Range. ex) "A2:K2"
734    /// # Examples
735    /// ```
736    /// let mut book = umya_spreadsheet::new_file();
737    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
738    /// worksheet.set_auto_filter("A2:K2");
739    /// ```
740    #[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    // Remove Auto Filter.
748    #[inline]
749    pub fn remove_auto_filter(&mut self) {
750        self.auto_filter = None;
751    }
752
753    // ************************
754    // Column Dimensions
755    // ************************
756    /// Get Column Dimension List.
757    #[inline]
758    pub fn get_column_dimensions(&self) -> &[Column] {
759        self.column_dimensions.get_column_collection()
760    }
761
762    /// Get Column Dimension List in mutable.
763    #[inline]
764    pub fn get_column_dimensions_mut(&mut self) -> &mut ThinVec<Column> {
765        self.column_dimensions.get_column_collection_mut()
766    }
767
768    /// Calculation Auto Width.
769    #[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    /// Get Column Dimension.
779    /// # Arguments
780    /// * `column` - Column Char. ex) "A"
781    #[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    /// Get Column Dimension in mutable.
787    /// # Arguments
788    /// * `column` - Column Char. ex) "A"
789    #[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    /// Get Column Dimension.
795    /// # Arguments
796    /// * `col` - Column Number.
797    #[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    /// Get Column Dimension in mutable.
803    /// # Arguments
804    /// * `col` - Column Number.
805    #[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    /// (This method is crate only.)
811    /// Get Column Dimension.
812    #[inline]
813    pub(crate) fn get_column_dimensions_crate(&self) -> &Columns {
814        &self.column_dimensions
815    }
816
817    /// (This method is crate only.)
818    /// Get Column Dimension in mutable.
819    #[inline]
820    pub(crate) fn get_column_dimensions_crate_mut(&mut self) -> &mut Columns {
821        &mut self.column_dimensions
822    }
823
824    /// (This method is crate only.)
825    /// Set Column Dimension.
826    #[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    // ************************
833    // Row Dimensions
834    // ************************
835    #[inline]
836    pub fn has_sheet_data(&self) -> bool {
837        self.row_dimensions.has_sheet_data()
838    }
839
840    /// Get Row Dimension List.
841    #[inline]
842    pub fn get_row_dimensions(&self) -> Vec<&Row> {
843        self.row_dimensions.get_row_dimensions()
844    }
845
846    /// Get Row Dimension List in mutable.
847    #[inline]
848    pub fn get_row_dimensions_mut(&mut self) -> Vec<&mut Row> {
849        self.row_dimensions.get_row_dimensions_mut()
850    }
851
852    /// Get Row Dimension convert Hashmap.
853    #[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    /// Get Row Dimension.
864    #[inline]
865    pub fn get_row_dimension(&self, row: &u32) -> Option<&Row> {
866        self.row_dimensions.get_row_dimension(row)
867    }
868
869    /// Get Row Dimension in mutable.
870    #[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    /// (This method is crate only.)
876    /// Set Row Dimension.
877    #[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    /// (This method is crate only.)
884    /// Get Row Dimension in mutable.
885    #[inline]
886    pub(crate) fn get_row_dimensions_crate_mut(&mut self) -> &mut Rows {
887        &mut self.row_dimensions
888    }
889
890    /// (This method is crate only.)
891    /// Get Row Dimension.
892    #[inline]
893    pub(crate) fn _get_row_dimensions_crate(&self) -> &Rows {
894        &self.row_dimensions
895    }
896
897    // ************************
898    // WorksheetDrawing
899    // ************************
900    /// Get WorksheetDrawing.
901    #[inline]
902    pub fn get_worksheet_drawing(&self) -> &WorksheetDrawing {
903        &self.worksheet_drawing
904    }
905
906    /// Get WorksheetDrawing in mutable.
907    #[inline]
908    pub fn get_worksheet_drawing_mut(&mut self) -> &mut WorksheetDrawing {
909        &mut self.worksheet_drawing
910    }
911
912    /// Set WorksheetDrawing.
913    /// # Arguments
914    /// * `value` - WorksheetDrawing
915    #[inline]
916    pub fn set_worksheet_drawing(&mut self, value: WorksheetDrawing) {
917        self.worksheet_drawing = value;
918    }
919
920    /// Has WorksheetDrawing.
921    #[inline]
922    pub fn has_drawing_object(&self) -> bool {
923        self.worksheet_drawing.has_drawing_object()
924    }
925
926    // ************************
927    // update Coordinate
928    // ************************
929    /// Insert new rows.
930    /// # Arguments
931    /// * `row_index` - Specify point of insert. ex) 1
932    /// * `num_rows` - Specify number to insert. ex) 2
933    /// # Examples
934    /// ```
935    /// let mut book = umya_spreadsheet::new_file();
936    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
937    /// worksheet.insert_new_row(&2, &3);
938    /// ```
939    #[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    /// Adjust for references to other sheets.
947    #[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    /// Insert new columns.
959    /// # Arguments
960    /// * `column` - Specify point of insert. ex) "B"
961    /// * `num_columns` - Specify number to insert. ex) 3
962    /// # Examples
963    /// ```
964    /// let mut book = umya_spreadsheet::new_file();
965    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
966    /// worksheet.insert_new_column("B", &3);
967    /// ```
968    #[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    /// Adjust for references to other sheets.
974    #[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    /// Insert new columns.
989    /// # Arguments
990    /// * `column_index` - Specify point of insert. ex) 2
991    /// * `num_columns` - Specify number to insert. ex) 3
992    /// # Examples
993    /// ```
994    /// let mut book = umya_spreadsheet::new_file();
995    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
996    /// worksheet.insert_new_column_by_index(&2, &3);
997    /// ```
998    #[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    /// Adjust for references to other sheets.
1006    #[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    /// Remove rows.
1018    /// # Arguments
1019    /// * `row_index` - Specify point of remove. ex) 1
1020    /// * `num_rows` - Specify number to remove. ex) 2
1021    /// # Examples
1022    /// ```
1023    /// let mut book = umya_spreadsheet::new_file();
1024    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
1025    /// worksheet.remove_row(&2, &3);
1026    /// ```
1027    #[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    /// Adjust for references to other sheets.
1035    #[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    /// Remove columns.
1047    /// # Arguments
1048    /// * `sheet_name` - Specify the sheet name. ex) "Sheet1"
1049    /// * `column` - Specify point of remove. ex) "B"
1050    /// * `num_columns` - Specify number to remove. ex) 3
1051    /// # Examples
1052    /// ```
1053    /// let mut book = umya_spreadsheet::new_file();
1054    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
1055    /// worksheet.remove_column("B", &3);
1056    /// ```
1057    #[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    /// Adjust for references to other sheets.
1063    #[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    /// Remove columns.
1078    /// # Arguments
1079    /// * `column_index` - Specify point of remove. ex) 2
1080    /// * `num_columns` - Specify number to remove. ex) 3
1081    /// # Examples
1082    /// ```
1083    /// let mut book = umya_spreadsheet::new_file();
1084    /// let mut worksheet = book.get_sheet_mut(&0).unwrap();
1085    /// worksheet.remove_column_by_index(&2, &3);
1086    /// ```
1087    #[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    /// Adjust for references to other sheets.
1095    #[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    /// Get Code Name.
1107    #[inline]
1108    pub fn get_code_name(&self) -> Option<&str> {
1109        self.code_name.get_value()
1110    }
1111
1112    /// Set Code Name.
1113    /// # Arguments
1114    /// * `value` - Code Name
1115    #[inline]
1116    pub fn set_code_name<S: Into<String>>(&mut self, value: S) {
1117        self.code_name.set_value(value);
1118    }
1119
1120    /// Get Header Footer.
1121    #[inline]
1122    pub fn get_header_footer(&self) -> &HeaderFooter {
1123        &self.header_footer
1124    }
1125
1126    /// Get Header Footer in mutable.
1127    #[inline]
1128    pub fn get_header_footer_mut(&mut self) -> &mut HeaderFooter {
1129        &mut self.header_footer
1130    }
1131
1132    /// Set Header Footer.
1133    /// # Arguments
1134    /// * `value` - Header Footer
1135    #[inline]
1136    pub fn set_header_footer(&mut self, value: HeaderFooter) -> &mut Self {
1137        self.header_footer = value;
1138        self
1139    }
1140
1141    /// Get Active Cell.
1142    #[inline]
1143    pub fn get_active_cell(&self) -> &str {
1144        &self.active_cell
1145    }
1146
1147    /// Set Active Cell.
1148    /// # Arguments
1149    /// * `cell` - Cell ex) "A1"
1150    #[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    /// Get R Id.
1156    #[inline]
1157    pub(crate) fn get_r_id(&self) -> &str {
1158        &self.r_id
1159    }
1160
1161    /// (This method is crate only.)
1162    /// Set r Id.
1163    #[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    /// Get Sheet Id.
1169    #[inline]
1170    pub fn get_sheet_id(&self) -> &str {
1171        &self.sheet_id
1172    }
1173
1174    /// (This method is crate only.)
1175    /// Set Sheet Id.
1176    #[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    /// Has Code Name.
1182    #[inline]
1183    pub fn has_code_name(&self) -> bool {
1184        self.code_name.has_value()
1185    }
1186
1187    /// Get Tab Color.
1188    #[inline]
1189    pub fn get_tab_color(&self) -> Option<&Color> {
1190        self.tab_color.as_ref()
1191    }
1192
1193    /// Get Tab Color in mutable.
1194    #[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    /// Set Tab Color.
1204    /// # Arguments
1205    /// * `value` - Color
1206    #[inline]
1207    pub fn set_tab_color(&mut self, value: Color) -> &mut Self {
1208        self.tab_color = Some(value);
1209        self
1210    }
1211
1212    /// Remove Tab Color.
1213    #[inline]
1214    pub fn remove_tab_color(&mut self) -> &mut Self {
1215        self.tab_color = None;
1216        self
1217    }
1218
1219    /// Calculate Worksheet Dimension.
1220    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    // Get Highest Column and Row Index
1230    /// # Return value
1231    /// *`(u32, u32)` - (column, row)
1232    #[inline]
1233    pub fn get_highest_column_and_row(&self) -> (u32, u32) {
1234        self.cell_collection.get_highest_column_and_row()
1235    }
1236
1237    // Get Highest Column Index
1238    #[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    // Get Highest Row Index
1245    #[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    /// Get SheetName.
1252    #[inline]
1253    pub fn get_name(&self) -> &str {
1254        &self.title
1255    }
1256
1257    /// Set SheetName.
1258    /// # Arguments
1259    /// * `sheet_name` - Sheet Name. [Caution] no duplicate other worksheet.
1260    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    // Get Sheet State
1296    #[inline]
1297    pub fn get_sheet_state(&self) -> &str {
1298        &self.sheet_state
1299    }
1300
1301    /// Set Sheet State.
1302    /// # Arguments
1303    /// * `value` - Sheet State.
1304    #[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    // Get Page Setup.
1311    #[inline]
1312    pub fn get_page_setup(&self) -> &PageSetup {
1313        &self.page_setup
1314    }
1315
1316    // Get Page Setup in mutable.
1317    #[inline]
1318    pub fn get_page_setup_mut(&mut self) -> &mut PageSetup {
1319        &mut self.page_setup
1320    }
1321
1322    /// Set Page Setup.
1323    /// # Arguments
1324    /// * `value` - PageSetup.
1325    #[inline]
1326    pub fn set_page_setup(&mut self, value: PageSetup) -> &mut Self {
1327        self.page_setup = value;
1328        self
1329    }
1330
1331    // Get Page Margins.
1332    #[inline]
1333    pub fn get_page_margins(&self) -> &PageMargins {
1334        &self.page_margins
1335    }
1336
1337    // Get Page Margins in mutable.
1338    #[inline]
1339    pub fn get_page_margins_mut(&mut self) -> &mut PageMargins {
1340        &mut self.page_margins
1341    }
1342
1343    /// Set Page Margins.
1344    /// # Arguments
1345    /// * `value` - PageMargins.
1346    #[inline]
1347    pub fn set_page_margins(&mut self, value: PageMargins) -> &mut Self {
1348        self.page_margins = value;
1349        self
1350    }
1351
1352    // Get SheetViews.
1353    #[inline]
1354    pub fn get_sheets_views(&self) -> &SheetViews {
1355        &self.sheet_views
1356    }
1357
1358    // Get SheetViews in mutable.
1359    #[inline]
1360    pub fn get_sheet_views_mut(&mut self) -> &mut SheetViews {
1361        &mut self.sheet_views
1362    }
1363
1364    /// Set SheetViews.
1365    /// # Arguments
1366    /// * `value` - SheetViews.
1367    #[inline]
1368    pub fn set_sheets_views(&mut self, value: SheetViews) -> &mut Self {
1369        self.sheet_views = value;
1370        self
1371    }
1372
1373    // Get Ole Objects.
1374    #[inline]
1375    pub fn get_ole_objects(&self) -> &OleObjects {
1376        &self.ole_objects
1377    }
1378
1379    // Get Ole Objects in mutable.
1380    #[inline]
1381    pub fn get_ole_objects_mut(&mut self) -> &mut OleObjects {
1382        &mut self.ole_objects
1383    }
1384
1385    /// Set Ole Objects.
1386    /// # Arguments
1387    /// * `value` - OleObjects.
1388    #[inline]
1389    pub fn set_ole_objects(&mut self, value: OleObjects) -> &mut Self {
1390        self.ole_objects = value;
1391        self
1392    }
1393
1394    /// Get Defined Name (Vec).
1395    #[inline]
1396    pub fn get_defined_names(&self) -> &[DefinedName] {
1397        &self.defined_names
1398    }
1399
1400    /// Get Defined Name (Vec) in mutable.
1401    #[inline]
1402    pub fn get_defined_names_mut(&mut self) -> &mut ThinVec<DefinedName> {
1403        &mut self.defined_names
1404    }
1405
1406    /// Set Defined Name (Vec).
1407    /// # Arguments
1408    /// * `value` - Vec<DefinedName>.
1409    #[inline]
1410    pub fn set_defined_names(&mut self, value: impl Into<ThinVec<DefinedName>>) {
1411        self.defined_names = value.into();
1412    }
1413
1414    /// Add Defined Name.
1415    /// # Arguments
1416    /// * `value` - DefinedName.
1417    #[inline]
1418    pub fn add_defined_names(&mut self, value: DefinedName) {
1419        self.defined_names.push(value);
1420    }
1421
1422    /// Add Defined Name.
1423    /// # Arguments
1424    /// * `name` - Name. ex) "DefinedName01"
1425    /// * `address` - Address. ex) "A1:A2"
1426    #[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    /// Get Print Options.
1436    #[inline]
1437    pub fn get_print_options(&self) -> &PrintOptions {
1438        &self.print_options
1439    }
1440
1441    /// Get Print Options in mutable.
1442    #[inline]
1443    pub fn get_print_options_mut(&mut self) -> &mut PrintOptions {
1444        &mut self.print_options
1445    }
1446
1447    /// Set Print Options.
1448    /// # Arguments
1449    /// * `value` - PrintOptions.
1450    #[inline]
1451    pub fn set_print_options(&mut self, value: PrintOptions) -> &mut Self {
1452        self.print_options = value;
1453        self
1454    }
1455
1456    /// Get Column Breaks.
1457    #[inline]
1458    pub fn get_column_breaks(&self) -> &ColumnBreaks {
1459        &self.column_breaks
1460    }
1461
1462    /// Get Column Breaks in mutable.
1463    #[inline]
1464    pub fn get_column_breaks_mut(&mut self) -> &mut ColumnBreaks {
1465        &mut self.column_breaks
1466    }
1467
1468    /// Set Column Breaks.
1469    /// # Arguments
1470    /// * `value` - ColumnBreaks.
1471    #[inline]
1472    pub fn set_column_breaks(&mut self, value: ColumnBreaks) -> &mut Self {
1473        self.column_breaks = value;
1474        self
1475    }
1476
1477    /// Get Row Breaks.
1478    #[inline]
1479    pub fn get_row_breaks(&self) -> &RowBreaks {
1480        &self.row_breaks
1481    }
1482
1483    /// Get Row Breaks in mutable.
1484    #[inline]
1485    pub fn get_row_breaks_mut(&mut self) -> &mut RowBreaks {
1486        &mut self.row_breaks
1487    }
1488
1489    /// Set Row Breaks.
1490    /// # Arguments
1491    /// * `value` - RowBreaks.
1492    #[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    /// Outputs all images contained in the worksheet.
1599    /// # Return value
1600    /// * `&Vec<Image>` - Image Object List.
1601    #[inline]
1602    pub fn get_image_collection(&self) -> &[Image] {
1603        self.get_worksheet_drawing().get_image_collection()
1604    }
1605
1606    /// Outputs all images contained in the worksheet.
1607    /// # Return value
1608    /// * `&mut Vec<Image>` - Image Object List.
1609    #[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    /// Outputs all Charts contained in the worksheet.
1662    /// # Return value
1663    /// * `&Vec<Chart>` - Chart Object List.
1664    #[inline]
1665    pub fn get_chart_collection(&self) -> &[Chart] {
1666        self.get_worksheet_drawing().get_chart_collection()
1667    }
1668
1669    /// Outputs all Charts contained in the worksheet.
1670    /// # Return value
1671    /// * `&mut Vec<Chart>` - Chart Object List.
1672    #[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    /// Outputs all media contained in the worksheet.
1720    /// # Return value
1721    /// * `Vec<&MediaObject>` - Media Object List.
1722    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    /// (This method is crate only.)
1786    /// Has Defined Names.
1787    #[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    /// (This method is crate only.)
1840    /// Has Ole Objects.
1841    #[inline]
1842    pub(crate) fn has_ole_objects(&self) -> bool {
1843        !self.ole_objects.get_ole_object().is_empty()
1844    }
1845
1846    /// (This method is crate only.)
1847    /// Has Legacy Drawing.
1848    #[inline]
1849    pub(crate) fn has_legacy_drawing(&self) -> bool {
1850        self.has_comments() || self.has_ole_objects()
1851    }
1852
1853    /// Moving a section of the sheet
1854    /// # Arguments
1855    /// 'range' - Specify like "A1:G8"
1856    /// 'row' - The number of rows to move by (negative numbers mean move 'left')
1857    /// 'column' - the number of columns to move by (negative numbers mean move 'up')
1858    #[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    /// Copying a section of the sheet
1864    /// # Arguments
1865    /// 'range' - Specify like "A1:G8"
1866    /// 'row' - The number of rows to move by (negative numbers mean move 'left')
1867    /// 'column' - the number of columns to move by (negative numbers mean move 'up')
1868    #[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    // Moving or copying a section of the sheet
1874    #[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        // Check to ensure coordinates to move are within range (eg: moving A1 cells to the left is
1883        // impossible)
1884
1885        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        // Iterate row by row, collecting cell information (do I copy)
1895        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        // Delete cell information as iterating through in move mode
1903        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        // repaste by setting cell values
1916        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    /// Remove invisible garbage data.
1926    /// Doing so may reduce file size.
1927    /// Processing may take some time.
1928    #[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    /// Copy the style of a given Row to the target.
1967    /// # Arguments
1968    /// * `source_row_no` - Source Row Number.
1969    /// * `target_row_no` - Target Row Number.
1970    /// * `start_col` - Start Column Number. If None, minimum value
1971    /// * `end_col` - End Column Number. If None, maximum value
1972    #[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    /// Copy the style of a given Column to the target.
2000    /// # Arguments
2001    /// * `source_col_no` - Source Column Number.
2002    /// * `target_col_no` - Target Column Number.
2003    /// * `start_row` - Start Row Number. If None, minimum value
2004    /// * `end_row` - End Row Number. If None, maximum value
2005    #[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            // column dimensions
2042            self.column_dimensions
2043                .adjustment_insert_value(root_col_num, offset_col_num);
2044        }
2045        if offset_row_num != &0 {
2046            // row dimensions
2047            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        // defined_names
2055        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        // cell
2066        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        // worksheet_drawing
2074        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        // comments
2082        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        // conditional styles
2092        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        // merge cells
2102        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        // auto filter
2112        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            // column dimensions
2131            self.column_dimensions
2132                .adjustment_remove_value(root_col_num, offset_col_num);
2133        }
2134        if offset_row_num != &0 {
2135            // row dimensions
2136            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        // defined_names
2144        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        // cell
2166        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        // worksheet_drawing
2174        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        // comments
2183        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        // conditional styles
2196        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        // merge cells
2209        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        // auto filter
2222        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        // cell formula coordinate
2258        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        // worksheet_drawing
2270        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        // cell formula coordinate
2293        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        // worksheet_drawing
2305        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}