A Rust crate for manipulating and parsing to and from A1 notation. A1 notation is what you
typically see in spreadsheets where the first cell (at (0, 0)
) is referred to as cell A1
where
A
represents the first column (0
) and 1
represents the first row.
You can parse an A1-notation value using the FromStr
trait:
``` use a1notation::A1; let a1 = A1::fromstr("A1").unwrap();
asserteq!(a1.x(), Some(0)); asserteq!(a1.y(), Some(0)); ```
Or if you have absolute coordinates and want to build A1 notation, you can use the builder functions:
``` // Cell A1 let a1absolute = A1::builder() .xy(0, 0) .sheetname("Important_stuff") .build() .unwrap();
asserteq!(a1absolute.tostring(), "Importantstuff!A1");
// Column A let a1_relative = A1::builder().x(0).build().unwrap();
asserteq!(a1relative.to_string(), "A:A");
// Range A:D let a1_range = A1::builder() .range() .from(A1::builder().x(0).build().unwrap()) .to(A1::builder().x(3).build().unwrap()) .build() .unwrap();
asserteq!(a1range.to_string(), "A:D"); ```
Here is a table illustrating A1 references:
| Reference | Meaning |
|:------------------|:--------------------------|
| "A1"
| Cell A1 |
| "A1:B5"
| Cells A1 through B5 |
| "C5:D9,G9:H16"
| A multiple-area selection |
| "A:A"
| Column A |
| "1:1"
| Row 1 |
| "A:C"
| Columns A through C |
| "1:5"
| Rows 1 through 5 |
| "1:1,3:3,8:8"
| Rows 1, 3, and 8 |
| "A:A,C:C,F:F"
| Columns A, C, and F |
For more info take a look at the Rust docs.