# spreadsheet-column
[](#contributors-)
[](https://crates.io/crates/spreadsheet-column)
[](https://docs.rs/spreadsheet-column)
[](https://github.com/trananhtung/spreadsheet-column/actions/workflows/ci.yml)
[](#license)
**Convert between spreadsheet column numbers and letters** — `1` ↔ `A`, `26` ↔ `Z`, `27` ↔
`AA` (the bijective base-26 used by Excel, Google Sheets, …).
A faithful Rust port of the
[`spreadsheet-column`](https://www.npmjs.com/package/spreadsheet-column) npm package.
- **Zero dependencies**, **`#![no_std]`**
- One-based (default) or zero-based columns
- Differential-tested against the reference `spreadsheet-column` implementation (60k cases)
## Install
```toml
[dependencies]
spreadsheet-column = "0.1"
```
## Usage
```rust
use spreadsheet_column::{from_int, from_str, SpreadsheetColumn};
assert_eq!(from_int(27).unwrap(), "AA");
assert_eq!(from_str("AA").unwrap(), 27);
assert_eq!(from_int(16384).unwrap(), "XFD"); // Excel's last column
// Zero-based columns:
let sc = SpreadsheetColumn::zero_based();
assert_eq!(sc.from_int(0).unwrap(), "A");
assert_eq!(sc.from_str("AA").unwrap(), 26);
```
In one-based mode, `from_int(0)` is an error (the smallest column is `1`); negative numbers
and non-letter strings are errors in both modes.
## Contributors ✨
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the [emoji key](https://allcontributors.org/docs/en/emoji-key) for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/trananhtung"><img src="https://avatars.githubusercontent.com/u/30992229?v=4?s=100" width="100px;" alt="Tung Tran"/><br /><sub><b>Tung Tran</b></sub></a><br /><a href="https://github.com/trananhtung/./commits?author=trananhtung" title="Code">💻</a> <a href="#maintenance-trananhtung" title="Maintenance">🚧</a></td>
</tr>
</tbody>
</table>
## License
Licensed under either of [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE) at your option.