a1col
Spreadsheet A1 references for Python: column letters, cells, ranges, whole rows and columns, sheet names with correct quoting, and R1C1 conversion. Typed, frozen, dependency free.
Install
pip install a1col
Usage
from a1col import column_to_index, index_to_column
column_to_index("A") # 1
column_to_index("AA") # 27
column_to_index("aa") # 27, letters are case-insensitive
column_to_index("$C") # 3, a leading absolute marker is allowed
index_to_column(28) # "AB"
index_to_column(27) # "AA"
Zero-based variants carry the base in their name:
from a1col import column_to_index0, index0_to_column
column_to_index0("A") # 0
index0_to_column(26) # "AA"
Cells, ranges and sheets
from a1col import CellRef, RangeRef, parse_ref
cell = CellRef.parse("'Q1 Sales'!$B3")
cell.column, cell.row # (2, 3)
cell.sheet # "Q1 Sales"
str(cell.offset(rows=1, columns=1)) # "'Q1 Sales'!$C4"
str(cell.translate(rows=1, columns=1)) # "'Q1 Sales'!$B4", like copying a formula
rng = RangeRef.parse("A1:C3")
rng.width, rng.height, rng.size # (3, 3, 9)
CellRef.parse("B2") in rng # True
str(rng.intersection(RangeRef.parse("B2:D4"))) # "B2:C3"
[str(c) for c in RangeRef.parse("A1:B2")] # ["A1", "B1", "A2", "B2"]
parse_ref("A:C") # ColumnSpan(first=1, last=3, ...)
parse_ref("1:3") # RowSpan(first=1, last=3, ...)
R1C1 and application limits
from a1col import EXCEL, EXCEL_97, CellRef, a1_to_r1c1, r1c1_to_a1
a1_to_r1c1("B3", "A1") # "R[2]C[1]"
r1c1_to_a1("R[-1]C[2]", "C3") # "E2"
r1c1_to_a1("R5C3") # "$C$5"
a1_to_r1c1("A:C") # "C1:C3"
CellRef.parse("XFD1048576", limits=EXCEL) # fine, the last Excel cell
CellRef.parse("IW1", limits=EXCEL_97) # raises OutOfBoundsError
Presets: EXCEL (16,384 columns to XFD, 1,048,576 rows), EXCEL_97 (256 by
65,536), LIBREOFFICE (Calc 7.4 and later, same grid as Excel) and GOOGLE_SHEETS
(18,278 columns to ZZZ). Without limits any positive size is accepted.
Errors
Every error is a ValueError subclass of A1Error: InvalidReferenceError (with
InvalidColumnError and InvalidRowError below it) for bad text, and
OutOfBoundsError for numbers below one or past the chosen limits. A wrong argument
type (for example a float where an index is expected) raises TypeError.
Command line
$ a1col column AA
27
$ a1col parse "'My Sheet'!A1:C3"
kind: range
a1: 'My Sheet'!A1:C3
sheet: My Sheet
columns: 1..3
rows: 1..3
size: 3 rows x 3 columns = 9 cells
$ a1col cells --by-row A1:B2
A1 B1
A2 B2
$ a1col r1c1 B3 --anchor A1
R[2]C[1]
$ a1col offset B2 --rows 3 --columns -1
A5
a1col --help lists every command with examples. Results go to stdout; errors go
to stderr with exit code 1.
See GUIDE.md for every concept and edge case.
Why
Spreadsheet column letters count in base 26 with no zero, so Z is followed by
AA, not BA. References add absolute markers, sheet names with their own quoting
rules, and a second notation (R1C1) that is relative to the cell holding the
formula. The standard library has no primitive for any of it, and reaching for a
full workbook library just to read 'Q1'!$A$1:C3 pulls in a large dependency. This
package does only that, with no dependencies.
License
MIT. See LICENSE.
Links
- Website: https://lianes8studio.com
- GitHub: https://github.com/JaviLianes8
- LinkedIn: https://www.linkedin.com/in/jlianes/
Metadata
Release files for a1col 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| a1col-0.2.0.tar.gz | 35.0 kB | Without provenance | Details for a1col-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| a1col-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for a1col-0.2.0-py3-none-any.whl |
Total release size: 60.4 kB
Release files / a1col-0.2.0.tar.gz
| Download URL | a1col-0.2.0.tar.gz |
|---|---|
| Size | 35.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8d0b5fbfa6e7de61bf0a790bb7e01dbb64be91760beb35a960bc7dbba82edad
|
|
BLAKE2b-256 checksum How to use checksums |
3ca8bfeb80edf04ceb1924c706c885d447952012521bd75e85a5a57e58f024da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / a1col-0.2.0-py3-none-any.whl
| Download URL | a1col-0.2.0-py3-none-any.whl |
|---|---|
| Size | 25.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c2d7a0f58dd18939c4b73135e29736eecc8529239bbd381aec58e522783d030
|
|
BLAKE2b-256 checksum How to use checksums |
0e8e7b14dd52e1629e7212a35b3a2a864bf7b1a005503f715ef4c3eb7e2c26e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Security for a1col 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.