calamine 0.36.1: header rows load differently per format, and tests/ never ships
A pure Rust Excel/OpenDocument SpreadSheets file reader: rust on metal sheets
At a glance
- What is it?
- calamine is a pure Rust spreadsheet reader for the Excel family and OpenDocument formats, MIT licensed and pinned to Rust 1.88 by its zip dependency. It excludes tests/ from the published package, keeps the archive layer on deflate alone, and offers three optional features of which one is a deprecated synonym.
- Who is it for?
- calamine suits a Rust program that has to read a spreadsheet someone else produced and hand the values to serde, because the deserializer path, the header row handling and the type coercion helpers cover the parts of that job that are tedious rather than the parts that are interesting. Three things are worth checking before you commit to it.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 11 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- tafia/calamine2,476 ★ · +37
| Repository | 2026-09-30 | 2026-11-25 |
|---|---|---|
| tafia/calamine | 2.4k | 2.5k |
37 Stars in the last 56 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
A header row takes effect during the read on xlsx and xlsb, and after it on xls and ods
Header handling is the one place where calamine's behaviour depends on the file format rather than on the API, and the difference comes from when the sheets get loaded. For `xlsx` and `xlsb` files, lazy loading means specifying a header row takes effect immediately when a sheet range is read. For `xls` and `ods`, all sheets are loaded at once when the workbook is opened with default settings, so setting the header row only applies afterward and provides no performance benefit.
The API is the same in both cases, which is what makes the difference easy to miss. You call `with_header_row` on the reader and then ask for the range:
use calamine::{HeaderRow, Reader, Xlsx, open_workbook};
let mut excel: Xlsx<_> = open_workbook("file.xlsx").unwrap();
let sheet1 = excel
.with_header_row(HeaderRow::Row(3))
.worksheet_range("Sheet1")
.unwrap();`HeaderRow::Row(3)` names the third row as the header. The order of the two calls matters for the lazy formats, since the reader has to know about the header before the range is materialised. On the eagerly loaded formats the same sequence still works, but the sheet data is already in memory by then, which is exactly why the text says there is nothing to gain.
If the file type is not known when the code is compiled, `open_workbook_auto` takes a path and picks the reader, and `DataType` is what the more involved example imports alongside it. For a program that reads whatever a user drops into a folder, that is the entry point, and the format-dependent header behaviour above applies to whichever reader it selects.
One helper discards invalid cells, its sibling returns them as strings
Spreadsheets are typed by convention rather than by schema, so a column meant to hold floats can contain text. calamine exposes two helpers for that case and they differ in what happens to the bad values. `deserialize_as_f64_or_none` discards all invalid values. `deserialize_as_f64_or_string` is the similar function that returns them as `String`s instead. Both plug into serde through its `deserialize_with` field attribute, so the choice is made per field:
use calamine::{deserialize_as_f64_or_none, open_workbook, RangeDeserializerBuilder, Reader, Xlsx};
use serde::Deserialize;
#[derive(Deserialize)]
struct Record {
metric: String,
#[serde(deserialize_with = "deserialize_as_f64_or_none")]
value: Option<f64>,
}The example struct pairs a `String` label with an `Option<f64>`, which is the shape you would write when a missing number is acceptable but a wrong type should not abort the run. The example also shows how a missing sheet is turned into calamine's own error type, mapping the worksheet lookup failure onto `calamine::Error::Msg("Cannot find Sheet1")` instead of letting a generic error escape.
That combination, a typed record plus a per field coercion, is what the examples directory is built around. There are separate files for a fallible deserializer, a flattened one, one that skips headers, one that deserializes a range, one that seeds values, one that builds a struct, one that converts a workbook to CSV, and one that searches for errors. Two of them cover capabilities the visible documentation does not describe at all: reading hyperlinks and streaming formulas from xlsx.
Nothing in the text available here states how many rows the deserializer reads before it stops, or whether a bad cell aborts the iterator, so the fallible example is the place to look for that behaviour rather than the overview.
The archive layer is configured for deflate, and the Rust floor is set by a dependency
An xlsx file is a zip archive, so the compression configuration in the manifest decides what calamine can open. The `zip` dependency is declared as version 8.6 with `default-features = false` and a single feature, `deflate`. Every other compression method the crate could negotiate is switched off, which makes the dependency list smaller at the cost of restricting what an archive may contain. The XML side is `quick-xml` 0.42 with its `encoding` feature, paired with `encoding_rs` 0.8, and `codepage` 0.1 sits alongside it for the legacy code pages that binary Excel formats still use.
The rest of the dependency list explains what each format needs. `atoi_simd` 0.18 and `fast-float2` 0.2 are numeric parsers, which matters for a reader whose job is to turn text cells into numbers. `byteorder` 1.5 is there for the binary formats, `xlsb` among them. `log` 0.4 is the only logging facade, and `serde` 1.0 is a hard dependency rather than an optional one, which is why the deserializer examples need no feature flag.
One line in the manifest is worth reading on its own: `rust-version = "1.88"` carries the comment `For zip`. The minimum supported Rust version is therefore set by a transitive dependency rather than by the code in this repository. Edition 2021 is declared, and the crate is excluded from its own published package with `exclude = ["tests/**/*"]`.
Three optional features, one of them deprecated, and docs.rs enables two of them
The feature set starts empty. `[features] default = []` means a plain `cargo add calamine` gives you the reader with no extras, and the three switches are opt in. `chrono` adds support for Chrono date and time types to the API and is wired to the optional dependency with `chrono = ["dep:chrono"]`, where the dependency itself is declared with its `serde` feature and its own default features disabled. `picture` adds support for reading raw data for pictures in spreadsheets and pulls in no crate at all, since `picture = []` is an empty list.
The third is `dates`, described as a deprecated backwards compatible synonym for `chrono` and defined as `dates = ["chrono"]`. It exists so that a manifest written against an older release keeps resolving, and it carries the deprecation in its description rather than in any runtime behaviour. Two features can be enabled from the command line:
cargo add calamine -F chronoTurning a feature on changes what compiles, not only what runs. The `read_picture_data` example declares `required-features = ["picture"]`, so without the flag cargo skips that example instead of building it, and `deserialize_struct.rs` and `deserialize_seed.rs` sit in the same directory with no such requirement.
The documentation build takes a different set. The `docs.rs` metadata block enables `chrono` and `picture` together and passes `--cfg docsrs` as a rustdoc argument, which means the API reference you read on docs.rs documents a wider surface than a default build compiles, and a signature that mentions a Chrono type will not appear in your own rustdoc unless you enable the same feature.
The comparison prints four programs and the measurements are not in the text
The performance section compares calamine with three libraries written in three other languages, `excelize` in Go, `ClosedXML` in C#, and `openpyxl` in Python, and the comparison is deliberately narrow. Since calamine is readonly, the programs only open an xlsx file and iterate over the rows, so nothing here measures writing. The dataset is a sample of New York 311 service requests for 2010 to 2020, distributed as a 7z archive, which converts to a 186MB xlsx file once the csv form is produced.
The measurement method is stated as precisely as the file size: plotting data comes from the `sysinfo` crate, sampled at a 200ms interval, and the program samples the reported values for the running process and records them. Sampling a running process at that interval means the plotted lines are memory and CPU over wall clock time, not throughput figures, so the comparison is about how quickly each reader reaches a steady state on one large file rather than about requests per second.
What the text available here does not contain is the result. Each language gets the same program printed in full, and the `ClosedXML` listing stops partway through a `private static void Main(string[] args)` declaration before the code fence ends. No table of numbers and no plotted image appears in the section, so a reader cannot check the outcome from the text alone, and the choice of three libraries is stated without a criterion for choosing them.
The first example reads a tests/ file that the published crate does not ship
The serde example opens its workbook with `format!("{}/tests/temperature.xlsx", env!("CARGO_MANIFEST_DIR"))`. In the repository that path exists, and the crate excludes `tests/**/*` from its published package, so the fixture is not in what a dependent downloads. In someone else's project `CARGO_MANIFEST_DIR` resolves to their crate root, which means the path points at a tests directory that has nothing to do with calamine. The opening lines therefore describe a shape rather than a program that runs as written, and the second example swaps the fixture for `tests/excel.xlsx` with the same construction.
The same file also shows what a complete call sequence looks like: `open_workbook(path)` into an `Xlsx` reader, `worksheet_range("Sheet1")` into a range, and `RangeDeserializerBuilder::new().from_range(&range)?` into an iterator whose first item is destructured as a `(String, f64)` pair. The version in the repository asserts that the label is `celsius` and that the value is 22.2222, which is the sort of expectation a fixture pins.
The repository keeps what the package drops. Alongside `src/` there is `benches/` with a `basic` benchmark declared under `harness = false` for criterion, a `fuzz/` directory for fuzzing, and `tests/` for the integration tests, with `rstest` 0.26 for parameterised cases, `glob`, `sha2` and `env_logger` as development dependencies. A `.typos.toml` sits at the root next to `Changelog.md` and `LICENSE-MIT.md`, so spelling and release history are checked in the repository rather than left to review.
Editorial conclusion
calamine suits a Rust program that has to read a spreadsheet someone else produced and hand the values to serde, because the deserializer path, the header row handling and the type coercion helpers cover the parts of that job that are tedious rather than the parts that are interesting. Three things are worth checking before you commit to it. The header row semantics differ by format: on xls and ods the sheets are already loaded when the workbook opens, so the header row applies afterward and buys no speed, while xlsx and xlsb read lazily and apply it during the range read. The archive layer enables only deflate, so a file compressed with something else is outside what the manifest configures. And the crate sets its own floor at Rust 1.88 for the zip crate's sake, which will end a build on an older toolchain regardless of your own code. The examples also assume a tests directory that the published package excludes, so treat the snippets as shapes to adapt rather than programs to paste.
Frequently asked questions
Which spreadsheet formats can calamine read?
The Excel family formats xls, xlsx, xlsm, xlsb, xla and xlam, plus OpenDocument spreadsheets in ods. The manifest keywords name excel, ods, xls, xlsx and xlsb, and the library is described as working as long as files are simple enough.
How do I add calamine to a Rust project?
The documented command is cargo add calamine, and an optional feature is enabled with cargo add calamine -F chrono. The crate declares an empty default feature set, so nothing extra is compiled unless you ask for it.
Which optional features does calamine have?
Three, all off by default: chrono adds Chrono date and time types to the API, picture adds reading of raw picture data, and dates is a deprecated backwards compatible synonym for chrono. The docs.rs build enables chrono and picture.
How does calamine handle a column with invalid numbers?
The deserialize_as_f64_or_none helper discards all invalid values, while the similar deserialize_as_f64_or_string returns them as strings. Both are used through serde's deserialize_with field attribute on a field typed as Option<f64>.
Which Rust version does calamine require?
The manifest sets rust-version to 1.88, with a comment tying that floor to the zip dependency, and declares edition 2021. The zip dependency itself is version 8.6 with default features disabled and only the deflate feature enabled.
Does header row handling differ between file formats in calamine?
Yes. xlsx and xlsb files support lazy loading, so specifying a header row takes effect immediately when reading a sheet range. For xls and ods all sheets are loaded at once when the workbook is opened, so the header row only applies afterward and brings no performance benefit.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/tafia-calamine)Star history chart for your README
[](https://hysenlabs.com/projects/tafia-calamine)Was this useful?