For parsing XLSX files in Rust, the most recommended and widely used library is calamine. It is a pure Rust library designed to read and deserialize various spreadsheet formats including .xlsx, .xls, .xlsb, and even OpenDocument spreadsheets (.ods). Calamine is read-only but supports reading cell values efficiently and can handle large files with lazy loading for .xlsx and .xlsb formats. It is considered fast and reliable for reading Excel files in Rust[4].
Key Features of Calamine:
- Supports multiple Excel formats:
.xls, .xlsx, .xlsm, .xlsb, .xla, .xlam.
- Supports OpenDocument spreadsheets (
.ods).
- Lazy loading for
.xlsx and .xlsb files.
- Simple API to open workbooks and iterate over rows.
- Can specify header rows for easier data handling.
- Focused on reading cell values and VBA code; no support for writing Excel files.
- MIT licensed and actively maintained.
Basic Usage Example:
use calamine::{Reader, Xlsx, open_workbook};
fn main() {
let mut excel: Xlsx<_> = open_workbook("file.xlsx").unwrap();
if let Some(Ok(range)) = excel.worksheet_range("Sheet1") {
for row in range.rows() {
println!("{:?}", row);
}
}
}
Other Options and Related Tools:
- rust_xlsxwriter: A Rust library focused on writing Excel
.xlsx files, supporting text, numbers, dates, formulas, charts, formatting, and more. It does not support reading Excel files but is excellent for creating and writing Excel files from Rust[6].
- Polars with Calamine: The Polars data frame library in Rust does not have a native Excel reader but can use Calamine as an external engine to read Excel files into data frames. This is useful if you want to process Excel data with Polars[1][3][7].
Summary Table
| Library | Functionality | Supported Formats | Read/Write | Notes |
|---|
| calamine | Read Excel files | .xls, .xlsx, .xlsb, .ods | Read-only | Fast, pure Rust, widely used |
| rust_xlsxwriter | Write Excel files | .xlsx | Write-only | Full Excel writing support, no reading |
| Polars + Calamine | Read Excel into DataFrame | .xlsx, .xlsb, .xls | Read-only | Use Calamine as engine for Excel reading |
Recommendation
- Use calamine for reading
.xlsx files in Rust.
- Use rust_xlsxwriter if you need to write
.xlsx files.
- For data analysis workflows, consider combining Calamine with Polars for efficient Excel data processing.
This combination covers most needs for Excel file handling in Rust, with calamine being the go-to parser for XLSX files[1][3][4][6][7].