pub struct Model<'a> {
pub workbook: Workbook,
pub parsed_formulas: Vec<Vec<(Node, StaticResult)>>,
/* private fields */
}Expand description
A dynamical IronCalc model.
Its is composed of a Workbook. Everything else are dynamical quantities:
- The Locale: a parsed version of the Workbook’s locale
- The Timezone: an object representing the Workbook’s timezone
- The language. Note that the timezone and the locale belong to the workbook while the language can be different for different users looking at the same 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: WorkbookA Rust internal representation of an Excel workbook
parsed_formulas: Vec<Vec<(Node, StaticResult)>>A list of parsed formulas
Implementations§
Source§impl<'a> Model<'a>
impl<'a> Model<'a>
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 duplicate_sheet(
&mut self,
source_index: u32,
) -> Result<(String, u32), String>
pub fn duplicate_sheet( &mut self, source_index: u32, ) -> Result<(String, u32), String>
Duplicates an existing sheet, placing the copy immediately after the original. Returns the new sheet’s name and index.
The new sheet is named "{original} ({n})", where n is the smallest
positive integer that makes the name unique (so Sheet1 becomes
Sheet1 (1), then Sheet1 (2), …).
All the cell data, styles, conditional formatting rules, the sheet tab color and the view state are copied. Formulas are copied too:
- references to the source sheet itself (whether implicit, like
A1, or explicit, likeSheet1!A1) are retargeted to the new sheet, and - references to other sheets are left untouched.
When copying a sheet:
- names local to the source sheet are duplicated as names local to the new sheet, and
- global names that reference the source sheet get a new sheet-local copy on the new sheet (the original global name is kept unchanged).
In both cases references to the source sheet are retargeted to the copy.
Fails if source_index is out of range.
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 out of bounds
- 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 move_sheet(
&mut self,
sheet_index: u32,
new_index: u32,
) -> Result<(), String>
pub fn move_sheet( &mut self, sheet_index: u32, new_index: u32, ) -> Result<(), String>
Moves the worksheet at sheet_index to new_index, shifting the other
sheets to accommodate. The moved worksheet ends up at exactly new_index.
Sheet order is only a position in the worksheet vector; formulas key off
the sheet name (and defined names off the sheet id), so cross-sheet
references stay valid across a move — reset_parsed_structures re-resolves
every reference by name against the reordered vector.
Fails if either index is out of range. Moving a sheet to its current position is a no-op.
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<'a> Model<'a>
impl<'a> Model<'a>
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_columns_action(
&mut self,
sheet: u32,
column: i32,
column_count: i32,
delta: i32,
) -> Result<(), String>
pub fn move_columns_action( &mut self, sheet: u32, column: i32, column_count: i32, delta: i32, ) -> Result<(), String>
Moves a group of columns [column, column+column_count-1] by delta positions. CSE array formulas fully within the moved group are preserved as arrays. 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 moves the data and column styles along with the formulas
Sourcepub fn move_rows_action(
&mut self,
sheet: u32,
row: i32,
row_count: i32,
delta: i32,
) -> Result<(), String>
pub fn move_rows_action( &mut self, sheet: u32, row: i32, row_count: i32, delta: i32, ) -> Result<(), String>
Displaces cells due to a move row action from initial_row to target_row = initial_row + row_delta References will be updated following the same rules as move_column_action NOTE: This moves the data and row styles along with the formulas Moves a group of rows [row, row+row_count-1] by delta positions. CSE array formulas fully within the moved group are preserved as arrays.
Source§impl<'a> Model<'a>
impl<'a> Model<'a>
Sourcepub fn evaluate_conditional_formatting(&mut self)
pub fn evaluate_conditional_formatting(&mut self)
Evaluates all conditional formatting rules for the workbook.
Iterates every worksheet’s CF rules in priority order (lowest priority number,
processed last). The result for each cell is stored in
cf_cache and consumed by get_extended_style_for_cell.
Sourcepub fn get_extended_style_for_cell(
&self,
sheet: u32,
row: i32,
column: i32,
) -> Result<ExtendedStyle, String>
pub fn get_extended_style_for_cell( &self, sheet: u32, row: i32, column: i32, ) -> Result<ExtendedStyle, String>
Returns the extended cell style for (sheet, row, column), including
any conditional-formatting overlay computed by the last evaluate() call.
Sourcepub fn get_conditional_formatting_list(
&self,
sheet: u32,
) -> Result<Vec<ConditionalFormattingView>, String>
pub fn get_conditional_formatting_list( &self, sheet: u32, ) -> Result<Vec<ConditionalFormattingView>, String>
Returns all CF rules for the given sheet, sorted by priority descending (highest priority first).
Each entry carries its index into the worksheet’s stored
conditional_formatting vector so callers can pass it back to the
index-based mutators (Self::get_dxf_for_conditional_formatting,
Self::update_conditional_formatting, Self::delete_conditional_formatting,
Self::raise_conditional_formatting_priority,
Self::lower_conditional_formatting_priority) without having to infer the
index from the display position.
Formulas are stored internally in English; they are translated into the active language/locale for display.
Sourcepub fn get_dxf_for_conditional_formatting(
&self,
sheet: u32,
index: usize,
) -> Result<Option<Dxf>, String>
pub fn get_dxf_for_conditional_formatting( &self, sheet: u32, index: usize, ) -> Result<Option<Dxf>, String>
Returns the differential format (Dxf) for the CF rule at index on sheet,
or None if the rule type has no dxf (e.g. ColorScale, DataBar, IconSet).
Sourcepub fn add_conditional_formatting(
&mut self,
sheet: u32,
range: &str,
rule: CfRuleInput,
) -> Result<u32, String>
pub fn add_conditional_formatting( &mut self, sheet: u32, range: &str, rule: CfRuleInput, ) -> Result<u32, String>
Adds a new CF rule to sheet, appended with priority = 1 + current max.
Returns the assigned priority.
Sourcepub fn delete_conditional_formatting(
&mut self,
sheet: u32,
index: usize,
) -> Result<ConditionalFormatting, String>
pub fn delete_conditional_formatting( &mut self, sheet: u32, index: usize, ) -> Result<ConditionalFormatting, String>
Removes the CF rule at index from sheet. Returns the removed rule.
Sourcepub fn update_conditional_formatting(
&mut self,
sheet: u32,
index: usize,
new_range: &str,
new_rule: CfRuleInput,
) -> Result<ConditionalFormatting, String>
pub fn update_conditional_formatting( &mut self, sheet: u32, index: usize, new_range: &str, new_rule: CfRuleInput, ) -> Result<ConditionalFormatting, String>
Replaces the range and rule of the CF entry at index on sheet.
The priority is preserved. Returns the previous entry.
Sourcepub fn raise_conditional_formatting_priority(
&mut self,
sheet: u32,
index: usize,
) -> Result<(), String>
pub fn raise_conditional_formatting_priority( &mut self, sheet: u32, index: usize, ) -> Result<(), String>
Raises the priority of the CF rule at index on sheet.
In IronCalc a higher priority number means higher priority. Raising a rule swaps its priority with the rule that has the next-higher priority number (the closest rule above it). If the rule is already the highest-priority one, this is a no-op.
Sourcepub fn lower_conditional_formatting_priority(
&mut self,
sheet: u32,
index: usize,
) -> Result<(), String>
pub fn lower_conditional_formatting_priority( &mut self, sheet: u32, index: usize, ) -> Result<(), String>
Lowers the priority of the CF rule at index on sheet.
In IronCalc a higher priority number means higher priority. Lowering a rule swaps its priority with the rule that has the next-lower priority number (the closest rule below it). If the rule is already the lowest-priority one, this is a no-op.
Source§impl<'a> Model<'a>
impl<'a> Model<'a>
Sourcepub fn formula_completion(
&mut self,
sheet: u32,
row: i32,
column: i32,
formula: &str,
cursor: usize,
) -> Result<CompletionContext, String>
pub fn formula_completion( &mut self, sheet: u32, row: i32, column: i32, formula: &str, cursor: usize, ) -> Result<CompletionContext, String>
Returns completion information for a formula being edited in a cell.
formula is the raw cell input (it may start with =) and cursor is a
char offset into it. The references in the formula are resolved relative
to the cell at (sheet, row, column). See
CompletionContext.
Sourcepub fn set_sheet_color(
&mut self,
sheet: u32,
color: &Color,
) -> Result<(), String>
pub fn set_sheet_color( &mut self, sheet: u32, color: &Color, ) -> Result<(), String>
Sets the color of the sheet tab.
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
assert_eq!(model.workbook.worksheet(0)?.color, Color::None);
model.set_sheet_color(0, &Color::Rgb("#DBBE29".to_string()))?;
assert_eq!(model.workbook.worksheet(0)?.color, Color::Rgb("#DBBE29".to_string()));Sourcepub fn set_sheet_state(
&mut self,
sheet: u32,
state: SheetState,
) -> Result<(), String>
pub fn set_sheet_state( &mut self, sheet: u32, state: SheetState, ) -> Result<(), String>
Changes the visibility of a sheet
Sourcepub fn set_show_grid_lines(
&mut self,
sheet: u32,
show_grid_lines: bool,
) -> Result<(), String>
pub fn set_show_grid_lines( &mut self, sheet: u32, show_grid_lines: bool, ) -> Result<(), String>
Makes the grid lines in the sheet visible (true) or hidden (false)
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 the cell is completely empty.
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
assert_eq!(model.is_empty_cell(0, 1, 1)?, true);
model.set_user_input(0, 1, 1, "Attention is all you need".to_string());
assert_eq!(model.is_empty_cell(0, 1, 1)?, false);Sourcepub fn from_bytes(s: &[u8], language_id: &'a str) -> Result<Model<'a>, String>
pub fn from_bytes(s: &[u8], language_id: &'a str) -> Result<Model<'a>, String>
Returns a model from an internal binary representation of a workbook
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
model.set_user_input(0, 1, 1, "Stella!".to_string());
let model2 = Model::from_bytes(&model.to_bytes(), "en")?;
assert_eq!(
model2.get_cell_value_by_index(0, 1, 1),
Ok(CellValue::String("Stella!".to_string()))
);See also:
Sourcepub fn from_workbook(
workbook: Workbook,
language_id: &str,
) -> Result<Model<'_>, String>
pub fn from_workbook( workbook: Workbook, language_id: &str, ) -> Result<Model<'_>, String>
Returns a model from a Workbook object
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
model.set_user_input(0, 1, 1, "Stella!".to_string());
let model2 = Model::from_workbook(model.workbook, "en")?;
assert_eq!(
model2.get_cell_value_by_index(0, 1, 1),
Ok(CellValue::String("Stella!".to_string()))
);Sourcepub fn parse_reference(&self, s: &str) -> Option<CellReferenceIndex>
pub fn parse_reference(&self, s: &str) -> Option<CellReferenceIndex>
Parses a reference like “Sheet1!B4” into {0, 2, 4}
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
model.set_user_input(0, 1, 1, "Stella!".to_string());
let reference = model.parse_reference("Sheet1!D40");
assert_eq!(reference, Some(CellReferenceIndex {sheet: 0, row: 40, column: 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 formula value from source (in area) to target.
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let source = CellReferenceIndex { sheet: 0, row: 3, column: 1};
let target = CellReferenceIndex { sheet: 0, row: 50, column: 1};
let area = Area { sheet: 0, row: 1, column: 1, width: 5, height: 4};
let result = model.move_cell_value_to_area("=B1", &source, &target, &area)?;
assert_eq!(&result, "=B48");See also:
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) in the same sheet
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let (sheet, row, column) = (0, 1, 1);
model.set_user_input(sheet, row, column, "=B1*D4".to_string());
let (target_row, target_column) = (30, 1);
let result = model.extend_to(sheet, row, column, target_row, target_column)?;
assert_eq!(&result, "=B30*D33");See also:
Sourcepub fn extend_copied_value(
&mut self,
value: &str,
source: &CellReferenceIndex,
target: &CellReferenceIndex,
) -> Result<String, String>
pub fn extend_copied_value( &mut self, value: &str, source: &CellReferenceIndex, target: &CellReferenceIndex, ) -> Result<String, String>
‘Extends’ the formula value from source to target
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let source = CellReferenceIndex {sheet: 0, row: 1, column: 1};
let target = CellReferenceIndex {sheet: 0, row: 30, column: 1};
let result = model.extend_copied_value("=B1*D4", &source, &target)?;
assert_eq!(&result, "=B30*D33");See also:
Sourcepub fn get_cell_formula(
&self,
sheet: u32,
row: i32,
column: i32,
) -> Result<Option<String>, String>
pub fn get_cell_formula( &self, sheet: u32, row: i32, column: i32, ) -> Result<Option<String>, String>
Returns the formula in (sheet, row, column) if any
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let (sheet, row, column) = (0, 1, 1);
model.set_user_input(sheet, row, column, "=SIN(B1*C3)+1".to_string());
model.evaluate();
let result = model.get_cell_formula(sheet, row, column)?;
assert_eq!(result, Some("=SIN(B1*C3)+1".to_string()));See also:
Sourcepub fn update_cell_with_text(
&mut self,
sheet: u32,
row: i32,
column: i32,
value: &str,
) -> Result<(), String>
pub fn update_cell_with_text( &mut self, sheet: u32, row: i32, column: i32, value: &str, ) -> Result<(), String>
Updates the value of a cell with some text It does not change the style unless needs to add “quoting”
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let (sheet, row, column) = (0, 1, 1);
model.set_user_input(sheet, row, column, "Hello!".to_string())?;
assert_eq!(model.get_localized_cell_content(sheet, row, column)?, "Hello!".to_string());
model.update_cell_with_text(sheet, row, column, "Goodbye!")?;
assert_eq!(model.get_localized_cell_content(sheet, row, column)?, "Goodbye!".to_string());See also:
Sourcepub fn update_cell_with_bool(
&mut self,
sheet: u32,
row: i32,
column: i32,
value: bool,
) -> Result<(), String>
pub fn update_cell_with_bool( &mut self, sheet: u32, row: i32, column: i32, value: bool, ) -> Result<(), String>
Updates the value of a cell with a boolean value It does not change the style
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let (sheet, row, column) = (0, 1, 1);
model.set_user_input(sheet, row, column, "TRUE".to_string())?;
assert_eq!(model.get_localized_cell_content(sheet, row, column)?, "TRUE".to_string());
model.update_cell_with_bool(sheet, row, column, false)?;
assert_eq!(model.get_localized_cell_content(sheet, row, column)?, "FALSE".to_string());See also:
Sourcepub fn update_cell_with_number(
&mut self,
sheet: u32,
row: i32,
column: i32,
value: f64,
) -> Result<(), String>
pub fn update_cell_with_number( &mut self, sheet: u32, row: i32, column: i32, value: f64, ) -> Result<(), String>
Updates the value of a cell with a number It does not change the style
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let (sheet, row, column) = (0, 1, 1);
model.set_user_input(sheet, row, column, "42".to_string())?;
assert_eq!(model.get_localized_cell_content(sheet, row, column)?, "42".to_string());
model.update_cell_with_number(sheet, row, column, 23.0)?;
assert_eq!(model.get_localized_cell_content(sheet, row, column)?, "23".to_string());See also:
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 “=”
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let (sheet, row, column) = (0, 1, 1);
model.set_user_input(sheet, row, column, "=A2*2".to_string())?;
model.evaluate();
assert_eq!(model.get_localized_cell_content(sheet, row, column)?, "=A2*2".to_string());
model.update_cell_with_formula(sheet, row, column, "=A3*2".to_string())?;
model.evaluate();
assert_eq!(model.get_localized_cell_content(sheet, row, column)?, "=A3*2".to_string());See also:
Sourcepub fn set_user_input(
&mut self,
sheet: u32,
row: i32,
column: i32,
value: String,
) -> Result<(), String>
pub fn set_user_input( &mut self, sheet: u32, row: i32, column: i32, value: String, ) -> Result<(), 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
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
model.set_user_input(0, 1, 1, "100$".to_string());
model.set_user_input(0, 2, 1, "125$".to_string());
model.set_user_input(0, 3, 1, "-10$".to_string());
model.set_user_input(0, 1, 2, "=SUM(A:A)".to_string());
model.evaluate();
assert_eq!(model.get_cell_value_by_index(0, 1, 2), Ok(CellValue::Number(215.0)));
assert_eq!(model.get_formatted_cell_value(0, 1, 2), Ok("215$".to_string()));See also:
Sourcepub fn set_user_array_formula(
&mut self,
sheet: u32,
row: i32,
column: i32,
width: i32,
height: i32,
value: &str,
) -> Result<(), String>
pub fn set_user_array_formula( &mut self, sheet: u32, row: i32, column: i32, width: i32, height: i32, value: &str, ) -> Result<(), String>
Sets an array formula in an area (CSE formula)
Sourcepub fn get_defined_name_list(&self) -> Vec<(String, Option<u32>, String)>
pub fn get_defined_name_list(&self) -> Vec<(String, Option<u32>, String)>
Returns the list of defined names as (name, scope, formula).
Formulas are stored internally in English; they are translated into the active language/locale for display.
Sourcepub fn get_cell_value_by_index(
&self,
sheet_index: u32,
row: i32,
column: i32,
) -> Result<CellValue, String>
pub fn get_cell_value_by_index( &self, sheet_index: u32, row: i32, column: i32, ) -> Result<CellValue, String>
Sourcepub fn get_formatted_cell_value(
&self,
sheet_index: u32,
row: i32,
column: i32,
) -> Result<String, String>
pub fn get_formatted_cell_value( &self, sheet_index: u32, row: i32, column: i32, ) -> Result<String, String>
Returns the formatted cell value for (sheet, row, column)
See also:
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let (sheet, row, column) = (0, 1, 1);
model.set_user_input(sheet, row, column, "=1/3".to_string());
model.evaluate();
let result = model.get_formatted_cell_value(sheet, row, column)?;
assert_eq!(result, "0.333333333".to_string());Sourcepub fn get_cell_type(
&self,
sheet: u32,
row: i32,
column: i32,
) -> Result<CellType, String>
pub fn get_cell_type( &self, sheet: u32, row: i32, column: i32, ) -> Result<CellType, String>
Return the typeof a cell
Sourcepub fn get_localized_cell_content(
&self,
sheet: u32,
row: i32,
column: i32,
) -> Result<String, String>
pub fn get_localized_cell_content( &self, sheet: u32, row: i32, column: i32, ) -> Result<String, String>
Returns a string with the cell content in the given language and locale. If there is a formula returns the formula If the cell is empty returns the empty string Returns an error if there is no worksheet If the cell has quote prefix style it adds a ’ at the beginning of the value If the cell is date formatted it tries to format it as date
Sourcepub fn get_all_cells(&self) -> Vec<CellIndex>
pub fn get_all_cells(&self) -> Vec<CellIndex>
Returns a list of all cells
Sourcepub fn evaluate(&mut self)
pub fn evaluate(&mut self)
Evaluates the model using a two-phase algorithm that correctly handles dynamic arrays.
Phase 1 evaluates all spill-capable cells first (in dependency order), so their spill areas are populated before any other cell reads from them. When a spill cell writes into a position that an earlier spill cell depends on, the two cells are reordered and the phase restarts. A restart bound of N*N prevents infinite loops caused by circular dependencies between spill cells.
Phase 2 evaluates every remaining cell in natural order. Because all spill areas have already been written, regular cells always read the correct spill values.
Sourcepub fn range_clear_contents(&mut self, range: &Area) -> Result<(), String>
pub fn range_clear_contents(&mut self, range: &Area) -> Result<(), String>
Removes the content of every cell in the range but leaves the style.
See also:
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let (sheet, row, column) = (0, 1, 1);
model.set_user_input(sheet, row, column, "100$".to_string());
let area = Area {
sheet,
row,
column,
width: 1,
height: 1,
};
model.range_clear_contents(&area)?;
model.set_user_input(sheet, row, column, "10".to_string());
let result = model.get_formatted_cell_value(sheet, row, column)?;
assert_eq!(result, "10$".to_string());Sourcepub fn range_clear_all(&mut self, area: &Area) -> Result<(), String>
pub fn range_clear_all(&mut self, area: &Area) -> Result<(), String>
Deletes a range by removing it from worksheet data. All content and style is removed. It fails if it deletes part of an array formula. Deletes the whole spill if it is part of a dynamic array formula.
See also:
§Examples
let mut model = Model::new_empty("model", "en", "UTC", "en")?;
let (sheet, row, column) = (0, 1, 1);
model.set_user_input(sheet, row, column, "100$".to_string());
let area = Area {
sheet,
row,
column,
width: 1,
height: 1,
};
model.range_clear_all(&area)?;
model.set_user_input(sheet, row, column, "10".to_string());
let result = model.get_formatted_cell_value(sheet, row, column)?;
assert_eq!(result, "10".to_string());Sourcepub fn get_cell_style_index(
&self,
sheet: u32,
row: i32,
column: i32,
) -> Result<i32, String>
pub fn get_cell_style_index( &self, sheet: u32, row: i32, column: i32, ) -> Result<i32, String>
Returns the style index for cell (sheet, row, column)
Sourcepub fn get_style_for_cell(
&self,
sheet: u32,
row: i32,
column: i32,
) -> Result<Style, String>
pub fn get_style_for_cell( &self, sheet: u32, row: i32, column: i32, ) -> Result<Style, String>
Returns the style for cell (sheet, row, column)
If the cell does not have a style defined we check the row, otherwise the column and finally a default
Sourcepub fn get_cell_style_or_none(
&self,
sheet: u32,
row: i32,
column: i32,
) -> Result<Option<Style>, String>
pub fn get_cell_style_or_none( &self, sheet: u32, row: i32, column: i32, ) -> Result<Option<Style>, String>
Returns the style defined in a cell if any.
Sourcepub fn get_worksheets_properties(&self) -> Vec<SheetProperties>
pub fn get_worksheets_properties(&self) -> Vec<SheetProperties>
Returns data about the worksheets
Sourcepub fn get_sheet_markup(&self, sheet: u32) -> Result<String, String>
pub fn get_sheet_markup(&self, sheet: u32) -> Result<String, String>
Returns markup representation of the given sheet.
Sourcepub fn get_frozen_rows_count(&self, sheet: u32) -> Result<i32, String>
pub fn get_frozen_rows_count(&self, sheet: u32) -> Result<i32, String>
Returns the number of frozen rows in sheet
Sourcepub fn get_frozen_columns_count(&self, sheet: u32) -> Result<i32, String>
pub fn get_frozen_columns_count(&self, sheet: u32) -> Result<i32, String>
Return the number of frozen columns in sheet
Sourcepub fn set_frozen_rows(
&mut self,
sheet: u32,
frozen_rows: i32,
) -> Result<(), String>
pub fn set_frozen_rows( &mut self, sheet: u32, frozen_rows: i32, ) -> Result<(), String>
Sets the number of frozen rows to frozen_rows in the workbook.
Fails if frozen_rows is either too small (<0) or too large (>LAST_ROW)
Sourcepub fn set_frozen_columns(
&mut self,
sheet: u32,
frozen_columns: i32,
) -> Result<(), String>
pub fn set_frozen_columns( &mut self, sheet: u32, frozen_columns: i32, ) -> Result<(), String>
Sets the number of frozen columns to frozen_column in the workbook.
Fails if frozen_columns is either too small (<0) or too large (>LAST_COLUMN)
Sourcepub fn get_column_width(&self, sheet: u32, column: i32) -> Result<f64, String>
pub fn get_column_width(&self, sheet: u32, column: i32) -> Result<f64, String>
Returns the width of a column
Sourcepub fn set_column_width(
&mut self,
sheet: u32,
column: i32,
width: f64,
) -> Result<(), String>
pub fn set_column_width( &mut self, sheet: u32, column: i32, width: f64, ) -> Result<(), String>
Sets the width of a column
Sets whether a column is hidden
Sets whether a row is hidden
Returns whether a column is hidden
Returns whether a row is hidden
Sourcepub fn get_row_height(&self, sheet: u32, row: i32) -> Result<f64, String>
pub fn get_row_height(&self, sheet: u32, row: i32) -> Result<f64, String>
Returns the height of a row
Sourcepub fn set_row_height(
&mut self,
sheet: u32,
column: i32,
height: f64,
) -> Result<(), String>
pub fn set_row_height( &mut self, sheet: u32, column: i32, height: f64, ) -> Result<(), String>
Sets the height of a row
Sourcepub fn new_defined_name(
&mut self,
name: &str,
scope: Option<u32>,
formula: &str,
) -> Result<(), String>
pub fn new_defined_name( &mut self, name: &str, scope: Option<u32>, formula: &str, ) -> Result<(), String>
Adds a new defined name. If scope is None it is a global defined name, otherwise it is local to the sheet with index scope.
Sourcepub fn is_valid_defined_name(
&mut self,
name: &str,
scope: Option<u32>,
formula: &str,
) -> Result<Option<u32>, String>
pub fn is_valid_defined_name( &mut self, name: &str, scope: Option<u32>, formula: &str, ) -> Result<Option<u32>, String>
Validates if a defined name can be created
Sourcepub fn delete_defined_name(
&mut self,
name: &str,
scope: Option<u32>,
) -> Result<(), String>
pub fn delete_defined_name( &mut self, name: &str, scope: Option<u32>, ) -> Result<(), String>
Delete defined name of name and scope
Sourcepub fn update_defined_name(
&mut self,
name: &str,
scope: Option<u32>,
new_name: &str,
new_scope: Option<u32>,
new_formula: &str,
) -> Result<(), String>
pub fn update_defined_name( &mut self, name: &str, scope: Option<u32>, new_name: &str, new_scope: Option<u32>, new_formula: &str, ) -> Result<(), String>
Update defined name
Sourcepub fn get_column_style(
&self,
sheet: u32,
column: i32,
) -> Result<Option<Style>, String>
pub fn get_column_style( &self, sheet: u32, column: i32, ) -> Result<Option<Style>, String>
Returns the style object of a column, if any
Sourcepub fn get_row_style(
&self,
sheet: u32,
row: i32,
) -> Result<Option<Style>, String>
pub fn get_row_style( &self, sheet: u32, row: i32, ) -> Result<Option<Style>, String>
Returns the style object of a row, if any
Sourcepub fn set_column_style(
&mut self,
sheet: u32,
column: i32,
style: &Style,
) -> Result<(), String>
pub fn set_column_style( &mut self, sheet: u32, column: i32, style: &Style, ) -> Result<(), String>
Sets a column with style
Sourcepub fn set_row_style(
&mut self,
sheet: u32,
row: i32,
style: &Style,
) -> Result<(), String>
pub fn set_row_style( &mut self, sheet: u32, row: i32, style: &Style, ) -> Result<(), String>
Sets a row with style
Sourcepub fn delete_column_style(
&mut self,
sheet: u32,
column: i32,
) -> Result<(), String>
pub fn delete_column_style( &mut self, sheet: u32, column: i32, ) -> Result<(), String>
Deletes the style of a column if the is any
Sourcepub fn delete_row_style(&mut self, sheet: u32, row: i32) -> Result<(), String>
pub fn delete_row_style(&mut self, sheet: u32, row: i32) -> Result<(), String>
Deletes the style of a row if there is any
Sourcepub fn set_locale(&mut self, locale_id: &str) -> Result<(), String>
pub fn set_locale(&mut self, locale_id: &str) -> Result<(), String>
Sets the locale of the model
Sourcepub fn set_timezone(&mut self, timezone: &str) -> Result<(), String>
pub fn set_timezone(&mut self, timezone: &str) -> Result<(), String>
Sets the timezone of the model
Sourcepub fn get_language(&self) -> String
pub fn get_language(&self) -> String
Gets the current language
Sourcepub fn get_timezone(&self) -> String
pub fn get_timezone(&self) -> String
Gets the timezone of the model
Sourcepub fn get_locale(&self) -> String
pub fn get_locale(&self) -> String
Gets the locale of the model
Sourcepub fn get_fmt_settings(&self) -> FmtSettings
pub fn get_fmt_settings(&self) -> FmtSettings
Gets the formatting settings based on the locale
Sourcepub fn cycle_reference(
&self,
value: &str,
start: usize,
end: usize,
) -> Result<(String, i32, i32), String>
pub fn cycle_reference( &self, value: &str, start: usize, end: usize, ) -> Result<(String, i32, i32), String>
Cycles the references touched by the cursor through the four absolute/relative states, Excel F4 style: A1 -> $A$1 -> A$1 -> $A1 -> A1. Returns the new text together with the new cursor start and end.
Given cycle_reference(“=A1”, 3, 3) returns (“=$A$1”, 5, 5)
Source§impl<'a> Model<'a>
impl<'a> Model<'a>
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>
Applies the named style “style_name” to the cell. Only the categories the style includes are stamped; the rest of the cell’s formatting is kept as local overrides.
pub fn set_sheet_style( &mut self, sheet: u32, style_name: &str, ) -> Result<(), String>
pub fn set_sheet_row_style( &mut self, sheet: u32, row: i32, style_name: &str, ) -> Result<(), String>
pub fn set_sheet_column_style( &mut self, sheet: u32, column: i32, style_name: &str, ) -> Result<(), String>
Sourcepub fn get_named_style_list(&self) -> Vec<String>
pub fn get_named_style_list(&self) -> Vec<String>
Returns the list of all named style names.
Sourcepub fn get_named_style(&self, name: &str) -> Result<Style, String>
pub fn get_named_style(&self, name: &str) -> Result<Style, String>
Returns the Style associated with the named style.
Sourcepub fn get_named_style_includes(
&self,
name: &str,
) -> Result<StyleIncludes, String>
pub fn get_named_style_includes( &self, name: &str, ) -> Result<StyleIncludes, String>
Returns which formatting categories the named style includes.
Sourcepub fn create_named_style(
&mut self,
name: &str,
style: &Style,
includes: StyleIncludes,
) -> Result<(), String>
pub fn create_named_style( &mut self, name: &str, style: &Style, includes: StyleIncludes, ) -> Result<(), String>
Creates a new named style. Fails if a style with that name already exists.
Sourcepub fn delete_named_style(&mut self, name: &str) -> Result<(), String>
pub fn delete_named_style(&mut self, name: &str) -> Result<(), String>
Deletes a named style. Fails if the style does not exist or is built-in. Cells that used this style keep their formatting; only the name association is removed.
Sourcepub fn update_named_style(
&mut self,
name: &str,
new_name: &str,
style: &Style,
includes: StyleIncludes,
) -> Result<(), String>
pub fn update_named_style( &mut self, name: &str, new_name: &str, style: &Style, includes: StyleIncludes, ) -> Result<(), String>
Updates the formatting and optionally the name of a named style.
The style’s xf_id never changes:
- The style’s
cell_style_xfsrecord is rewritten in place. - The new components are propagated to every
cell_xfsentry parented to the style, except those a cell overrides locally (itsapply_*flags).
Cells keep their style index, so they pick up the new formatting without
being touched. style.quote_prefix is ignored: a quote prefix belongs
to a cell’s content, not to a named style, and is never propagated.
includes replaces the style’s category set (the record’s apply*
flags). It governs exporting and future applications of the style;
dependent cells keep their own apply_* ownership flags, so changing
the includes never rewrites which components a cell owns.