Skip to main content

Workbook

Struct Workbook 

Source
pub struct Workbook { /* private fields */ }
Expand description

A wrapper around an Excel workbook providing a clean API.

Implementations§

Source§

impl Workbook

Source

pub fn new() -> Self

Create a new empty workbook with one default sheet.

Source

pub fn open(path: impl AsRef<Path>) -> ExcelResult<Self>

Open a workbook from a file path.

Source

pub fn open_from_bytes(bytes: &[u8]) -> ExcelResult<Self>

Open a workbook from bytes in memory.

Source

pub fn open_from_bytes_cached(bytes: Vec<u8>) -> ExcelResult<Self>

Open a workbook from bytes, caching the bytes for fast calamine reads.

Use this on upload: the original bytes are kept so read_sheet_data_fast() can use calamine directly without re-serializing through umya.

Source

pub fn save(&self, path: impl AsRef<Path>) -> ExcelResult<()>

Save the workbook to a file path.

Source

pub fn save_to_bytes(&self) -> ExcelResult<Vec<u8>>

Serialize the workbook to bytes.

Source

pub fn info(&self) -> WorkbookInfo

Get summary info about the workbook.

Source

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

Get the names of all sheets.

Source

pub fn add_sheet(&mut self, name: &str) -> ExcelResult<()>

Add a new empty sheet with the given name.

Source

pub fn remove_sheet(&mut self, name: &str) -> ExcelResult<()>

Remove a sheet by name.

Source

pub fn rename_sheet( &mut self, old_name: &str, new_name: &str, ) -> ExcelResult<()>

Rename a sheet.

Source

pub fn get_sheet(&self, name: &str) -> ExcelResult<&Worksheet>

Get an immutable reference to a sheet by name.

Source

pub fn get_sheet_mut(&mut self, name: &str) -> ExcelResult<&mut Worksheet>

Get a mutable reference to a sheet by name.

Source

pub fn inner(&self) -> &Spreadsheet

Get a reference to the inner spreadsheet.

Source

pub fn inner_mut(&mut self) -> &mut Spreadsheet

Get a mutable reference to the inner spreadsheet.

Source

pub fn mark_dirty(&mut self)

Mark the workbook as dirty, invalidating cached bytes. Call this after any mutation (cell write, row/col insert, style change, etc.).

Source

pub fn has_cache(&self) -> bool

Whether cached bytes are available for fast reads.

Source

pub fn read_sheet_data(&self, name: &str) -> ExcelResult<RangeData>

Fast bulk read of an entire sheet’s data using calamine.

If cached bytes are available (from upload), reads directly from them with calamine (~2.4x faster). Otherwise falls back to serializing through umya first.

Source

pub fn create_from_data( sheets: Vec<(String, RangeData)>, ) -> ExcelResult<Vec<u8>>

Create a new .xlsx file from raw data using rust_xlsxwriter.

This bypasses umya-spreadsheet entirely for maximum write performance. Each tuple in the input is (sheet_name, data). Returns the .xlsx bytes.

Source

pub fn save_to_bytes_fast(&self) -> ExcelResult<Vec<u8>>

Serialize the workbook to bytes using rust_xlsxwriter for speed.

Walks the umya in-memory model and writes cell data via rust_xlsxwriter (~1.4x faster than umya’s native writer). Falls back to umya on error. Note: styles/merges/formatting may not be fully preserved — use save_to_bytes() when full fidelity is needed.

Source

pub fn read_data_from_bytes( bytes: &[u8], sheet_name: &str, ) -> ExcelResult<RangeData>

Read sheet data directly from raw .xlsx bytes using calamine only.

This is the true fast path — no umya-spreadsheet involved at all. Use this when you already have raw bytes (e.g. from an upload) and just need to extract cell data without loading into the mutable model.

Trait Implementations§

Source§

impl Default for Workbook

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