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.
Key Features
Section titled βKey Featuresβ- Effortless Initialization: Initializing a new Excel workbook is simplified with the
Excelclass/struct. Developers can swiftly create new workbooks or open existing ones, setting the stage for easy data management. - 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.
- 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.
- Data Import and Export: The
Excelclass/struct supports seamless data import from external sources and export to various formats. This enables efficient integration with external data sets and applications.
Workbook Methods
Section titled βWorkbook Methodsβ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.
| Rust | C# | Go | Function |
|---|---|---|---|
Excel::new(path, 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 |
Basic Code Samples
Section titled βBasic Code Samplesβ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 namefile.add_sheet_mut(Some("Test".to_string())).expect("Failed to add Sheet");// Add Sheet with default namefile.add_sheet_mut(None).expect("Failed to add Sheet");// Save the result filefile.save_as("./output.xlsx").expect("File Save Failed");using draviavemal.openxml_office.spreadsheet_2007;
Excel excel = new Excel();using Worksheet worksheet = excel.AddSheet("Test");excel.SaveAs("./output.xlsx");import "draviavemal_openxml_office/spreadsheet/spreadsheet_2007"
excel, err := spreadsheet_2007.NewExcel()if err != nil {panic(err)}worksheet, err := excel.AddSheet("Test")if err != nil {panic(err)}if err := worksheet.Flush(); err != nil {panic(err)}if err := excel.SaveAs("./output.xlsx"); err != nil {panic(err)}Not yet available.
Not yet available.
Not yet available.
ExcelProperties Options
Section titled βExcelProperties Optionsβ| Rust | C# | Type | Details |
|---|---|---|---|
is_editable | isEditable | bool | Open the source file in editable mode when a path is supplied |