Skip to content

This content is for v4.x version. Switch to the Stable version.

Excel

The Excel class/struct, an integral part of the library, facilitates seamless interaction with Excel workbooks. Designed to simplify the creation and manipulation of Excel (.xlsx) files, this class/struct provides a user-friendly interface for developers to efficiently handle data, worksheets, and formatting.

  1. Effortless Initialization: Initializing a new Excel workbook is simplified with the Excel class/struct. Developers can swiftly create new workbooks or open existing ones, setting the stage for easy data management.
  2. Worksheet Manipulation: The class/struct offers intuitive methods for adding, deleting, and manipulating worksheets within a workbook. Developers can efficiently organize data and structure it across multiple sheets.
  3. Cell-Level Operations: Granular control over individual cells is provided, allowing developers to set values, apply formatting, and perform various operations on specific cells within a worksheet.
  4. Data Import and Export: The Excel class/struct supports seamless data import from external sources and export to various formats. This enables efficient integration with external data sets and applications.

The table below lists the workbook-level methods that are currently available and covered by the language test suites. Method names follow each language’s own naming convention.

RustC#GoFunction
Excel::new(path, props)

new Excel() / new Excel(props)

NewExcel()Create a new workbook or open an existing file
add_sheet_mut(name)AddSheet(name)AddSheet(name)Add a worksheet (optional name)
get_worksheet_mut(name)β€”β€”Get an existing worksheet by name
rename_sheet_name_mut(old, new)RenameSheet(old, new)β€”Rename an existing worksheet
set_active_sheet_mut(name)β€”β€”Set the active worksheet
hide_sheet_mut(name)β€”β€”Hide a worksheet
minimize_workbook_mut(bool)β€”β€”Minimize the workbook ribbon
set_visibility_mut(bool)β€”β€”Set workbook window visibility
hide_horizontal_scroll_mut(bool)β€”β€”Show/hide horizontal scrollbar
hide_vertical_scroll_mut(bool)β€”β€”Show/hide vertical scrollbar
hide_sheet_tabs_mut(bool)β€”β€”Show/hide worksheet tabs
get_style_id_mut(setting)GetStyleId(setting)

β€”

Register a cell style and get its id (see Style)

save_as(path)SaveAs(path)SaveAs(path)Save the workbook to a file
use draviavemal_openxml_office::spreadsheet_2007::{Excel, ExcelPropertiesModel};
// Create a new workbook (pass Some(path) to open an existing file)
let mut file = Excel::new(None, ExcelPropertiesModel::default())
.expect("File Created Failed");
// Add Sheet with custom name
file.add_sheet_mut(Some("Test".to_string()))
.expect("Failed to add Sheet");
// Add Sheet with default name
file.add_sheet_mut(None)
.expect("Failed to add Sheet");
// Save the result file
file.save_as("./output.xlsx")
.expect("File Save Failed");
RustC#TypeDetails
is_editableisEditableboolOpen the source file in editable mode when a path is supplied