pub struct Workbook { /* private fields */ }Expand description
In-memory representation of an .xlsx workbook.
Implementations§
Source§impl Workbook
impl Workbook
Sourcepub fn get_cell_value(&self, sheet: &str, cell: &str) -> Result<CellValue>
pub fn get_cell_value(&self, sheet: &str, cell: &str) -> Result<CellValue>
Get the value of a cell.
Returns CellValue::Empty for cells that have no value or do not
exist in the sheet data.
Sourcepub fn set_cell_value(
&mut self,
sheet: &str,
cell: &str,
value: impl Into<CellValue>,
) -> Result<()>
pub fn set_cell_value( &mut self, sheet: &str, cell: &str, value: impl Into<CellValue>, ) -> Result<()>
Set the value of a cell.
The value can be any type that implements Into<CellValue>, including
&str, String, f64, i32, i64, and bool.
Setting a cell to CellValue::Empty removes the cell from the row.
Sourcepub fn get_cell_formatted_value(
&self,
sheet: &str,
cell: &str,
) -> Result<String>
pub fn get_cell_formatted_value( &self, sheet: &str, cell: &str, ) -> Result<String>
Get the formatted display text for a cell, applying its number format.
If the cell has a style with a number format, the raw numeric value is formatted according to that format code. String and boolean cells return their default display text. Empty cells return an empty string.
Sourcepub fn add_style(&mut self, style: &Style) -> Result<u32>
pub fn add_style(&mut self, style: &Style) -> Result<u32>
Register a new style and return its ID.
The style is deduplicated: if an identical style already exists in the stylesheet, the existing ID is returned.
Sourcepub fn get_cell_style(&self, sheet: &str, cell: &str) -> Result<Option<u32>>
pub fn get_cell_style(&self, sheet: &str, cell: &str) -> Result<Option<u32>>
Get the style ID applied to a cell.
Returns None if the cell does not exist or has no explicit style
(i.e. uses the default style 0).
Sourcepub fn set_cell_style(
&mut self,
sheet: &str,
cell: &str,
style_id: u32,
) -> Result<()>
pub fn set_cell_style( &mut self, sheet: &str, cell: &str, style_id: u32, ) -> Result<()>
Set the style ID for a cell.
If the cell does not exist, an empty cell with just the style is created.
The style_id must be a valid index in cellXfs.
Sourcepub fn merge_cells(
&mut self,
sheet: &str,
top_left: &str,
bottom_right: &str,
) -> Result<()>
pub fn merge_cells( &mut self, sheet: &str, top_left: &str, bottom_right: &str, ) -> Result<()>
Merge a range of cells on the given sheet.
top_left and bottom_right are cell references like “A1” and “C3”.
Returns an error if the range overlaps with an existing merge region.
Sourcepub fn unmerge_cell(&mut self, sheet: &str, reference: &str) -> Result<()>
pub fn unmerge_cell(&mut self, sheet: &str, reference: &str) -> Result<()>
Remove a merged cell range from the given sheet.
reference is the exact range string like “A1:C3”.
Sourcepub fn get_merge_cells(&self, sheet: &str) -> Result<Vec<String>>
pub fn get_merge_cells(&self, sheet: &str) -> Result<Vec<String>>
Get all merged cell ranges on the given sheet.
Returns a list of range strings like ["A1:B2", "D1:F3"].
Sourcepub fn set_cell_formula(
&mut self,
sheet: &str,
cell: &str,
formula: &str,
) -> Result<()>
pub fn set_cell_formula( &mut self, sheet: &str, cell: &str, formula: &str, ) -> Result<()>
Set a formula on a cell.
This is a convenience wrapper around [set_cell_value] with
CellValue::Formula.
Sourcepub fn fill_formula(
&mut self,
sheet: &str,
range: &str,
formula: &str,
) -> Result<()>
pub fn fill_formula( &mut self, sheet: &str, range: &str, formula: &str, ) -> Result<()>
Fill a range of cells with a formula, adjusting row references for each row relative to the first cell in the range.
range is an A1-style range like "D2:D10". The formula is the base
formula for the first cell of the range. For each subsequent row, the
row references in the formula are shifted by the row offset. Absolute
row references ($1) are left unchanged.
Sourcepub fn set_cell_rich_text(
&mut self,
sheet: &str,
cell: &str,
runs: Vec<RichTextRun>,
) -> Result<()>
pub fn set_cell_rich_text( &mut self, sheet: &str, cell: &str, runs: Vec<RichTextRun>, ) -> Result<()>
Set a cell to a rich text value (multiple formatted runs).
Sourcepub fn get_cell_rich_text(
&self,
sheet: &str,
cell: &str,
) -> Result<Option<Vec<RichTextRun>>>
pub fn get_cell_rich_text( &self, sheet: &str, cell: &str, ) -> Result<Option<Vec<RichTextRun>>>
Get rich text runs for a cell, if it contains rich text.
Returns None if the cell is empty, contains a plain string, or holds
a non-string value.
Sourcepub fn set_cell_values(
&mut self,
sheet: &str,
entries: Vec<(String, CellValue)>,
) -> Result<()>
pub fn set_cell_values( &mut self, sheet: &str, entries: Vec<(String, CellValue)>, ) -> Result<()>
Set multiple cell values at once. Each entry is a (cell_ref, value) pair.
This is more efficient than calling set_cell_value repeatedly from
FFI because it crosses the language boundary only once.
Sourcepub fn set_sheet_data(
&mut self,
sheet: &str,
data: Vec<Vec<CellValue>>,
start_row: u32,
start_col: u32,
) -> Result<()>
pub fn set_sheet_data( &mut self, sheet: &str, data: Vec<Vec<CellValue>>, start_row: u32, start_col: u32, ) -> Result<()>
Set a contiguous block of cell values from a 2D array.
data is a row-major 2D array of values. start_row and start_col
are 1-based. The first value in data[0][0] maps to the cell at
(start_col, start_row).
This is the fastest way to populate a sheet from JS because it crosses the FFI boundary only once for the entire dataset.
Source§impl Workbook
impl Workbook
Sourcepub fn add_pivot_table(&mut self, config: &PivotTableConfig) -> Result<()>
pub fn add_pivot_table(&mut self, config: &PivotTableConfig) -> Result<()>
Add a pivot table to the workbook.
The pivot table summarizes data from config.source_sheet /
config.source_range and places its output on config.target_sheet
starting at config.target_cell.
Sourcepub fn get_pivot_tables(&self) -> Vec<PivotTableInfo>
pub fn get_pivot_tables(&self) -> Vec<PivotTableInfo>
Get information about all pivot tables in the workbook.
Sourcepub fn delete_pivot_table(&mut self, name: &str) -> Result<()>
pub fn delete_pivot_table(&mut self, name: &str) -> Result<()>
Delete a pivot table by name.
Sourcepub fn add_sparkline(
&mut self,
sheet: &str,
config: &SparklineConfig,
) -> Result<()>
pub fn add_sparkline( &mut self, sheet: &str, config: &SparklineConfig, ) -> Result<()>
Add a sparkline to a worksheet.
Sourcepub fn get_sparklines(&self, sheet: &str) -> Result<Vec<SparklineConfig>>
pub fn get_sparklines(&self, sheet: &str) -> Result<Vec<SparklineConfig>>
Get all sparklines for a worksheet.
Sourcepub fn remove_sparkline(&mut self, sheet: &str, location: &str) -> Result<()>
pub fn remove_sparkline(&mut self, sheet: &str, location: &str) -> Result<()>
Remove a sparkline by its location cell reference.
Sourcepub fn evaluate_formula(&self, sheet: &str, formula: &str) -> Result<CellValue>
pub fn evaluate_formula(&self, sheet: &str, formula: &str) -> Result<CellValue>
Evaluate a single formula string in the context of sheet.
A [CellSnapshot] is built from the current workbook state so
that cell references within the formula can be resolved.
Sourcepub fn calculate_all(&mut self) -> Result<()>
pub fn calculate_all(&mut self) -> Result<()>
Recalculate every formula cell across all sheets and store the computed result back into each cell. Uses a dependency graph and topological sort so formulas are evaluated after their dependencies.
Sourcepub fn get_occupied_cells(&self, sheet: &str) -> Result<Vec<(u32, u32)>>
pub fn get_occupied_cells(&self, sheet: &str) -> Result<Vec<(u32, u32)>>
Return (col, row) pairs for all occupied cells on the named sheet.
Sourcepub fn set_doc_props(&mut self, props: DocProperties)
pub fn set_doc_props(&mut self, props: DocProperties)
Set the core document properties (title, author, etc.).
Sourcepub fn get_doc_props(&self) -> DocProperties
pub fn get_doc_props(&self) -> DocProperties
Get the core document properties.
Sourcepub fn set_app_props(&mut self, props: AppProperties)
pub fn set_app_props(&mut self, props: AppProperties)
Set the application properties (company, app version, etc.).
Sourcepub fn get_app_props(&self) -> AppProperties
pub fn get_app_props(&self) -> AppProperties
Get the application properties.
Sourcepub fn set_custom_property(&mut self, name: &str, value: CustomPropertyValue)
pub fn set_custom_property(&mut self, name: &str, value: CustomPropertyValue)
Set a custom property by name. If a property with the same name already exists, its value is replaced.
Sourcepub fn get_custom_property(&self, name: &str) -> Option<CustomPropertyValue>
pub fn get_custom_property(&self, name: &str) -> Option<CustomPropertyValue>
Get a custom property value by name, or None if it does not exist.
Sourcepub fn delete_custom_property(&mut self, name: &str) -> bool
pub fn delete_custom_property(&mut self, name: &str) -> bool
Remove a custom property by name. Returns true if a property was
found and removed.
Sourcepub fn add_slicer(&mut self, sheet: &str, config: &SlicerConfig) -> Result<()>
pub fn add_slicer(&mut self, sheet: &str, config: &SlicerConfig) -> Result<()>
Add a slicer to a sheet targeting a table column.
Creates the slicer definition, slicer cache, content type overrides, and worksheet relationships needed for Excel to render the slicer.
Sourcepub fn get_slicers(&self, sheet: &str) -> Result<Vec<SlicerInfo>>
pub fn get_slicers(&self, sheet: &str) -> Result<Vec<SlicerInfo>>
Get information about all slicers on a sheet.
Source§impl Workbook
impl Workbook
Sourcepub fn add_chart(
&mut self,
sheet: &str,
from_cell: &str,
to_cell: &str,
config: &ChartConfig,
) -> Result<()>
pub fn add_chart( &mut self, sheet: &str, from_cell: &str, to_cell: &str, config: &ChartConfig, ) -> Result<()>
Add a chart to a sheet, anchored between two cells.
The chart spans from from_cell (e.g., "B2") to to_cell
(e.g., "J15"). The config specifies the chart type, series data,
title, and legend visibility.
Sourcepub fn add_shape(&mut self, sheet: &str, config: &ShapeConfig) -> Result<()>
pub fn add_shape(&mut self, sheet: &str, config: &ShapeConfig) -> Result<()>
Add a shape to a sheet, anchored between two cells.
The shape spans from config.from_cell to config.to_cell. Unlike
charts and images, shapes do not reference external parts and therefore
do not need a relationship entry.
Sourcepub fn add_image(&mut self, sheet: &str, config: &ImageConfig) -> Result<()>
pub fn add_image(&mut self, sheet: &str, config: &ImageConfig) -> Result<()>
Add an image to a sheet from bytes.
The image is anchored to the cell specified in config.from_cell.
Dimensions are specified in pixels via config.width_px and
config.height_px.
Sourcepub fn delete_chart(&mut self, sheet: &str, cell: &str) -> Result<()>
pub fn delete_chart(&mut self, sheet: &str, cell: &str) -> Result<()>
Delete a chart anchored at the given cell.
Removes the drawing anchor, chart data, relationship entry, and content
type override for the chart at cell on sheet.
Sourcepub fn delete_picture(&mut self, sheet: &str, cell: &str) -> Result<()>
pub fn delete_picture(&mut self, sheet: &str, cell: &str) -> Result<()>
Delete a picture anchored at the given cell.
Removes the drawing anchor, image data, relationship entry, and content
type for the picture at cell on sheet. Searches both one-cell and
two-cell anchors.
Sourcepub fn get_pictures(&self, sheet: &str, cell: &str) -> Result<Vec<PictureInfo>>
pub fn get_pictures(&self, sheet: &str, cell: &str) -> Result<Vec<PictureInfo>>
Get all pictures anchored at the given cell.
Returns picture data, format, anchor cell, and dimensions for each picture found at the specified cell.
Source§impl Workbook
impl Workbook
Sourcepub fn add_data_validation(
&mut self,
sheet: &str,
config: &DataValidationConfig,
) -> Result<()>
pub fn add_data_validation( &mut self, sheet: &str, config: &DataValidationConfig, ) -> Result<()>
Add a data validation rule to a sheet.
Sourcepub fn get_data_validations(
&self,
sheet: &str,
) -> Result<Vec<DataValidationConfig>>
pub fn get_data_validations( &self, sheet: &str, ) -> Result<Vec<DataValidationConfig>>
Get all data validation rules for a sheet.
Sourcepub fn remove_data_validation(&mut self, sheet: &str, sqref: &str) -> Result<()>
pub fn remove_data_validation(&mut self, sheet: &str, sqref: &str) -> Result<()>
Remove a data validation rule matching the given cell range from a sheet.
Sourcepub fn set_conditional_format(
&mut self,
sheet: &str,
sqref: &str,
rules: &[ConditionalFormatRule],
) -> Result<()>
pub fn set_conditional_format( &mut self, sheet: &str, sqref: &str, rules: &[ConditionalFormatRule], ) -> Result<()>
Set conditional formatting rules on a cell range of a sheet.
Sourcepub fn get_conditional_formats(
&self,
sheet: &str,
) -> Result<Vec<(String, Vec<ConditionalFormatRule>)>>
pub fn get_conditional_formats( &self, sheet: &str, ) -> Result<Vec<(String, Vec<ConditionalFormatRule>)>>
Get all conditional formatting rules for a sheet.
Returns a list of (sqref, rules) pairs.
Sourcepub fn delete_conditional_format(
&mut self,
sheet: &str,
sqref: &str,
) -> Result<()>
pub fn delete_conditional_format( &mut self, sheet: &str, sqref: &str, ) -> Result<()>
Delete conditional formatting rules for a specific cell range on a sheet.
Sourcepub fn add_comment(&mut self, sheet: &str, config: &CommentConfig) -> Result<()>
pub fn add_comment(&mut self, sheet: &str, config: &CommentConfig) -> Result<()>
Add a comment to a cell on the given sheet.
A VML drawing part is generated automatically when saving so that the comment renders correctly in Excel.
Sourcepub fn get_comments(&self, sheet: &str) -> Result<Vec<CommentConfig>>
pub fn get_comments(&self, sheet: &str) -> Result<Vec<CommentConfig>>
Get all comments for a sheet.
Sourcepub fn remove_comment(&mut self, sheet: &str, cell: &str) -> Result<()>
pub fn remove_comment(&mut self, sheet: &str, cell: &str) -> Result<()>
Remove a comment from a cell on the given sheet.
When the last comment on a sheet is removed, the VML drawing part is cleaned up automatically during save.
Sourcepub fn add_threaded_comment(
&mut self,
sheet: &str,
cell: &str,
input: &ThreadedCommentInput,
) -> Result<String>
pub fn add_threaded_comment( &mut self, sheet: &str, cell: &str, input: &ThreadedCommentInput, ) -> Result<String>
Add a threaded comment to a cell on the given sheet.
Returns the generated comment ID. If the author does not exist in the person list, they are added automatically.
Sourcepub fn get_threaded_comments(
&self,
sheet: &str,
) -> Result<Vec<ThreadedCommentData>>
pub fn get_threaded_comments( &self, sheet: &str, ) -> Result<Vec<ThreadedCommentData>>
Get all threaded comments for a sheet.
Sourcepub fn get_threaded_comments_by_cell(
&self,
sheet: &str,
cell: &str,
) -> Result<Vec<ThreadedCommentData>>
pub fn get_threaded_comments_by_cell( &self, sheet: &str, cell: &str, ) -> Result<Vec<ThreadedCommentData>>
Get threaded comments for a specific cell on a sheet.
Sourcepub fn delete_threaded_comment(
&mut self,
sheet: &str,
comment_id: &str,
) -> Result<()>
pub fn delete_threaded_comment( &mut self, sheet: &str, comment_id: &str, ) -> Result<()>
Delete a threaded comment by its ID.
Returns an error if the comment was not found.
Sourcepub fn resolve_threaded_comment(
&mut self,
sheet: &str,
comment_id: &str,
done: bool,
) -> Result<()>
pub fn resolve_threaded_comment( &mut self, sheet: &str, comment_id: &str, done: bool, ) -> Result<()>
Set the resolved (done) state of a threaded comment.
Returns an error if the comment was not found.
Sourcepub fn add_person(&mut self, input: &PersonInput) -> String
pub fn add_person(&mut self, input: &PersonInput) -> String
Add a person to the person list. Returns the person ID. If a person with the same display name already exists, returns their ID.
Sourcepub fn get_persons(&self) -> Vec<PersonData>
pub fn get_persons(&self) -> Vec<PersonData>
Get all persons in the person list.
Sourcepub fn set_auto_filter(&mut self, sheet: &str, range: &str) -> Result<()>
pub fn set_auto_filter(&mut self, sheet: &str, range: &str) -> Result<()>
Set an auto-filter on a sheet for the given cell range.
Sourcepub fn remove_auto_filter(&mut self, sheet: &str) -> Result<()>
pub fn remove_auto_filter(&mut self, sheet: &str) -> Result<()>
Remove the auto-filter from a sheet.
Sourcepub fn add_table(&mut self, sheet: &str, config: &TableConfig) -> Result<()>
pub fn add_table(&mut self, sheet: &str, config: &TableConfig) -> Result<()>
Add a table to a sheet.
Creates the table XML part, adds the appropriate relationship and content type entries. The table name must be unique within the workbook.
Sourcepub fn get_tables(&self, sheet: &str) -> Result<Vec<TableInfo>>
pub fn get_tables(&self, sheet: &str) -> Result<Vec<TableInfo>>
List all tables on a sheet.
Returns metadata for each table associated with the given sheet.
Sourcepub fn delete_table(&mut self, sheet: &str, table_name: &str) -> Result<()>
pub fn delete_table(&mut self, sheet: &str, table_name: &str) -> Result<()>
Delete a table from a sheet by name.
Removes the table part, relationship, and content type entries.
Sourcepub fn set_panes(&mut self, sheet: &str, cell: &str) -> Result<()>
pub fn set_panes(&mut self, sheet: &str, cell: &str) -> Result<()>
Set freeze panes on a sheet.
The cell reference indicates the top-left cell of the scrollable area.
For example, "A2" freezes row 1, "B1" freezes column A, and "B2"
freezes both row 1 and column A.
Sourcepub fn unset_panes(&mut self, sheet: &str) -> Result<()>
pub fn unset_panes(&mut self, sheet: &str) -> Result<()>
Remove any freeze or split panes from a sheet.
Sourcepub fn get_panes(&self, sheet: &str) -> Result<Option<String>>
pub fn get_panes(&self, sheet: &str) -> Result<Option<String>>
Get the current freeze pane cell reference for a sheet, if any.
Returns the top-left cell of the unfrozen area (e.g., "A2" if row 1
is frozen), or None if no panes are configured.
Sourcepub fn set_page_margins(
&mut self,
sheet: &str,
margins: &PageMarginsConfig,
) -> Result<()>
pub fn set_page_margins( &mut self, sheet: &str, margins: &PageMarginsConfig, ) -> Result<()>
Set page margins on a sheet.
Sourcepub fn get_page_margins(&self, sheet: &str) -> Result<PageMarginsConfig>
pub fn get_page_margins(&self, sheet: &str) -> Result<PageMarginsConfig>
Get page margins for a sheet, returning Excel defaults if not set.
Sourcepub fn set_page_setup(
&mut self,
sheet: &str,
orientation: Option<Orientation>,
paper_size: Option<PaperSize>,
scale: Option<u32>,
fit_to_width: Option<u32>,
fit_to_height: Option<u32>,
) -> Result<()>
pub fn set_page_setup( &mut self, sheet: &str, orientation: Option<Orientation>, paper_size: Option<PaperSize>, scale: Option<u32>, fit_to_width: Option<u32>, fit_to_height: Option<u32>, ) -> Result<()>
Set page setup options (orientation, paper size, scale, fit-to-page).
Only non-None parameters are applied; existing values for None
parameters are preserved.
Sourcepub fn get_orientation(&self, sheet: &str) -> Result<Option<Orientation>>
pub fn get_orientation(&self, sheet: &str) -> Result<Option<Orientation>>
Get the page orientation for a sheet.
Sourcepub fn get_paper_size(&self, sheet: &str) -> Result<Option<PaperSize>>
pub fn get_paper_size(&self, sheet: &str) -> Result<Option<PaperSize>>
Get the paper size for a sheet.
Sourcepub fn get_page_setup_details(
&self,
sheet: &str,
) -> Result<(Option<u32>, Option<u32>, Option<u32>)>
pub fn get_page_setup_details( &self, sheet: &str, ) -> Result<(Option<u32>, Option<u32>, Option<u32>)>
Get scale, fit-to-width, and fit-to-height values for a sheet.
Returns (scale, fit_to_width, fit_to_height), each None if not set.
Set header and footer text for printing.
Get the header and footer text for a sheet.
Sourcepub fn set_print_options(
&mut self,
sheet: &str,
grid_lines: Option<bool>,
headings: Option<bool>,
h_centered: Option<bool>,
v_centered: Option<bool>,
) -> Result<()>
pub fn set_print_options( &mut self, sheet: &str, grid_lines: Option<bool>, headings: Option<bool>, h_centered: Option<bool>, v_centered: Option<bool>, ) -> Result<()>
Set print options on a sheet.
Sourcepub fn get_print_options(
&self,
sheet: &str,
) -> Result<(Option<bool>, Option<bool>, Option<bool>, Option<bool>)>
pub fn get_print_options( &self, sheet: &str, ) -> Result<(Option<bool>, Option<bool>, Option<bool>, Option<bool>)>
Get print options for a sheet.
Returns (grid_lines, headings, horizontal_centered, vertical_centered).
Sourcepub fn insert_page_break(&mut self, sheet: &str, row: u32) -> Result<()>
pub fn insert_page_break(&mut self, sheet: &str, row: u32) -> Result<()>
Insert a horizontal page break before the given 1-based row.
Sourcepub fn remove_page_break(&mut self, sheet: &str, row: u32) -> Result<()>
pub fn remove_page_break(&mut self, sheet: &str, row: u32) -> Result<()>
Remove a horizontal page break at the given 1-based row.
Sourcepub fn get_page_breaks(&self, sheet: &str) -> Result<Vec<u32>>
pub fn get_page_breaks(&self, sheet: &str) -> Result<Vec<u32>>
Get all row page break positions (1-based row numbers).
Sourcepub fn set_cell_hyperlink(
&mut self,
sheet: &str,
cell: &str,
link: HyperlinkType,
display: Option<&str>,
tooltip: Option<&str>,
) -> Result<()>
pub fn set_cell_hyperlink( &mut self, sheet: &str, cell: &str, link: HyperlinkType, display: Option<&str>, tooltip: Option<&str>, ) -> Result<()>
Set a hyperlink on a cell.
For external URLs and email links, a relationship entry is created in
the worksheet’s .rels file. Internal sheet references use only the
location attribute without a relationship.
Sourcepub fn get_cell_hyperlink(
&self,
sheet: &str,
cell: &str,
) -> Result<Option<HyperlinkInfo>>
pub fn get_cell_hyperlink( &self, sheet: &str, cell: &str, ) -> Result<Option<HyperlinkInfo>>
Get hyperlink information for a cell.
Returns None if the cell has no hyperlink.
Sourcepub fn delete_cell_hyperlink(&mut self, sheet: &str, cell: &str) -> Result<()>
pub fn delete_cell_hyperlink(&mut self, sheet: &str, cell: &str) -> Result<()>
Delete a hyperlink from a cell.
Removes both the hyperlink element from the worksheet XML and any associated relationship entry.
Sourcepub fn protect_workbook(&mut self, config: WorkbookProtectionConfig)
pub fn protect_workbook(&mut self, config: WorkbookProtectionConfig)
Protect the workbook structure and/or windows.
Sourcepub fn unprotect_workbook(&mut self)
pub fn unprotect_workbook(&mut self)
Remove workbook protection.
Sourcepub fn is_workbook_protected(&self) -> bool
pub fn is_workbook_protected(&self) -> bool
Check if the workbook is protected.
Sourcepub fn get_theme_color(&self, index: u32, tint: Option<f64>) -> Option<String>
pub fn get_theme_color(&self, index: u32, tint: Option<f64>) -> Option<String>
Resolve a theme color by index (0-11) with optional tint. Returns the ARGB hex string (e.g. “FF4472C4”) or None if the index is out of range.
Sourcepub fn set_defined_name(
&mut self,
name: &str,
value: &str,
scope: Option<&str>,
comment: Option<&str>,
) -> Result<()>
pub fn set_defined_name( &mut self, name: &str, value: &str, scope: Option<&str>, comment: Option<&str>, ) -> Result<()>
Add or update a defined name in the workbook.
If scope is None, the name is workbook-scoped (visible from all sheets).
If scope is Some(sheet_name), it is sheet-scoped using the sheet’s 0-based index.
If a name with the same name and scope already exists, its value and comment are updated.
Sourcepub fn get_defined_name(
&self,
name: &str,
scope: Option<&str>,
) -> Result<Option<DefinedNameInfo>>
pub fn get_defined_name( &self, name: &str, scope: Option<&str>, ) -> Result<Option<DefinedNameInfo>>
Get a defined name by name and scope.
If scope is None, looks for a workbook-scoped name.
If scope is Some(sheet_name), looks for a sheet-scoped name.
Returns None if no matching defined name is found.
Sourcepub fn get_all_defined_names(&self) -> Vec<DefinedNameInfo>
pub fn get_all_defined_names(&self) -> Vec<DefinedNameInfo>
List all defined names in the workbook.
Sourcepub fn delete_defined_name(
&mut self,
name: &str,
scope: Option<&str>,
) -> Result<()>
pub fn delete_defined_name( &mut self, name: &str, scope: Option<&str>, ) -> Result<()>
Delete a defined name by name and scope.
Returns an error if the name does not exist for the given scope.
Sourcepub fn protect_sheet(
&mut self,
sheet: &str,
config: &SheetProtectionConfig,
) -> Result<()>
pub fn protect_sheet( &mut self, sheet: &str, config: &SheetProtectionConfig, ) -> Result<()>
Protect a sheet with optional password and permission settings.
Delegates to crate::sheet::protect_sheet after looking up the sheet.
Sourcepub fn unprotect_sheet(&mut self, sheet: &str) -> Result<()>
pub fn unprotect_sheet(&mut self, sheet: &str) -> Result<()>
Remove sheet protection.
Sourcepub fn is_sheet_protected(&self, sheet: &str) -> Result<bool>
pub fn is_sheet_protected(&self, sheet: &str) -> Result<bool>
Check if a sheet is protected.
Sourcepub fn set_sheet_view_options(
&mut self,
sheet: &str,
opts: &SheetViewOptions,
) -> Result<()>
pub fn set_sheet_view_options( &mut self, sheet: &str, opts: &SheetViewOptions, ) -> Result<()>
Set sheet view display options (gridlines, formulas, zoom, view mode, etc.).
Only non-None fields in the options struct are applied.
Sourcepub fn get_sheet_view_options(&self, sheet: &str) -> Result<SheetViewOptions>
pub fn get_sheet_view_options(&self, sheet: &str) -> Result<SheetViewOptions>
Get the current sheet view display options.
Sourcepub fn set_sheet_visibility(
&mut self,
sheet: &str,
visibility: SheetVisibility,
) -> Result<()>
pub fn set_sheet_visibility( &mut self, sheet: &str, visibility: SheetVisibility, ) -> Result<()>
Set the visibility state of a sheet (Visible, Hidden, VeryHidden).
At least one sheet must remain visible. Returns an error if hiding this sheet would leave no visible sheets.
Sourcepub fn get_sheet_visibility(&self, sheet: &str) -> Result<SheetVisibility>
pub fn get_sheet_visibility(&self, sheet: &str) -> Result<SheetVisibility>
Get the visibility state of a sheet.
Sourcepub fn get_vba_project(&self) -> Option<&[u8]>
pub fn get_vba_project(&self) -> Option<&[u8]>
Get the raw VBA project binary (xl/vbaProject.bin), if present.
Returns None for standard .xlsx files (which have no VBA project).
Returns Some(bytes) for .xlsm files that contain a VBA project.
Sourcepub fn get_vba_modules(&self) -> Result<Option<VbaProject>>
pub fn get_vba_modules(&self) -> Result<Option<VbaProject>>
Extract VBA module source code from the workbook’s VBA project.
Parses the OLE/CFB container inside xl/vbaProject.bin, reads the
dir stream for module metadata, and decompresses each module’s
source code.
Returns Ok(None) if no VBA project is present.
Returns Ok(Some(project)) with the extracted modules and any warnings.
Returns Err if the VBA project exists but is corrupt or unreadable.
Sourcepub fn add_form_control(
&mut self,
sheet: &str,
config: FormControlConfig,
) -> Result<()>
pub fn add_form_control( &mut self, sheet: &str, config: FormControlConfig, ) -> Result<()>
Add a form control to a sheet.
The control is positioned at the cell specified in config.cell.
Supported control types: Button, CheckBox, OptionButton, SpinButton,
ScrollBar, GroupBox, Label.
Sourcepub fn get_form_controls(&mut self, sheet: &str) -> Result<Vec<FormControlInfo>>
pub fn get_form_controls(&mut self, sheet: &str) -> Result<Vec<FormControlInfo>>
Get all form controls on a sheet.
If the sheet has VML content from an opened file, form controls are hydrated from the VML first and then returned.
Sourcepub fn delete_form_control(&mut self, sheet: &str, index: usize) -> Result<()>
pub fn delete_form_control(&mut self, sheet: &str, index: usize) -> Result<()>
Delete a form control from a sheet by its 0-based index.
Sourcepub fn render_to_svg(&self, options: &RenderOptions) -> Result<String>
pub fn render_to_svg(&self, options: &RenderOptions) -> Result<String>
Render a worksheet to an SVG string.
Produces a visual representation of the sheet’s cells, styles, gridlines,
and headers. The options parameter controls which sheet, range, and
visual features to include.
Source§impl Workbook
impl Workbook
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty workbook containing a single empty sheet named “Sheet1”.
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open an existing .xlsx file from disk.
If the file is encrypted (CFB container), returns
Error::FileEncrypted. Use [Workbook::open_with_password] instead.
Sourcepub fn open_with_options<P: AsRef<Path>>(
path: P,
options: &OpenOptions,
) -> Result<Self>
pub fn open_with_options<P: AsRef<Path>>( path: P, options: &OpenOptions, ) -> Result<Self>
Open an existing .xlsx file with custom parsing options.
See OpenOptions for available options including row limits,
sheet filtering, and ZIP safety limits.
Sourcepub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
Save the workbook to a file at the given path.
The target format is inferred from the file extension. Supported
extensions are .xlsx, .xlsm, .xltx, .xltm, and .xlam.
An unsupported extension returns Error::UnsupportedFileExtension.
The inferred format overrides the workbook’s stored format so that the content type in the output always matches the extension.
Sourcepub fn save_to_buffer(&self) -> Result<Vec<u8>>
pub fn save_to_buffer(&self) -> Result<Vec<u8>>
Serialize the workbook to an in-memory buffer using the stored format.
Sourcepub fn open_from_buffer(data: &[u8]) -> Result<Self>
pub fn open_from_buffer(data: &[u8]) -> Result<Self>
Open a workbook from an in-memory .xlsx buffer.
Sourcepub fn open_from_buffer_with_options(
data: &[u8],
options: &OpenOptions,
) -> Result<Self>
pub fn open_from_buffer_with_options( data: &[u8], options: &OpenOptions, ) -> Result<Self>
Open a workbook from an in-memory buffer with custom parsing options.
Source§impl Workbook
impl Workbook
Sourcepub fn sheet_names(&self) -> Vec<&str>
pub fn sheet_names(&self) -> Vec<&str>
Return the names of all sheets in workbook order.
Sourcepub fn new_sheet(&mut self, name: &str) -> Result<usize>
pub fn new_sheet(&mut self, name: &str) -> Result<usize>
Create a new empty sheet with the given name. Returns the 0-based sheet index.
Sourcepub fn delete_sheet(&mut self, name: &str) -> Result<()>
pub fn delete_sheet(&mut self, name: &str) -> Result<()>
Delete a sheet by name.
Sourcepub fn copy_sheet(&mut self, source: &str, target: &str) -> Result<usize>
pub fn copy_sheet(&mut self, source: &str, target: &str) -> Result<usize>
Copy a sheet, returning the 0-based index of the new copy.
Sourcepub fn get_sheet_index(&self, name: &str) -> Option<usize>
pub fn get_sheet_index(&self, name: &str) -> Option<usize>
Get a sheet’s 0-based index by name. Returns None if not found.
Sourcepub fn get_active_sheet(&self) -> &str
pub fn get_active_sheet(&self) -> &str
Get the name of the active sheet.
Sourcepub fn set_active_sheet(&mut self, name: &str) -> Result<()>
pub fn set_active_sheet(&mut self, name: &str) -> Result<()>
Set the active sheet by name.
Sourcepub fn new_stream_writer(&self, sheet_name: &str) -> Result<StreamWriter>
pub fn new_stream_writer(&self, sheet_name: &str) -> Result<StreamWriter>
Create a StreamWriter for a new sheet.
The sheet will be added to the workbook when the StreamWriter is applied
via apply_stream_writer.
Sourcepub fn apply_stream_writer(&mut self, writer: StreamWriter) -> Result<usize>
pub fn apply_stream_writer(&mut self, writer: StreamWriter) -> Result<usize>
Apply a completed StreamWriter to the
workbook, adding it as a new sheet.
Returns the 0-based index of the new sheet.
Sourcepub fn insert_rows(
&mut self,
sheet: &str,
start_row: u32,
count: u32,
) -> Result<()>
pub fn insert_rows( &mut self, sheet: &str, start_row: u32, count: u32, ) -> Result<()>
Insert count empty rows starting at start_row in the named sheet.
Sourcepub fn remove_row(&mut self, sheet: &str, row: u32) -> Result<()>
pub fn remove_row(&mut self, sheet: &str, row: u32) -> Result<()>
Remove a single row from the named sheet, shifting rows below it up.
Sourcepub fn duplicate_row(&mut self, sheet: &str, row: u32) -> Result<()>
pub fn duplicate_row(&mut self, sheet: &str, row: u32) -> Result<()>
Duplicate a row, inserting the copy directly below.
Sourcepub fn set_row_height(
&mut self,
sheet: &str,
row: u32,
height: f64,
) -> Result<()>
pub fn set_row_height( &mut self, sheet: &str, row: u32, height: f64, ) -> Result<()>
Set the height of a row in points.
Sourcepub fn get_row_height(&self, sheet: &str, row: u32) -> Result<Option<f64>>
pub fn get_row_height(&self, sheet: &str, row: u32) -> Result<Option<f64>>
Get the height of a row.
Sourcepub fn set_row_visible(
&mut self,
sheet: &str,
row: u32,
visible: bool,
) -> Result<()>
pub fn set_row_visible( &mut self, sheet: &str, row: u32, visible: bool, ) -> Result<()>
Set the visibility of a row.
Sourcepub fn get_row_visible(&self, sheet: &str, row: u32) -> Result<bool>
pub fn get_row_visible(&self, sheet: &str, row: u32) -> Result<bool>
Get the visibility of a row. Returns true if visible (not hidden).
Sourcepub fn set_row_outline_level(
&mut self,
sheet: &str,
row: u32,
level: u8,
) -> Result<()>
pub fn set_row_outline_level( &mut self, sheet: &str, row: u32, level: u8, ) -> Result<()>
Set the outline level of a row.
Sourcepub fn get_row_outline_level(&self, sheet: &str, row: u32) -> Result<u8>
pub fn get_row_outline_level(&self, sheet: &str, row: u32) -> Result<u8>
Get the outline level of a row. Returns 0 if not set.
Sourcepub fn set_row_style(
&mut self,
sheet: &str,
row: u32,
style_id: u32,
) -> Result<()>
pub fn set_row_style( &mut self, sheet: &str, row: u32, style_id: u32, ) -> Result<()>
Set the style for an entire row.
The style_id must be a valid index in cellXfs (returned by add_style).
Sourcepub fn get_row_style(&self, sheet: &str, row: u32) -> Result<u32>
pub fn get_row_style(&self, sheet: &str, row: u32) -> Result<u32>
Get the style ID for a row. Returns 0 (default) if not set.
Sourcepub fn get_rows(&self, sheet: &str) -> Result<Vec<(u32, Vec<(u32, CellValue)>)>>
pub fn get_rows(&self, sheet: &str) -> Result<Vec<(u32, Vec<(u32, CellValue)>)>>
Get all rows with their data from a sheet.
Returns a Vec of (row_number, Vec<(column_number, CellValue)>) tuples.
Column numbers are 1-based (A=1, B=2, …). Only rows that contain at
least one cell are included (sparse).
Sourcepub fn get_cols(
&self,
sheet: &str,
) -> Result<Vec<(String, Vec<(u32, CellValue)>)>>
pub fn get_cols( &self, sheet: &str, ) -> Result<Vec<(String, Vec<(u32, CellValue)>)>>
Get all columns with their data from a sheet.
Returns a Vec of (column_name, Vec<(row_number, CellValue)>) tuples.
Only columns that have data are included (sparse).
Sourcepub fn set_col_width(
&mut self,
sheet: &str,
col: &str,
width: f64,
) -> Result<()>
pub fn set_col_width( &mut self, sheet: &str, col: &str, width: f64, ) -> Result<()>
Set the width of a column.
Sourcepub fn get_col_width(&self, sheet: &str, col: &str) -> Result<Option<f64>>
pub fn get_col_width(&self, sheet: &str, col: &str) -> Result<Option<f64>>
Get the width of a column.
Sourcepub fn set_col_visible(
&mut self,
sheet: &str,
col: &str,
visible: bool,
) -> Result<()>
pub fn set_col_visible( &mut self, sheet: &str, col: &str, visible: bool, ) -> Result<()>
Set the visibility of a column.
Sourcepub fn get_col_visible(&self, sheet: &str, col: &str) -> Result<bool>
pub fn get_col_visible(&self, sheet: &str, col: &str) -> Result<bool>
Get the visibility of a column. Returns true if visible (not hidden).
Sourcepub fn set_col_outline_level(
&mut self,
sheet: &str,
col: &str,
level: u8,
) -> Result<()>
pub fn set_col_outline_level( &mut self, sheet: &str, col: &str, level: u8, ) -> Result<()>
Set the outline level of a column.
Sourcepub fn get_col_outline_level(&self, sheet: &str, col: &str) -> Result<u8>
pub fn get_col_outline_level(&self, sheet: &str, col: &str) -> Result<u8>
Get the outline level of a column. Returns 0 if not set.
Sourcepub fn set_col_style(
&mut self,
sheet: &str,
col: &str,
style_id: u32,
) -> Result<()>
pub fn set_col_style( &mut self, sheet: &str, col: &str, style_id: u32, ) -> Result<()>
Set the style for an entire column.
The style_id must be a valid index in cellXfs (returned by add_style).
Sourcepub fn get_col_style(&self, sheet: &str, col: &str) -> Result<u32>
pub fn get_col_style(&self, sheet: &str, col: &str) -> Result<u32>
Get the style ID for a column. Returns 0 (default) if not set.
Source§impl Workbook
impl Workbook
Sourcepub fn format(&self) -> WorkbookFormat
pub fn format(&self) -> WorkbookFormat
Return the detected or assigned workbook format.
Sourcepub fn set_format(&mut self, format: WorkbookFormat)
pub fn set_format(&mut self, format: WorkbookFormat)
Set the workbook format. This determines the content type written for
xl/workbook.xml on save.
Sourcepub fn worksheet_xml_ref(&self, sheet: &str) -> Result<&WorksheetXml>
pub fn worksheet_xml_ref(&self, sheet: &str) -> Result<&WorksheetXml>
Public immutable reference to a worksheet’s XML by sheet name.
Sourcepub fn sst_ref(&self) -> &SharedStringTable
pub fn sst_ref(&self) -> &SharedStringTable
Public immutable reference to the shared string table.