Skip to main content

Workbook

Struct Workbook 

Source
pub struct Workbook {
Show 24 fields pub sheets: Vec<Arc<Sheet>>, pub names: Vec<DefinedName>, pub styles: StyleTable, pub theme: Theme, pub date_system: DateSystem, pub calc: CalcSettings, pub show_objects: ShowObjects, pub remove_personal_info: bool, pub active_sheet: ActiveSheet, pub view: WorkbookView, pub props: DocProps, pub protected_structure: bool, pub structure_password: Option<PasswordHash>, pub custom_lists: Vec<Vec<String>>, pub cell_styles: Vec<(String, Style)>, pub phonetics: Vec<PhoneticString>, pub vba_project: Option<Arc<Vec<u8>>>, pub csv_delimiter: Option<u8>, pub macros: Macros, pub macros_read: Vec<Value>, pub macros_unread: Arc<Vec<Value>>, pub preserved: Option<Arc<Preserved>>, pub source_dir: Option<PathBuf>, pub source_path: Option<PathBuf>,
}

Fields§

§sheets: Vec<Arc<Sheet>>§names: Vec<DefinedName>§styles: StyleTable§theme: Theme§date_system: DateSystem§calc: CalcSettings§show_objects: ShowObjects§remove_personal_info: bool

Trust Center › Privacy Options › “Remove personal information from file properties on save” (<workbookPr filterPrivacy="1"/>): kept with the file, and while it is on the author and company are left out of the XLSX files GridCraft writes, as Excel leaves them empty. Other formats aren’t filtered: the workbook’s own serialization still holds them.

§active_sheet: ActiveSheet§view: WorkbookView

The workbook window’s display settings (<workbookView>), kept across an open + save.

§props: DocProps§protected_structure: bool

Workbook structure protection.

§structure_password: Option<PasswordHash>

Password of the structure protection (XLSX workbookProtection), never the password.

§custom_lists: Vec<Vec<String>>

Custom fill lists (Options › Custom Lists) beyond the built-in ones.

§cell_styles: Vec<(String, Style)>

Named cell styles (Cell Styles gallery): name → style.

§phonetics: Vec<PhoneticString>

Phonetic (furigana) data of shared strings (xl/sharedStrings.xml), one entry per string text, so that an open + save keeps a Japanese workbook’s readings. Written back next to the <si> holding the same text.

Keyed by text because that is all a cell keeps of its shared string: the saved table holds each text once (the format’s uniqueCount), so two <si> items that share a base text can only keep one reading — the reader keeps the first and warns. Empty for workbooks without phonetic data; not present in older JSON. Modelled data (unlike Workbook::preserved, which holds unmodelled parts), so it is saved to JSON as well as to XLSX.

§vba_project: Option<Arc<Vec<u8>>>

VBA project (xl/vbaProject.bin) carried through unchanged. GridCraft does not run macros; the blob is preserved so that saving a macro-enabled workbook never destroys the macros it arrived with. base64 in JSON. None = the workbook has no macros. Shared, so a copy of the workbook (every edit’s undo step) doesn’t copy it.

§csv_delimiter: Option<u8>

Field separator of the CSV this workbook was read from, so saving it as CSV writes the same separator back (a ; file stays a ; file). None = not read from CSV: CSV saves use ,.

§macros: Macros

GridCraft macros (typed command lists, not VBA), in the order the macro list shows them. The JSON format keeps them as this field; xlsx keeps them in hidden defined names.

§macros_read: Vec<Value>

The macros entries of a JSON file as read, before the engine checks each one on its own and moves it into macros, so one damaged or newer macro doesn’t stop the file opening. Never written.

§macros_unread: Arc<Vec<Value>>

Macros in a newer format than this build reads, as the file held them. They are never read, listed or run; a save writes them back unchanged, so the newer build gets them back whole. Shared between snapshots, as nothing changes them.

§preserved: Option<Arc<Preserved>>

Unmodelled file content kept for saving (package root and workbook level). Not in JSON.

§source_dir: Option<PathBuf>

The folder the workbook was read from, which relative paths to linked workbooks in preserved are relative to. Saving into another folder rewrites them from there. Not in JSON.

§source_path: Option<PathBuf>

The file this workbook reports as its own, which is what CELL("filename") returns. None = no file yet, which Excel reports as an empty string until the workbook has been saved once. Deliberately separate from source_dir: that one names the folder relative links are relative to and must keep naming it after a Save As into another folder, since the links in memory are still written for the old one. Not in JSON.

Implementations§

Source§

impl Workbook

Source

pub fn new() -> Workbook

A new workbook with one sheet, “Sheet1”.

Source

pub fn sheet(&self, i: usize) -> Option<&Sheet>

Source

pub fn sheet_mut(&mut self, i: usize) -> Option<&mut Sheet>

Source

pub fn sheet_index(&self, name: &str) -> Option<usize>

Source

pub fn active_sheet(&self) -> usize

The index of the sheet the workbook’s window shows (the file’s active tab).

Source

pub fn set_active_sheet(&self, i: usize)

Changes the active sheet in place, also through a shared Arc<Workbook>: it is view state, so switching sheets or windows neither copies the workbook nor makes it a new version.

Source

pub fn active(&self) -> Option<&Sheet>

Source

pub fn next_sheet_name(&self) -> String

A fresh sheet name SheetN not in use.

Source

pub fn check_sheet_name( &self, name: &str, except: Option<usize>, ) -> Result<(), String>

Validates a sheet name like Excel: 1–31 chars, none of : \ / ? * [ ], not starting or ending with ', unique (case-insensitive) unless it is except’s own name.

Source

pub fn name(&self, name: &str, sheet: usize) -> Option<&DefinedName>

Finds a defined name visible from sheet: sheet scope first, then workbook scope.

Source

pub fn name_call_case(&self, e: Expr) -> Expr

Spells calls of LAMBDA names the way the names are defined (Double(4), where the parser gives DOUBLE(4): it upper-cases function names, as built-in ones are shown).

Source

pub fn apply_name_call_case(&mut self)

Workbook::name_call_case for every cell formula and defined name (after reading a file).

Source

pub fn table(&self, name: &str) -> Option<(usize, usize)>

Table by name across sheets: (sheet index, table index).

Source

pub fn refresh_equations(&mut self)

Rebuilds the cached layout of every equation whose source changed (or was never laid out, as after loading a file). One call lays out at most MAX_EQUATION_LAYOUT_BYTES of source: one equation can take a tenth of a second to lay out, so a file with thousands of them would otherwise hold the app for minutes. Equations past the budget get an error instead (they show their source; editing one lays it out).

Source

pub fn next_object_id(&self) -> u32

A free id for a new chart, picture, shape, table, slicer or form control: one more than the largest in use, or, when that is u32::MAX (a file can carry any id), the lowest free one.

Source

pub fn free_object_ids(&self, count: usize) -> Vec<u32>

count distinct ids no object in the workbook uses, sorted: the ones above the largest id in use while they last, then the lowest free ones. Fewer come back only when the id space is exhausted.

Trait Implementations§

Source§

impl Clone for Workbook

Source§

fn clone(&self) -> Workbook

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 Workbook

Source§

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

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

impl Default for Workbook

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Workbook

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Workbook

Source§

fn eq(&self, other: &Workbook) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Workbook

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Workbook

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.