Struct spreadsheet_ods::Sheet
source · pub struct Sheet { /* private fields */ }Expand description
One sheet of the spreadsheet.
Contains the data and the style-references. The can also be styles on the whole sheet, columns and rows. The more complicated grouping tags are not covered.
Implementations§
source§impl Sheet
impl Sheet
sourcepub fn new_with_name<S: Into<String>>(name: S) -> Self
👎Deprecated
pub fn new_with_name<S: Into<String>>(name: S) -> Self
Create an empty sheet.
sourcepub fn new<S: Into<String>>(name: S) -> Self
pub fn new<S: Into<String>>(name: S) -> Self
Create an empty sheet.
The name is shown as the tab-title, but also as a reference for this sheet in formulas and sheet-metadata. Giving an empty string here is allowed and a name will be generated, when the document is opened. But any metadata will not be applied.
Renaming the sheet works for metadata, but formulas will not be fixed.
Examples found in repository?
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
pub fn main() -> Result<(), OdsError> {
let mut wb = WorkBook::new(locale!("de_AT"));
// positive format
let mut f_number = ValueFormatNumber::new_localized("num0", locale!("de_AT"));
f_number
.part_number()
.decimal_places(2)
.min_integer_digits(1)
.grouping()
.build();
let f_number = wb.add_number_format(f_number);
// negative format
let mut f_number_red = ValueFormatNumber::new_localized("num0red", locale!("de_AT"));
f_number_red.part_text("-").build();
f_number_red
.part_number()
.decimal_places(2)
.min_integer_digits(1)
.grouping()
.build();
f_number_red.set_color(Rgb::new(255, 0, 0));
f_number_red.push_stylemap(ValueStyleMap::new(ValueCondition::value_ge(0), f_number));
let f_number_red = wb.add_number_format(f_number_red);
// cellstyle for this number format
let s_number = CellStyle::new("num_red", &f_number_red);
let s_number = wb.add_cellstyle(s_number);
// ...
let mut sheet = Sheet::new("sample");
sheet.set_styled_value(0, 0, 723, &s_number);
sheet.set_styled_value(1, 0, -723, &s_number);
wb.push_sheet(sheet);
write_ods(&mut wb, "examples/neg.ods")?;
Ok(())
}sourcepub fn clone_no_data(&self) -> Self
pub fn clone_no_data(&self) -> Self
Copy all the attributes but not the actual data.
sourcepub fn cell_count(&self) -> usize
pub fn cell_count(&self) -> usize
Count all cells with any data.
sourcepub fn config(&self) -> &SheetConfig
pub fn config(&self) -> &SheetConfig
Configuration for the sheet.
sourcepub fn config_mut(&mut self) -> &mut SheetConfig
pub fn config_mut(&mut self) -> &mut SheetConfig
Configuration for the sheet.
sourcepub fn set_style(&mut self, style: &TableStyleRef)
pub fn set_style(&mut self, style: &TableStyleRef)
Sets the table-style
sourcepub fn set_colstyle(&mut self, col: u32, style: &ColStyleRef)
pub fn set_colstyle(&mut self, col: u32, style: &ColStyleRef)
Column style.
sourcepub fn clear_colstyle(&mut self, col: u32)
pub fn clear_colstyle(&mut self, col: u32)
Remove the style.
sourcepub fn set_col_cellstyle(&mut self, col: u32, style: &CellStyleRef)
pub fn set_col_cellstyle(&mut self, col: u32, style: &CellStyleRef)
Default cell style for this column.
sourcepub fn clear_col_cellstyle(&mut self, col: u32)
pub fn clear_col_cellstyle(&mut self, col: u32)
Remove the style.
sourcepub fn col_cellstyle(&self, col: u32) -> Option<&String>
pub fn col_cellstyle(&self, col: u32) -> Option<&String>
Returns the default cell style for this column.
sourcepub fn set_col_visible(&mut self, col: u32, visible: Visibility)
pub fn set_col_visible(&mut self, col: u32, visible: Visibility)
Visibility of the column
sourcepub fn col_visible(&self, col: u32) -> Visibility
pub fn col_visible(&self, col: u32) -> Visibility
Returns the default cell style for this column.
sourcepub fn set_col_width(&mut self, col: u32, width: Length)
pub fn set_col_width(&mut self, col: u32, width: Length)
Sets the column width for this column.
sourcepub fn set_rowstyle(&mut self, row: u32, style: &RowStyleRef)
pub fn set_rowstyle(&mut self, row: u32, style: &RowStyleRef)
Row style.
sourcepub fn clear_rowstyle(&mut self, row: u32)
pub fn clear_rowstyle(&mut self, row: u32)
Remove the style.
sourcepub fn set_row_cellstyle(&mut self, row: u32, style: &CellStyleRef)
pub fn set_row_cellstyle(&mut self, row: u32, style: &CellStyleRef)
Default cell style for this row.
sourcepub fn clear_row_cellstyle(&mut self, row: u32)
pub fn clear_row_cellstyle(&mut self, row: u32)
Remove the style.
sourcepub fn row_cellstyle(&self, row: u32) -> Option<&String>
pub fn row_cellstyle(&self, row: u32) -> Option<&String>
Returns the default cell style for this row.
sourcepub fn set_row_visible(&mut self, row: u32, visible: Visibility)
pub fn set_row_visible(&mut self, row: u32, visible: Visibility)
Visibility of the row
sourcepub fn row_visible(&self, row: u32) -> Visibility
pub fn row_visible(&self, row: u32) -> Visibility
Returns the default cell style for this row.
sourcepub fn set_row_repeat(&mut self, row: u32, repeat: u32)
pub fn set_row_repeat(&mut self, row: u32, repeat: u32)
Sets the repeat count for this row. Usually this is the last row with data in a sheet. Setting the repeat count will not change the row number of following rows. But they will be changed after writing to an ODS file and reading it again.
Panics
Panics if the repeat is 0.
sourcepub fn row_repeat(&self, row: u32) -> u32
pub fn row_repeat(&self, row: u32) -> u32
Returns the repeat count for this row.
sourcepub fn set_row_height(&mut self, row: u32, height: Length)
pub fn set_row_height(&mut self, row: u32, height: Length)
Sets the row-height.
sourcepub fn row_height(&self, row: u32) -> Length
pub fn row_height(&self, row: u32) -> Length
Returns the row-height
sourcepub fn used_grid_size(&self) -> (u32, u32)
pub fn used_grid_size(&self) -> (u32, u32)
Returns a tuple of (max(row)+1, max(col)+1)
sourcepub fn set_display(&mut self, display: bool)
pub fn set_display(&mut self, display: bool)
Is the sheet displayed?
sourcepub fn is_empty(&self, row: u32, col: u32) -> bool
pub fn is_empty(&self, row: u32, col: u32) -> bool
Returns true if there is no SCell at the given position.
sourcepub fn cell(&self, row: u32, col: u32) -> Option<CellContent>
pub fn cell(&self, row: u32, col: u32) -> Option<CellContent>
Basic range operator. Returns a copy of the cell content.
sourcepub fn cell_ref(&self, row: u32, col: u32) -> Option<CellContentRef<'_>>
pub fn cell_ref(&self, row: u32, col: u32) -> Option<CellContentRef<'_>>
Returns a copy of the cell content.
sourcepub fn add_cell(&mut self, row: u32, col: u32, cell: CellContent)
pub fn add_cell(&mut self, row: u32, col: u32, cell: CellContent)
Consumes the CellContent and sets the values.
sourcepub fn remove_cell(&mut self, row: u32, col: u32) -> Option<CellContent>
pub fn remove_cell(&mut self, row: u32, col: u32) -> Option<CellContent>
Removes the cell and returns the values as CellContent.
sourcepub fn set_styled_value<V: Into<Value>>(
&mut self,
row: u32,
col: u32,
value: V,
style: &CellStyleRef
)
pub fn set_styled_value<V: Into<Value>>( &mut self, row: u32, col: u32, value: V, style: &CellStyleRef )
Sets a value for the specified cell. Creates a new cell if necessary.
Examples found in repository?
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
pub fn main() -> Result<(), OdsError> {
let mut wb = WorkBook::new(locale!("de_AT"));
// positive format
let mut f_number = ValueFormatNumber::new_localized("num0", locale!("de_AT"));
f_number
.part_number()
.decimal_places(2)
.min_integer_digits(1)
.grouping()
.build();
let f_number = wb.add_number_format(f_number);
// negative format
let mut f_number_red = ValueFormatNumber::new_localized("num0red", locale!("de_AT"));
f_number_red.part_text("-").build();
f_number_red
.part_number()
.decimal_places(2)
.min_integer_digits(1)
.grouping()
.build();
f_number_red.set_color(Rgb::new(255, 0, 0));
f_number_red.push_stylemap(ValueStyleMap::new(ValueCondition::value_ge(0), f_number));
let f_number_red = wb.add_number_format(f_number_red);
// cellstyle for this number format
let s_number = CellStyle::new("num_red", &f_number_red);
let s_number = wb.add_cellstyle(s_number);
// ...
let mut sheet = Sheet::new("sample");
sheet.set_styled_value(0, 0, 723, &s_number);
sheet.set_styled_value(1, 0, -723, &s_number);
wb.push_sheet(sheet);
write_ods(&mut wb, "examples/neg.ods")?;
Ok(())
}sourcepub fn set_value<V: Into<Value>>(&mut self, row: u32, col: u32, value: V)
pub fn set_value<V: Into<Value>>(&mut self, row: u32, col: u32, value: V)
Sets a value for the specified cell. Creates a new cell if necessary.
sourcepub fn set_formula<V: Into<String>>(&mut self, row: u32, col: u32, formula: V)
pub fn set_formula<V: Into<String>>(&mut self, row: u32, col: u32, formula: V)
Sets a formula for the specified cell. Creates a new cell if necessary.
sourcepub fn clear_formula(&mut self, row: u32, col: u32)
pub fn clear_formula(&mut self, row: u32, col: u32)
Removes the formula.
sourcepub fn set_col_repeat(&mut self, row: u32, col: u32, repeat: u32)
pub fn set_col_repeat(&mut self, row: u32, col: u32, repeat: u32)
Sets a repeat counter for the cell.
sourcepub fn col_repeat(&self, row: u32, col: u32) -> u32
pub fn col_repeat(&self, row: u32, col: u32) -> u32
Returns the repeat counter for the cell.
sourcepub fn set_cellstyle(&mut self, row: u32, col: u32, style: &CellStyleRef)
pub fn set_cellstyle(&mut self, row: u32, col: u32, style: &CellStyleRef)
Sets the cell-style for the specified cell. Creates a new cell if necessary.
sourcepub fn clear_cellstyle(&mut self, row: u32, col: u32)
pub fn clear_cellstyle(&mut self, row: u32, col: u32)
Removes the cell-style.
sourcepub fn set_validation(&mut self, row: u32, col: u32, validation: &ValidationRef)
pub fn set_validation(&mut self, row: u32, col: u32, validation: &ValidationRef)
Sets a content-validation for this cell.
sourcepub fn clear_validation(&mut self, row: u32, col: u32)
pub fn clear_validation(&mut self, row: u32, col: u32)
Removes the cell-style.
sourcepub fn validation(&self, row: u32, col: u32) -> Option<&String>
pub fn validation(&self, row: u32, col: u32) -> Option<&String>
Returns a content-validation name for this cell.
sourcepub fn set_row_span(&mut self, row: u32, col: u32, span: u32)
pub fn set_row_span(&mut self, row: u32, col: u32, span: u32)
Sets the rowspan of the cell. Must be greater than 0.
sourcepub fn set_col_span(&mut self, row: u32, col: u32, span: u32)
pub fn set_col_span(&mut self, row: u32, col: u32, span: u32)
Sets the colspan of the cell. Must be greater than 0.
sourcepub fn set_matrix_row_span(&mut self, row: u32, col: u32, span: u32)
pub fn set_matrix_row_span(&mut self, row: u32, col: u32, span: u32)
Sets the rowspan of the cell. Must be greater than 0.
sourcepub fn matrix_row_span(&self, row: u32, col: u32) -> u32
pub fn matrix_row_span(&self, row: u32, col: u32) -> u32
Rowspan of the cell.
sourcepub fn set_matrix_col_span(&mut self, row: u32, col: u32, span: u32)
pub fn set_matrix_col_span(&mut self, row: u32, col: u32, span: u32)
Sets the colspan of the cell. Must be greater than 0.
sourcepub fn matrix_col_span(&self, row: u32, col: u32) -> u32
pub fn matrix_col_span(&self, row: u32, col: u32) -> u32
Colspan of the cell.
sourcepub fn set_annotation(&mut self, row: u32, col: u32, annotation: Annotation)
pub fn set_annotation(&mut self, row: u32, col: u32, annotation: Annotation)
Sets a annotation for this cell.
sourcepub fn clear_annotation(&mut self, row: u32, col: u32)
pub fn clear_annotation(&mut self, row: u32, col: u32)
Removes the annotation.
sourcepub fn annotation(&self, row: u32, col: u32) -> Option<&Annotation>
pub fn annotation(&self, row: u32, col: u32) -> Option<&Annotation>
Returns a content-validation name for this cell.
sourcepub fn annotation_mut(&mut self, row: u32, col: u32) -> Option<&mut Annotation>
pub fn annotation_mut(&mut self, row: u32, col: u32) -> Option<&mut Annotation>
Returns a content-validation name for this cell.
sourcepub fn add_draw_frame(&mut self, row: u32, col: u32, draw_frame: DrawFrame)
pub fn add_draw_frame(&mut self, row: u32, col: u32, draw_frame: DrawFrame)
Add a drawframe to a specific cell.
sourcepub fn clear_draw_frames(&mut self, row: u32, col: u32)
pub fn clear_draw_frames(&mut self, row: u32, col: u32)
Removes all drawframes.
sourcepub fn draw_frames(&self, row: u32, col: u32) -> Option<&Vec<DrawFrame>>
pub fn draw_frames(&self, row: u32, col: u32) -> Option<&Vec<DrawFrame>>
Returns the draw-frames.
sourcepub fn draw_frames_mut(
&mut self,
row: u32,
col: u32
) -> Option<&mut Vec<DrawFrame>>
pub fn draw_frames_mut( &mut self, row: u32, col: u32 ) -> Option<&mut Vec<DrawFrame>>
Returns a content-validation name for this cell.
sourcepub fn set_header_rows(&mut self, row_start: u32, row_end: u32)
pub fn set_header_rows(&mut self, row_start: u32, row_end: u32)
Defines a range of rows as header rows.
sourcepub fn clear_header_rows(&mut self)
pub fn clear_header_rows(&mut self)
Clears the header-rows definition.
sourcepub fn header_rows(&self) -> &Option<RowRange>
pub fn header_rows(&self) -> &Option<RowRange>
Returns the header rows.
sourcepub fn set_header_cols(&mut self, col_start: u32, col_end: u32)
pub fn set_header_cols(&mut self, col_start: u32, col_end: u32)
Defines a range of columns as header columns.
sourcepub fn clear_header_cols(&mut self)
pub fn clear_header_cols(&mut self)
Clears the header-columns definition.
sourcepub fn header_cols(&self) -> &Option<ColRange>
pub fn header_cols(&self) -> &Option<ColRange>
Returns the header columns.
sourcepub fn add_print_range(&mut self, range: CellRange)
pub fn add_print_range(&mut self, range: CellRange)
Print ranges.
sourcepub fn clear_print_ranges(&mut self)
pub fn clear_print_ranges(&mut self)
Remove print ranges.
sourcepub fn print_ranges(&self) -> Option<&Vec<CellRange>>
pub fn print_ranges(&self) -> Option<&Vec<CellRange>>
Return the print ranges.
sourcepub fn split_col_header(&mut self, col: u32)
pub fn split_col_header(&mut self, col: u32)
Split horizontally on a cell boundary. The splitting is fixed in position.
sourcepub fn split_row_header(&mut self, row: u32)
pub fn split_row_header(&mut self, row: u32)
Split vertically on a cell boundary. The splitting is fixed in position.
sourcepub fn split_horizontal(&mut self, col: u32)
pub fn split_horizontal(&mut self, col: u32)
Split horizontally with a pixel width. The split can be moved around. For more control look at SheetConfig.
sourcepub fn split_vertical(&mut self, col: u32)
pub fn split_vertical(&mut self, col: u32)
Split vertically with a pixel width. The split can be moved around. For more control look at SheetConfig.
sourcepub fn add_col_group(&mut self, from: u32, to: u32)
pub fn add_col_group(&mut self, from: u32, to: u32)
Add a column group.
Panic
Column groups can be contained within another, but they can’t overlap. From must be less than or equal to.
sourcepub fn remove_col_group(&mut self, from: u32, to: u32)
pub fn remove_col_group(&mut self, from: u32, to: u32)
Remove a column group.
sourcepub fn set_col_group_displayed(&mut self, from: u32, to: u32, display: bool)
pub fn set_col_group_displayed(&mut self, from: u32, to: u32, display: bool)
Change the expansion/collapse of a col group.
Does nothing if no such group exists.
sourcepub fn col_group_count(&self) -> usize
pub fn col_group_count(&self) -> usize
Count of column groups.
sourcepub fn col_group_mut(&mut self, idx: usize) -> Option<&mut Grouped>
pub fn col_group_mut(&mut self, idx: usize) -> Option<&mut Grouped>
Returns the nth column group.
sourcepub fn col_group_iter(&self) -> impl Iterator<Item = &Grouped>
pub fn col_group_iter(&self) -> impl Iterator<Item = &Grouped>
Iterate the column groups.
sourcepub fn add_row_group(&mut self, from: u32, to: u32)
pub fn add_row_group(&mut self, from: u32, to: u32)
Add a row group.
Panic
Row groups can be contained within another, but they can’t overlap. From must be less than or equal to.
sourcepub fn remove_row_group(&mut self, from: u32, to: u32)
pub fn remove_row_group(&mut self, from: u32, to: u32)
Remove a row group.
sourcepub fn set_row_group_displayed(&mut self, from: u32, to: u32, display: bool)
pub fn set_row_group_displayed(&mut self, from: u32, to: u32, display: bool)
Change the expansion/collapse of a row group.
Does nothing if no such group exists.
sourcepub fn row_group_count(&self) -> usize
pub fn row_group_count(&self) -> usize
Count of row groups.
sourcepub fn row_group_iter(&self) -> impl Iterator<Item = &Grouped>
pub fn row_group_iter(&self) -> impl Iterator<Item = &Grouped>
Iterate row groups.