pub struct Workbook { /* private fields */ }Expand description
A wrapper around an Excel workbook providing a clean API.
Implementations§
Source§impl Workbook
impl Workbook
Sourcepub fn open(path: impl AsRef<Path>) -> ExcelResult<Self>
pub fn open(path: impl AsRef<Path>) -> ExcelResult<Self>
Open a workbook from a file path.
Sourcepub fn open_from_bytes(bytes: &[u8]) -> ExcelResult<Self>
pub fn open_from_bytes(bytes: &[u8]) -> ExcelResult<Self>
Open a workbook from bytes in memory.
Sourcepub fn open_from_bytes_cached(bytes: Vec<u8>) -> ExcelResult<Self>
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.
Sourcepub fn save(&self, path: impl AsRef<Path>) -> ExcelResult<()>
pub fn save(&self, path: impl AsRef<Path>) -> ExcelResult<()>
Save the workbook to a file path.
Sourcepub fn save_to_bytes(&self) -> ExcelResult<Vec<u8>>
pub fn save_to_bytes(&self) -> ExcelResult<Vec<u8>>
Serialize the workbook to bytes.
Sourcepub fn info(&self) -> WorkbookInfo
pub fn info(&self) -> WorkbookInfo
Get summary info about the workbook.
Sourcepub fn sheet_names(&self) -> Vec<String>
pub fn sheet_names(&self) -> Vec<String>
Get the names of all sheets.
Sourcepub fn add_sheet(&mut self, name: &str) -> ExcelResult<()>
pub fn add_sheet(&mut self, name: &str) -> ExcelResult<()>
Add a new empty sheet with the given name.
Sourcepub fn remove_sheet(&mut self, name: &str) -> ExcelResult<()>
pub fn remove_sheet(&mut self, name: &str) -> ExcelResult<()>
Remove a sheet by name.
Sourcepub fn rename_sheet(
&mut self,
old_name: &str,
new_name: &str,
) -> ExcelResult<()>
pub fn rename_sheet( &mut self, old_name: &str, new_name: &str, ) -> ExcelResult<()>
Rename a sheet.
Sourcepub fn get_sheet(&self, name: &str) -> ExcelResult<&Worksheet>
pub fn get_sheet(&self, name: &str) -> ExcelResult<&Worksheet>
Get an immutable reference to a sheet by name.
Sourcepub fn get_sheet_mut(&mut self, name: &str) -> ExcelResult<&mut Worksheet>
pub fn get_sheet_mut(&mut self, name: &str) -> ExcelResult<&mut Worksheet>
Get a mutable reference to a sheet by name.
Sourcepub fn inner(&self) -> &Spreadsheet
pub fn inner(&self) -> &Spreadsheet
Get a reference to the inner spreadsheet.
Sourcepub fn inner_mut(&mut self) -> &mut Spreadsheet
pub fn inner_mut(&mut self) -> &mut Spreadsheet
Get a mutable reference to the inner spreadsheet.
Sourcepub fn mark_dirty(&mut self)
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.).
Sourcepub fn read_sheet_data(&self, name: &str) -> ExcelResult<RangeData>
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.
Sourcepub fn create_from_data(
sheets: Vec<(String, RangeData)>,
) -> ExcelResult<Vec<u8>>
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.
Sourcepub fn save_to_bytes_fast(&self) -> ExcelResult<Vec<u8>>
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.
Sourcepub fn read_data_from_bytes(
bytes: &[u8],
sheet_name: &str,
) -> ExcelResult<RangeData>
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.