Skip to main content

SpreadsheetState

Struct SpreadsheetState 

Source
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

Source

pub fn new() -> Self

A new, empty workbook with one sheet.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn cell_text(&self, cell: &str) -> String

What a cell given as A1 shows on the active sheet, with its number format applied.

Source

pub fn cell_input(&self, cell: &str) -> String

What editing a cell given as A1 starts from: its formula, or the value as typed.

Source

pub fn active_cell(&self) -> String

The active cell, as A1.

Source

pub fn selection(&self) -> String

The selection, as A1:B2 (areas joined by commas).

Source

pub fn select(&self, range: &str) -> Result<(), String>

Selects a cell or a range given as A1 or A1:C3.

Source

pub fn sheet_names(&self) -> Vec<String>

The names of the sheets, in order.

Source

pub fn active_sheet(&self) -> usize

The position of the sheet being shown.

Source

pub fn to_xlsx(&self) -> Result<Vec<u8>, String>

The workbook as an .xlsx file.

Source

pub fn to_csv(&self) -> Result<Vec<u8>, String>

The active sheet’s values as CSV.

Source

pub fn file_name(&self) -> String

The name Save offers, ending in .xlsx.

Source

pub fn set_file_name(&self, name: &str)

Changes the name Save offers; .xlsx is added when missing.

Source

pub fn can_undo(&self) -> bool

Whether there is something to undo.

Source

pub fn can_redo(&self) -> bool

Whether there is something to redo.

Source

pub fn read<R>(&self, f: impl FnOnce(&Workbook) -> R) -> R

Reads the workbook, for anything the methods here do not cover.

Source

pub fn version(&self) -> u64

Goes up after every change: reading it in a view rebuilds that view on the next one.

Source

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.

Source

pub fn error(&self) -> Option<String>

The latest refusal from the engine, if the last command was refused.

Trait Implementations§

Source§

impl Clone for SpreadsheetState

Source§

fn clone(&self) -> SpreadsheetState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SpreadsheetState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpreadsheetState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more