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>§shared_strings: HashMap<String, usize>§parser: Parser§cells: HashMap<(u32, i32, i32), CellState>§locale: Locale§language: Language§tz: Tz

Implementations§

source§

impl Model

source

pub fn set_sheet_color(&mut self, sheet: u32, color: &str) -> Result<(), String>

source

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.

source

pub fn from_json(s: &str) -> Result<Model, String>

Returns a model from a String representation of a workbook

source

pub fn from_workbook(workbook: Workbook) -> Result<Model, String>

source

pub fn parse_reference(&self, s: &str) -> Option<CellReference>

Parses a reference like “Sheet1!B4” into {0, 2, 4}

source

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.

source

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]

source

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]

source

pub fn cell_formula( &self, sheet: u32, row: i32, column: i32 ) -> Result<Option<String>, String>

source

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”

source

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

source

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

source

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 “=”

source

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

source

pub fn get_cell_value_by_ref(&self, cell_ref: &str) -> Result<CellValue, String>

Gets the Excel Value (Bool, Number, String) of a cell

source

pub fn get_cell_value_by_index( &self, sheet_index: u32, row: i32, column: i32 ) -> Result<CellValue, String>

source

pub fn formatted_cell_value( &self, sheet_index: u32, row: i32, column: i32 ) -> Result<String, String>

source

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

source

pub fn get_all_cells(&self) -> Vec<CellIndex>

Returns a list of all cells

source

pub fn evaluate(&mut self)

Evaluates the model with a top-down recursive algorithm

source

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.

source

pub fn delete_cell( &mut self, sheet: u32, row: i32, column: i32 ) -> Result<(), String>

Deletes a cell by removing it from worksheet data.

source

pub fn get_cell_style_index(&self, sheet: u32, row: i32, column: i32) -> i32

source

pub fn get_style_for_cell(&self, sheet: u32, row: i32, column: i32) -> Style

source

pub fn to_json_str(&self) -> String

Returns a JSON string of the workbook

source

pub fn sheet_markup(&self, sheet: u32) -> Result<String, String>

Returns markup representation of the given sheet.

source

pub fn set_currency(&mut self, iso: &str) -> Result<(), &str>

source

pub fn get_frozen_rows(&self, sheet: u32) -> Result<i32, String>

source

pub fn get_frozen_columns(&self, sheet: u32) -> Result<i32, String>

source

pub fn set_frozen_rows( &mut self, sheet: u32, frozen_rows: i32 ) -> Result<(), String>

source

pub fn set_frozen_columns( &mut self, sheet: u32, frozen_columns: i32 ) -> Result<(), String>

source§

impl Model

source

pub fn get_new_sheet_id(&self) -> u32

source

pub fn new_sheet(&mut self)

Adds a sheet with a automatically generated name

source

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

source

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

source

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
source

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
source

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
source

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

pub fn delete_sheet_by_sheet_id(&mut self, sheet_id: u32) -> Result<(), String>

Deletes a sheet by sheet_id. Fails if:

  • The sheet by sheet_id does not exists
  • It is the last sheet
source

pub fn new_empty( name: &str, locale_id: &str, timezone: &str ) -> Result<Model, String>

Creates a new workbook with one empty sheet

source§

impl Model

source

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.
source

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.
source

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.
source

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.
source

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

source

pub fn set_cell_style( &mut self, sheet: u32, row: i32, column: i32, style: &Style ) -> Result<(), String>

source

pub fn copy_cell_style( &mut self, source_cell: (u32, i32, i32), destination_cell: (u32, i32, i32) ) -> Result<(), String>

source

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

source

pub fn set_sheet_style( &mut self, sheet: u32, style_name: &str ) -> Result<(), String>

source

pub fn set_sheet_row_style( &mut self, sheet: u32, row: i32, style_name: &str ) -> Result<(), String>

source

pub fn set_sheet_column_style( &mut self, sheet: u32, column: i32, style_name: &str ) -> Result<(), String>

source§

impl Model

source

pub fn forward_references( &mut self, source_area: &Area, target: &CellReferenceIndex ) -> Result<Vec<SetCellValue>, String>

Trait Implementations§

source§

impl Clone for Model

source§

fn clone(&self) -> Model

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnwindSafe for Model

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V