use std::collections::HashMap;
use crate::{
StringValue,
helper::{
const_str::PIVOT_CACHE_DEF_NS,
coordinate::{
CellCoordinates,
column_index_from_string,
coordinate_from_index,
string_from_column_index,
},
range::{
get_coordinate_list,
get_start_and_end_point,
},
},
reader::xlsx::worksheet::read_lite,
structs::{
AutoFilter,
Cell,
CellValue,
Cells,
Chart,
Color,
Column,
ColumnBreaks,
Columns,
Comment,
ConditionalFormatting,
DataValidations,
DefinedName,
EnumValue,
HeaderFooter,
Hyperlink,
Image,
MediaObject,
MergeCells,
OleObjects,
PageMargins,
PageSetup,
PivotTable,
PrintOptions,
Range,
Row,
RowBreaks,
Rows,
SharedStringTable,
SheetFormatProperties,
SheetProtection,
SheetStateValues,
SheetViews,
Style,
Stylesheet,
Table,
drawing::spreadsheet::WorksheetDrawing,
office2010::excel::DataValidations as DataValidations2010,
office2019::threaded_comment::ThreadedComment,
raw::RawWorksheet,
},
traits::{
AdjustmentCoordinate,
AdjustmentCoordinateWith2Sheet,
AdjustmentCoordinateWithSheet,
AdjustmentValue,
},
};
#[derive(Clone, Debug, Default)]
pub struct Worksheet {
raw_data_of_worksheet: Option<RawWorksheet>,
r_id: Box<str>,
sheet_id: Box<str>,
title: Box<str>,
state: EnumValue<SheetStateValues>,
cells: Cells,
rows: Rows,
columns: Columns,
worksheet_drawing: WorksheetDrawing,
sheet_state: Box<str>,
page_setup: PageSetup,
page_margins: PageMargins,
header_footer: HeaderFooter,
sheet_views: SheetViews,
conditional_formatting_collection: Vec<ConditionalFormatting>,
merge_cells: MergeCells,
auto_filter: Option<AutoFilter>,
comments: Vec<Comment>,
threaded_comments: Vec<ThreadedComment>,
active_cell: Box<str>,
tab_color: Option<Color>,
code_name: StringValue,
ole_objects: OleObjects,
defined_names: Vec<DefinedName>,
print_options: PrintOptions,
column_breaks: ColumnBreaks,
row_breaks: RowBreaks,
tables: Vec<Table>,
pivot_tables: Vec<PivotTable>,
data_validations: Option<DataValidations>,
data_validations_2010: Option<DataValidations2010>,
sheet_format_properties: SheetFormatProperties,
sheet_protection: Option<SheetProtection>,
}
impl Worksheet {
#[inline]
pub fn value<T>(&self, coordinate: T) -> String
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.cell((col, row))
.map(|v| v.value().into())
.unwrap_or_default()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use value()")]
pub fn get_value<T>(&self, coordinate: T) -> String
where
T: Into<CellCoordinates>,
{
self.value(coordinate)
}
#[inline]
pub fn value_number<T>(&self, coordinate: T) -> Option<f64>
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.cell((col, row)).and_then(Cell::value_number)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use value_number()")]
pub fn get_value_number<T>(&self, coordinate: T) -> Option<f64>
where
T: Into<CellCoordinates>,
{
self.value_number(coordinate)
}
#[inline]
pub fn formatted_value<T>(&self, coordinate: T) -> String
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.cells.formatted_value_by_column_and_row(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use formatted_value()")]
pub fn get_formatted_value<T>(&self, coordinate: T) -> String
where
T: Into<CellCoordinates>,
{
self.formatted_value(coordinate)
}
#[inline]
#[must_use]
pub fn cells(&self) -> Vec<&Cell> {
self.cells.iter_collection().collect()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use cells()")]
pub fn get_cells(&self) -> Vec<&Cell> {
self.cells()
}
#[inline]
#[must_use]
pub fn cells_sorted(&self) -> Vec<&Cell> {
self.cells
.iter_cells_sorted_by_row_column()
.collect()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use cells_sorted()")]
pub fn get_cells_sorted(&self) -> Vec<&Cell> {
self.cells_sorted()
}
#[inline]
pub fn cells_mut(&mut self) -> Vec<&mut Cell> {
self.cells.collection_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use cells_mut()")]
pub fn get_cells_mut(&mut self) -> Vec<&mut Cell> {
self.cells_mut()
}
#[inline]
#[must_use]
pub fn collection_to_hashmap(&self) -> &HashMap<(u32, u32), Box<Cell>> {
self.cells.collection_to_hashmap()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use collection_to_hashmap()")]
pub fn get_collection_to_hashmap(&self) -> &HashMap<(u32, u32), Box<Cell>> {
self.collection_to_hashmap()
}
#[inline]
pub fn collection_to_hashmap_mut(&mut self) -> &mut HashMap<(u32, u32), Box<Cell>> {
self.cells.collection_to_hashmap_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use collection_to_hashmap_mut()")]
pub fn get_collection_to_hashmap_mut(&mut self) -> &mut HashMap<(u32, u32), Box<Cell>> {
self.collection_to_hashmap_mut()
}
pub(crate) fn cells_stream(
&self,
shared_string_table: &SharedStringTable,
stylesheet: &Stylesheet,
) -> Cells {
assert!(!self.is_deserialized(), "This Worksheet is Deserialized.");
read_lite(
self.raw_data_of_worksheet.as_ref().unwrap(),
shared_string_table,
stylesheet,
)
}
#[deprecated(since = "3.0.0", note = "Use cells_stream()")]
pub(crate) fn get_cells_stream(
&self,
shared_string_table: &SharedStringTable,
stylesheet: &Stylesheet,
) -> Cells {
self.cells_stream(shared_string_table, stylesheet)
}
#[inline]
pub(crate) fn cells_crate(&self) -> &Cells {
&self.cells
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use cells_crate()")]
pub(crate) fn get_cells_crate(&self) -> &Cells {
self.cells_crate()
}
#[inline]
pub(crate) fn cells_crate_mut(&mut self) -> &mut Cells {
&mut self.cells
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use cells_crate_mut()")]
pub(crate) fn get_cells_crate_mut(&mut self) -> &mut Cells {
self.cells_crate_mut()
}
#[inline]
pub fn cell<T>(&self, coordinate: T) -> Option<&Cell>
where
T: Into<CellCoordinates>,
{
self.cells.get(coordinate)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use cell()")]
pub fn get_cell<T>(&self, coordinate: T) -> Option<&Cell>
where
T: Into<CellCoordinates>,
{
self.cell(coordinate)
}
pub fn cell_mut<T>(&mut self, coordinate: T) -> &mut Cell
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.row_dimension_mut(row);
let row_dimension = self.row_dimension_mut(row).clone();
let col_dimension = self.column_dimension_by_number_mut(col).clone();
self.cells
.get_mut((col, row), &row_dimension, &col_dimension)
}
#[deprecated(since = "3.0.0", note = "Use cell_mut()")]
pub fn get_cell_mut<T>(&mut self, coordinate: T) -> &mut Cell
where
T: Into<CellCoordinates>,
{
self.cell_mut(coordinate)
}
#[inline]
#[must_use]
pub fn collection_by_column(&self, column_num: u32) -> Vec<&Cell> {
self.cells
.iter_cells_by_column(column_num)
.collect()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use collection_by_column()")]
pub fn get_collection_by_column(&self, column_num: &u32) -> Vec<&Cell> {
self.collection_by_column(*column_num)
}
#[inline]
#[must_use]
pub fn collection_by_row(&self, row_num: u32) -> Vec<&Cell> {
self.cells.iter_cells_by_row(row_num).collect()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use collection_by_row()")]
pub fn get_collection_by_row(&self, row_num: &u32) -> Vec<&Cell> {
self.collection_by_row(*row_num)
}
#[inline]
#[must_use]
pub fn collection_by_column_to_hashmap(&self, column_num: u32) -> HashMap<u32, &Cell> {
self.cells.collection_by_column_to_hashmap(column_num)
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use collection_by_column_to_hashmap()")]
pub fn get_collection_by_column_to_hashmap(&self, column_num: &u32) -> HashMap<u32, &Cell> {
self.collection_by_column_to_hashmap(*column_num)
}
#[inline]
#[must_use]
pub fn collection_by_row_to_hashmap(&self, row_num: u32) -> HashMap<u32, &Cell> {
self.cells.collection_by_row_to_hashmap(row_num)
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use collection_by_row_to_hashmap()")]
pub fn get_collection_by_row_to_hashmap(&self, row_num: &u32) -> HashMap<u32, &Cell> {
self.collection_by_row_to_hashmap(*row_num)
}
pub fn set_cell(&mut self, cell: Cell) -> &mut Self {
let row_dimension = self
.row_dimension_mut(cell.coordinate().row_num())
.clone();
let col_dimension = self
.column_dimension_by_number_mut(cell.coordinate().col_num())
.clone();
self.cells.set(cell, &row_dimension, &col_dimension);
self
}
#[inline]
pub fn remove_cell<T>(&mut self, coordinate: T) -> bool
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.cells.remove(col, row)
}
#[inline]
pub fn cell_value<T>(&self, coordinate: T) -> &CellValue
where
T: Into<CellCoordinates>,
{
self.cells.cell_value(coordinate)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use cell_value()")]
pub fn get_cell_value<T>(&self, coordinate: T) -> &CellValue
where
T: Into<CellCoordinates>,
{
self.cell_value(coordinate)
}
#[inline]
pub fn cell_value_mut<T>(&mut self, coordinate: T) -> &mut CellValue
where
T: Into<CellCoordinates>,
{
self.cell_mut(coordinate).cell_value_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use cell_value_mut()")]
pub fn get_cell_value_mut<T>(&mut self, coordinate: T) -> &mut CellValue
where
T: Into<CellCoordinates>,
{
self.cell_value_mut(coordinate)
}
#[inline]
#[must_use]
pub fn cell_value_by_range(&self, range: &str) -> Vec<&CellValue> {
self.cells
.iter_all_cell_values_by_range_sorted_by_row(range)
.collect()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use cell_value_by_range()")]
pub fn get_cell_value_by_range(&self, range: &str) -> Vec<&CellValue> {
self.cell_value_by_range(range)
}
pub fn map_merged_cell<T>(&self, coordinate: T) -> (u32, u32)
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.merge_cells
.range_collection()
.iter()
.find_map(|range| {
let start_col = range.coordinate_start_col()?;
let start_row = range.coordinate_start_row()?;
let end_col = range.coordinate_end_col()?;
let end_row = range.coordinate_end_row()?;
if col >= start_col.num()
&& col <= end_col.num()
&& row >= start_row.num()
&& row <= end_row.num()
{
Some((start_col.num(), start_row.num()))
} else {
None
}
})
.unwrap_or((col, row))
}
#[inline]
pub fn style<T>(&self, coordinate: T) -> &Style
where
T: Into<CellCoordinates>,
{
self.cells.style(coordinate)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use style()")]
pub fn get_style<T>(&self, coordinate: T) -> &Style
where
T: Into<CellCoordinates>,
{
self.style(coordinate)
}
#[inline]
pub fn style_mut<T>(&mut self, coordinate: T) -> &mut Style
where
T: Into<CellCoordinates>,
{
self.cell_mut(coordinate).style_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use style_mut()")]
pub fn get_style_mut<T>(&mut self, coordinate: T) -> &mut Style
where
T: Into<CellCoordinates>,
{
self.style_mut(coordinate)
}
#[inline]
pub fn set_style<T>(&mut self, coordinate: T, style: Style) -> &mut Self
where
T: Into<CellCoordinates>,
{
self.cell_mut(coordinate).set_style(style);
self
}
pub fn set_style_by_range(&mut self, range: &str, style: &Style) -> &mut Self {
let coordinate_list = get_coordinate_list(range);
let (col_num_start, row_num_start) = coordinate_list[0];
if col_num_start == 0 {
let (_, row_num_end) = coordinate_list[1];
for row_num in row_num_start..=row_num_end {
self.row_dimension_mut(row_num).set_style(style.clone());
}
return self;
}
if row_num_start == 0 {
let (col_num_end, _) = coordinate_list[1];
for col_num in col_num_start..=col_num_end {
self.column_dimension_by_number_mut(col_num)
.set_style(style.clone());
}
return self;
}
for (col_num, row_num) in coordinate_list {
self.set_style((col_num, row_num), style.clone());
}
self
}
#[inline]
#[must_use]
pub fn comments(&self) -> &[Comment] {
&self.comments
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use comments()")]
pub fn get_comments(&self) -> &[Comment] {
self.comments()
}
#[inline]
pub fn comments_mut(&mut self) -> &mut Vec<Comment> {
&mut self.comments
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use comments_mut()")]
pub fn get_comments_mut(&mut self) -> &mut Vec<Comment> {
self.comments_mut()
}
#[inline]
#[must_use]
pub fn comments_to_hashmap(&self) -> HashMap<String, &Comment> {
let mut result = HashMap::default();
for comment in &self.comments {
result.insert(comment.coordinate().to_string(), comment);
}
result
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use comments_to_hashmap()")]
pub fn get_comments_to_hashmap(&self) -> HashMap<String, &Comment> {
self.comments_to_hashmap()
}
#[inline]
pub fn set_comments(&mut self, value: impl Into<Vec<Comment>>) {
self.comments = value.into();
}
#[inline]
pub fn add_comments(&mut self, value: Comment) {
self.comments.push(value);
}
#[inline]
#[must_use]
pub fn has_comments(&self) -> bool {
!self.comments.is_empty()
}
#[inline]
#[must_use]
pub fn threaded_comments(&self) -> &[ThreadedComment] {
&self.threaded_comments
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use threaded_comments()")]
pub fn get_threaded_comments(&self) -> &[ThreadedComment] {
self.threaded_comments()
}
#[inline]
pub fn threaded_comments_mut(&mut self) -> &mut Vec<ThreadedComment> {
&mut self.threaded_comments
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use threaded_comments_mut()")]
pub fn get_threaded_comments_mut(&mut self) -> &mut Vec<ThreadedComment> {
self.threaded_comments_mut()
}
#[inline]
#[must_use]
pub fn threaded_comments_to_hashmap(&self) -> HashMap<String, &ThreadedComment> {
let mut result = HashMap::default();
for threaded_comment in &self.threaded_comments {
result.insert(
threaded_comment.coordinate().to_string(),
threaded_comment,
);
}
result
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use threaded_comments_to_hashmap()")]
pub fn get_threaded_comments_to_hashmap(&self) -> HashMap<String, &ThreadedComment> {
self.threaded_comments_to_hashmap()
}
#[inline]
pub fn set_threaded_comments(&mut self, value: impl Into<Vec<ThreadedComment>>) {
self.threaded_comments = value.into();
}
#[inline]
pub fn add_threaded_comments(&mut self, value: ThreadedComment) {
self.threaded_comments.push(value);
}
#[inline]
#[must_use]
pub fn has_threaded_comments(&self) -> bool {
!self.threaded_comments.is_empty()
}
#[inline]
#[must_use]
pub fn conditional_formatting_collection(&self) -> &[ConditionalFormatting] {
&self.conditional_formatting_collection
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use conditional_formatting_collection()")]
pub fn get_conditional_formatting_collection(&self) -> &[ConditionalFormatting] {
self.conditional_formatting_collection()
}
#[inline]
pub fn set_conditional_formatting_collection(
&mut self,
value: impl Into<Vec<ConditionalFormatting>>,
) {
self.conditional_formatting_collection = value.into();
}
#[inline]
pub fn add_conditional_formatting_collection(&mut self, value: ConditionalFormatting) {
self.conditional_formatting_collection.push(value);
}
pub(crate) fn hyperlink_collection(&self) -> Vec<(String, &Hyperlink)> {
let mut result: Vec<(String, &Hyperlink)> = Vec::new();
for cell in self.cells.collection_sorted() {
if let Some(hyperlink) = cell.hyperlink() {
let coordition = coordinate_from_index(
cell.coordinate().col_num(),
cell.coordinate().row_num(),
);
result.push((coordition, hyperlink));
}
}
result
}
#[deprecated(since = "3.0.0", note = "Use hyperlink_collection()")]
pub(crate) fn get_hyperlink_collection(&self) -> Vec<(String, &Hyperlink)> {
self.hyperlink_collection()
}
#[inline]
pub(crate) fn has_hyperlink(&self) -> bool {
self.cells.has_hyperlink()
}
#[inline]
#[must_use]
pub fn merge_cells(&self) -> &[Range] {
self.merge_cells.range_collection()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use merge_cells()")]
pub fn get_merge_cells(&self) -> &[Range] {
self.merge_cells()
}
#[inline]
pub fn merge_cells_mut(&mut self) -> &mut Vec<Range> {
self.merge_cells.range_collection_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use merge_cells_mut()")]
pub fn get_merge_cells_mut(&mut self) -> &mut Vec<Range> {
self.merge_cells_mut()
}
#[inline]
pub fn add_merge_cells<S: Into<String>>(&mut self, range: S) -> &mut Self {
self.merge_cells.add_range(range);
self
}
#[inline]
pub(crate) fn merge_cells_crate(&self) -> &MergeCells {
&self.merge_cells
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use merge_cells_crate()")]
pub(crate) fn get_merge_cells_crate(&self) -> &MergeCells {
self.merge_cells_crate()
}
#[inline]
pub(crate) fn merge_cells_crate_mut(&mut self) -> &mut MergeCells {
&mut self.merge_cells
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use merge_cells_crate_mut()")]
pub(crate) fn get_merge_cells_crate_mut(&mut self) -> &mut MergeCells {
self.merge_cells_crate_mut()
}
#[inline]
#[must_use]
pub fn auto_filter(&self) -> Option<&AutoFilter> {
self.auto_filter.as_ref()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use auto_filter()")]
pub fn get_auto_filter(&self) -> Option<&AutoFilter> {
self.auto_filter()
}
#[inline]
pub fn auto_filter_mut(&mut self) -> Option<&mut AutoFilter> {
self.auto_filter.as_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use auto_filter_mut()")]
pub fn get_auto_filter_mut(&mut self) -> Option<&mut AutoFilter> {
self.auto_filter_mut()
}
#[inline]
pub fn set_auto_filter<S: Into<String>>(&mut self, range: S) {
let mut auto_filter = AutoFilter::default();
auto_filter.set_range(range);
self.auto_filter = Some(auto_filter);
}
#[inline]
pub fn remove_auto_filter(&mut self) {
self.auto_filter = None;
}
#[inline]
#[must_use]
pub fn column_dimensions(&self) -> &[Column] {
self.columns.column_collection()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use column_dimensions()")]
pub fn get_column_dimensions(&self) -> &[Column] {
self.column_dimensions()
}
#[inline]
pub fn column_dimensions_mut(&mut self) -> &mut Vec<Column> {
self.columns.column_collection_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use column_dimensions_mut()")]
pub fn get_column_dimensions_mut(&mut self) -> &mut Vec<Column> {
self.column_dimensions_mut()
}
#[inline]
pub fn calculation_auto_width(&mut self) -> &mut Self {
let cells = self.cells_crate().clone();
let merge_cells = self.merge_cells_crate().clone();
self.column_dimensions_crate_mut()
.calculation_auto_width(&cells, &merge_cells);
self
}
#[inline]
#[must_use]
pub fn column_dimension(&self, column: &str) -> Option<&Column> {
self.column_dimension_by_number(column_index_from_string(column))
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use column_dimension()")]
pub fn get_column_dimension(&self, column: &str) -> Option<&Column> {
self.column_dimension(column)
}
#[inline]
pub fn column_dimension_mut(&mut self, column: &str) -> &mut Column {
self.column_dimension_by_number_mut(column_index_from_string(column))
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use column_dimension_mut()")]
pub fn get_column_dimension_mut(&mut self, column: &str) -> &mut Column {
self.column_dimension_mut(column)
}
#[inline]
#[must_use]
pub fn column_dimension_by_number(&self, col: u32) -> Option<&Column> {
self.column_dimensions_crate().column(col)
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use column_dimension_by_number()")]
pub fn get_column_dimension_by_number(&self, col: &u32) -> Option<&Column> {
self.column_dimension_by_number(*col)
}
#[inline]
pub fn column_dimension_by_number_mut(&mut self, col: u32) -> &mut Column {
self.column_dimensions_crate_mut().column_mut(col)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use column_dimension_by_number_mut()")]
pub fn get_column_dimension_by_number_mut(&mut self, col: &u32) -> &mut Column {
self.column_dimension_by_number_mut(*col)
}
#[inline]
pub(crate) fn column_dimensions_crate(&self) -> &Columns {
&self.columns
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use column_dimensions_crate()")]
pub(crate) fn get_column_dimensions_crate(&self) -> &Columns {
self.column_dimensions_crate()
}
#[inline]
pub(crate) fn column_dimensions_crate_mut(&mut self) -> &mut Columns {
&mut self.columns
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use column_dimensions_crate_mut()")]
pub(crate) fn get_column_dimensions_crate_mut(&mut self) -> &mut Columns {
self.column_dimensions_crate_mut()
}
#[inline]
pub(crate) fn set_column_dimensions_crate(&mut self, value: Columns) -> &mut Self {
self.columns = value;
self
}
#[inline]
#[must_use]
pub fn has_sheet_data(&self) -> bool {
self.rows.has_sheet_data()
}
#[inline]
#[must_use]
pub fn row_dimensions(&self) -> Vec<&Row> {
self.rows.row_dimensions()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use row_dimensions()")]
pub fn get_row_dimensions(&self) -> Vec<&Row> {
self.row_dimensions()
}
#[inline]
pub fn row_dimensions_mut(&mut self) -> Vec<&mut Row> {
self.rows.row_dimensions_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use row_dimensions_mut()")]
pub fn get_row_dimensions_mut(&mut self) -> Vec<&mut Row> {
self.row_dimensions_mut()
}
#[inline]
#[must_use]
pub fn row_dimensions_to_hashmap(&self) -> &HashMap<u32, Box<Row>> {
self.rows.row_dimensions_to_hashmap()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use row_dimensions_to_hashmap()")]
pub fn get_row_dimensions_to_hashmap(&self) -> &HashMap<u32, Box<Row>> {
self.row_dimensions_to_hashmap()
}
#[inline]
pub fn row_dimensions_to_hashmap_mut(&mut self) -> &mut HashMap<u32, Box<Row>> {
self.rows.row_dimensions_to_hashmap_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use row_dimensions_to_hashmap_mut()")]
pub fn get_row_dimensions_to_hashmap_mut(&mut self) -> &mut HashMap<u32, Box<Row>> {
self.row_dimensions_to_hashmap_mut()
}
#[inline]
#[must_use]
pub fn row_dimension(&self, row: u32) -> Option<&Row> {
self.rows.row_dimension(row)
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use row_dimension()")]
pub fn get_row_dimension(&self, row: &u32) -> Option<&Row> {
self.row_dimension(*row)
}
#[inline]
pub fn row_dimension_mut(&mut self, row: u32) -> &mut Row {
self.rows.row_dimension_mut(row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use row_dimension_mut()")]
pub fn get_row_dimension_mut(&mut self, row: &u32) -> &mut Row {
self.row_dimension_mut(*row)
}
#[inline]
pub(crate) fn set_row_dimension(&mut self, value: Row) -> &mut Self {
self.rows.set_row_dimension(value);
self
}
#[inline]
pub(crate) fn row_dimensions_crate_mut(&mut self) -> &mut Rows {
&mut self.rows
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use row_dimensions_crate_mut()")]
pub(crate) fn get_row_dimensions_crate_mut(&mut self) -> &mut Rows {
self.row_dimensions_crate_mut()
}
#[inline]
pub(crate) fn row_dimensions_crate(&self) -> &Rows {
&self.rows
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use row_dimensions_crate()")]
pub(crate) fn get_row_dimensions_crate(&self) -> &Rows {
self.row_dimensions_crate()
}
#[inline]
#[must_use]
pub fn worksheet_drawing(&self) -> &WorksheetDrawing {
&self.worksheet_drawing
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use worksheet_drawing()")]
pub fn get_worksheet_drawing(&self) -> &WorksheetDrawing {
self.worksheet_drawing()
}
#[inline]
pub fn worksheet_drawing_mut(&mut self) -> &mut WorksheetDrawing {
&mut self.worksheet_drawing
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use worksheet_drawing_mut()")]
pub fn get_worksheet_drawing_mut(&mut self) -> &mut WorksheetDrawing {
self.worksheet_drawing_mut()
}
#[inline]
pub fn set_worksheet_drawing(&mut self, value: WorksheetDrawing) {
self.worksheet_drawing = value;
}
#[inline]
#[must_use]
pub fn has_drawing_object(&self) -> bool {
self.worksheet_drawing.has_drawing_object()
}
#[inline]
pub fn insert_new_row(&mut self, row_index: u32, num_rows: u32) {
let title = self.title.clone();
self.adjustment_insert_coordinate(0, 0, row_index, num_rows);
self.adjustment_insert_coordinate_with_sheet(&title, 0, 0, row_index, num_rows);
}
#[inline]
pub fn insert_new_row_from_other_sheet(
&mut self,
sheet_name: &str,
row_index: u32,
num_rows: u32,
) {
self.adjustment_insert_coordinate(0, 0, row_index, num_rows);
self.adjustment_insert_coordinate_with_sheet(sheet_name, 0, 0, row_index, num_rows);
}
#[inline]
pub fn insert_new_column(&mut self, column: &str, num_columns: u32) {
self.insert_new_column_by_index(column_index_from_string(column), num_columns);
}
#[inline]
pub fn insert_new_column_from_other_sheet(
&mut self,
sheet_name: &str,
column: &str,
num_columns: u32,
) {
self.insert_new_column_by_index_from_other_sheet(
sheet_name,
column_index_from_string(column),
num_columns,
);
}
#[inline]
pub fn insert_new_column_by_index(&mut self, column_index: u32, num_columns: u32) {
let title = self.title.clone();
self.adjustment_insert_coordinate(column_index, num_columns, 0, 0);
self.adjustment_insert_coordinate_with_sheet(&title, column_index, num_columns, 0, 0);
}
#[inline]
pub fn insert_new_column_by_index_from_other_sheet(
&mut self,
sheet_name: &str,
column_index: u32,
num_columns: u32,
) {
self.adjustment_insert_coordinate(column_index, num_columns, 0, 0);
self.adjustment_insert_coordinate_with_sheet(sheet_name, column_index, num_columns, 0, 0);
}
#[inline]
pub fn remove_row(&mut self, row_index: u32, num_rows: u32) {
let title = self.title.clone();
self.adjustment_remove_coordinate(0, 0, row_index, num_rows);
self.adjustment_remove_coordinate_with_sheet(&title, 0, 0, row_index, num_rows);
}
#[inline]
pub fn remove_row_from_other_sheet(&mut self, sheet_name: &str, row_index: u32, num_rows: u32) {
self.adjustment_remove_coordinate(0, 0, row_index, num_rows);
self.adjustment_remove_coordinate_with_sheet(sheet_name, 0, 0, row_index, num_rows);
}
#[inline]
pub fn remove_column(&mut self, column: &str, num_columns: u32) {
self.remove_column_by_index(column_index_from_string(column), num_columns);
}
#[inline]
pub fn remove_column_from_other_sheet(
&mut self,
sheet_name: &str,
column: &str,
num_columns: u32,
) {
self.remove_column_by_index_from_other_sheet(
sheet_name,
column_index_from_string(column),
num_columns,
);
}
#[inline]
pub fn remove_column_by_index(&mut self, column_index: u32, num_columns: u32) {
let title = self.title.clone();
self.adjustment_remove_coordinate(column_index, num_columns, 0, 0);
self.adjustment_remove_coordinate_with_sheet(&title, column_index, num_columns, 0, 0);
}
#[inline]
pub fn remove_column_by_index_from_other_sheet(
&mut self,
sheet_name: &str,
column_index: u32,
num_columns: u32,
) {
self.adjustment_remove_coordinate(column_index, num_columns, 0, 0);
self.adjustment_remove_coordinate_with_sheet(sheet_name, column_index, num_columns, 0, 0);
}
#[inline]
#[must_use]
pub fn code_name(&self) -> Option<&str> {
self.code_name.value()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use code_name()")]
pub fn get_code_name(&self) -> Option<&str> {
self.code_name()
}
#[inline]
pub fn set_code_name<S: Into<String>>(&mut self, value: S) {
self.code_name.set_value(value);
}
#[inline]
#[must_use]
pub fn header_footer(&self) -> &HeaderFooter {
&self.header_footer
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use header_footer()")]
pub fn get_header_footer(&self) -> &HeaderFooter {
self.header_footer()
}
#[inline]
pub fn header_footer_mut(&mut self) -> &mut HeaderFooter {
&mut self.header_footer
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use header_footer_mut()")]
pub fn get_header_footer_mut(&mut self) -> &mut HeaderFooter {
self.header_footer_mut()
}
#[inline]
pub fn set_header_footer(&mut self, value: HeaderFooter) -> &mut Self {
self.header_footer = value;
self
}
#[inline]
#[must_use]
pub fn active_cell(&self) -> &str {
&self.active_cell
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use active_cell()")]
pub fn get_active_cell(&self) -> &str {
self.active_cell()
}
#[inline]
pub fn set_active_cell<S: Into<String>>(&mut self, cell: S) {
self.active_cell = cell.into().into_boxed_str();
}
#[inline]
pub(crate) fn r_id(&self) -> &str {
&self.r_id
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use r_id()")]
pub(crate) fn get_r_id(&self) -> &str {
self.r_id()
}
#[inline]
pub(crate) fn set_r_id<S: Into<String>>(&mut self, value: S) {
self.r_id = value.into().into_boxed_str();
}
#[inline]
#[must_use]
pub fn sheet_id(&self) -> &str {
&self.sheet_id
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use sheet_id()")]
pub fn get_sheet_id(&self) -> &str {
self.sheet_id()
}
#[inline]
pub(crate) fn set_sheet_id<S: Into<String>>(&mut self, value: S) {
self.sheet_id = value.into().into_boxed_str();
}
#[inline]
#[must_use]
pub fn has_code_name(&self) -> bool {
self.code_name.has_value()
}
#[inline]
#[must_use]
pub fn tab_color(&self) -> Option<&Color> {
self.tab_color.as_ref()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use tab_color()")]
pub fn get_tab_color(&self) -> Option<&Color> {
self.tab_color()
}
#[inline]
#[allow(clippy::unnecessary_unwrap)]
pub fn tab_color_mut(&mut self) -> &mut Color {
if self.tab_color.is_some() {
return self.tab_color.as_mut().unwrap();
}
self.set_tab_color(Color::default());
self.tab_color.as_mut().unwrap()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use tab_color_mut()")]
pub fn get_tab_color_mut(&mut self) -> &mut Color {
self.tab_color_mut()
}
#[inline]
pub fn set_tab_color(&mut self, value: Color) -> &mut Self {
self.tab_color = Some(value);
self
}
#[inline]
pub fn remove_tab_color(&mut self) -> &mut Self {
self.tab_color = None;
self
}
#[must_use]
pub fn calculate_worksheet_dimension(&self) -> String {
let (column, row) = self.cells.highest_column_and_row();
if row == 0 {
return "A1".to_string();
}
let column_str = string_from_column_index(column);
format!("A1:{column_str}{row}")
}
#[inline]
#[must_use]
pub fn highest_column_and_row(&self) -> (u32, u32) {
self.cells.highest_column_and_row()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use highest_column_and_row()")]
pub fn get_highest_column_and_row(&self) -> (u32, u32) {
self.highest_column_and_row()
}
#[inline]
#[must_use]
pub fn highest_column(&self) -> u32 {
let (column, _row) = self.cells.highest_column_and_row();
column
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use highest_column()")]
pub fn get_highest_column(&self) -> u32 {
self.highest_column()
}
#[inline]
#[must_use]
pub fn highest_row(&self) -> u32 {
let (_column, row) = self.cells.highest_column_and_row();
row
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use highest_row()")]
pub fn get_highest_row(&self) -> u32 {
self.highest_row()
}
#[inline]
#[must_use]
pub fn name(&self) -> &str {
&self.title
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use name()")]
pub fn get_name(&self) -> &str {
self.name()
}
pub fn set_name<S: Into<String>>(&mut self, sheet_name: S) -> &mut Self {
self.title = sheet_name.into().into_boxed_str();
let title = self.name().to_string();
for defined_name in self.defined_names_mut() {
defined_name.set_sheet_name(&title);
}
self
}
#[inline]
pub(crate) fn has_state(&self) -> bool {
self.state.has_value()
}
#[inline]
#[must_use]
pub fn state(&self) -> &SheetStateValues {
self.state.value()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use state()")]
pub fn get_state(&self) -> &SheetStateValues {
self.state()
}
#[inline]
pub(crate) fn state_str(&self) -> &str {
self.state.value_string()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use state_str()")]
pub(crate) fn get_state_str(&self) -> &str {
self.state_str()
}
pub fn set_state(&mut self, value: SheetStateValues) -> &mut Self {
self.state.set_value(value);
self
}
#[inline]
pub(crate) fn set_state_str(&mut self, value: &str) -> &mut Self {
self.state.set_value_string(value);
self
}
#[inline]
#[must_use]
pub fn sheet_state(&self) -> &str {
&self.sheet_state
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use sheet_state()")]
pub fn get_sheet_state(&self) -> &str {
self.sheet_state()
}
#[inline]
pub fn set_sheet_state(&mut self, value: String) -> &mut Self {
self.sheet_state = value.into_boxed_str();
self
}
#[inline]
#[must_use]
pub fn page_setup(&self) -> &PageSetup {
&self.page_setup
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use page_setup()")]
pub fn get_page_setup(&self) -> &PageSetup {
self.page_setup()
}
#[inline]
pub fn page_setup_mut(&mut self) -> &mut PageSetup {
&mut self.page_setup
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use page_setup_mut()")]
pub fn get_page_setup_mut(&mut self) -> &mut PageSetup {
self.page_setup_mut()
}
#[inline]
pub fn set_page_setup(&mut self, value: PageSetup) -> &mut Self {
self.page_setup = value;
self
}
#[inline]
#[must_use]
pub fn page_margins(&self) -> &PageMargins {
&self.page_margins
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use page_margins()")]
pub fn get_page_margins(&self) -> &PageMargins {
self.page_margins()
}
#[inline]
pub fn page_margins_mut(&mut self) -> &mut PageMargins {
&mut self.page_margins
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use page_margins_mut()")]
pub fn get_page_margins_mut(&mut self) -> &mut PageMargins {
self.page_margins_mut()
}
#[inline]
pub fn set_page_margins(&mut self, value: PageMargins) -> &mut Self {
self.page_margins = value;
self
}
#[inline]
#[must_use]
pub fn sheets_views(&self) -> &SheetViews {
&self.sheet_views
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use sheets_views()")]
pub fn get_sheets_views(&self) -> &SheetViews {
self.sheets_views()
}
#[inline]
pub fn sheet_views_mut(&mut self) -> &mut SheetViews {
&mut self.sheet_views
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use sheet_views_mut()")]
pub fn get_sheet_views_mut(&mut self) -> &mut SheetViews {
self.sheet_views_mut()
}
#[inline]
pub fn set_sheets_views(&mut self, value: SheetViews) -> &mut Self {
self.sheet_views = value;
self
}
#[inline]
#[must_use]
pub fn ole_objects(&self) -> &OleObjects {
&self.ole_objects
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use get_ole_objects()")]
pub fn get_ole_objects(&self) -> &OleObjects {
self.ole_objects()
}
#[inline]
pub fn ole_objects_mut(&mut self) -> &mut OleObjects {
&mut self.ole_objects
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use ole_objects_mut()")]
pub fn get_ole_objects_mut(&mut self) -> &mut OleObjects {
self.ole_objects_mut()
}
#[inline]
pub fn set_ole_objects(&mut self, value: OleObjects) -> &mut Self {
self.ole_objects = value;
self
}
#[inline]
#[must_use]
pub fn defined_names(&self) -> &[DefinedName] {
&self.defined_names
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use defined_names()")]
pub fn get_defined_names(&self) -> &[DefinedName] {
self.defined_names()
}
#[inline]
pub fn defined_names_mut(&mut self) -> &mut Vec<DefinedName> {
&mut self.defined_names
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use defined_names_mut()")]
pub fn get_defined_names_mut(&mut self) -> &mut Vec<DefinedName> {
self.defined_names_mut()
}
#[inline]
pub fn set_defined_names(&mut self, value: impl Into<Vec<DefinedName>>) {
self.defined_names = value.into();
}
#[inline]
pub fn add_defined_names(&mut self, value: DefinedName) {
self.defined_names.push(value);
}
#[inline]
pub fn add_defined_name<S: Into<String>>(&mut self, name: S, address: S) -> Result<(), &str> {
let mut defined_name = DefinedName::default();
defined_name.set_name(name.into());
defined_name.set_address(address.into());
self.add_defined_names(defined_name);
Ok(())
}
#[inline]
#[must_use]
pub fn print_options(&self) -> &PrintOptions {
&self.print_options
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use print_options()")]
pub fn get_print_options(&self) -> &PrintOptions {
self.print_options()
}
#[inline]
pub fn print_options_mut(&mut self) -> &mut PrintOptions {
&mut self.print_options
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use print_options_mut()")]
pub fn get_print_options_mut(&mut self) -> &mut PrintOptions {
self.print_options_mut()
}
#[inline]
pub fn set_print_options(&mut self, value: PrintOptions) -> &mut Self {
self.print_options = value;
self
}
#[inline]
#[must_use]
pub fn column_breaks(&self) -> &ColumnBreaks {
&self.column_breaks
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use column_breaks()")]
pub fn get_column_breaks(&self) -> &ColumnBreaks {
self.column_breaks()
}
#[inline]
pub fn column_breaks_mut(&mut self) -> &mut ColumnBreaks {
&mut self.column_breaks
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use column_breaks_mut()")]
pub fn get_column_breaks_mut(&mut self) -> &mut ColumnBreaks {
self.column_breaks_mut()
}
#[inline]
pub fn set_column_breaks(&mut self, value: ColumnBreaks) -> &mut Self {
self.column_breaks = value;
self
}
#[inline]
#[must_use]
pub fn row_breaks(&self) -> &RowBreaks {
&self.row_breaks
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use row_breaks()")]
pub fn get_row_breaks(&self) -> &RowBreaks {
self.row_breaks()
}
#[inline]
pub fn row_breaks_mut(&mut self) -> &mut RowBreaks {
&mut self.row_breaks
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use row_breaks_mut()")]
pub fn get_row_breaks_mut(&mut self) -> &mut RowBreaks {
self.row_breaks_mut()
}
#[inline]
pub fn set_row_breaks(&mut self, value: RowBreaks) -> &mut Self {
self.row_breaks = value;
self
}
#[inline]
#[must_use]
pub fn has_table(&self) -> bool {
!self.tables.is_empty()
}
#[inline]
pub fn add_table(&mut self, table: Table) {
self.tables.push(table);
}
#[inline]
#[must_use]
pub fn tables(&self) -> &[Table] {
&self.tables
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use tables()")]
pub fn get_tables(&self) -> &[Table] {
self.tables()
}
#[inline]
pub fn tables_mut(&mut self) -> &mut Vec<Table> {
&mut self.tables
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use tables_mut()")]
pub fn get_tables_mut(&mut self) -> &mut Vec<Table> {
self.tables_mut()
}
#[inline]
#[must_use]
pub fn has_pivot_table(&self) -> bool {
!self.pivot_tables.is_empty()
}
#[inline]
pub fn add_pivot_table(&mut self, pivot_table: PivotTable) {
self.pivot_tables.push(pivot_table);
}
#[inline]
#[must_use]
pub fn pivot_tables(&self) -> &[PivotTable] {
&self.pivot_tables
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use pivot_tables()")]
pub fn get_pivot_tables(&self) -> &[PivotTable] {
self.pivot_tables()
}
#[inline]
pub fn pivot_tables_mut(&mut self) -> &mut Vec<PivotTable> {
&mut self.pivot_tables
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use pivot_tables_mut()")]
pub fn get_pivot_tables_mut(&mut self) -> &mut Vec<PivotTable> {
self.pivot_tables_mut()
}
#[inline]
#[must_use]
pub fn data_validations(&self) -> Option<&DataValidations> {
self.data_validations.as_ref()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use data_validations()")]
pub fn get_data_validations(&self) -> Option<&DataValidations> {
self.data_validations()
}
#[inline]
pub fn data_validations_mut(&mut self) -> Option<&mut DataValidations> {
self.data_validations.as_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use data_validations_mut()")]
pub fn get_data_validations_mut(&mut self) -> Option<&mut DataValidations> {
self.data_validations_mut()
}
#[inline]
pub fn set_data_validations(&mut self, value: DataValidations) -> &mut Self {
self.data_validations = Some(value);
self
}
#[inline]
pub fn remove_data_validations(&mut self) -> &mut Self {
self.data_validations = None;
self
}
#[inline]
#[must_use]
pub fn data_validations_2010(&self) -> Option<&DataValidations2010> {
self.data_validations_2010.as_ref()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use data_validations_mut()")]
pub fn get_data_validations_2010(&self) -> Option<&DataValidations2010> {
self.data_validations_2010()
}
#[inline]
pub fn data_validations_2010_mut(&mut self) -> Option<&mut DataValidations2010> {
self.data_validations_2010.as_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use data_validations_2010_mut()")]
pub fn get_data_validations_2010_mut(&mut self) -> Option<&mut DataValidations2010> {
self.data_validations_2010_mut()
}
#[inline]
pub fn set_data_validations_2010(&mut self, value: DataValidations2010) -> &mut Self {
self.data_validations_2010 = Some(value);
self
}
#[inline]
pub fn remove_data_validations_2010(&mut self) -> &mut Self {
self.data_validations_2010 = None;
self
}
#[inline]
#[must_use]
pub fn sheet_format_properties(&self) -> &SheetFormatProperties {
&self.sheet_format_properties
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use sheet_format_properties()")]
pub fn get_sheet_format_properties(&self) -> &SheetFormatProperties {
self.sheet_format_properties()
}
#[inline]
pub fn sheet_format_properties_mut(&mut self) -> &mut SheetFormatProperties {
&mut self.sheet_format_properties
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use sheet_format_properties_mut()")]
pub fn get_sheet_format_properties_mut(&mut self) -> &mut SheetFormatProperties {
self.sheet_format_properties_mut()
}
#[inline]
pub fn set_sheet_format_properties(&mut self, value: SheetFormatProperties) -> &mut Self {
self.sheet_format_properties = value;
self
}
#[inline]
#[must_use]
pub fn image_collection(&self) -> &[Image] {
self.worksheet_drawing().image_collection()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use image_collection()")]
pub fn get_image_collection(&self) -> &[Image] {
self.image_collection()
}
#[inline]
pub fn image_collection_mut(&mut self) -> &mut Vec<Image> {
self.worksheet_drawing_mut().image_collection_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use image_collection_mut()")]
pub fn get_image_collection_mut(&mut self) -> &mut Vec<Image> {
self.image_collection_mut()
}
#[inline]
pub fn add_image(&mut self, value: Image) -> &mut Self {
self.worksheet_drawing_mut().add_image(value);
self
}
#[inline]
pub fn image<T>(&self, coordinate: T) -> Option<&Image>
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.worksheet_drawing().image(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use image()")]
pub fn get_image<T>(&self, coordinate: T) -> Option<&Image>
where
T: Into<CellCoordinates>,
{
self.image(coordinate)
}
#[inline]
pub fn image_mut<T>(&mut self, coordinate: T) -> Option<&mut Image>
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.worksheet_drawing_mut().image_mut(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use image_mut()")]
pub fn get_image_mut<T>(&mut self, coordinate: T) -> Option<&mut Image>
where
T: Into<CellCoordinates>,
{
self.image_mut(coordinate)
}
#[inline]
pub fn image_by_column_and_row_mut(&mut self, col: u32, row: u32) -> Option<&mut Image> {
self.worksheet_drawing_mut().image_mut(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use image_by_column_and_row_mut()")]
pub fn get_image_by_column_and_row_mut(&mut self, col: &u32, row: &u32) -> Option<&mut Image> {
self.image_by_column_and_row_mut(*col, *row)
}
#[inline]
pub fn images<T>(&self, coordinate: T) -> Vec<&Image>
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.worksheet_drawing().images(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use images()")]
pub fn get_images<T>(&self, coordinate: T) -> Vec<&Image>
where
T: Into<CellCoordinates>,
{
self.images(coordinate)
}
#[inline]
pub fn images_mut<T>(&mut self, coordinate: T) -> Vec<&mut Image>
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.worksheet_drawing_mut().images_mut(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use images_mut()")]
pub fn get_images_mut<T>(&mut self, coordinate: T) -> Vec<&mut Image>
where
T: Into<CellCoordinates>,
{
self.images_mut(coordinate)
}
#[inline]
#[must_use]
pub fn chart_collection(&self) -> &[Chart] {
self.worksheet_drawing().chart_collection()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use chart_collection()")]
pub fn get_chart_collection(&self) -> &[Chart] {
self.chart_collection()
}
#[inline]
pub fn chart_collection_mut(&mut self) -> &mut Vec<Chart> {
self.worksheet_drawing_mut().chart_collection_mut()
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use chart_collection_mut()")]
pub fn get_chart_collection_mut(&mut self) -> &mut Vec<Chart> {
self.chart_collection_mut()
}
#[inline]
pub fn add_chart(&mut self, value: Chart) -> &mut Self {
self.worksheet_drawing_mut().add_chart_collection(value);
self
}
#[inline]
pub fn chart<T>(&self, coordinate: T) -> Option<&Chart>
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.worksheet_drawing().chart(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use chart()")]
pub fn get_chart<T>(&self, coordinate: T) -> Option<&Chart>
where
T: Into<CellCoordinates>,
{
self.chart(coordinate)
}
#[inline]
pub fn chart_mut<T>(&mut self, coordinate: T) -> Option<&mut Chart>
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.worksheet_drawing_mut().chart_mut(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use chart_mut()")]
pub fn get_chart_mut<T>(&mut self, coordinate: T) -> Option<&mut Chart>
where
T: Into<CellCoordinates>,
{
self.chart_mut(coordinate)
}
#[inline]
pub fn charts<T>(&self, coordinate: T) -> Vec<&Chart>
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.worksheet_drawing().charts(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use charts()")]
pub fn get_charts<T>(&self, coordinate: T) -> Vec<&Chart>
where
T: Into<CellCoordinates>,
{
self.charts(coordinate)
}
#[inline]
pub fn charts_mut<T>(&mut self, coordinate: T) -> Vec<&mut Chart>
where
T: Into<CellCoordinates>,
{
let CellCoordinates { col, row } = coordinate.into();
self.worksheet_drawing_mut().charts_mut(col, row)
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use charts_mut()")]
pub fn get_charts_mut<T>(&mut self, coordinate: T) -> Vec<&mut Chart>
where
T: Into<CellCoordinates>,
{
self.charts_mut(coordinate)
}
pub(crate) fn media_object_collection(&self) -> Vec<&MediaObject> {
let mut list: Vec<&MediaObject> = Vec::new();
for image in self.worksheet_drawing().image_collection() {
for media_object in image.media_object() {
let is_new = !list
.iter()
.any(|v| v.image_name() == media_object.image_name());
if is_new {
list.push(media_object);
}
}
}
for ole_objects in self.ole_objects().ole_object() {
let media_object = ole_objects.embedded_object_properties().image();
let is_new = !list
.iter()
.any(|v| v.image_name() == media_object.image_name());
if is_new {
list.push(media_object);
}
}
for ole_objects in self.ole_objects().ole_object() {
if let Some(fill) = ole_objects.shape().fill() {
if let Some(media_object) = fill.image() {
let is_new = !list
.iter()
.any(|v| v.image_name() == media_object.image_name());
if is_new {
list.push(media_object);
}
}
}
}
for comment in self.comments() {
if let Some(fill) = comment.shape().fill() {
if let Some(media_object) = fill.image() {
let is_new = !list
.iter()
.any(|v| v.image_name() == media_object.image_name());
if is_new {
list.push(media_object);
}
}
}
}
list
}
#[deprecated(since = "3.0.0", note = "Use media_object_collection()")]
pub(crate) fn get_media_object_collection(&self) -> Vec<&MediaObject> {
self.media_object_collection()
}
pub(crate) fn pivot_cache_definition_collection(&self) -> Vec<&str> {
let mut result: Vec<&str> = Vec::new();
if let Some(raw_data) = &self.raw_data_of_worksheet {
for relationships in raw_data.relationships_list() {
for row in relationships.relationship_list() {
if row.get_type() == PIVOT_CACHE_DEF_NS {
result.push(row.raw_file().file_target());
}
}
}
}
result
}
#[deprecated(since = "3.0.0", note = "Use pivot_cache_definition_collection()")]
pub(crate) fn get_pivot_cache_definition_collection(&self) -> Vec<&str> {
self.pivot_cache_definition_collection()
}
#[inline]
pub(crate) fn has_defined_names(&self) -> bool {
!self.defined_names().is_empty()
}
#[inline]
pub(crate) fn is_deserialized(&self) -> bool {
self.raw_data_of_worksheet.is_none()
}
#[inline]
pub(crate) fn raw_data_of_worksheet(&self) -> &RawWorksheet {
self.raw_data_of_worksheet
.as_ref()
.expect("Not found at raw data of worksheet.")
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use raw_data_of_worksheet()")]
pub(crate) fn get_raw_data_of_worksheet(&self) -> &RawWorksheet {
self.raw_data_of_worksheet()
}
#[inline]
pub(crate) fn set_raw_data_of_worksheet(&mut self, value: RawWorksheet) -> &mut Self {
self.raw_data_of_worksheet = Some(value);
self
}
#[inline]
pub(crate) fn take_raw_data_of_worksheet(&mut self) -> RawWorksheet {
self.raw_data_of_worksheet
.take()
.expect("Not found at raw data of worksheet.")
}
#[inline]
pub(crate) fn remove_raw_data_of_worksheet(&mut self) -> &mut Self {
self.raw_data_of_worksheet = None;
self
}
#[inline]
#[must_use]
pub fn sheet_protection(&self) -> Option<&SheetProtection> {
self.sheet_protection.as_ref()
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use sheet_protection()")]
pub fn get_sheet_protection(&self) -> Option<&SheetProtection> {
self.sheet_protection()
}
#[inline]
pub fn sheet_protection_mut(&mut self) -> &mut SheetProtection {
self.sheet_protection
.get_or_insert(SheetProtection::default())
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use sheet_protection_mut()")]
pub fn get_sheet_protection_mut(&mut self) -> &mut SheetProtection {
self.sheet_protection_mut()
}
#[inline]
pub fn set_sheet_protection(&mut self, value: SheetProtection) -> &mut Self {
self.sheet_protection = Some(value);
self
}
#[inline]
pub fn remove_sheet_protection(&mut self) -> &mut Self {
self.sheet_protection = None;
self
}
#[inline]
pub(crate) fn has_ole_objects(&self) -> bool {
!self.ole_objects.ole_object().is_empty()
}
#[inline]
pub(crate) fn has_legacy_drawing(&self) -> bool {
self.has_comments() || self.has_ole_objects()
}
#[inline]
pub fn move_range(&mut self, range: &str, row: i32, column: i32) -> &mut Self {
self.move_or_copy_range(range, row, column, true)
}
#[inline]
pub fn copy_range(&mut self, range: &str, row: i32, column: i32) -> &mut Self {
self.move_or_copy_range(range, row, column, false)
}
#[inline]
#[allow(clippy::cast_sign_loss)]
fn move_or_copy_range(
&mut self,
range: &str,
row: i32,
column: i32,
is_move: bool,
) -> &mut Self {
let (row_start, row_end, col_start, col_end) = get_start_and_end_point(range);
if (num_traits::cast::<_, i32>(col_start).unwrap() + column) < 1
|| (num_traits::cast::<_, i32>(row_start).unwrap() + row) < 1
|| (num_traits::cast::<_, i32>(col_end).unwrap() + column) > 16384
|| (num_traits::cast::<_, i32>(row_end).unwrap() + row) > 1_048_576
{
panic!("Out of Range.");
}
let mut copy_cells: Vec<Cell> = self
.cells
.iter_all_cells_by_range_sorted_by_row(range)
.flatten().cloned()
.collect();
if is_move {
for (col_num, row_num) in &get_coordinate_list(range) {
self.cells.remove(*col_num, *row_num);
self.cells.remove(
*col_num + num_traits::cast::<_, u32>(column).unwrap(),
*row_num + num_traits::cast::<_, u32>(row).unwrap(),
);
}
}
for cell in &mut copy_cells {
cell.coordinate_mut().offset_col_num(column);
cell.coordinate_mut().offset_row_num(row);
self.set_cell(cell.clone());
}
self
}
#[inline]
pub fn cleanup(&mut self) {
let (_, max_row) = self.highest_column_and_row();
for row in (1..=max_row).rev() {
if self.rows.row_dimension(row).is_some() {
let mut indexes: Vec<(u32, u32)> = Vec::new();
{
let cells: Vec<&Cell> = self.cells.iter_cells_by_row(row).collect();
for cell in cells {
if !cell.is_visually_empty() {
return;
}
indexes.push((
cell.coordinate().row_num(),
cell.coordinate().col_num(),
));
}
}
self.rows.row_dimensions_to_hashmap_mut().remove(&row);
for (i_row, i_col) in indexes {
self.cells.remove(i_col, i_row);
}
}
}
}
#[inline]
pub fn copy_cell_styling<T>(&mut self, source: T, target: T)
where
T: Into<CellCoordinates>,
{
let style = self.cells.style(source).clone();
self.cell_mut(target).set_style(style);
}
#[inline]
pub fn copy_row_styling(
&mut self,
source_row_no: u32,
target_row_no: u32,
start_col: Option<u32>,
end_col: Option<u32>,
) {
let start_no = start_col.unwrap_or(1);
let end_no = end_col.unwrap_or(self.highest_column());
if let Some(row_style) = self
.row_dimensions_crate()
.row_dimension(source_row_no)
.map(Row::style)
.cloned()
{
self.row_dimensions_crate_mut()
.row_dimension_mut(target_row_no)
.set_style(row_style);
}
for col_no in start_no..=end_no {
self.copy_cell_styling((col_no, source_row_no), (col_no, target_row_no));
}
}
#[inline]
pub fn copy_col_styling(
&mut self,
source_col_no: u32,
target_col_no: u32,
start_row: Option<u32>,
end_row: Option<u32>,
) {
let start_no = start_row.unwrap_or(1);
let end_no = end_row.unwrap_or(self.highest_row());
if let Some(col_style) = self
.column_dimensions_crate()
.column(source_col_no)
.map(Column::style)
.cloned()
{
self.column_dimensions_crate_mut()
.column_mut(target_col_no)
.set_style(col_style);
}
for row_no in start_no..=end_no {
self.copy_cell_styling((source_col_no, row_no), (target_col_no, row_no));
}
}
}
impl AdjustmentCoordinate for Worksheet {
fn adjustment_insert_coordinate(
&mut self,
root_col_num: u32,
offset_col_num: u32,
root_row_num: u32,
offset_row_num: u32,
) {
if offset_col_num != 0 {
self.columns
.adjustment_insert_value(root_col_num, offset_col_num);
}
if offset_row_num != 0 {
self.row_dimensions_crate_mut()
.adjustment_insert_value(root_row_num, offset_row_num);
}
if offset_col_num == 0 && offset_row_num == 0 {
return;
}
for defined_name in &mut self.defined_names {
defined_name.adjustment_insert_coordinate_with_sheet(
&self.title,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
self.cells.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
self.worksheet_drawing
.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
for comment in &mut self.comments {
comment.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
for conditional_styles in &mut self.conditional_formatting_collection {
conditional_styles.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
for merge_cell in self.merge_cells_mut() {
merge_cell.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
if let Some(v) = self.auto_filter_mut() {
v.adjustment_insert_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
}
fn adjustment_remove_coordinate(
&mut self,
root_col_num: u32,
offset_col_num: u32,
root_row_num: u32,
offset_row_num: u32,
) {
if offset_col_num != 0 {
self.columns
.adjustment_remove_value(root_col_num, offset_col_num);
}
if offset_row_num != 0 {
self.rows
.adjustment_remove_value(root_row_num, offset_row_num);
}
if offset_col_num == 0 && offset_row_num == 0 {
return;
}
let title = &self.title;
self.defined_names.retain(|defined_name| {
!defined_name.is_remove_coordinate_with_sheet(
title,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
)
});
for defined_name in &mut self.defined_names {
defined_name.adjustment_remove_coordinate_with_sheet(
&self.title,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
self.cells.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
self.worksheet_drawing_mut()
.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
self.comments.retain(|x| {
!(x.is_remove_coordinate(root_col_num, offset_col_num, root_row_num, offset_row_num))
});
for comment in &mut self.comments {
comment.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
self.conditional_formatting_collection.retain(|x| {
!x.is_remove_coordinate(root_col_num, offset_col_num, root_row_num, offset_row_num)
});
for conditional_styles in &mut self.conditional_formatting_collection {
conditional_styles.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
self.merge_cells_mut().retain(|x| {
!(x.is_remove_coordinate(root_col_num, offset_col_num, root_row_num, offset_row_num))
});
for merge_cell in self.merge_cells_mut() {
merge_cell.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
let is_remove = match self.auto_filter() {
Some(v) => v.range().is_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
),
None => false,
};
if is_remove {
self.remove_auto_filter();
}
if let Some(v) = self.auto_filter_mut() {
v.adjustment_remove_coordinate(
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
}
}
impl AdjustmentCoordinateWithSheet for Worksheet {
fn adjustment_insert_coordinate_with_sheet(
&mut self,
sheet_name: &str,
root_col_num: u32,
offset_col_num: u32,
root_row_num: u32,
offset_row_num: u32,
) {
if offset_col_num == 0 && offset_row_num == 0 {
return;
}
let title = self.title.clone();
self.cells_crate_mut()
.adjustment_insert_coordinate_with_2sheet(
&title,
sheet_name,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
self.worksheet_drawing
.adjustment_insert_coordinate_with_sheet(
sheet_name,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
fn adjustment_remove_coordinate_with_sheet(
&mut self,
sheet_name: &str,
root_col_num: u32,
offset_col_num: u32,
root_row_num: u32,
offset_row_num: u32,
) {
if offset_col_num == 0 && offset_row_num == 0 {
return;
}
let title = self.title.clone();
self.cells_crate_mut()
.adjustment_remove_coordinate_with_2sheet(
&title,
sheet_name,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
self.worksheet_drawing
.adjustment_remove_coordinate_with_sheet(
sheet_name,
root_col_num,
offset_col_num,
root_row_num,
offset_row_num,
);
}
}