pub struct SpreadsheetState { /* private fields */ }Expand description
A workbook with its selection and undo history, shared between a Spreadsheet and the
application. Clones share the same workbook.
Every change goes through the engine’s commands (see Self::execute), which is how the
toolbar, the keyboard and the application change it alike.
use ravenrs_spreadsheet::SpreadsheetState;
let sheet = SpreadsheetState::new();
sheet.set_cell("A1", "2").unwrap();
sheet.set_cell("A2", "=A1*21").unwrap();
assert_eq!(sheet.cell_text("A2"), "42");Implementations§
Source§impl SpreadsheetState
impl SpreadsheetState
Sourcepub fn open(name: &str, bytes: &[u8]) -> Result<Self, String>
pub fn open(name: &str, bytes: &[u8]) -> Result<Self, String>
Opens a workbook from the bytes of a file: .xlsx, .xlsm, .xls, .ods, .csv or
.tsv, told apart by name’s extension and by the content.
Sourcepub fn replace(&self, name: &str, bytes: &[u8]) -> Result<(), String>
pub fn replace(&self, name: &str, bytes: &[u8]) -> Result<(), String>
Replaces the workbook with the one in a file’s bytes, as Self::open reads them.
Undo starts over.
Sourcepub fn execute(&self, command: &str, params: Json) -> Result<Json, String>
pub fn execute(&self, command: &str, params: Json) -> Result<Json, String>
Runs one of the engine’s commands, such as cell.set, home.bold or edit.undo,
with its parameters, and gives what it answered. A refused command changes nothing and
its reason shows under the formula bar.
Sourcepub fn set_cell(&self, cell: &str, input: &str) -> Result<(), String>
pub fn set_cell(&self, cell: &str, input: &str) -> Result<(), String>
Types input into a cell given as A1: a number, text, a date or a =formula, read as
a person typing it would be.
Sourcepub fn cell_text(&self, cell: &str) -> String
pub fn cell_text(&self, cell: &str) -> String
What a cell given as A1 shows on the active sheet, with its number format applied.
Sourcepub fn cell_input(&self, cell: &str) -> String
pub fn cell_input(&self, cell: &str) -> String
What editing a cell given as A1 starts from: its formula, or the value as typed.
Sourcepub fn active_cell(&self) -> String
pub fn active_cell(&self) -> String
The active cell, as A1.
Sourcepub fn select(&self, range: &str) -> Result<(), String>
pub fn select(&self, range: &str) -> Result<(), String>
Selects a cell or a range given as A1 or A1:C3.
Sourcepub fn sheet_names(&self) -> Vec<String>
pub fn sheet_names(&self) -> Vec<String>
The names of the sheets, in order.
Sourcepub fn active_sheet(&self) -> usize
pub fn active_sheet(&self) -> usize
The position of the sheet being shown.
Sourcepub fn set_file_name(&self, name: &str)
pub fn set_file_name(&self, name: &str)
Changes the name Save offers; .xlsx is added when missing.
Sourcepub fn read<R>(&self, f: impl FnOnce(&Workbook) -> R) -> R
pub fn read<R>(&self, f: impl FnOnce(&Workbook) -> R) -> R
Reads the workbook, for anything the methods here do not cover.
Sourcepub fn version(&self) -> u64
pub fn version(&self) -> u64
Goes up after every change: reading it in a view rebuilds that view on the next one.
Sourcepub fn with_session<R>(&self, f: impl FnOnce(&mut Session) -> R) -> R
pub fn with_session<R>(&self, f: impl FnOnce(&mut Session) -> R) -> R
Runs f with the engine’s session, for commands with replies or state not covered here.
Views showing the workbook rebuild afterwards.
Trait Implementations§
Source§impl Clone for SpreadsheetState
impl Clone for SpreadsheetState
Source§fn clone(&self) -> SpreadsheetState
fn clone(&self) -> SpreadsheetState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more