1. Products
  2.   Spreadsheet
  3.   Rust
  4.   excelize-rs

excelize-rs

 
 

Open Source Rust Library for Excel Spreadsheets

Read, Write & Manipulate Microsoft Excel™ (XLSX, XLSM, XLTX, XLTM, XLAM) Files via Pure Rust API.

What is excelize-rs?

excelize-rs is a pure Rust library for reading and writing Microsoft Excel™ spreadsheet documents (XLSX, XLSM, XLTX, XLTM, XLAM) without requiring external dependencies or system libraries. It is a direct port of the popular Go Excelize library, designed for high performance and memory safety in Rust applications. The library fully complies with ECMA-376 Standard Part 1, ensuring compatibility with Excel 2007 and later versions. Developers can use it to generate reports, process data, and automate Excel workflows directly in Rust.

With excelize-rs, you can programmatically create complex spreadsheets featuring formulas, charts, styles, images, and pivot tables—all from safe, idiomatic Rust code. It supports reading cell values, manipulating rows/columns, merging cells, applying conditional formatting, and filtering data. The API is intuitive and well-documented, with comprehensive examples and a growing ecosystem of helper crates. Whether you're building CLI tools, web services, or desktop apps, excelize-rs provides a reliable, cross-platform solution for Excel file handling in Rust.

Previous Next

Getting Started with excelize-rs

To begin using excelize-rs, add it to your Cargo.toml via `cargo add excelize`. The latest version is available on Crates.io and the source code is hosted on GitHub. The library requires Rust 1.60 or higher and has no external system dependencies. Once installed, you can start reading or writing Excel files with just a few lines of code. Its zero-dependency design ensures fast compilation and deployment across environments.

Install excelize-rs via Cargo

cargo add excelize

Read Excel Files with Cell Value Access

excelize-rs provides a straightforward API to open Excel workbooks and retrieve cell values by sheet name and coordinates. It supports automatic type inference for numbers, strings, booleans, and dates, returning them as native Rust types. The library handles shared strings, formulas, and formatting metadata transparently, allowing developers to focus on data extraction. With its ergonomic error handling, you can use standard Rust `match` or `?` operators to manage failures gracefully. This makes it ideal for data pipelines, reporting tools, and migration utilities.

How to Read a Cell Value from an Excel File via Rust?

use excelize::*;

fn main() {
    let path = String::from("Book1.xlsx");
    let wb = Spreadsheet::open_file(path).unwrap();
    match wb.get_cell_value("Sheet1", 1, 1) {
        Ok(c) => println!("Cell A1 value: {}", String::from(c)),
        Err(e) => println!("Error: {:?}", e),
    }
}

Write Formulas, Styles & Charts

excelize-rs enables full-featured spreadsheet creation, including formulas, cell styling, and embedded charts. You can set cell values, apply number formats, fonts, borders, and fill patterns programmatically. The library supports complex formulas with relative/absolute references, array formulas, and named ranges. Charts—including bar, line, pie, and scatter—can be generated and inserted into worksheets with customizable axes, legends, and data series. Pivot tables are also supported for dynamic data analysis. All operations are performed in-memory, ensuring high performance and thread safety in concurrent applications.

How to Write a Formula and Apply Style to a Cell via Rust?

use excelize::*;

fn main() {
    let mut wb = Spreadsheet::new();
    wb.set_cell_value("Sheet1", "A1", &Value::String(String::from("Total")));
    wb.set_cell_value("Sheet1", "A2", &Value::Float(100.0));
    wb.set_cell_value("Sheet1", "A3", &Value::Float(200.0));
    wb.set_cell_formula("A4", "SUM(A2:A3)");
    wb.set_default_style("A4", &Style::new().set_font_bold(true));
    wb.save("output.xlsx").unwrap();
}

Merge, Split & Manipulate Sheets

excelize-rs offers powerful sheet manipulation capabilities, including merging multiple workbooks into one, splitting a workbook into separate files, and copying sheets between workbooks. You can insert, delete, rename, or reorder worksheets programmatically. The library supports hidden and very-hidden sheets, as well as sheet protection and password encryption. With methods like `copy_sheet` and `duplicate_sheet`, you can clone templates efficiently. This makes it ideal for report generation, data consolidation, and workbook automation workflows where dynamic sheet management is required.

How to Merge Two Excel Files into One Workbook via Rust?

use excelize::*;

fn main() {
    let mut wb1 = Spreadsheet::open_file("file1.xlsx").unwrap();
    let wb2 = Spreadsheet::open_file("file2.xlsx").unwrap();
    
    // Copy all sheets from wb2 to wb1
    for sheet in wb2.get_sheet_list() {
        let new_name = format!("{}_copied", sheet);
        wb1.copy_sheet(&sheet, &new_name).unwrap();
    }
    wb1.save("merged.xlsx").unwrap();
}

Data Filtering & Conditional Formatting

excelize-rs supports advanced data presentation features like AutoFilter, conditional formatting rules, and data validation. You can apply filters to cell ranges to hide rows based on criteria, sort data, and highlight top/bottom values or date ranges. Conditional formatting supports color scales, icon sets, and custom formula-based rules. Data validation ensures user input conforms to defined constraints (e.g., numeric ranges, dropdowns, date limits). These features are essential for building interactive dashboards, audit tools, and user-facing reporting applications where data clarity and integrity are critical.

How to Apply AutoFilter to a Data Range via Rust?

use excelize::*;

fn main() {
    let mut wb = Spreadsheet::new();
    // Add sample data
    wb.set_cell_value("Sheet1", "A1", &Value::String(String::from("Name")));
    wb.set_cell_value("Sheet1", "B1", &Value::String(String::from("Score")));
    wb.set_cell_value("Sheet1", "A2", &Value::String(String::from("Alice")));
    wb.set_cell_value("Sheet1", "B2", &Value::Float(95.0));
    wb.set_cell_value("Sheet1", "A3", &Value::String(String::from("Bob")));
    wb.set_cell_value("Sheet1", "B3", &Value::Float(88.0));
    
    // Apply filter to range A1:B3
    wb.set_auto_filter("Sheet1", "A1:B3", &String::from("")).unwrap();
    wb.save("filtered.xlsx").unwrap();
}