Struct ironcalc_base::model::Model
source · pub struct Model {
pub workbook: Workbook,
pub parsed_formulas: Vec<Vec<Node>>,
pub parsed_defined_names: HashMap<(Option<u32>, String), ParsedDefinedName>,
pub shared_strings: HashMap<String, usize>,
pub parser: Parser,
pub cells: HashMap<(u32, i32, i32), CellState>,
pub locale: Locale,
pub language: Language,
pub tz: Tz,
}Expand description
A model includes: * A Workbook: An internal representation of and Excel workbook * Parsed Formulas: All the formulas in the workbook are parsed here (runtime only) * A list of cells with its status (evaluating, evaluated, not evaluated) * A dictionary with the shared strings and their indices. This is an optimization for large files (~1 million rows)
Fields§
§workbook: Workbook§parsed_formulas: Vec<Vec<Node>>§parsed_defined_names: HashMap<(Option<u32>, String), ParsedDefinedName>§parser: Parser§cells: HashMap<(u32, i32, i32), CellState>§locale: Locale§language: Language§tz: TzImplementations§
source§impl Model
impl Model
pub fn set_sheet_color(&mut self, sheet: u32, color: &str) -> Result<(), String>
sourcepub fn is_empty_cell(
&self,
sheet: u32,
row: i32,
column: i32
) -> Result<bool, String>
pub fn is_empty_cell( &self, sheet: u32, row: i32, column: i32 ) -> Result<bool, String>
Returns true if cell is completely empty. Cell with formula that evaluates to empty string is not considered empty.
sourcepub fn from_json(s: &str) -> Result<Model, String>
pub fn from_json(s: &str) -> Result<Model, String>
Returns a model from a String representation of a workbook
pub fn from_workbook(workbook: Workbook) -> Result<Model, String>
sourcepub fn parse_reference(&self, s: &str) -> Option<CellReference>
pub fn parse_reference(&self, s: &str) -> Option<CellReference>
Parses a reference like “Sheet1!B4” into {0, 2, 4}
sourcepub fn move_cell_value_to_area(
&mut self,
value: &str,
source: &CellReferenceIndex,
target: &CellReferenceIndex,
area: &Area
) -> Result<String, String>
pub fn move_cell_value_to_area( &mut self, value: &str, source: &CellReferenceIndex, target: &CellReferenceIndex, area: &Area ) -> Result<String, String>
moves the value in area from source to target.
sourcepub fn extend_to(
&self,
sheet: u32,
row: i32,
column: i32,
target_row: i32,
target_column: i32
) -> Result<String, String>
pub fn extend_to( &self, sheet: u32, row: i32, column: i32, target_row: i32, target_column: i32 ) -> Result<String, String>
‘Extends’ the value from cell [sheet, row, column] to [target_row, target_column]
sourcepub fn extend_copied_value(
&mut self,
value: &str,
source_sheet_name: &str,
source: &CellReferenceIndex,
target: &CellReferenceIndex
) -> Result<String, String>
pub fn extend_copied_value( &mut self, value: &str, source_sheet_name: &str, source: &CellReferenceIndex, target: &CellReferenceIndex ) -> Result<String, String>
‘Extends’ value from cell [sheet, row, column] to [target_row, target_column]
pub fn cell_formula( &self, sheet: u32, row: i32, column: i32 ) -> Result<Option<String>, String>
sourcepub fn update_cell_with_text(
&mut self,
sheet: u32,
row: i32,
column: i32,
value: &str
)
pub fn update_cell_with_text( &mut self, sheet: u32, row: i32, column: i32, value: &str )
Updates the value of a cell with some text It does not change the style unless needs to add “quoting”
sourcepub fn update_cell_with_bool(
&mut self,
sheet: u32,
row: i32,
column: i32,
value: bool
)
pub fn update_cell_with_bool( &mut self, sheet: u32, row: i32, column: i32, value: bool )
Updates the value of a cell with a boolean value It does not change the style
sourcepub fn update_cell_with_number(
&mut self,
sheet: u32,
row: i32,
column: i32,
value: f64
)
pub fn update_cell_with_number( &mut self, sheet: u32, row: i32, column: i32, value: f64 )
Updates the value of a cell with a number It does not change the style
sourcepub fn update_cell_with_formula(
&mut self,
sheet: u32,
row: i32,
column: i32,
formula: String
) -> Result<(), String>
pub fn update_cell_with_formula( &mut self, sheet: u32, row: i32, column: i32, formula: String ) -> Result<(), String>
Updates the formula of given cell It does not change the style unless needs to add “quoting” Expects the formula to start with “=”
sourcepub fn set_user_input(
&mut self,
sheet: u32,
row: i32,
column: i32,
value: String
)
pub fn set_user_input( &mut self, sheet: u32, row: i32, column: i32, value: String )
Sets a cell parametrized by (sheet, row, column) with value
This mimics a user entering a value on a cell.
If you enter a currency $100 it will set as a number and update the style
Note that for currencies/percentage there is only one possible style
The value is always a string, so we need to try to cast it into numbers/booleans/errors
sourcepub fn get_cell_value_by_ref(&self, cell_ref: &str) -> Result<CellValue, String>
pub fn get_cell_value_by_ref(&self, cell_ref: &str) -> Result<CellValue, String>
Gets the Excel Value (Bool, Number, String) of a cell
pub fn get_cell_value_by_index( &self, sheet_index: u32, row: i32, column: i32 ) -> Result<CellValue, String>
pub fn formatted_cell_value( &self, sheet_index: u32, row: i32, column: i32 ) -> Result<String, String>
sourcepub fn get_cell_content(
&self,
sheet: u32,
row: i32,
column: i32
) -> Result<String, String>
pub fn get_cell_content( &self, sheet: u32, row: i32, column: i32 ) -> Result<String, String>
Returns a string with the cell content. If there is a formula returns the formula If the cell is empty returns the empty string Raises an error if there is no worksheet
sourcepub fn get_all_cells(&self) -> Vec<CellIndex>
pub fn get_all_cells(&self) -> Vec<CellIndex>
Returns a list of all cells
sourcepub fn set_cell_empty(
&mut self,
sheet: u32,
row: i32,
column: i32
) -> Result<(), String>
pub fn set_cell_empty( &mut self, sheet: u32, row: i32, column: i32 ) -> Result<(), String>
Sets cell to empty. Can be used to delete value without affecting style.
sourcepub fn delete_cell(
&mut self,
sheet: u32,
row: i32,
column: i32
) -> Result<(), String>
pub fn delete_cell( &mut self, sheet: u32, row: i32, column: i32 ) -> Result<(), String>
Deletes a cell by removing it from worksheet data.
pub fn get_cell_style_index(&self, sheet: u32, row: i32, column: i32) -> i32
pub fn get_style_for_cell(&self, sheet: u32, row: i32, column: i32) -> Style
sourcepub fn to_json_str(&self) -> String
pub fn to_json_str(&self) -> String
Returns a JSON string of the workbook
sourcepub fn sheet_markup(&self, sheet: u32) -> Result<String, String>
pub fn sheet_markup(&self, sheet: u32) -> Result<String, String>
Returns markup representation of the given sheet.
pub fn set_currency(&mut self, iso: &str) -> Result<(), &str>
pub fn get_frozen_rows(&self, sheet: u32) -> Result<i32, String>
pub fn get_frozen_columns(&self, sheet: u32) -> Result<i32, String>
pub fn set_frozen_rows( &mut self, sheet: u32, frozen_rows: i32 ) -> Result<(), String>
pub fn set_frozen_columns( &mut self, sheet: u32, frozen_columns: i32 ) -> Result<(), String>
source§impl Model
impl Model
pub fn get_new_sheet_id(&self) -> u32
sourcepub fn insert_sheet(
&mut self,
sheet_name: &str,
sheet_index: u32,
sheet_id: Option<u32>
) -> Result<(), String>
pub fn insert_sheet( &mut self, sheet_name: &str, sheet_index: u32, sheet_id: Option<u32> ) -> Result<(), String>
Inserts a sheet with a particular index Fails if a worksheet with that name already exists or the name is invalid Fails if the index is too large
sourcepub fn add_sheet(&mut self, sheet_name: &str) -> Result<(), String>
pub fn add_sheet(&mut self, sheet_name: &str) -> Result<(), String>
Adds a sheet with a specific name Fails if a worksheet with that name already exists or the name is invalid
sourcepub fn rename_sheet(
&mut self,
old_name: &str,
new_name: &str
) -> Result<(), String>
pub fn rename_sheet( &mut self, old_name: &str, new_name: &str ) -> Result<(), String>
Renames a sheet and updates all existing references to that sheet. It can fail if:
- The original sheet does not exists
- The target sheet already exists
- The target sheet name is invalid
sourcepub fn rename_sheet_by_index(
&mut self,
sheet_index: u32,
new_name: &str
) -> Result<(), String>
pub fn rename_sheet_by_index( &mut self, sheet_index: u32, new_name: &str ) -> Result<(), String>
Renames a sheet and updates all existing references to that sheet. It can fail if:
- The original index is too large
- The target sheet name already exists
- The target sheet name is invalid
sourcepub fn delete_sheet(&mut self, sheet_index: u32) -> Result<(), String>
pub fn delete_sheet(&mut self, sheet_index: u32) -> Result<(), String>
Deletes a sheet by index. Fails if:
- The sheet does not exists
- It is the last sheet
sourcepub fn delete_sheet_by_name(&mut self, name: &str) -> Result<(), String>
pub fn delete_sheet_by_name(&mut self, name: &str) -> Result<(), String>
Deletes a sheet by name. Fails if:
- The sheet does not exists
- It is the last sheet
source§impl Model
impl Model
sourcepub fn insert_columns(
&mut self,
sheet: u32,
column: i32,
column_count: i32
) -> Result<(), String>
pub fn insert_columns( &mut self, sheet: u32, column: i32, column_count: i32 ) -> Result<(), String>
Inserts one or more new columns into the model at the specified index.
This method shifts existing columns to the right to make space for the new columns.
Arguments
sheet- The sheet number to retrieve columns from.column- The index at which the new columns should be inserted.column_count- The number of columns to insert.
sourcepub fn delete_columns(
&mut self,
sheet: u32,
column: i32,
column_count: i32
) -> Result<(), String>
pub fn delete_columns( &mut self, sheet: u32, column: i32, column_count: i32 ) -> Result<(), String>
Deletes one or more columns from the model starting at the specified index.
Arguments
sheet- The sheet number to retrieve columns from.column- The index of the first column to delete.count- The number of columns to delete.
sourcepub fn insert_rows(
&mut self,
sheet: u32,
row: i32,
row_count: i32
) -> Result<(), String>
pub fn insert_rows( &mut self, sheet: u32, row: i32, row_count: i32 ) -> Result<(), String>
Inserts one or more new rows into the model at the specified index.
Arguments
sheet- The sheet number to retrieve columns from.row- The index at which the new rows should be inserted.row_count- The number of rows to insert.
sourcepub fn delete_rows(
&mut self,
sheet: u32,
row: i32,
row_count: i32
) -> Result<(), String>
pub fn delete_rows( &mut self, sheet: u32, row: i32, row_count: i32 ) -> Result<(), String>
Deletes one or more rows from the model starting at the specified index.
Arguments
sheet- The sheet number to retrieve columns from.row- The index of the first row to delete.row_count- The number of rows to delete.
sourcepub fn move_column_action(
&mut self,
sheet: u32,
column: i32,
delta: i32
) -> Result<(), &'static str>
pub fn move_column_action( &mut self, sheet: u32, column: i32, delta: i32 ) -> Result<(), &'static str>
Displaces cells due to a move column action from initial_column to target_column = initial_column + column_delta References will be updated following: Cell references:
- All cell references to initial_column will go to target_column
- All cell references to columns in between (initial_column, target_column] will be displaced one to the left
- All other cell references are left unchanged Ranges. This is the tricky bit:
- Column is one of the extremes of the range. The new extreme would be target_column. Range is then normalized
- Any other case, range is left unchanged. NOTE: This does NOT move the data in the columns or move the colum styles
source§impl Model
impl Model
pub fn set_cell_style( &mut self, sheet: u32, row: i32, column: i32, style: &Style ) -> Result<(), String>
pub fn copy_cell_style( &mut self, source_cell: (u32, i32, i32), destination_cell: (u32, i32, i32) ) -> Result<(), String>
sourcepub fn set_cell_style_by_name(
&mut self,
sheet: u32,
row: i32,
column: i32,
style_name: &str
) -> Result<(), String>
pub fn set_cell_style_by_name( &mut self, sheet: u32, row: i32, column: i32, style_name: &str ) -> Result<(), String>
Sets the style “style_name” in cell